libkernel
Advanced tools
Comparing version 0.0.75 to 0.0.76
@@ -1,3 +0,2 @@ | ||
declare function addContextToErr(err: string | null, context: string): string | null; | ||
declare function composeErr(...inputs: any): string; | ||
import { addContextToErr, composeErr } from "libskynet"; | ||
export { addContextToErr, composeErr }; |
@@ -1,44 +0,2 @@ | ||
import { logErr } from "./init.js"; | ||
// addContextToErr is a helper function that standardizes the formatting of | ||
// adding context to an error. Within the world of go we discovered that being | ||
// persistent about layering context onto errors is helpful when debugging, | ||
// even though it often creates rather verbose error messages. | ||
// | ||
// addContextToErr will return null if the input err is null. | ||
function addContextToErr(err, context) { | ||
if (err === null) { | ||
return null; | ||
} | ||
return context + ": " + err; | ||
} | ||
// 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. | ||
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 { | ||
logErr("unable to stringify input to composeErr"); | ||
} | ||
} | ||
return result; | ||
} | ||
import { addContextToErr, composeErr } from "libskynet"; | ||
export { addContextToErr, composeErr }; |
@@ -1,17 +0,5 @@ | ||
export { blake2b } from "./blake2b.js"; | ||
export { defaultPortalList } from "./defaultportals.js"; | ||
export { dictionary } from "./dictionary.js"; | ||
export { ed25519Sign, ed25519Verify } from "./ed25519.js"; | ||
export { b64ToBuf, bufToB64, bufToHex, encodePrefixedBytes, encodeU64, hexToBuf } from "./encoding.js"; | ||
export { download } from "./download.js"; | ||
export { addContextToErr, composeErr } from "./err.js"; | ||
export { init, newKernelQuery } from "./init.js"; | ||
export { blake2bAddLeafBytesToProofStack, blake2bMerkleRoot, blake2bProofStackRoot } from "./merkle.js"; | ||
export { callModule, download, testMessage, upload } from "./messages.js"; | ||
export { progressiveFetch } from "./progressivefetch.js"; | ||
export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink, verifyRegistrySignature } from "./registry.js"; | ||
export { generateSeedPhraseDeterministic, validSeedPhrase } from "./seed.js"; | ||
export { sha512 } from "./sha512.js"; | ||
export { parseSkylinkBitfield, skylinkV1Bitfield } from "./skylinkbitfield.js"; | ||
export { validateSkyfileMetadata, validateSkyfilePath, validSkylink } from "./skylinkvalidate.js"; | ||
export { verifyResolverLinkProofs } from "./skylinkverifyresolver.js"; | ||
export { verifyDownload } from "./verifydownload.js"; | ||
export { callModule, testMessage } from "./messages.js"; | ||
export { upload } from "./upload.js"; |
@@ -1,17 +0,5 @@ | ||
export { blake2b } from "./blake2b.js"; | ||
export { defaultPortalList } from "./defaultportals.js"; | ||
export { dictionary } from "./dictionary.js"; | ||
export { ed25519Sign, ed25519Verify } from "./ed25519.js"; | ||
export { b64ToBuf, bufToB64, bufToHex, encodePrefixedBytes, encodeU64, hexToBuf } from "./encoding.js"; | ||
export { download } from "./download.js"; | ||
export { addContextToErr, composeErr } from "./err.js"; | ||
export { init, newKernelQuery } from "./init.js"; | ||
export { blake2bAddLeafBytesToProofStack, blake2bMerkleRoot, blake2bProofStackRoot } from "./merkle.js"; | ||
export { callModule, download, testMessage, upload } from "./messages.js"; | ||
export { progressiveFetch } from "./progressivefetch.js"; | ||
export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink, verifyRegistrySignature } from "./registry.js"; | ||
export { generateSeedPhraseDeterministic, validSeedPhrase } from "./seed.js"; | ||
export { sha512 } from "./sha512.js"; | ||
export { parseSkylinkBitfield, skylinkV1Bitfield } from "./skylinkbitfield.js"; | ||
export { validateSkyfileMetadata, validateSkyfilePath, validSkylink } from "./skylinkvalidate.js"; | ||
export { verifyResolverLinkProofs } from "./skylinkverifyresolver.js"; | ||
export { verifyDownload } from "./verifydownload.js"; | ||
export { callModule, testMessage } from "./messages.js"; | ||
export { upload } from "./upload.js"; |
@@ -1,5 +0,3 @@ | ||
declare function log(...inputs: any): void; | ||
declare function logErr(...inputs: any): void; | ||
declare function newKernelQuery(data: any, update: any): [any, Promise<any>]; | ||
declare function init(): Promise<string>; | ||
export { init, log, logErr, newKernelQuery }; | ||
export { init, newKernelQuery }; |
@@ -1,10 +0,2 @@ | ||
// log provides a wrapper for console.log that prefixes 'libkernel'. | ||
function log(...inputs) { | ||
console.log("[libkernel]", ...inputs); | ||
} | ||
// logErr provides a wrapper for console.error that prefixes '[libkernel]' to | ||
// the output. | ||
function logErr(...inputs) { | ||
console.error("[libkernel]", ...inputs); | ||
} | ||
import { logErr } from "./log.js"; | ||
// Establish a hashmap for matching queries to their responses by their nonces. | ||
@@ -182,2 +174,2 @@ // nextNonce needs to start at '1' because '0' is reserved for the bridgeTest | ||
} | ||
export { init, log, logErr, newKernelQuery }; | ||
export { init, newKernelQuery }; |
declare function testMessage(): Promise<string>; | ||
declare function callModule(module: string, method: string, data: any): Promise<any>; | ||
declare function upload(filename: string, fileData: Uint8Array): Promise<string>; | ||
declare function download(skylink: string): Promise<Uint8Array>; | ||
export { callModule, download, testMessage, upload }; | ||
export { callModule, testMessage }; |
import { addContextToErr, composeErr } from "./err.js"; | ||
import { logErr, init, newKernelQuery } from "./init.js"; | ||
import { init, newKernelQuery } from "./init.js"; | ||
import { logErr } from "./log.js"; | ||
const noBridge = "the bridge failed to initialize (do you have the Skynet browser extension?)"; | ||
@@ -99,68 +100,2 @@ // testMessage will send a test message to the kernel, ensuring that basic | ||
} | ||
// upload will take a filename and some file data and perform a secure upload | ||
// to Skynet. Secure in this case means that all data is verified before being | ||
// uploaded - the portal cannot lie about the skylink that it returns after | ||
// uploading the data. | ||
// | ||
// NOTE: The largest allowed file is currently slightly less than 4 MiB | ||
// (roughly 500 bytes less) | ||
function upload(filename, fileData) { | ||
return new Promise((resolve, reject) => { | ||
init() | ||
.then(() => { | ||
let [, query] = newKernelQuery({ | ||
method: "moduleCall", | ||
data: { | ||
module: "AQAT_a0MzOInZoJzt1CwBM2U8oQ3GIfP5yKKJu8Un-SfNg", | ||
method: "secureUpload", | ||
data: { | ||
filename, | ||
fileData, | ||
}, | ||
}, | ||
}, null); | ||
query | ||
.then((response) => { | ||
resolve(response.skylink); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}) | ||
.catch((x) => { | ||
reject(x); | ||
}); | ||
}); | ||
} | ||
// download will take a skylink and return the fileData for that skylink. | ||
// | ||
// NOTE: download currently only supports downloading files that fully fit into | ||
// the base sector. | ||
function download(skylink) { | ||
return new Promise((resolve, reject) => { | ||
init() | ||
.then(() => { | ||
let [, query] = newKernelQuery({ | ||
method: "moduleCall", | ||
data: { | ||
module: "AQCIaQ0P-r6FwPEDq3auCZiuH_jqrHfqRcY7TjZ136Z_Yw", | ||
method: "secureDownload", | ||
data: { | ||
skylink, | ||
}, | ||
}, | ||
}, null); | ||
query | ||
.then((response) => { | ||
resolve(response.fileData); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
export { callModule, download, testMessage, upload }; | ||
export { callModule, testMessage }; |
{ | ||
"name": "libkernel", | ||
"version": "0.0.75", | ||
"version": "0.0.76", | ||
"description": "helper library to interact with skynet and the skynet kernel", | ||
@@ -15,3 +15,3 @@ "main": "dist/index.js", | ||
"lint": "npm run prettier && npm run eslint", | ||
"test": "tsc && tsc --project tsconfig.test.json && node ./dist-test/src-test/test.js", | ||
"test": "tsc && tsc --project tsconfig.test.json && node ./dist-test/test.js", | ||
"prepare": "npm run lint && npm run test" | ||
@@ -25,3 +25,6 @@ }, | ||
"prettier": "^2.6.2" | ||
}, | ||
"dependencies": { | ||
"libskynet": "^0.0.1" | ||
} | ||
} |
# libkernel | ||
libkernel is a node module for web developers that would like to use the Skynet | ||
kernel in their applications, or would like to build modules for the Skynet | ||
kernel. It contains a bunch of helper functions and syntax sugar for | ||
interacting with the kernel itself, and it also contains a bunch of functions | ||
for dealing with Skynet objects such as skylinks. | ||
libkernel is a node module for web developers what would like to use Skynet in | ||
their applications. It creates a direct connection to the Skynet kernel and | ||
then provides helper methods for interacting with the kernel. | ||
libkernel for the time being should be considered highly unstable - there is | ||
ongoing discussion about whether the scope of libkernel is too broad and | ||
whether some of the Skynet related functions should be split out into their own | ||
libraries. Methods you depend on today may be gone or have altered APIs | ||
tomorrow, we hope to have libkernel in a stable place within the next 2-3 | ||
weeks. | ||
A quirk of libkernel is that errors are of the type `string | null` rather than | ||
being type `Error`. This is because libkernel is frequently used in webworkers | ||
and other settings where errors need to be sent over postmessage, and the | ||
`Error` type is not suitable for postmessage. | ||
A particular quirk of libkernel is that errors are always of the type `string | null` rather than being of type `Error`. This is because libkernel is | ||
frequently used in webworkers and other settings where errors need to be | ||
serialized and send over postMessage, and the `Error` type is generally not | ||
suitable for this. We therefore use strings everywhere as errors, to ensure | ||
that libkernel can be used in all relevant places. | ||
libkernel is still being reviewed, but is expected to be stable. There may be a | ||
small number of breaking changes in the near future, and after that we will be | ||
providing strong compatibility promises around the libkernel API. | ||
@@ -22,0 +16,0 @@ ## Roadmap |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
16483
1
16
382
23
+ Addedlibskynet@^0.0.1
+ Addedlibskynet@0.0.1(transitive)