libkernel
Advanced tools
Comparing version 0.0.52 to 0.0.53
@@ -1,2 +0,8 @@ | ||
export { init, newKernelQuery } from './init'; | ||
export { testMessage, callModule, upload, padAndEncrypt } from './messages'; | ||
export { blake2b } from "./blake2b.js"; | ||
export { b64ToBuf } from "./encoding.js"; | ||
export { addContextToErr } from "./err.js"; | ||
export { init, newKernelQuery } from "./init"; | ||
export { testMessage, callModule, upload, padAndEncrypt } from "./messages"; | ||
export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink } from "./registry.js"; | ||
export { generateSeedPhrase, validSeedPhrase } from "./seed.js"; | ||
export { sha512 } from "./sha512.js"; |
@@ -1,2 +0,8 @@ | ||
export { init, newKernelQuery } from './init'; | ||
export { testMessage, callModule, upload, padAndEncrypt } from './messages'; | ||
export { blake2b } from "./blake2b.js"; | ||
export { b64ToBuf } from "./encoding.js"; | ||
export { addContextToErr } from "./err.js"; | ||
export { init, newKernelQuery } from "./init"; | ||
export { testMessage, callModule, upload, padAndEncrypt } from "./messages"; | ||
export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink } from "./registry.js"; | ||
export { generateSeedPhrase, validSeedPhrase } from "./seed.js"; | ||
export { sha512 } from "./sha512.js"; |
export declare function log(...inputs: any): void; | ||
export declare function logErr(...inputs: any): void; | ||
export declare function composeErr(...inputs: any): string; | ||
export declare function newKernelQuery(data: any, update: Function): [Function, Promise<any>]; | ||
export declare function newKernelQuery(data: any, update: any): [any, Promise<any>]; | ||
export declare function init(): Promise<string>; |
@@ -10,32 +10,2 @@ // log provides a wrapper for console.log that prefixes 'libkernel'. | ||
} | ||
// composeErr takes a series of inputs and composes them into a single string. | ||
// Each element will be separated by a newline. If the input is not a string, | ||
// it will be transformed into a string with JSON.stringify. | ||
// | ||
// Any object that cannot be stringified will be skipped, though an error will | ||
// be logged. | ||
export function composeErr(...inputs) { | ||
let result = ""; | ||
for (let i = 0; i < inputs.length; i++) { | ||
// Prepend a newline if this isn't the first element. | ||
if (i !== 0) { | ||
result += "\n"; | ||
} | ||
// Strings can be added without modification. | ||
if (typeof inputs[i] === "string") { | ||
result += inputs[i]; | ||
continue; | ||
} | ||
// Everything else needs to be stringified, log an error if it | ||
// fails. | ||
try { | ||
let str = JSON.stringify(inputs[i]); | ||
result += str; | ||
} | ||
catch (_a) { | ||
logErr("unable to stringify input to composeErr"); | ||
} | ||
} | ||
return result; | ||
} | ||
// Establish a hashmap for matching queries to their responses by their nonces. | ||
@@ -45,4 +15,4 @@ // nextNonce needs to start at '1' because '0' is reserved for the bridgeTest | ||
const namespace = "libkernel-v0"; | ||
var nextNonce = 1; | ||
var queries = new Object(); | ||
let nextNonce = 1; | ||
let queries = new Object(); | ||
// handleBridgeResponse will handle a response from the bridge indicating that | ||
@@ -79,6 +49,6 @@ // the bridge is working. This needs to be declared before the remaining bridge | ||
// respond. | ||
var initialized; | ||
var bridgeExists; | ||
var bridgeAvailable; | ||
var blockForBridge = new Promise((resolve, reject) => { | ||
let initialized; | ||
let bridgeExists; | ||
let bridgeAvailable; | ||
let blockForBridge = new Promise((resolve, reject) => { | ||
bridgeAvailable = { resolve, reject, update: null, handle: handleBridgeResponse }; | ||
@@ -85,0 +55,0 @@ }); |
@@ -1,2 +0,3 @@ | ||
import { logErr, composeErr, init, newKernelQuery } from './init'; | ||
import { composeErr } from "./err.js"; | ||
import { logErr, init, newKernelQuery } from "./init.js"; | ||
const noBridge = "the bridge failed to initialize (do you have the Skynet browser extension?)"; | ||
@@ -17,3 +18,3 @@ // testMessage will send a test message to the kernel, ensuring that basic | ||
init() | ||
.then(x => { | ||
.then(() => { | ||
// Send a 'test' message to the kernel, which is a | ||
@@ -34,3 +35,3 @@ // method with no parameters. | ||
// updateHandler. | ||
let [_, query] = newKernelQuery({ | ||
let [, query] = newKernelQuery({ | ||
method: "test", | ||
@@ -44,3 +45,4 @@ }, null); | ||
// with promise chaining. | ||
query.then(response => { | ||
query | ||
.then((response) => { | ||
if (!("version" in response)) { | ||
@@ -52,3 +54,3 @@ resolve("kernel did not report a version"); | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
let cErr = composeErr("newKernelQuery failed", err); | ||
@@ -58,3 +60,3 @@ reject(cErr); | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
// For some reason, the bridge is not available. | ||
@@ -79,4 +81,4 @@ // Likely, this means that the user has not installed | ||
init() | ||
.then(x => { | ||
let [_, query] = newKernelQuery({ | ||
.then(() => { | ||
let [, query] = newKernelQuery({ | ||
method: "moduleCall", | ||
@@ -87,13 +89,14 @@ data: { | ||
data, | ||
} | ||
}, | ||
}, null); | ||
query.then(response => { | ||
query | ||
.then((response) => { | ||
resolve(response); | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
let cErr = composeErr("moduleCall query to kernel failed", err); | ||
reject(err); | ||
reject(cErr); | ||
}); | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
let cErr = composeErr(noBridge, err); | ||
@@ -115,4 +118,4 @@ logErr(cErr); | ||
init() | ||
.then(x => { | ||
let [_, query] = newKernelQuery({ | ||
.then(() => { | ||
let [, query] = newKernelQuery({ | ||
method: "moduleCall", | ||
@@ -128,10 +131,11 @@ data: { | ||
}, null); | ||
query.then(response => { | ||
query | ||
.then((response) => { | ||
resolve(response.skylink); | ||
}) | ||
.catch(err => { | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}) | ||
.catch(x => { | ||
.catch((x) => { | ||
reject(x); | ||
@@ -151,4 +155,4 @@ }); | ||
init() | ||
.then(x => { | ||
let [_, query] = newKernelQuery({ | ||
.then(() => { | ||
let [, query] = newKernelQuery({ | ||
kernelMethod: "moduleCall", | ||
@@ -162,10 +166,11 @@ module: "AQAs00kS6OKUd-FIWj9qdJLArCiEDMVgYBSkaetuTF-MsQ", | ||
}, null); | ||
query.then(response => { | ||
query | ||
.then((response) => { | ||
resolve(response.output); | ||
}) | ||
.catch(response => { | ||
.catch((response) => { | ||
reject(response.err); | ||
}); | ||
}) | ||
.catch(x => { | ||
.catch((x) => { | ||
reject(x); | ||
@@ -172,0 +177,0 @@ }); |
{ | ||
"name": "libkernel", | ||
"version": "0.0.52", | ||
"description": "helper library to interact with the skynet kernel", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.js", | ||
"files": [ | ||
"/dist" | ||
] | ||
"name": "libkernel", | ||
"version": "0.0.53", | ||
"description": "helper library to interact with skynet and the skynet kernel", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.js", | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"eslint": "eslint src --fix", | ||
"prettier": "prettier --write .", | ||
"lint": "npm run prettier && npm run eslint", | ||
"test": "tsc && tsc --project tsconfig.test.json && node ./dist-test/src-test/test.js", | ||
"prepare": "npm run lint && npm run test" | ||
}, | ||
"author": "David Vorick", | ||
"devDependencies": { | ||
"@types/node": "^17.0.23", | ||
"@typescript-eslint/eslint-plugin": "^5.19.0", | ||
"eslint": "^8.13.0", | ||
"prettier": "^2.6.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
108094
30
0
3740
1
Yes
4
1