Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libkernel

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libkernel - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

51

dist/messages.js

@@ -1,4 +0,39 @@

// TODO: Need to write the nonce framework.
// Establish a system for matching messages to the kernel with responses from
// the kernel.
var nextNonce = 0;
var queries = new Object();
// handleMessage will handle a message from the kernel, using the reponse to
// resolve the appropriate promise in the set of queries.
function handleMessage(event) {
// Check the message source.
if (event.source !== window) {
return;
}
// Check that this message is a kernelResponse.
if (!("data" in event) || !("method" in event.data)) {
return;
}
if (event.data.method !== "kernelResponse") {
return;
}
// Check that we have a promise for the provided nonce.
if (!(event.data.nonce in queries)) {
console.log("received message with missing nonce\n", event, "\n", queries);
return;
}
// Either resolve or reject the promise associated with this response.
if (event.data.resp !== null) {
let resolve = queries[event.data.nonce].resolve;
resolve(event.data.resp);
}
else if (event.data.resp !== null) {
let reject = queries[event.data.nonce].reject;
reject(event.data.err);
}
else {
console.log("received malformed response from bridge\n", event.data);
}
delete queries[event.data.nonce];
console.log("got message from bridge\n", event, "\n", event.data);
}
// init will add an event listener for messages from the kernel bridge.

@@ -9,11 +44,3 @@ //

export function init() {
window.addEventListener("message", function (event) {
if (!("data" in event) || !("method" in event.data)) {
return;
}
if (event.data.method !== "kernelResponse") {
return;
}
console.log("got message from bridge\n", event, "\n", event.data);
});
window.addEventListener("message", handleMessage);
}

@@ -27,6 +54,6 @@ // kernelRequestTest will send a message to the bridge asking for a kernel

export function testMessage() {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
let nonce = nextNonce;
nextNonce++;
queries[nonce] = resolve;
queries[nonce] = { resolve, reject };
window.postMessage({

@@ -33,0 +60,0 @@ method: "kernelMessage",

{
"name": "libkernel",
"version": "0.0.4",
"version": "0.0.5",
"description": "helper library to interact with the skynet kernel",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc