@zkpassport/sdk 0.5.6 → 0.5.7-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +0,0 @@
1
- import type { JsonRpcRequest, JsonRpcResponse } from "@zkpassport/utils";
2
- import { WebSocketClient } from "./websocket";
3
- export declare function createJsonRpcRequest(method: string, params: any): JsonRpcRequest;
4
- export declare function createEncryptedJsonRpcRequest(method: string, params: any, sharedSecret: Uint8Array, topic: string): Promise<JsonRpcRequest>;
5
- export declare function sendEncryptedJsonRpcRequest(method: string, params: any, sharedSecret: Uint8Array, topic: string, wsClient: WebSocketClient): Promise<boolean>;
6
- export declare function createJsonRpcResponse(id: string, result: any): JsonRpcResponse;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createJsonRpcRequest = createJsonRpcRequest;
4
- exports.createEncryptedJsonRpcRequest = createEncryptedJsonRpcRequest;
5
- exports.sendEncryptedJsonRpcRequest = sendEncryptedJsonRpcRequest;
6
- exports.createJsonRpcResponse = createJsonRpcResponse;
7
- const crypto_1 = require("crypto");
8
- const encryption_1 = require("./encryption");
9
- const logger_1 = require("./logger");
10
- function createJsonRpcRequest(method, params) {
11
- return {
12
- jsonrpc: "2.0",
13
- id: (0, crypto_1.randomBytes)(16).toString("hex"),
14
- method,
15
- params,
16
- };
17
- }
18
- async function createEncryptedJsonRpcRequest(method, params, sharedSecret, topic) {
19
- const encryptedMessage = await (0, encryption_1.encrypt)(JSON.stringify({ method, params: params || {} }), sharedSecret, topic);
20
- return createJsonRpcRequest("encryptedMessage", {
21
- payload: Buffer.from(encryptedMessage).toString("base64"),
22
- });
23
- }
24
- async function sendEncryptedJsonRpcRequest(method, params, sharedSecret, topic, wsClient) {
25
- try {
26
- const message = { method, params: params || {} };
27
- const encryptedMessage = await (0, encryption_1.encrypt)(JSON.stringify(message), sharedSecret, topic);
28
- const request = createJsonRpcRequest("encryptedMessage", {
29
- payload: Buffer.from(encryptedMessage).toString("base64"),
30
- });
31
- logger_1.noLogger.debug("Sending encrypted message (original):", message);
32
- logger_1.noLogger.debug("Sending encrypted message (encrypted):", request);
33
- wsClient.send(JSON.stringify(request));
34
- return true;
35
- }
36
- catch (error) {
37
- logger_1.noLogger.error("Error sending encrypted message:", error);
38
- return false;
39
- }
40
- }
41
- function createJsonRpcResponse(id, result) {
42
- return {
43
- jsonrpc: "2.0",
44
- id,
45
- result,
46
- };
47
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noLogger = exports.customLogger = void 0;
4
- exports.customLogger = {
5
- debug: (message, ...args) => console.debug(message, ...args),
6
- info: (message, ...args) => console.info(message, ...args),
7
- warn: (message, ...args) => console.warn(message, ...args),
8
- error: (message, ...args) => console.error(message, ...args),
9
- };
10
- exports.noLogger = {
11
- debug: (..._) => { },
12
- info: (..._) => { },
13
- warn: (..._) => { },
14
- error: (..._) => { },
15
- };
@@ -1,39 +0,0 @@
1
- export declare class ZkPassportProver {
2
- private domain?;
3
- private topicToKeyPair;
4
- private topicToWebSocketClient;
5
- private topicToRemoteDomainVerified;
6
- private topicToSharedSecret;
7
- private topicToRemotePublicKey;
8
- private onDomainVerifiedCallbacks;
9
- private onBridgeConnectCallbacks;
10
- private onWebsiteDomainVerifyFailureCallbacks;
11
- constructor();
12
- /**
13
- * @notice Handle an encrypted message.
14
- * @param request The request.
15
- * @param outerRequest The outer request.
16
- */
17
- private handleEncryptedMessage;
18
- /**
19
- * @notice Scan a credentirequest QR code.
20
- * @returns
21
- */
22
- scan(url: string, { keyPairOverride, }?: {
23
- keyPairOverride?: {
24
- privateKey: Uint8Array;
25
- publicKey: Uint8Array;
26
- };
27
- }): Promise<{
28
- domain: string;
29
- requestId: string;
30
- isBridgeConnected: () => boolean;
31
- isDomainVerified: () => boolean;
32
- onDomainVerified: (callback: () => void) => number;
33
- onBridgeConnect: (callback: () => void) => number;
34
- notifyReject: () => Promise<void>;
35
- notifyAccept: () => Promise<void>;
36
- notifyDone: (proof: any) => Promise<void>;
37
- notifyError: (error: string) => Promise<void>;
38
- }>;
39
- }
@@ -1,130 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZkPassportProver = void 0;
4
- const utils_1 = require("@noble/ciphers/utils");
5
- const websocket_1 = require("./websocket");
6
- const json_rpc_1 = require("./json-rpc");
7
- const encryption_1 = require("./encryption");
8
- const logger_1 = require("./logger");
9
- class ZkPassportProver {
10
- constructor() {
11
- this.topicToKeyPair = {};
12
- this.topicToWebSocketClient = {};
13
- this.topicToRemoteDomainVerified = {};
14
- this.topicToSharedSecret = {};
15
- this.topicToRemotePublicKey = {};
16
- this.onDomainVerifiedCallbacks = {};
17
- this.onBridgeConnectCallbacks = {};
18
- this.onWebsiteDomainVerifyFailureCallbacks = {};
19
- }
20
- /**
21
- * @notice Handle an encrypted message.
22
- * @param request The request.
23
- * @param outerRequest The outer request.
24
- */
25
- async handleEncryptedMessage(topic, request, outerRequest) {
26
- logger_1.noLogger.debug("Received encrypted message:", request);
27
- if (request.method === "hello") {
28
- logger_1.noLogger.info(`Successfully verified origin domain name: ${outerRequest.origin}`);
29
- this.topicToRemoteDomainVerified[topic] = true;
30
- await Promise.all(this.onDomainVerifiedCallbacks[topic].map((callback) => callback()));
31
- }
32
- else if (request.method === "closed_page") {
33
- // TODO: Implement
34
- }
35
- }
36
- /**
37
- * @notice Scan a credentirequest QR code.
38
- * @returns
39
- */
40
- async scan(url, { keyPairOverride, } = {}) {
41
- const parsedUrl = new URL(url);
42
- const domain = parsedUrl.searchParams.get("d");
43
- const topic = parsedUrl.searchParams.get("t");
44
- const pubkeyHex = parsedUrl.searchParams.get("p");
45
- if (!domain || !topic || !pubkeyHex) {
46
- throw new Error("Invalid URL: missing required parameters");
47
- }
48
- const pubkey = new Uint8Array(Buffer.from(pubkeyHex, "hex"));
49
- this.domain = domain;
50
- const keyPair = keyPairOverride || (await (0, encryption_1.generateECDHKeyPair)());
51
- this.topicToKeyPair[topic] = {
52
- privateKey: keyPair.privateKey,
53
- publicKey: keyPair.publicKey,
54
- };
55
- this.topicToRemotePublicKey[topic] = pubkey;
56
- this.topicToSharedSecret[topic] = await (0, encryption_1.getSharedSecret)((0, utils_1.bytesToHex)(keyPair.privateKey), (0, utils_1.bytesToHex)(pubkey));
57
- this.topicToRemoteDomainVerified[topic] = false;
58
- this.onDomainVerifiedCallbacks[topic] = [];
59
- this.onBridgeConnectCallbacks[topic] = [];
60
- // Set up WebSocket connection
61
- const wsClient = (0, websocket_1.getWebSocketClient)(`wss://bridge.zkpassport.id?topic=${topic}&pubkey=${(0, utils_1.bytesToHex)(keyPair.publicKey)}`);
62
- this.topicToWebSocketClient[topic] = wsClient;
63
- wsClient.onopen = async () => {
64
- logger_1.noLogger.info("[mobile] WebSocket connection established");
65
- await Promise.all(this.onBridgeConnectCallbacks[topic].map((callback) => callback()));
66
- // Server sends handshake automatically (when it sees a pubkey in websocket URI)
67
- // wsClient.send(
68
- // JSON.stringify(
69
- // createJsonRpcRequest('handshake', {
70
- // pubkey: bytesToHex(keyPair.publicKey),
71
- // }),
72
- // ),
73
- // )
74
- };
75
- wsClient.addEventListener("message", async (event) => {
76
- logger_1.noLogger.info("[mobile] Received message:", event.data);
77
- try {
78
- const data = JSON.parse(event.data);
79
- const originDomain = data.origin ? new URL(data.origin).hostname : undefined;
80
- // Origin domain must match domain in QR code
81
- if (originDomain !== this.domain) {
82
- logger_1.noLogger.warn(`[mobile] Origin does not match domain in QR code. Expected ${this.domain} but got ${originDomain}`);
83
- return;
84
- }
85
- if (data.method === "encryptedMessage") {
86
- // Decode the payload from base64 to Uint8Array
87
- const payload = new Uint8Array(atob(data.params.payload)
88
- .split("")
89
- .map((c) => c.charCodeAt(0)));
90
- try {
91
- // Decrypt the payload using the shared secret
92
- const decrypted = await (0, encryption_1.decrypt)(payload, this.topicToSharedSecret[topic], topic);
93
- const decryptedJson = JSON.parse(decrypted);
94
- await this.handleEncryptedMessage(topic, decryptedJson, data);
95
- }
96
- catch (error) {
97
- logger_1.noLogger.error("[mobile] Error decrypting message:", error);
98
- }
99
- }
100
- }
101
- catch (error) {
102
- logger_1.noLogger.error("[mobile] Error:", error);
103
- }
104
- });
105
- wsClient.onerror = (error) => {
106
- logger_1.noLogger.error("[mobile] WebSocket error:", error);
107
- };
108
- return {
109
- domain: this.domain,
110
- requestId: topic,
111
- isBridgeConnected: () => this.topicToWebSocketClient[topic].readyState === WebSocket.OPEN,
112
- isDomainVerified: () => this.topicToRemoteDomainVerified[topic] === true,
113
- onDomainVerified: (callback) => this.onDomainVerifiedCallbacks[topic].push(callback),
114
- onBridgeConnect: (callback) => this.onBridgeConnectCallbacks[topic].push(callback),
115
- notifyReject: async () => {
116
- await (0, json_rpc_1.sendEncryptedJsonRpcRequest)("reject", null, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
117
- },
118
- notifyAccept: async () => {
119
- await (0, json_rpc_1.sendEncryptedJsonRpcRequest)("accept", null, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
120
- },
121
- notifyDone: async (proof) => {
122
- await (0, json_rpc_1.sendEncryptedJsonRpcRequest)("done", { proof }, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
123
- },
124
- notifyError: async (error) => {
125
- await (0, json_rpc_1.sendEncryptedJsonRpcRequest)("error", { error }, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
126
- },
127
- };
128
- }
129
- }
130
- exports.ZkPassportProver = ZkPassportProver;
@@ -1,2 +0,0 @@
1
- export declare function getWebSocketClient(url: string, origin?: string): WebSocket | import("ws").WebSocket;
2
- export type WebSocketClient = ReturnType<typeof getWebSocketClient>;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWebSocketClient = getWebSocketClient;
4
- function getWebSocketClient(url, origin) {
5
- if (typeof window !== "undefined" && window.WebSocket) {
6
- // Browser environment
7
- return new WebSocket(url);
8
- }
9
- else {
10
- // Node.js environment
11
- const WebSocket = require("ws");
12
- return new WebSocket(url, {
13
- headers: {
14
- Origin: origin || "nodejs",
15
- },
16
- });
17
- }
18
- }
@@ -1,7 +0,0 @@
1
- export declare function generateECDHKeyPair(): Promise<{
2
- privateKey: import("@noble/secp256k1").Bytes;
3
- publicKey: import("@noble/secp256k1").Bytes;
4
- }>;
5
- export declare function getSharedSecret(privateKey: string, publicKey: string): Promise<Uint8Array<ArrayBuffer>>;
6
- export declare function encrypt(message: string, sharedSecret: Uint8Array, topic: string): Promise<Uint8Array<ArrayBufferLike>>;
7
- export declare function decrypt(ciphertext: Uint8Array, sharedSecret: Uint8Array, topic: string): Promise<string>;
@@ -1,40 +0,0 @@
1
- import { gcm } from "@noble/ciphers/aes";
2
- import { utf8ToBytes } from "@noble/ciphers/utils";
3
- async function sha256Truncate(topic) {
4
- const encoder = new TextEncoder();
5
- const data = encoder.encode(topic);
6
- const hashBuffer = await crypto.subtle.digest("SHA-256", data);
7
- const fullHashArray = new Uint8Array(hashBuffer);
8
- const truncatedHashArray = fullHashArray.slice(0, 12);
9
- return truncatedHashArray;
10
- }
11
- export async function generateECDHKeyPair() {
12
- const secp256k1 = await import("@noble/secp256k1");
13
- const privKey = secp256k1.utils.randomPrivateKey();
14
- const pubKey = secp256k1.getPublicKey(privKey);
15
- return {
16
- privateKey: privKey,
17
- publicKey: pubKey,
18
- };
19
- }
20
- export async function getSharedSecret(privateKey, publicKey) {
21
- const secp256k1 = await import("@noble/secp256k1");
22
- const sharedSecret = secp256k1.getSharedSecret(privateKey, publicKey);
23
- return sharedSecret.slice(0, 32);
24
- }
25
- export async function encrypt(message, sharedSecret, topic) {
26
- // Nonce must be 12 bytes
27
- const nonce = await sha256Truncate(topic);
28
- const aes = gcm(sharedSecret, nonce);
29
- const data = utf8ToBytes(message);
30
- const ciphertext = aes.encrypt(data);
31
- return ciphertext;
32
- }
33
- export async function decrypt(ciphertext, sharedSecret, topic) {
34
- // Nonce must be 12 bytes
35
- const nonce = await sha256Truncate(topic);
36
- const aes = gcm(sharedSecret, nonce);
37
- const data = aes.decrypt(ciphertext);
38
- const dataString = new TextDecoder().decode(data);
39
- return dataString;
40
- }
@@ -1,6 +0,0 @@
1
- import type { JsonRpcRequest, JsonRpcResponse } from "@zkpassport/utils";
2
- import { WebSocketClient } from "./websocket";
3
- export declare function createJsonRpcRequest(method: string, params: any): JsonRpcRequest;
4
- export declare function createEncryptedJsonRpcRequest(method: string, params: any, sharedSecret: Uint8Array, topic: string): Promise<JsonRpcRequest>;
5
- export declare function sendEncryptedJsonRpcRequest(method: string, params: any, sharedSecret: Uint8Array, topic: string, wsClient: WebSocketClient): Promise<boolean>;
6
- export declare function createJsonRpcResponse(id: string, result: any): JsonRpcResponse;
@@ -1,41 +0,0 @@
1
- import { randomBytes } from "crypto";
2
- import { encrypt } from "./encryption";
3
- import { noLogger as logger } from "./logger";
4
- export function createJsonRpcRequest(method, params) {
5
- return {
6
- jsonrpc: "2.0",
7
- id: randomBytes(16).toString("hex"),
8
- method,
9
- params,
10
- };
11
- }
12
- export async function createEncryptedJsonRpcRequest(method, params, sharedSecret, topic) {
13
- const encryptedMessage = await encrypt(JSON.stringify({ method, params: params || {} }), sharedSecret, topic);
14
- return createJsonRpcRequest("encryptedMessage", {
15
- payload: Buffer.from(encryptedMessage).toString("base64"),
16
- });
17
- }
18
- export async function sendEncryptedJsonRpcRequest(method, params, sharedSecret, topic, wsClient) {
19
- try {
20
- const message = { method, params: params || {} };
21
- const encryptedMessage = await encrypt(JSON.stringify(message), sharedSecret, topic);
22
- const request = createJsonRpcRequest("encryptedMessage", {
23
- payload: Buffer.from(encryptedMessage).toString("base64"),
24
- });
25
- logger.debug("Sending encrypted message (original):", message);
26
- logger.debug("Sending encrypted message (encrypted):", request);
27
- wsClient.send(JSON.stringify(request));
28
- return true;
29
- }
30
- catch (error) {
31
- logger.error("Error sending encrypted message:", error);
32
- return false;
33
- }
34
- }
35
- export function createJsonRpcResponse(id, result) {
36
- return {
37
- jsonrpc: "2.0",
38
- id,
39
- result,
40
- };
41
- }
@@ -1,39 +0,0 @@
1
- export declare class ZkPassportProver {
2
- private domain?;
3
- private topicToKeyPair;
4
- private topicToWebSocketClient;
5
- private topicToRemoteDomainVerified;
6
- private topicToSharedSecret;
7
- private topicToRemotePublicKey;
8
- private onDomainVerifiedCallbacks;
9
- private onBridgeConnectCallbacks;
10
- private onWebsiteDomainVerifyFailureCallbacks;
11
- constructor();
12
- /**
13
- * @notice Handle an encrypted message.
14
- * @param request The request.
15
- * @param outerRequest The outer request.
16
- */
17
- private handleEncryptedMessage;
18
- /**
19
- * @notice Scan a credentirequest QR code.
20
- * @returns
21
- */
22
- scan(url: string, { keyPairOverride, }?: {
23
- keyPairOverride?: {
24
- privateKey: Uint8Array;
25
- publicKey: Uint8Array;
26
- };
27
- }): Promise<{
28
- domain: string;
29
- requestId: string;
30
- isBridgeConnected: () => boolean;
31
- isDomainVerified: () => boolean;
32
- onDomainVerified: (callback: () => void) => number;
33
- onBridgeConnect: (callback: () => void) => number;
34
- notifyReject: () => Promise<void>;
35
- notifyAccept: () => Promise<void>;
36
- notifyDone: (proof: any) => Promise<void>;
37
- notifyError: (error: string) => Promise<void>;
38
- }>;
39
- }
@@ -1,126 +0,0 @@
1
- import { bytesToHex } from "@noble/ciphers/utils";
2
- import { getWebSocketClient } from "./websocket";
3
- import { sendEncryptedJsonRpcRequest } from "./json-rpc";
4
- import { decrypt, generateECDHKeyPair, getSharedSecret } from "./encryption";
5
- import { noLogger as logger } from "./logger";
6
- export class ZkPassportProver {
7
- constructor() {
8
- this.topicToKeyPair = {};
9
- this.topicToWebSocketClient = {};
10
- this.topicToRemoteDomainVerified = {};
11
- this.topicToSharedSecret = {};
12
- this.topicToRemotePublicKey = {};
13
- this.onDomainVerifiedCallbacks = {};
14
- this.onBridgeConnectCallbacks = {};
15
- this.onWebsiteDomainVerifyFailureCallbacks = {};
16
- }
17
- /**
18
- * @notice Handle an encrypted message.
19
- * @param request The request.
20
- * @param outerRequest The outer request.
21
- */
22
- async handleEncryptedMessage(topic, request, outerRequest) {
23
- logger.debug("Received encrypted message:", request);
24
- if (request.method === "hello") {
25
- logger.info(`Successfully verified origin domain name: ${outerRequest.origin}`);
26
- this.topicToRemoteDomainVerified[topic] = true;
27
- await Promise.all(this.onDomainVerifiedCallbacks[topic].map((callback) => callback()));
28
- }
29
- else if (request.method === "closed_page") {
30
- // TODO: Implement
31
- }
32
- }
33
- /**
34
- * @notice Scan a credentirequest QR code.
35
- * @returns
36
- */
37
- async scan(url, { keyPairOverride, } = {}) {
38
- const parsedUrl = new URL(url);
39
- const domain = parsedUrl.searchParams.get("d");
40
- const topic = parsedUrl.searchParams.get("t");
41
- const pubkeyHex = parsedUrl.searchParams.get("p");
42
- if (!domain || !topic || !pubkeyHex) {
43
- throw new Error("Invalid URL: missing required parameters");
44
- }
45
- const pubkey = new Uint8Array(Buffer.from(pubkeyHex, "hex"));
46
- this.domain = domain;
47
- const keyPair = keyPairOverride || (await generateECDHKeyPair());
48
- this.topicToKeyPair[topic] = {
49
- privateKey: keyPair.privateKey,
50
- publicKey: keyPair.publicKey,
51
- };
52
- this.topicToRemotePublicKey[topic] = pubkey;
53
- this.topicToSharedSecret[topic] = await getSharedSecret(bytesToHex(keyPair.privateKey), bytesToHex(pubkey));
54
- this.topicToRemoteDomainVerified[topic] = false;
55
- this.onDomainVerifiedCallbacks[topic] = [];
56
- this.onBridgeConnectCallbacks[topic] = [];
57
- // Set up WebSocket connection
58
- const wsClient = getWebSocketClient(`wss://bridge.zkpassport.id?topic=${topic}&pubkey=${bytesToHex(keyPair.publicKey)}`);
59
- this.topicToWebSocketClient[topic] = wsClient;
60
- wsClient.onopen = async () => {
61
- logger.info("[mobile] WebSocket connection established");
62
- await Promise.all(this.onBridgeConnectCallbacks[topic].map((callback) => callback()));
63
- // Server sends handshake automatically (when it sees a pubkey in websocket URI)
64
- // wsClient.send(
65
- // JSON.stringify(
66
- // createJsonRpcRequest('handshake', {
67
- // pubkey: bytesToHex(keyPair.publicKey),
68
- // }),
69
- // ),
70
- // )
71
- };
72
- wsClient.addEventListener("message", async (event) => {
73
- logger.info("[mobile] Received message:", event.data);
74
- try {
75
- const data = JSON.parse(event.data);
76
- const originDomain = data.origin ? new URL(data.origin).hostname : undefined;
77
- // Origin domain must match domain in QR code
78
- if (originDomain !== this.domain) {
79
- logger.warn(`[mobile] Origin does not match domain in QR code. Expected ${this.domain} but got ${originDomain}`);
80
- return;
81
- }
82
- if (data.method === "encryptedMessage") {
83
- // Decode the payload from base64 to Uint8Array
84
- const payload = new Uint8Array(atob(data.params.payload)
85
- .split("")
86
- .map((c) => c.charCodeAt(0)));
87
- try {
88
- // Decrypt the payload using the shared secret
89
- const decrypted = await decrypt(payload, this.topicToSharedSecret[topic], topic);
90
- const decryptedJson = JSON.parse(decrypted);
91
- await this.handleEncryptedMessage(topic, decryptedJson, data);
92
- }
93
- catch (error) {
94
- logger.error("[mobile] Error decrypting message:", error);
95
- }
96
- }
97
- }
98
- catch (error) {
99
- logger.error("[mobile] Error:", error);
100
- }
101
- });
102
- wsClient.onerror = (error) => {
103
- logger.error("[mobile] WebSocket error:", error);
104
- };
105
- return {
106
- domain: this.domain,
107
- requestId: topic,
108
- isBridgeConnected: () => this.topicToWebSocketClient[topic].readyState === WebSocket.OPEN,
109
- isDomainVerified: () => this.topicToRemoteDomainVerified[topic] === true,
110
- onDomainVerified: (callback) => this.onDomainVerifiedCallbacks[topic].push(callback),
111
- onBridgeConnect: (callback) => this.onBridgeConnectCallbacks[topic].push(callback),
112
- notifyReject: async () => {
113
- await sendEncryptedJsonRpcRequest("reject", null, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
114
- },
115
- notifyAccept: async () => {
116
- await sendEncryptedJsonRpcRequest("accept", null, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
117
- },
118
- notifyDone: async (proof) => {
119
- await sendEncryptedJsonRpcRequest("done", { proof }, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
120
- },
121
- notifyError: async (error) => {
122
- await sendEncryptedJsonRpcRequest("error", { error }, this.topicToSharedSecret[topic], topic, this.topicToWebSocketClient[topic]);
123
- },
124
- };
125
- }
126
- }
@@ -1,2 +0,0 @@
1
- export declare function getWebSocketClient(url: string, origin?: string): WebSocket | import("ws").WebSocket;
2
- export type WebSocketClient = ReturnType<typeof getWebSocketClient>;
@@ -1,15 +0,0 @@
1
- export function getWebSocketClient(url, origin) {
2
- if (typeof window !== "undefined" && window.WebSocket) {
3
- // Browser environment
4
- return new WebSocket(url);
5
- }
6
- else {
7
- // Node.js environment
8
- const WebSocket = require("ws");
9
- return new WebSocket(url, {
10
- headers: {
11
- Origin: origin || "nodejs",
12
- },
13
- });
14
- }
15
- }