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

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/kernel",
"version": "0.1.0-develop.10",
"version": "0.1.0-develop.11",
"type": "module",
"repository": {
"type": "git",
@ -19,6 +19,6 @@
"semantic-release": "semantic-release"
},
"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 { SignedRegistryEntry } from "@lumeweb/libs5";
import { base58btc } from "multiformats/bases/base58";
import { decodeCid } from "@lumeweb/libweb";
import {
decodeRegistryValue,
encodeCid,
decodeRegistryCid,
} from "@lumeweb/libweb";
const CORE_MODULES = {
swarm: "zdiLmwHCC15afFNLYzzT2DVV7m27SrBde7oXHdSzAe95GpFZXzdpatUN6b",
@ -32,7 +35,7 @@ function moduleLoaded(module: string) {
}
export async function resolveModuleRegistryEntry(module: string) {
const [cid] = decodeCid(module);
const [cid] = decodeRegistryCid(module);
const pubkey = cid.hash;
@ -42,5 +45,18 @@ export async function resolveModuleRegistryEntry(module: string) {
{ pubkey },
)) 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
// testing. You should only add to this array in the event of an error that
// indicates a bug with the kernel.
import { OpenQueryResponse } from "./queries.js";
const notableErrors: string[] = [];
// respondErr will send an error response to the caller that closes out the
@ -13,6 +15,7 @@ function respondErr(
event: MessageEvent,
messagePortal: any,
isWorker: boolean,
isInternal: false | ((message: OpenQueryResponse) => void),
err: string,
) {
const message = {
@ -20,9 +23,11 @@ function respondErr(
method: "response",
data: {},
err,
};
if (isWorker === true) {
} as OpenQueryResponse;
if (isWorker) {
messagePortal.postMessage(message);
} else if (isInternal) {
isInternal(message);
} else {
messagePortal.postMessage(message, event.origin);
}

View File

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

View File

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

View File

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