UNPKG

ic-websocket-js

Version:
29 lines 991 B
import { Principal } from "@dfinity/principal"; export const isClientIncomingMessage = (arg) => { return (arg instanceof Object && typeof arg.key === "string" && arg.content instanceof Uint8Array && arg.cert instanceof Uint8Array && arg.tree instanceof Uint8Array); }; const isPrincipal = (arg) => { // the Principal.from method doesn't throw if the argument is a string, // but in our case it must already be a Principal instance // see https://github.com/dfinity/agent-js/blob/349598672c50d738100d123a43f5d1c8fac77854/packages/principal/src/index.ts#L39-L53 if (typeof arg === "string") { return false; } try { Principal.from(arg); } catch (e) { console.error("isPrincipal", e); return false; } return true; }; export const isGatewayHandshakeMessage = (arg) => { return (arg instanceof Object && isPrincipal(arg.gateway_principal)); }; //# sourceMappingURL=types.js.map