libkernel
Advanced tools
Comparing version 0.1.16 to 0.1.17
import { log, logErr } from "./log.js"; | ||
import { bufToB64, encodeU64 } from "libskynet"; | ||
// Create the queryMap singleton. | ||
// Create the queryMap. | ||
let queries = {}; | ||
@@ -43,4 +43,5 @@ // Define the nonce handling. nonceSeed is 16 random bytes that get generated | ||
function handleMessage(event) { | ||
// Ignore all messages that aren't from approved kernel sources. The | ||
// two approved sources are skt.us and | ||
// Ignore all messages that aren't from approved kernel sources. The two | ||
// approved sources are skt.us and the browser extension bridge (which has | ||
// an event.source equal to 'window') | ||
if (event.source !== window && event.origin !== "https://skt.us") { | ||
@@ -75,11 +76,10 @@ return; | ||
if (initResolved === true) { | ||
console.error("kernel sent an auth status message, but init is already finished"); | ||
console.log("kernel sent an auth status message, but init is already finished"); | ||
return; | ||
} | ||
initResolved = true; | ||
if (event.data.data.userAuthorized) { | ||
initResolved = true; | ||
initResolve(null); | ||
} | ||
else { | ||
initResolved = true; | ||
initResolve("user is not logged in"); | ||
@@ -115,6 +115,5 @@ } | ||
// If no update handler was provided, there is nothing to do. | ||
if (typeof query.receiveUpdate !== "function") { | ||
return; | ||
if (typeof query.receiveUpdate === "function") { | ||
query.receiveUpdate(event.data.data); | ||
} | ||
query.receiveUpdate(event.data.data); | ||
return; | ||
@@ -124,5 +123,4 @@ } | ||
if (event.data.method === "responseNonce") { | ||
let knr = queries[event.data.nonce].kernelNonceReceived; | ||
if (typeof knr === "function") { | ||
knr(event.data.data.nonce); | ||
if (typeof query.kernelNonceReceived === "function") { | ||
query.kernelNonceReceived(event.data.data.nonce); | ||
} | ||
@@ -129,0 +127,0 @@ return; |
{ | ||
"name": "libkernel", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "helper library to interact with skynet and the skynet kernel", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
23124
502