Compare commits

..

6 Commits

8 changed files with 69 additions and 34 deletions

View File

@ -1,3 +1,5 @@
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/kernel/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-09-04)
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/kernel/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-09-03) # [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/kernel/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-09-03)
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/kernel/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-09-03) # [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/kernel/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-09-03)

37
npm-shrinkwrap.json generated
View File

@ -1,14 +1,14 @@
{ {
"name": "@lumeweb/kernel", "name": "@lumeweb/kernel",
"version": "0.1.0-develop.10", "version": "0.1.0-develop.11",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lumeweb/kernel", "name": "@lumeweb/kernel",
"version": "0.1.0-develop.10", "version": "0.1.0-develop.11",
"dependencies": { "dependencies": {
"@lumeweb/libkernel": "0.1.0-develop.38" "@lumeweb/libkernel": "0.1.0-develop.44"
}, },
"devDependencies": { "devDependencies": {
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.43", "@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.43",
@ -1690,11 +1690,11 @@
} }
}, },
"node_modules/@lumeweb/libkernel": { "node_modules/@lumeweb/libkernel": {
"version": "0.1.0-develop.38", "version": "0.1.0-develop.44",
"resolved": "https://registry.npmjs.org/@lumeweb/libkernel/-/libkernel-0.1.0-develop.38.tgz", "resolved": "https://registry.npmjs.org/@lumeweb/libkernel/-/libkernel-0.1.0-develop.44.tgz",
"integrity": "sha512-kzaUoIY1tIqX8x0PQU/q7Jj+O7SCvZxCZsc5BtCKbYyUym8ws19DLW1WcI3penhRJBUnjGZ4nxnSybBNP1bjfg==", "integrity": "sha512-vja0bvr2YZvRs1/HocW4BBJOl39bbXFrJPMDGULqYFnW1GZOGIk3tYmqsv7FRxzMpty9aqX4HHxcrX/7AyGbGQ==",
"dependencies": { "dependencies": {
"@lumeweb/libweb": "0.2.0-develop.38", "@lumeweb/libweb": "0.2.0-develop.49",
"emittery": "^1.0.1", "emittery": "^1.0.1",
"p-defer": "^4.0.0" "p-defer": "^4.0.0"
} }
@ -1711,12 +1711,11 @@
} }
}, },
"node_modules/@lumeweb/libportal": { "node_modules/@lumeweb/libportal": {
"version": "0.2.0-develop.20", "version": "0.2.0-develop.23",
"resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.20.tgz", "resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.23.tgz",
"integrity": "sha512-9bjyih7fyXpkcOYSue/jcLufcXQckkp30Ptigg2qFIDJOnxiv3ymRr2aq7rvXspnmTxnaQgwND0nQ0W0YOCnGA==", "integrity": "sha512-KN7KqFu5I+aYDeOL8hhaw1sjFjof8TrrPRvbdGmlQ7RDgkRbqiOQ8LQx2zPteBJPPGJfOtrnWWygBqy9wjuiaw==",
"dependencies": { "dependencies": {
"@lumeweb/libs5": "^0.1.0-develop.43", "@lumeweb/libs5": "^0.1.0-develop.44",
"@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git",
"@noble/curves": "^1.1.0", "@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1", "@noble/hashes": "^1.3.1",
"detect-node": "^2.1.0", "detect-node": "^2.1.0",
@ -1729,9 +1728,9 @@
} }
}, },
"node_modules/@lumeweb/libs5": { "node_modules/@lumeweb/libs5": {
"version": "0.1.0-develop.43", "version": "0.1.0-develop.44",
"resolved": "https://registry.npmjs.org/@lumeweb/libs5/-/libs5-0.1.0-develop.43.tgz", "resolved": "https://registry.npmjs.org/@lumeweb/libs5/-/libs5-0.1.0-develop.44.tgz",
"integrity": "sha512-kUGuT4kK9YVggqyMUj+pPY7okAFKxzACZTlA4BBBsgxAGIdr+iZLQwMfDlwzE4bdxndS52g1XM39Xv3K2xA/lQ==", "integrity": "sha512-BR/pII6v9i556tPBSDYUBszhFvSyQq+/Ptuopk7JIoRSqFzSsXWL0RteBi6v0qQzEffft7kOhaI1dLFOGZvWVQ==",
"dependencies": { "dependencies": {
"@noble/curves": "^1.1.0", "@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1", "@noble/hashes": "^1.3.1",
@ -1752,12 +1751,12 @@
} }
}, },
"node_modules/@lumeweb/libweb": { "node_modules/@lumeweb/libweb": {
"version": "0.2.0-develop.38", "version": "0.2.0-develop.49",
"resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.38.tgz", "resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.49.tgz",
"integrity": "sha512-Tuhf7TIe40oYKBQHKGf05hl+GMvBtYfpsZu6CdQL60reNquTZhG34j7TpEFsjuZG4qdj0jb3ryJ7UgSLq57qFw==", "integrity": "sha512-KwlluSiWwCHUEr47LEC6la0seMUeOpQ/d06K2eTT8b5ZlZ0lXjvDWJeLQm8azZexldG8nW9ikev5YlBUAWagdA==",
"dependencies": { "dependencies": {
"@lumeweb/community-portals": "^0.1.0-develop.6", "@lumeweb/community-portals": "^0.1.0-develop.6",
"@lumeweb/libportal": "0.2.0-develop.20", "@lumeweb/libportal": "0.2.0-develop.23",
"@lumeweb/node-library-preset": "0.2.7", "@lumeweb/node-library-preset": "0.2.7",
"@noble/curves": "^1.1.0", "@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1", "@noble/hashes": "^1.3.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lumeweb/kernel", "name": "@lumeweb/kernel",
"version": "0.1.0-develop.10", "version": "0.1.0-develop.11",
"type": "module", "type": "module",
"repository": { "repository": {
"type": "git", "type": "git",
@ -19,6 +19,6 @@
"semantic-release": "semantic-release" "semantic-release": "semantic-release"
}, },
"dependencies": { "dependencies": {
"@lumeweb/libkernel": "0.1.0-develop.38" "@lumeweb/libkernel": "0.1.0-develop.44"
} }
} }

View File

@ -1,7 +1,10 @@
import { internalModuleCall, modules } from "./queries.js"; import { internalModuleCall, modules } from "./queries.js";
import { SignedRegistryEntry } from "@lumeweb/libs5"; import { SignedRegistryEntry } from "@lumeweb/libs5";
import { base58btc } from "multiformats/bases/base58"; import {
import { decodeCid } from "@lumeweb/libweb"; decodeRegistryValue,
encodeCid,
decodeRegistryCid,
} from "@lumeweb/libweb";
const CORE_MODULES = { const CORE_MODULES = {
swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b", swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b",
@ -32,7 +35,7 @@ function moduleLoaded(module: string) {
} }
export async function resolveModuleRegistryEntry(module: string) { export async function resolveModuleRegistryEntry(module: string) {
const [cid] = decodeCid(module); const [cid] = decodeRegistryCid(module);
const pubkey = cid.hash; const pubkey = cid.hash;
@ -42,5 +45,18 @@ export async function resolveModuleRegistryEntry(module: string) {
{ pubkey }, { pubkey },
)) as SignedRegistryEntry; )) as SignedRegistryEntry;
return base58btc.encode(signedEntry.data); let [decodedRegistry, err] = decodeRegistryValue(signedEntry.data);
if (err) {
throw new Error(err);
}
let rawEncCid;
[rawEncCid, err] = encodeCid(decodedRegistry);
if (err) {
throw new Error(err);
}
return rawEncCid;
} }

View File

@ -1,6 +1,8 @@
// notableErrors is a persistent list of errors that should be checked after // notableErrors is a persistent list of errors that should be checked after
// testing. You should only add to this array in the event of an error that // testing. You should only add to this array in the event of an error that
// indicates a bug with the kernel. // indicates a bug with the kernel.
import { OpenQueryResponse } from "./queries.js";
const notableErrors: string[] = []; const notableErrors: string[] = [];
// respondErr will send an error response to the caller that closes out the // respondErr will send an error response to the caller that closes out the
@ -13,6 +15,7 @@ function respondErr(
event: MessageEvent, event: MessageEvent,
messagePortal: any, messagePortal: any,
isWorker: boolean, isWorker: boolean,
isInternal: false | ((message: OpenQueryResponse) => void),
err: string, err: string,
) { ) {
const message = { const message = {
@ -20,9 +23,11 @@ function respondErr(
method: "response", method: "response",
data: {}, data: {},
err, err,
}; } as OpenQueryResponse;
if (isWorker === true) { if (isWorker) {
messagePortal.postMessage(message); messagePortal.postMessage(message);
} else if (isInternal) {
isInternal(message);
} else { } else {
messagePortal.postMessage(message, event.origin); messagePortal.postMessage(message, event.origin);
} }

View File

@ -83,6 +83,7 @@ export const handleIncomingMessage = function (event: any) {
event, event,
event.source, event.source,
false, false,
false,
"caller is an extension, but not domain was provided", "caller is an extension, but not domain was provided",
); );
return; return;
@ -106,6 +107,7 @@ export const handleIncomingMessage = function (event: any) {
event, event,
event.source, event.source,
false, false,
false,
"unrecognized method: " + event.data.method, "unrecognized method: " + event.data.method,
); );
}; };

View File

@ -53,7 +53,7 @@ interface OpenQuery {
origin: string; origin: string;
} }
interface OpenQueryResponse { export interface OpenQueryResponse {
nonce: string; nonce: string;
method: string; method: string;
data: any; data: any;
@ -96,7 +96,7 @@ function handleWorkerMessage(event: MessageEvent, mod: Module, worker: Worker) {
// Perform input verification for a worker message. // Perform input verification for a worker message.
if (!("method" in event.data)) { if (!("method" in event.data)) {
logErr("worker", mod.domain, "received worker message with no method"); logErr("worker", mod.domain, "received worker message with no method");
respondErr(event, worker, true, "received message with no method"); respondErr(event, worker, true, false, "received message with no method");
return; return;
} }
@ -113,6 +113,7 @@ function handleWorkerMessage(event: MessageEvent, mod: Module, worker: Worker) {
event, event,
worker, worker,
true, true,
false,
"received log messsage with no data field", "received log messsage with no data field",
); );
return; return;
@ -127,6 +128,7 @@ function handleWorkerMessage(event: MessageEvent, mod: Module, worker: Worker) {
event, event,
worker, worker,
true, true,
false,
"received log messsage with no message field", "received log messsage with no message field",
); );
return; return;
@ -144,6 +146,7 @@ function handleWorkerMessage(event: MessageEvent, mod: Module, worker: Worker) {
event, event,
worker, worker,
true, true,
false,
"received log messsage with invalid isErr field", "received log messsage with invalid isErr field",
); );
return; return;
@ -169,7 +172,7 @@ function handleWorkerMessage(event: MessageEvent, mod: Module, worker: Worker) {
"worker sent a message with no nonce", "worker sent a message with no nonce",
event.data, event.data,
); );
respondErr(event, worker, true, "received message with no nonce"); respondErr(event, worker, true, false, "received message with no nonce");
return; return;
} }
@ -319,6 +322,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"moduleCall is missing 'module' field: " + JSON.stringify(event.data), "moduleCall is missing 'module' field: " + JSON.stringify(event.data),
); );
return; return;
@ -349,6 +353,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"'module' field in moduleCall is expected to be a raw CID or a resolver CID", "'module' field in moduleCall is expected to be a raw CID or a resolver CID",
); );
return; return;
@ -362,6 +367,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"no 'data.method' specified, module does not know what method to run", "no 'data.method' specified, module does not know what method to run",
); );
return; return;
@ -376,6 +382,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"'data.method' needs to be a string", "'data.method' needs to be a string",
); );
return; return;
@ -389,6 +396,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"presentSeed is a privileged method, only root is allowed to use it", "presentSeed is a privileged method, only root is allowed to use it",
); );
return; return;
@ -399,6 +407,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"no field data.data in moduleCall, data.data contains the module input", "no field data.data in moduleCall, data.data contains the module input",
); );
return; return;
@ -414,6 +423,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
"registry entry for module is not found", "registry entry for module is not found",
); );
}; };
@ -511,6 +521,7 @@ async function handleModuleCall(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
isInternal,
addContextToErr(errML, "module could not be loaded"), addContextToErr(errML, "module could not be loaded"),
); );
return; return;
@ -530,7 +541,7 @@ async function handleModuleCall(
const [moduleData, errDS] = await downloadSmallObject(finalModule); const [moduleData, errDS] = await downloadSmallObject(finalModule);
if (errDS !== null) { if (errDS !== null) {
const err = addContextToErr(errDS, "unable to load module"); const err = addContextToErr(errDS, "unable to load module");
respondErr(event, messagePortal, isWorker, err); respondErr(event, messagePortal, isWorker, isInternal, err);
resolve(err); resolve(err);
delete modulesLoading[moduleDomain]; delete modulesLoading[moduleDomain];
return; return;
@ -563,7 +574,7 @@ async function handleModuleCall(
const [mod, errCM] = await createModule(moduleData, moduleDomain); const [mod, errCM] = await createModule(moduleData, moduleDomain);
if (errCM !== null) { if (errCM !== null) {
const err = addContextToErr(errCM, "unable to create module"); const err = addContextToErr(errCM, "unable to create module");
respondErr(event, messagePortal, isWorker, err); respondErr(event, messagePortal, isWorker, isInternal, err);
resolve(err); resolve(err);
delete modulesLoading[moduleDomain]; delete modulesLoading[moduleDomain];
return; return;
@ -605,7 +616,7 @@ function handleModuleResponse(
if (!(event.data.nonce in queries)) { if (!(event.data.nonce in queries)) {
// If there's no corresponding query and this is a response, send an // If there's no corresponding query and this is a response, send an
// error. // error.
if (isResponse === true) { if (isResponse) {
logErr("worker", mod.domain, "received response for an unknown nonce"); logErr("worker", mod.domain, "received response for an unknown nonce");
return; return;
} }

View File

@ -11,7 +11,7 @@ const DEFAULT_MODULE_REGISTRY = new Map<string, string>(
"zduGKansawKCn6Uzr9sPKVbVkdJCgUVL1mizy38t7tHvUxfEGQMC14R3EP", "zduGKansawKCn6Uzr9sPKVbVkdJCgUVL1mizy38t7tHvUxfEGQMC14R3EP",
// s5 // s5
zdiT6quMF8gh8BhQdXE7CZYhp8S1BxSgsucSS48WuTGdars1noejvak6Qo: zdiT6quMF8gh8BhQdXE7CZYhp8S1BxSgsucSS48WuTGdars1noejvak6Qo:
"zduHdVUg8SUJQ5dwx1LnesjMTxDFxireNrppRng7z14QDZnqZCCiiWtcT9", "zduKLoxH3mmw2kHkkV18H2MLy99sA1RmFgarte63ng5WD39FmbeUXtB7iX",
}), }),
); );
const REGISTRY_ITEM_ID = "registry"; const REGISTRY_ITEM_ID = "registry";