nervur 0.21.4 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +215 -158
- package/dist/browser.js +4 -3
- package/dist/cli.js +16 -0
- package/dist/{being → core/being}/being.js +10 -0
- package/dist/{being → core/being}/faculty.js +5 -2
- package/dist/{being → core/being}/index.d.ts +1 -1
- package/dist/{being → core/being}/index.js +1 -1
- package/dist/{being → core/being}/kind.d.ts +2 -0
- package/dist/{being → core/being}/kind.js +6 -0
- package/dist/{being → core/being}/types.js +1 -1
- package/dist/{browser → core/browser}/index.d.ts +6 -5
- package/dist/{browser → core/browser}/index.js +10 -10
- package/dist/{browser → core/browser}/worker.d.ts +2 -3
- package/dist/{browser → core/browser}/worker.js +8 -11
- package/dist/{cli → core/cli}/command.d.ts +4 -4
- package/dist/{cli → core/cli}/command.js +116 -66
- package/dist/{cli → core/cli}/edge.js +4 -2
- package/dist/core/cli/harbor.d.ts +25 -0
- package/dist/{cli → core/cli}/harbor.js +45 -33
- package/dist/{contract → core/contract}/index.d.ts +6 -5
- package/dist/{contract → core/contract}/index.js +8 -9
- package/dist/core/contract/link.d.ts +4 -0
- package/dist/core/contract/link.js +45 -0
- package/dist/{crypto → core/crypto}/ed25519.js +22 -14
- package/dist/core/crypto/subtle.d.ts +3 -0
- package/dist/core/crypto/subtle.js +11 -0
- package/dist/core/crypto/x25519.js +24 -0
- package/dist/core/edge/index.d.ts +164 -0
- package/dist/core/edge/index.js +739 -0
- package/dist/core/edge/kit.d.ts +2 -0
- package/dist/core/edge/kit.js +2 -0
- package/dist/core/git/http.d.ts +6 -0
- package/dist/core/git/http.js +102 -0
- package/dist/core/git/index.d.ts +5 -0
- package/dist/core/git/index.js +10 -0
- package/dist/core/git/object.d.ts +40 -0
- package/dist/core/git/object.js +103 -0
- package/dist/core/git/pack.d.ts +9 -0
- package/dist/core/git/pack.js +171 -0
- package/dist/core/git/store.d.ts +23 -0
- package/dist/core/git/store.js +120 -0
- package/dist/core/git/zlib.d.ts +6 -0
- package/dist/core/git/zlib.js +210 -0
- package/dist/core/harbor/carrying.d.ts +51 -0
- package/dist/core/harbor/carrying.js +69 -0
- package/dist/core/harbor/catalogue.d.ts +33 -0
- package/dist/core/harbor/catalogue.js +365 -0
- package/dist/core/harbor/dna.d.ts +13 -0
- package/dist/core/harbor/dna.js +120 -0
- package/dist/{harbor → core/harbor}/dock.d.ts +22 -13
- package/dist/core/harbor/dock.js +381 -0
- package/dist/core/harbor/harbor.d.ts +16 -0
- package/dist/core/harbor/harbor.js +438 -0
- package/dist/core/harbor/index.d.ts +11 -0
- package/dist/{harbor → core/harbor}/index.js +5 -5
- package/dist/core/harbor/memory.d.ts +10 -0
- package/dist/core/harbor/memory.js +25 -0
- package/dist/{harbor → core/harbor}/package.d.ts +0 -1
- package/dist/{harbor → core/harbor}/package.js +9 -9
- package/dist/core/harbor/probe.d.ts +22 -0
- package/dist/core/harbor/probe.js +15 -0
- package/dist/core/harbor/registry.d.ts +15 -0
- package/dist/{harbor → core/harbor}/registry.js +26 -10
- package/dist/core/harbor/root-line.d.ts +7 -0
- package/dist/core/harbor/root-line.js +9 -0
- package/dist/{harbor → core/harbor}/terrain.d.ts +9 -6
- package/dist/{harbor → core/harbor}/terrain.js +5 -4
- package/dist/core/http/index.d.ts +2 -0
- package/dist/{http → core/http}/index.js +3 -5
- package/dist/{line → core/line}/answer.d.ts +2 -2
- package/dist/{line → core/line}/frame.d.ts +0 -5
- package/dist/{line → core/line}/frame.js +0 -4
- package/dist/core/line/ground.js +7 -0
- package/dist/core/line/index.d.ts +4 -0
- package/dist/core/line/index.js +8 -0
- package/dist/core/line/web.d.ts +12 -0
- package/dist/{line → core/line}/web.js +13 -77
- package/dist/{node → core/node}/index.d.ts +2 -15
- package/dist/core/node/index.js +124 -0
- package/dist/{pointer → core/pointer}/bodies.d.ts +7 -5
- package/dist/core/pointer/bodies.js +118 -0
- package/dist/core/pointer/index.d.ts +2 -0
- package/dist/{pointer → core/pointer}/index.js +1 -1
- package/dist/{pointer → core/pointer}/world.d.ts +13 -9
- package/dist/{pointer → core/pointer}/world.js +31 -16
- package/dist/{proof → core/proof}/contracts.d.ts +6 -2
- package/dist/{proof → core/proof}/contracts.js +11 -10
- package/dist/core/proof/index.d.ts +3 -0
- package/dist/{proof → core/proof}/index.js +2 -2
- package/dist/core/proof/law.d.ts +25 -0
- package/dist/core/proof/law.js +715 -0
- package/dist/{tcp → core/tcp}/index.d.ts +7 -4
- package/dist/{tcp → core/tcp}/index.js +11 -62
- package/dist/{ward/ward.d.ts → core/ward/house.d.ts} +24 -10
- package/dist/core/ward/house.js +473 -0
- package/dist/core/ward/index.d.ts +5 -0
- package/dist/core/ward/index.js +7 -0
- package/dist/{ward → core/ward}/partition.d.ts +1 -0
- package/dist/{ward → core/ward}/stance.d.ts +2 -2
- package/dist/{ward → core/ward}/stance.js +5 -2
- package/dist/{ward/ward-being.d.ts → core/ward/ward.d.ts} +14 -6
- package/dist/core/ward/ward.js +140 -0
- package/dist/core.d.ts +10 -0
- package/dist/core.js +19 -0
- package/dist/defaults/dock/index.d.ts +4 -0
- package/dist/defaults/dock/index.js +11 -0
- package/dist/defaults/index.d.ts +5 -0
- package/dist/defaults/index.js +10 -0
- package/dist/defaults/memory/index.d.ts +12 -0
- package/dist/defaults/memory/index.js +39 -0
- package/dist/defaults/tcp/index.d.ts +16 -0
- package/dist/defaults/tcp/index.js +82 -0
- package/dist/defaults/ward/index.d.ts +4 -0
- package/dist/defaults/ward/index.js +11 -0
- package/dist/defaults/web/index.d.ts +15 -0
- package/dist/defaults/web/index.js +90 -0
- package/dist/edge.js +4 -3
- package/dist/index.d.ts +1 -8
- package/dist/index.js +13 -18
- package/dist/kit.d.ts +4 -0
- package/dist/kit.js +12 -0
- package/dist/node.js +4 -3
- package/package.json +23 -18
- package/src/browser.ts +4 -3
- package/src/cli.ts +15 -0
- package/src/{being → core/being}/being.ts +4 -0
- package/src/{being → core/being}/faculty.ts +5 -2
- package/src/{being → core/being}/index.ts +1 -1
- package/src/{being → core/being}/kind.ts +7 -0
- package/src/{being → core/being}/types.ts +1 -1
- package/src/{browser → core/browser}/index.ts +16 -13
- package/src/{browser → core/browser}/worker.ts +11 -14
- package/src/{cli → core/cli}/command.ts +113 -66
- package/src/{cli → core/cli}/edge.ts +4 -2
- package/src/{cli → core/cli}/harbor.ts +48 -31
- package/src/{contract → core/contract}/index.ts +14 -14
- package/src/core/contract/link.ts +58 -0
- package/src/{crypto → core/crypto}/ed25519.ts +22 -14
- package/src/core/crypto/subtle.ts +13 -0
- package/src/core/crypto/x25519.ts +23 -0
- package/src/core/edge/index.ts +865 -0
- package/src/core/git/http.ts +103 -0
- package/src/core/git/index.ts +10 -0
- package/src/core/git/object.ts +116 -0
- package/src/core/git/pack.ts +147 -0
- package/src/core/git/store.ts +122 -0
- package/src/core/git/zlib.ts +197 -0
- package/src/core/harbor/carrying.ts +124 -0
- package/src/core/harbor/catalogue.ts +386 -0
- package/src/core/harbor/dna.ts +116 -0
- package/src/core/harbor/dock.ts +420 -0
- package/src/core/harbor/harbor.ts +433 -0
- package/src/core/harbor/index.ts +14 -0
- package/src/core/harbor/memory.ts +31 -0
- package/src/{harbor → core/harbor}/package.ts +15 -15
- package/src/core/harbor/probe.ts +39 -0
- package/src/{harbor → core/harbor}/registry.ts +28 -11
- package/src/core/harbor/root-line.ts +19 -0
- package/src/{harbor → core/harbor}/terrain.ts +14 -7
- package/src/{http → core/http}/index.ts +5 -8
- package/src/{line → core/line}/answer.ts +3 -2
- package/src/{line → core/line}/frame.ts +0 -5
- package/src/core/line/ground.ts +18 -0
- package/src/core/line/index.ts +8 -0
- package/src/{line → core/line}/web.ts +1 -105
- package/src/core/node/index.ts +139 -0
- package/src/core/pointer/bodies.ts +122 -0
- package/src/core/pointer/index.ts +4 -0
- package/src/{pointer → core/pointer}/world.ts +45 -21
- package/src/{proof → core/proof}/contracts.ts +18 -13
- package/src/{proof → core/proof}/index.ts +3 -3
- package/src/core/proof/law.ts +742 -0
- package/src/{stand → core/stand}/stand.ts +2 -2
- package/src/{tcp → core/tcp}/index.ts +17 -74
- package/src/core/ward/house.ts +524 -0
- package/src/core/ward/index.ts +7 -0
- package/src/{ward → core/ward}/partition.ts +5 -1
- package/src/{ward → core/ward}/stance.ts +5 -2
- package/src/core/ward/ward.ts +166 -0
- package/src/core.ts +55 -0
- package/src/defaults/dock/index.ts +12 -0
- package/src/defaults/index.ts +10 -0
- package/src/defaults/memory/index.ts +50 -0
- package/src/defaults/tcp/index.ts +89 -0
- package/src/defaults/ward/index.ts +12 -0
- package/src/defaults/web/index.ts +97 -0
- package/src/edge.ts +4 -3
- package/src/index.ts +13 -50
- package/src/kit.ts +15 -0
- package/src/node.ts +4 -3
- package/dist/cli/harbor.d.ts +0 -16
- package/dist/cli/main.js +0 -14
- package/dist/crypto/subtle.d.ts +0 -10
- package/dist/crypto/subtle.js +0 -29
- package/dist/crypto/x25519.js +0 -21
- package/dist/edge/index.d.ts +0 -81
- package/dist/edge/index.js +0 -400
- package/dist/harbor/carrying.d.ts +0 -17
- package/dist/harbor/carrying.js +0 -38
- package/dist/harbor/catalogue.d.ts +0 -28
- package/dist/harbor/catalogue.js +0 -109
- package/dist/harbor/dock.js +0 -236
- package/dist/harbor/harbor.d.ts +0 -45
- package/dist/harbor/harbor.js +0 -347
- package/dist/harbor/index.d.ts +0 -11
- package/dist/harbor/probe.d.ts +0 -18
- package/dist/harbor/probe.js +0 -15
- package/dist/harbor/registry.d.ts +0 -10
- package/dist/harbor/relay.d.ts +0 -15
- package/dist/harbor/relay.js +0 -406
- package/dist/harbor/root-line.d.ts +0 -9
- package/dist/harbor/root-line.js +0 -38
- package/dist/harbor/store.d.ts +0 -13
- package/dist/harbor/store.js +0 -53
- package/dist/http/index.d.ts +0 -4
- package/dist/line/ground.js +0 -9
- package/dist/line/index.d.ts +0 -5
- package/dist/line/index.js +0 -9
- package/dist/line/push.d.ts +0 -7
- package/dist/line/push.js +0 -92
- package/dist/line/web.d.ts +0 -30
- package/dist/node/index.js +0 -236
- package/dist/pointer/bodies.js +0 -80
- package/dist/pointer/index.d.ts +0 -2
- package/dist/proof/index.d.ts +0 -3
- package/dist/proof/law.d.ts +0 -90
- package/dist/proof/law.js +0 -591
- package/dist/tcp/frame.d.ts +0 -25
- package/dist/tcp/frame.js +0 -64
- package/dist/ward/index.d.ts +0 -6
- package/dist/ward/index.js +0 -8
- package/dist/ward/pilot.d.ts +0 -8
- package/dist/ward/pilot.js +0 -50
- package/dist/ward/ward-being.js +0 -82
- package/dist/ward/ward.js +0 -290
- package/src/cli/main.ts +0 -13
- package/src/crypto/subtle.ts +0 -33
- package/src/crypto/x25519.ts +0 -21
- package/src/edge/index.ts +0 -490
- package/src/harbor/carrying.ts +0 -56
- package/src/harbor/catalogue.ts +0 -134
- package/src/harbor/dock.ts +0 -265
- package/src/harbor/harbor.ts +0 -381
- package/src/harbor/index.ts +0 -14
- package/src/harbor/probe.ts +0 -34
- package/src/harbor/relay.ts +0 -418
- package/src/harbor/root-line.ts +0 -39
- package/src/harbor/store.ts +0 -69
- package/src/line/ground.ts +0 -19
- package/src/line/index.ts +0 -9
- package/src/line/push.ts +0 -112
- package/src/node/index.ts +0 -241
- package/src/pointer/bodies.ts +0 -82
- package/src/pointer/index.ts +0 -4
- package/src/proof/law.ts +0 -591
- package/src/ward/index.ts +0 -8
- package/src/ward/pilot.ts +0 -50
- package/src/ward/ward-being.ts +0 -103
- package/src/ward/ward.ts +0 -328
- /package/dist/{cli/main.d.ts → cli.d.ts} +0 -0
- /package/dist/{being → core/being}/being.d.ts +0 -0
- /package/dist/{being → core/being}/digest.d.ts +0 -0
- /package/dist/{being → core/being}/digest.js +0 -0
- /package/dist/{being → core/being}/faculty.d.ts +0 -0
- /package/dist/{being → core/being}/types.d.ts +0 -0
- /package/dist/{being → core/being}/words.d.ts +0 -0
- /package/dist/{being → core/being}/words.js +0 -0
- /package/dist/{cli → core/cli}/edge.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/aes.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/aes.js +0 -0
- /package/dist/{crypto → core/crypto}/bytes.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/bytes.js +0 -0
- /package/dist/{crypto → core/crypto}/ed25519.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/hash.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/hash.js +0 -0
- /package/dist/{crypto → core/crypto}/index.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/index.js +0 -0
- /package/dist/{crypto → core/crypto}/json.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/json.js +0 -0
- /package/dist/{crypto → core/crypto}/mlkem.d.ts +0 -0
- /package/dist/{crypto → core/crypto}/mlkem.js +0 -0
- /package/dist/{crypto → core/crypto}/x25519.d.ts +0 -0
- /package/dist/{folder → core/folder}/index.d.ts +0 -0
- /package/dist/{folder → core/folder}/index.js +0 -0
- /package/dist/{http → core/http}/websocket.d.ts +0 -0
- /package/dist/{http → core/http}/websocket.js +0 -0
- /package/dist/{line → core/line}/answer.js +0 -0
- /package/dist/{line → core/line}/ground.d.ts +0 -0
- /package/dist/{proof → core/proof}/expect.d.ts +0 -0
- /package/dist/{proof → core/proof}/expect.js +0 -0
- /package/dist/{quo → core/quo}/address.d.ts +0 -0
- /package/dist/{quo → core/quo}/address.js +0 -0
- /package/dist/{quo → core/quo}/door.d.ts +0 -0
- /package/dist/{quo → core/quo}/door.js +0 -0
- /package/dist/{quo → core/quo}/index.d.ts +0 -0
- /package/dist/{quo → core/quo}/index.js +0 -0
- /package/dist/{quo → core/quo}/invitation.d.ts +0 -0
- /package/dist/{quo → core/quo}/invitation.js +0 -0
- /package/dist/{quo → core/quo}/keys.d.ts +0 -0
- /package/dist/{quo → core/quo}/keys.js +0 -0
- /package/dist/{quo → core/quo}/payload.d.ts +0 -0
- /package/dist/{quo → core/quo}/payload.js +0 -0
- /package/dist/{quo → core/quo}/relations.d.ts +0 -0
- /package/dist/{quo → core/quo}/relations.js +0 -0
- /package/dist/{quo → core/quo}/reply.d.ts +0 -0
- /package/dist/{quo → core/quo}/reply.js +0 -0
- /package/dist/{quo → core/quo}/seal.d.ts +0 -0
- /package/dist/{quo → core/quo}/seal.js +0 -0
- /package/dist/{quo → core/quo}/standing.d.ts +0 -0
- /package/dist/{quo → core/quo}/standing.js +0 -0
- /package/dist/{ward → core/ward}/allowance.d.ts +0 -0
- /package/dist/{ward → core/ward}/allowance.js +0 -0
- /package/dist/{ward → core/ward}/cells.d.ts +0 -0
- /package/dist/{ward → core/ward}/cells.js +0 -0
- /package/dist/{ward → core/ward}/partition.js +0 -0
- /package/src/{being → core/being}/digest.ts +0 -0
- /package/src/{being → core/being}/words.ts +0 -0
- /package/src/{crypto → core/crypto}/aes.ts +0 -0
- /package/src/{crypto → core/crypto}/bytes.ts +0 -0
- /package/src/{crypto → core/crypto}/hash.ts +0 -0
- /package/src/{crypto → core/crypto}/index.ts +0 -0
- /package/src/{crypto → core/crypto}/json.ts +0 -0
- /package/src/{crypto → core/crypto}/mlkem.ts +0 -0
- /package/src/{folder → core/folder}/index.ts +0 -0
- /package/src/{http → core/http}/websocket.ts +0 -0
- /package/src/{proof → core/proof}/expect.ts +0 -0
- /package/src/{quo → core/quo}/address.ts +0 -0
- /package/src/{quo → core/quo}/door.ts +0 -0
- /package/src/{quo → core/quo}/index.ts +0 -0
- /package/src/{quo → core/quo}/invitation.ts +0 -0
- /package/src/{quo → core/quo}/keys.ts +0 -0
- /package/src/{quo → core/quo}/payload.ts +0 -0
- /package/src/{quo → core/quo}/relations.ts +0 -0
- /package/src/{quo → core/quo}/reply.ts +0 -0
- /package/src/{quo → core/quo}/seal.ts +0 -0
- /package/src/{quo → core/quo}/standing.ts +0 -0
- /package/src/{stand → core/stand}/main.ts +0 -0
- /package/src/{ward → core/ward}/allowance.ts +0 -0
- /package/src/{ward → core/ward}/cells.ts +0 -0
|
@@ -29,13 +29,14 @@ export type Module = {
|
|
|
29
29
|
readonly version: string;
|
|
30
30
|
readonly classes: readonly unknown[];
|
|
31
31
|
};
|
|
32
|
-
export type Loaded = Module & {
|
|
33
|
-
readonly from: string;
|
|
34
|
-
};
|
|
35
32
|
export declare abstract class Loader {
|
|
36
|
-
abstract load(
|
|
37
|
-
missing(_from: string): string | null;
|
|
33
|
+
abstract load(source: string, id: string): Promise<Module>;
|
|
38
34
|
}
|
|
35
|
+
export type Bundled = {
|
|
36
|
+
readonly source: string;
|
|
37
|
+
readonly module: Module;
|
|
38
|
+
};
|
|
39
|
+
export { bindKit, linked, moduleOf } from './link.ts';
|
|
39
40
|
export declare abstract class Carrier {
|
|
40
41
|
abstract carry(pk: string, bytes: Uint8Array): Promise<Uint8Array | null>;
|
|
41
42
|
}
|
|
@@ -17,17 +17,16 @@ export class Memory {
|
|
|
17
17
|
// secret a terrain holds.
|
|
18
18
|
export class Custody {
|
|
19
19
|
}
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
20
|
+
// Bytes become a module. A module's source is one self-contained ES
|
|
21
|
+
// module that imports nothing but `'nervur'`, and `id` is the git id of
|
|
22
|
+
// its blob, the one name a bundle finds it by. What does not load throws,
|
|
23
|
+
// saying why. How code runs differs by ground, an import of a data: URL,
|
|
24
|
+
// of a Blob URL, or a lookup in the bundle an edge was deployed with, so
|
|
25
|
+
// the loader is the one body beside the seed a terrain hands in that code
|
|
26
|
+
// passes through.
|
|
24
27
|
export class Loader {
|
|
25
|
-
// Why a name it found nothing under holds nothing, where it can say more
|
|
26
|
-
// than that: a bundle names that code comes from it alone.
|
|
27
|
-
missing(_from) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
28
|
}
|
|
29
|
+
export { bindKit, linked, moduleOf } from './link.js';
|
|
31
30
|
// Bytes to a ward pk in; bytes, or null for nothing, out. A harbor hands a
|
|
32
31
|
// terrain's carrier what it holds no route for; what it routes goes to its
|
|
33
32
|
// carrier faculties.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const KITS = 'org.nervur.kits';
|
|
2
|
+
const kits = () => {
|
|
3
|
+
const holder = globalThis;
|
|
4
|
+
return (holder[Symbol.for(KITS)] ??= new Map());
|
|
5
|
+
};
|
|
6
|
+
// This copy's token, the count of copies bound before it, since an edge
|
|
7
|
+
// draws no random bytes while its script loads.
|
|
8
|
+
let token;
|
|
9
|
+
// This copy's exports, as a module's `'nervur'` reads them.
|
|
10
|
+
export const bindKit = (kit) => {
|
|
11
|
+
const all = kits();
|
|
12
|
+
token ??= `kit${String(all.size)}`;
|
|
13
|
+
all.set(token, kit);
|
|
14
|
+
};
|
|
15
|
+
const IMPORT = /\bimport\s*(\{[^}]*\}|\*\s*as\s+[A-Za-z_$][\w$]*)\s*from\s*(['"])nervur\2\s*;?/g;
|
|
16
|
+
const OTHER = /(^|[\n;{}])\s*(import\s*[\w{*'"]|export\s*(\*|\{[^}]*\})\s*from\b)/;
|
|
17
|
+
// A module's source with its `'nervur'` imports read from this copy, or a
|
|
18
|
+
// throw where it imports anything else.
|
|
19
|
+
export const linked = (source) => {
|
|
20
|
+
if (token === undefined)
|
|
21
|
+
throw new Error('no kit is bound to link a module against');
|
|
22
|
+
const kit = `globalThis[Symbol.for(${JSON.stringify(KITS)})].get(${JSON.stringify(token)})`;
|
|
23
|
+
const out = source.replace(IMPORT, (_all, names) => {
|
|
24
|
+
if (names.startsWith('*'))
|
|
25
|
+
return `const ${names.replace(/^\*\s*as\s+/, '')} = ${kit};`;
|
|
26
|
+
const fields = names
|
|
27
|
+
.slice(1, -1)
|
|
28
|
+
.split(',')
|
|
29
|
+
.map((n) => n.trim())
|
|
30
|
+
.filter((n) => n !== '')
|
|
31
|
+
.map((n) => n.replace(/\s+as\s+/, ': '));
|
|
32
|
+
return `const { ${fields.join(', ')} } = ${kit};`;
|
|
33
|
+
});
|
|
34
|
+
if (OTHER.test(out))
|
|
35
|
+
throw new Error("a module imports nothing but 'nervur'");
|
|
36
|
+
return out;
|
|
37
|
+
};
|
|
38
|
+
// What a module's code exported, read as a module, or a throw saying what
|
|
39
|
+
// it lacks.
|
|
40
|
+
export const moduleOf = (exported) => {
|
|
41
|
+
const { module, version, classes } = (exported ?? {});
|
|
42
|
+
if (typeof module !== 'string' || typeof version !== 'string' || !Array.isArray(classes))
|
|
43
|
+
throw new Error('the code exports no module: module, version and classes');
|
|
44
|
+
return { module, version, classes };
|
|
45
|
+
};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Ed25519 signs, as RFC 8032 defines it,
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// Ed25519 signs, as RFC 8032 defines it, by `@noble/curves` in every
|
|
3
|
+
// engine, since an engine's Web Crypto may refuse a secret the curve takes,
|
|
4
|
+
// and verifies with the cofactorless check the spec names, which the
|
|
5
|
+
// library's own verify does not make. The decoding rules are held here:
|
|
5
6
|
//
|
|
6
7
|
// a signature of any length but sixty-four
|
|
7
8
|
// an `s` at or above the group order
|
|
8
9
|
// an `R` that does not decode, or whose bytes are not its point's encoding
|
|
9
10
|
// a public key that does not decode, or whose y is at or above the prime
|
|
10
11
|
// a public key of small order, in any spelling
|
|
11
|
-
import {
|
|
12
|
+
import { ed25519 } from '@noble/curves/ed25519.js';
|
|
13
|
+
import { concat } from './bytes.js';
|
|
14
|
+
import { own, subtle } from './subtle.js';
|
|
12
15
|
const P = 2n ** 255n - 19n;
|
|
13
16
|
const L = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
14
17
|
const mod = (a) => ((a % P) + P) % P;
|
|
@@ -63,8 +66,14 @@ const smallOrder = (p) => {
|
|
|
63
66
|
q = add(q, q);
|
|
64
67
|
return q.x === 0n && q.y === q.z;
|
|
65
68
|
};
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
const secretOf = (secret) => {
|
|
70
|
+
if (secret.length !== 32)
|
|
71
|
+
throw new TypeError('a secret is thirty-two bytes');
|
|
72
|
+
return secret;
|
|
73
|
+
};
|
|
74
|
+
export const ed25519Public = async (secret) => ed25519.getPublicKey(secretOf(secret));
|
|
75
|
+
export const sign = async (secret, message) => ed25519.sign(message, secretOf(secret));
|
|
76
|
+
// The cofactorless check, `[s]B = R + [k]A`, on points decoded as above.
|
|
68
77
|
export const verify = async (pk, message, signature) => {
|
|
69
78
|
if (signature.length !== 64)
|
|
70
79
|
return false;
|
|
@@ -73,13 +82,12 @@ export const verify = async (pk, message, signature) => {
|
|
|
73
82
|
return false;
|
|
74
83
|
if (decode(signature.subarray(0, 32)) === null)
|
|
75
84
|
return false;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const imported = await subtle().importKey('raw', own(pk), { name: 'Ed25519' }, false, ['verify']);
|
|
80
|
-
return await subtle().verify('Ed25519', imported, own(signature), own(message));
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
85
|
+
const s = little(signature.subarray(32));
|
|
86
|
+
if (s >= L)
|
|
83
87
|
return false;
|
|
84
|
-
|
|
88
|
+
const R = ed25519.Point.fromBytes(signature.subarray(0, 32));
|
|
89
|
+
const A = ed25519.Point.fromBytes(pk);
|
|
90
|
+
const hashed = new Uint8Array(await subtle().digest('SHA-512', own(concat(signature.subarray(0, 32), pk, message))));
|
|
91
|
+
const k = little(hashed) % L;
|
|
92
|
+
return ed25519.Point.BASE.multiplyUnsafe(s).equals(R.add(A.multiplyUnsafe(k)));
|
|
85
93
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Web Crypto, read at every use. A page on a plain http origin has `crypto`
|
|
3
|
+
// without `subtle`, and a terrain may install it after this module loads.
|
|
4
|
+
export const subtle = () => {
|
|
5
|
+
const found = globalThis.crypto?.subtle;
|
|
6
|
+
if (!found)
|
|
7
|
+
throw new Error('this terrain has no crypto.subtle: a ward needs a secure context');
|
|
8
|
+
return found;
|
|
9
|
+
};
|
|
10
|
+
// Web Crypto takes a buffer it owns, so every input is copied into one.
|
|
11
|
+
export const own = (bytes) => Uint8Array.from(bytes);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// X25519 agrees, by `@noble/curves` in every engine, since an engine's Web
|
|
3
|
+
// Crypto may refuse a secret the curve takes. A secret is thirty-two bytes,
|
|
4
|
+
// clamped by the function and never before.
|
|
5
|
+
import { x25519 } from '@noble/curves/ed25519.js';
|
|
6
|
+
import { zero } from './bytes.js';
|
|
7
|
+
export const x25519Public = async (secret) => {
|
|
8
|
+
if (secret.length !== 32)
|
|
9
|
+
throw new TypeError('a secret is thirty-two bytes');
|
|
10
|
+
return x25519.getPublicKey(secret);
|
|
11
|
+
};
|
|
12
|
+
// The agreement, or null for a public key that takes no seal: one whose
|
|
13
|
+
// agreement is thirty-two zero bytes.
|
|
14
|
+
export const agree = async (secret, pk) => {
|
|
15
|
+
if (pk.length !== 32 || secret.length !== 32)
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
const shared = x25519.getSharedSecret(secret, pk);
|
|
19
|
+
return zero(shared) ? null : shared;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Custody, Loader, Memory, type Entropy, type Module } from '../contract/index.ts';
|
|
2
|
+
import { type Carried, type Defaults, type Dialed, type GroundProbe, type Sockets, type TcpListening, type WebListen } from '../harbor/index.ts';
|
|
3
|
+
import { PointerTerrain } from '../pointer/index.ts';
|
|
4
|
+
export type { Carried } from '../harbor/index.ts';
|
|
5
|
+
export declare const EDGE = "edge";
|
|
6
|
+
export interface EdgeStorage {
|
|
7
|
+
get(key: string): Promise<unknown>;
|
|
8
|
+
put(entries: Record<string, unknown>): Promise<void>;
|
|
9
|
+
delete(keys: string[]): Promise<number>;
|
|
10
|
+
list(options: {
|
|
11
|
+
prefix: string;
|
|
12
|
+
}): Promise<Map<string, unknown>>;
|
|
13
|
+
transaction<T>(work: (txn: EdgeStorage) => Promise<T>): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
export interface EdgeState {
|
|
16
|
+
readonly storage: EdgeStorage;
|
|
17
|
+
blockConcurrencyWhile<T>(work: () => Promise<T>): Promise<T>;
|
|
18
|
+
}
|
|
19
|
+
export type EdgeEnv = {
|
|
20
|
+
readonly NERVUR_SECRET?: string;
|
|
21
|
+
};
|
|
22
|
+
export type EdgeGiven = {
|
|
23
|
+
readonly state: EdgeState;
|
|
24
|
+
readonly env: EdgeEnv;
|
|
25
|
+
readonly loader?: EdgeLoader;
|
|
26
|
+
readonly calls?: ChildCalls;
|
|
27
|
+
readonly package?: Packed;
|
|
28
|
+
};
|
|
29
|
+
export type CarriedModule = {
|
|
30
|
+
readonly blob: string;
|
|
31
|
+
readonly module: unknown;
|
|
32
|
+
};
|
|
33
|
+
export type CallContext = {
|
|
34
|
+
run<R>(call: number, work: () => R): R;
|
|
35
|
+
getStore(): number | undefined;
|
|
36
|
+
};
|
|
37
|
+
export declare class ChildCalls {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(context?: CallContext);
|
|
40
|
+
run<R>(call: number, work: () => R): R;
|
|
41
|
+
refused(): void;
|
|
42
|
+
kept(): void;
|
|
43
|
+
again(call: number): boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare class EdgeLoader extends Loader {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(carried?: readonly CarriedModule[], calls?: ChildCalls);
|
|
48
|
+
get carried(): string[];
|
|
49
|
+
refuse(refused: Readonly<Record<string, string>>): void;
|
|
50
|
+
get refused(): ReadonlyMap<string, string>;
|
|
51
|
+
load(source: string, id: string): Promise<Module>;
|
|
52
|
+
get missing(): boolean;
|
|
53
|
+
missed(): Map<string, string>;
|
|
54
|
+
}
|
|
55
|
+
export type Packed = {
|
|
56
|
+
readonly sealed: string;
|
|
57
|
+
readonly places: Carried['places'];
|
|
58
|
+
};
|
|
59
|
+
export type Pack = Record<string, Packed>;
|
|
60
|
+
export declare const isHarborName: (name: unknown) => name is string;
|
|
61
|
+
export declare const readPack: (value: unknown) => Pack | null;
|
|
62
|
+
export declare const sealSeed: (secret: string, seed: Uint8Array, entropy?: Entropy) => Promise<string>;
|
|
63
|
+
export declare class EdgeMemory extends Memory {
|
|
64
|
+
#private;
|
|
65
|
+
constructor(storage: EdgeStorage, root?: string, voided?: () => boolean, calls?: ChildCalls);
|
|
66
|
+
read(place: string): Promise<Map<string, Uint8Array>>;
|
|
67
|
+
write(place: string, entries: ReadonlyMap<string, Uint8Array | null>): Promise<void>;
|
|
68
|
+
places(): Promise<string[]>;
|
|
69
|
+
forget(place: string): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
export declare class EdgeCustody extends Custody {
|
|
72
|
+
#private;
|
|
73
|
+
constructor(storage: EdgeStorage, secret: string | undefined, entropy?: Entropy, root?: string);
|
|
74
|
+
kept(): Promise<boolean>;
|
|
75
|
+
land(sealed: string, txn?: EdgeStorage): Promise<void>;
|
|
76
|
+
seed(): Promise<Uint8Array>;
|
|
77
|
+
}
|
|
78
|
+
export declare class EdgeSockets implements Sockets {
|
|
79
|
+
#private;
|
|
80
|
+
dial(address: string, pk: string, bytes: Uint8Array): Promise<Dialed>;
|
|
81
|
+
listen(): Promise<TcpListening>;
|
|
82
|
+
close(): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export type EdgeParts = {
|
|
85
|
+
readonly given: EdgeGiven;
|
|
86
|
+
readonly defaults: Defaults;
|
|
87
|
+
};
|
|
88
|
+
export declare class EdgeTerrain extends PointerTerrain {
|
|
89
|
+
#private;
|
|
90
|
+
readonly given: EdgeGiven;
|
|
91
|
+
constructor(parts: EdgeParts);
|
|
92
|
+
get listening(): WebListen | undefined;
|
|
93
|
+
claim(): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
export declare const edgeGround: GroundProbe;
|
|
96
|
+
export declare const harborNameOf: (request: Request) => string | null;
|
|
97
|
+
export type Wanted = {
|
|
98
|
+
readonly live: string;
|
|
99
|
+
readonly liveBlobs: readonly string[];
|
|
100
|
+
readonly modules: Readonly<Record<string, string>>;
|
|
101
|
+
readonly missed: readonly string[];
|
|
102
|
+
};
|
|
103
|
+
export type Opened = {
|
|
104
|
+
readonly listen: WebListen | null;
|
|
105
|
+
readonly wanted: Wanted | null;
|
|
106
|
+
};
|
|
107
|
+
export type Arrived = {
|
|
108
|
+
readonly reply: Uint8Array | null;
|
|
109
|
+
readonly wanted: Wanted | null;
|
|
110
|
+
readonly again: boolean;
|
|
111
|
+
};
|
|
112
|
+
export declare const childKey: (live: string, blobs: readonly string[], liveBlobs: readonly string[]) => string;
|
|
113
|
+
export declare class HarborChild {
|
|
114
|
+
#private;
|
|
115
|
+
constructor(state: EdgeState, env: EdgeEnv, key: string, carried: readonly CarriedModule[], context: CallContext);
|
|
116
|
+
open(name: string, host: string, port: number, packed: Packed | null, refused: Readonly<Record<string, string>>): Promise<Opened>;
|
|
117
|
+
arrive(pk: string, box: Uint8Array, call: number): Promise<Arrived>;
|
|
118
|
+
}
|
|
119
|
+
type WorkerCode = {
|
|
120
|
+
readonly compatibilityDate: string;
|
|
121
|
+
readonly compatibilityFlags?: readonly string[];
|
|
122
|
+
readonly mainModule: string;
|
|
123
|
+
readonly modules: Record<string, {
|
|
124
|
+
js: string;
|
|
125
|
+
}>;
|
|
126
|
+
readonly env: Record<string, unknown>;
|
|
127
|
+
};
|
|
128
|
+
type LoadedWorker = {
|
|
129
|
+
getDurableObjectClass(name: string): unknown;
|
|
130
|
+
getEntrypoint(): {
|
|
131
|
+
fetch(request: Request): Promise<Response>;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export type WorkerLoader = {
|
|
135
|
+
get(id: string, code: () => Promise<WorkerCode>): LoadedWorker;
|
|
136
|
+
};
|
|
137
|
+
type ChildStub = {
|
|
138
|
+
open(name: string, host: string, port: number, packed: Packed | null, refused: Record<string, string>): Promise<Opened>;
|
|
139
|
+
arrive(pk: string, box: Uint8Array, call: number): Promise<Arrived>;
|
|
140
|
+
};
|
|
141
|
+
type Facets = {
|
|
142
|
+
get(name: string, start: () => Promise<{
|
|
143
|
+
class: unknown;
|
|
144
|
+
}>): ChildStub;
|
|
145
|
+
abort(name: string, reason: unknown): void;
|
|
146
|
+
};
|
|
147
|
+
export type ShellState = {
|
|
148
|
+
readonly facets: Facets;
|
|
149
|
+
};
|
|
150
|
+
export type ShellEnv = EdgeEnv & {
|
|
151
|
+
readonly LOADER?: WorkerLoader;
|
|
152
|
+
};
|
|
153
|
+
export type HarborShellParts = {
|
|
154
|
+
readonly kit: string;
|
|
155
|
+
readonly pack: Pack | ((env: EdgeEnv) => Pack | undefined);
|
|
156
|
+
};
|
|
157
|
+
export type HarborShell = {
|
|
158
|
+
fetch(request: Request): Promise<Response>;
|
|
159
|
+
};
|
|
160
|
+
export type HarborShellClass = new (state: ShellState, env: ShellEnv) => HarborShell;
|
|
161
|
+
export declare const harborShell: ({ kit, pack }: HarborShellParts) => HarborShellClass;
|
|
162
|
+
export declare const harborWorker: (binding?: string) => {
|
|
163
|
+
fetch(request: Request, env: Record<string, unknown>): Promise<Response>;
|
|
164
|
+
};
|