ic-websocket-js
Version:
IC WebSocket on the Internet Computer
34 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isGatewayHandshakeMessage = exports.isClientIncomingMessage = void 0;
const principal_1 = require("@dfinity/principal");
const isClientIncomingMessage = (arg) => {
return (arg instanceof Object &&
typeof arg.key === "string" &&
arg.content instanceof Uint8Array &&
arg.cert instanceof Uint8Array &&
arg.tree instanceof Uint8Array);
};
exports.isClientIncomingMessage = isClientIncomingMessage;
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_1.Principal.from(arg);
}
catch (e) {
console.error("isPrincipal", e);
return false;
}
return true;
};
const isGatewayHandshakeMessage = (arg) => {
return (arg instanceof Object &&
isPrincipal(arg.gateway_principal));
};
exports.isGatewayHandshakeMessage = isGatewayHandshakeMessage;
//# sourceMappingURL=types.js.map