nervur 0.19.2 → 0.20.1

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.
Files changed (235) hide show
  1. package/README.md +156 -104
  2. package/dist/being/being.d.ts +8 -15
  3. package/dist/being/being.js +20 -67
  4. package/dist/being/digest.d.ts +1 -1
  5. package/dist/being/digest.js +7 -27
  6. package/dist/being/faculty.d.ts +10 -0
  7. package/dist/being/faculty.js +74 -0
  8. package/dist/being/index.d.ts +5 -5
  9. package/dist/being/index.js +6 -5
  10. package/dist/being/kind.d.ts +4 -0
  11. package/dist/being/kind.js +28 -0
  12. package/dist/being/types.d.ts +35 -63
  13. package/dist/being/types.js +3 -57
  14. package/dist/being/words.d.ts +13 -0
  15. package/dist/being/words.js +14 -0
  16. package/dist/cli/command.d.ts +13 -0
  17. package/dist/cli/command.js +194 -0
  18. package/dist/cli/harbor.d.ts +21 -0
  19. package/dist/cli/harbor.js +141 -0
  20. package/dist/cli/main.d.ts +2 -0
  21. package/dist/cli/main.js +14 -0
  22. package/dist/contract/index.d.ts +39 -0
  23. package/dist/contract/index.js +33 -0
  24. package/dist/crypto/aes.d.ts +3 -0
  25. package/dist/crypto/aes.js +24 -0
  26. package/dist/crypto/bytes.d.ts +6 -0
  27. package/dist/crypto/bytes.js +33 -0
  28. package/dist/crypto/ed25519.d.ts +3 -0
  29. package/dist/crypto/ed25519.js +85 -0
  30. package/dist/crypto/hash.d.ts +2 -0
  31. package/dist/crypto/hash.js +11 -0
  32. package/dist/crypto/index.d.ts +7 -0
  33. package/dist/crypto/index.js +10 -0
  34. package/dist/crypto/json.d.ts +8 -0
  35. package/dist/crypto/json.js +250 -0
  36. package/dist/crypto/mlkem.d.ts +12 -0
  37. package/dist/crypto/mlkem.js +36 -0
  38. package/dist/crypto/subtle.d.ts +10 -0
  39. package/dist/crypto/subtle.js +29 -0
  40. package/dist/crypto/x25519.d.ts +2 -0
  41. package/dist/crypto/x25519.js +21 -0
  42. package/dist/folder/index.d.ts +14 -0
  43. package/dist/folder/index.js +87 -0
  44. package/dist/harbor/catalogue.d.ts +25 -0
  45. package/dist/harbor/catalogue.js +93 -0
  46. package/dist/harbor/dock.d.ts +29 -0
  47. package/dist/harbor/dock.js +122 -0
  48. package/dist/harbor/harbor.d.ts +31 -0
  49. package/dist/harbor/harbor.js +146 -0
  50. package/dist/harbor/index.d.ts +7 -10
  51. package/dist/harbor/index.js +9 -18
  52. package/dist/harbor/package.d.ts +10 -0
  53. package/dist/harbor/package.js +115 -0
  54. package/dist/harbor/registry.d.ts +9 -0
  55. package/dist/harbor/registry.js +78 -0
  56. package/dist/harbor/root-line.d.ts +9 -0
  57. package/dist/harbor/root-line.js +36 -0
  58. package/dist/harbor/terrain.d.ts +9 -0
  59. package/dist/harbor/terrain.js +2 -0
  60. package/dist/index.d.ts +7 -0
  61. package/dist/index.js +14 -0
  62. package/dist/pointer/bodies.d.ts +26 -0
  63. package/dist/pointer/bodies.js +64 -0
  64. package/dist/pointer/index.d.ts +2 -0
  65. package/dist/pointer/index.js +4 -0
  66. package/dist/pointer/world.d.ts +35 -0
  67. package/dist/pointer/world.js +85 -0
  68. package/dist/quo/door.d.ts +34 -0
  69. package/dist/quo/door.js +172 -0
  70. package/dist/quo/index.d.ts +8 -0
  71. package/dist/quo/index.js +11 -0
  72. package/dist/quo/invitation.d.ts +7 -0
  73. package/dist/quo/invitation.js +15 -0
  74. package/dist/quo/keys.d.ts +40 -0
  75. package/dist/quo/keys.js +79 -0
  76. package/dist/quo/payload.d.ts +15 -0
  77. package/dist/quo/payload.js +55 -0
  78. package/dist/quo/relations.d.ts +40 -0
  79. package/dist/quo/relations.js +33 -0
  80. package/dist/quo/reply.d.ts +13 -0
  81. package/dist/quo/reply.js +35 -0
  82. package/dist/quo/seal.d.ts +42 -0
  83. package/dist/quo/seal.js +78 -0
  84. package/dist/quo/standing.d.ts +39 -0
  85. package/dist/quo/standing.js +90 -0
  86. package/dist/tcp/frame.d.ts +29 -0
  87. package/dist/tcp/frame.js +74 -0
  88. package/dist/tcp/index.d.ts +18 -0
  89. package/dist/tcp/index.js +164 -0
  90. package/dist/ward/allowance.d.ts +13 -9
  91. package/dist/ward/allowance.js +28 -67
  92. package/dist/ward/cells.d.ts +6 -6
  93. package/dist/ward/cells.js +67 -179
  94. package/dist/ward/index.d.ts +6 -10
  95. package/dist/ward/index.js +7 -13
  96. package/dist/ward/partition.d.ts +44 -60
  97. package/dist/ward/partition.js +56 -285
  98. package/dist/ward/pilot.d.ts +8 -0
  99. package/dist/ward/pilot.js +50 -0
  100. package/dist/ward/stance.d.ts +27 -20
  101. package/dist/ward/stance.js +174 -406
  102. package/dist/ward/ward-being.d.ts +35 -0
  103. package/dist/ward/ward-being.js +82 -0
  104. package/dist/ward/ward.d.ts +45 -11
  105. package/dist/ward/ward.js +239 -357
  106. package/package.json +24 -31
  107. package/src/being/being.ts +35 -78
  108. package/src/being/digest.ts +7 -35
  109. package/src/being/faculty.ts +73 -0
  110. package/src/being/index.ts +6 -6
  111. package/src/being/kind.ts +30 -0
  112. package/src/being/types.ts +50 -146
  113. package/src/being/words.ts +31 -0
  114. package/src/cli/command.ts +188 -0
  115. package/src/cli/harbor.ts +137 -0
  116. package/src/cli/main.ts +13 -0
  117. package/src/contract/index.ts +73 -0
  118. package/src/crypto/aes.ts +26 -0
  119. package/src/crypto/bytes.ts +37 -0
  120. package/src/crypto/ed25519.ts +84 -0
  121. package/src/crypto/hash.ts +14 -0
  122. package/src/crypto/index.ts +10 -0
  123. package/src/crypto/json.ts +241 -0
  124. package/src/crypto/mlkem.ts +38 -0
  125. package/src/crypto/subtle.ts +33 -0
  126. package/src/crypto/x25519.ts +21 -0
  127. package/src/folder/index.ts +92 -0
  128. package/src/harbor/catalogue.ts +110 -0
  129. package/src/harbor/dock.ts +137 -0
  130. package/src/harbor/harbor.ts +180 -0
  131. package/src/harbor/index.ts +9 -19
  132. package/src/harbor/package.ts +131 -0
  133. package/src/harbor/registry.ts +73 -0
  134. package/src/harbor/root-line.ts +36 -0
  135. package/src/harbor/terrain.ts +15 -0
  136. package/src/index.ts +20 -0
  137. package/src/pointer/bodies.ts +65 -0
  138. package/src/pointer/index.ts +4 -0
  139. package/src/pointer/world.ts +94 -0
  140. package/src/quo/door.ts +178 -0
  141. package/src/quo/index.ts +11 -0
  142. package/src/quo/invitation.ts +15 -0
  143. package/src/quo/keys.ts +91 -0
  144. package/src/quo/payload.ts +61 -0
  145. package/src/quo/relations.ts +62 -0
  146. package/src/quo/reply.ts +38 -0
  147. package/src/quo/seal.ts +101 -0
  148. package/src/quo/standing.ts +111 -0
  149. package/src/stand/main.ts +20 -0
  150. package/src/stand/stand.ts +220 -0
  151. package/src/tcp/frame.ts +78 -0
  152. package/src/tcp/index.ts +173 -0
  153. package/src/ward/allowance.ts +37 -75
  154. package/src/ward/cells.ts +63 -176
  155. package/src/ward/index.ts +7 -17
  156. package/src/ward/partition.ts +86 -326
  157. package/src/ward/pilot.ts +50 -0
  158. package/src/ward/stance.ts +186 -420
  159. package/src/ward/ward-being.ts +103 -0
  160. package/src/ward/ward.ts +256 -359
  161. package/dist/being/lent.d.ts +0 -32
  162. package/dist/being/lent.js +0 -72
  163. package/dist/being/silence.d.ts +0 -12
  164. package/dist/being/silence.js +0 -41
  165. package/dist/conformance/assert.d.ts +0 -11
  166. package/dist/conformance/assert.js +0 -106
  167. package/dist/conformance/beings.d.ts +0 -199
  168. package/dist/conformance/beings.js +0 -188
  169. package/dist/conformance/estate.d.ts +0 -5
  170. package/dist/conformance/estate.js +0 -388
  171. package/dist/conformance/index.d.ts +0 -80
  172. package/dist/conformance/index.js +0 -819
  173. package/dist/conformance/reach.d.ts +0 -10
  174. package/dist/conformance/reach.js +0 -72
  175. package/dist/conformance/store.d.ts +0 -5
  176. package/dist/conformance/store.js +0 -113
  177. package/dist/harbor/box.d.ts +0 -121
  178. package/dist/harbor/box.js +0 -121
  179. package/dist/harbor/core.d.ts +0 -55
  180. package/dist/harbor/core.js +0 -662
  181. package/dist/harbor/dial.d.ts +0 -9
  182. package/dist/harbor/dial.js +0 -81
  183. package/dist/harbor/memory.d.ts +0 -29
  184. package/dist/harbor/memory.js +0 -104
  185. package/dist/harbor/reach.d.ts +0 -36
  186. package/dist/harbor/reach.js +0 -199
  187. package/dist/harbor/store.d.ts +0 -35
  188. package/dist/harbor/store.js +0 -62
  189. package/dist/vector/cases.d.ts +0 -42
  190. package/dist/vector/cases.js +0 -223
  191. package/dist/vector/index.d.ts +0 -6
  192. package/dist/vector/index.js +0 -8
  193. package/dist/vector/stand.d.ts +0 -9
  194. package/dist/vector/stand.js +0 -77
  195. package/dist/vector/world.d.ts +0 -144
  196. package/dist/vector/world.js +0 -209
  197. package/dist/ward/arithmetic.d.ts +0 -31
  198. package/dist/ward/arithmetic.js +0 -249
  199. package/dist/ward/door.d.ts +0 -18
  200. package/dist/ward/door.js +0 -186
  201. package/dist/ward/ground.d.ts +0 -29
  202. package/dist/ward/ground.js +0 -56
  203. package/dist/ward/heirs.d.ts +0 -13
  204. package/dist/ward/heirs.js +0 -117
  205. package/dist/ward/json.d.ts +0 -2
  206. package/dist/ward/json.js +0 -163
  207. package/dist/ward/owner.d.ts +0 -13
  208. package/dist/ward/owner.js +0 -220
  209. package/dist/ward/seal.d.ts +0 -52
  210. package/dist/ward/seal.js +0 -150
  211. package/src/being/lent.ts +0 -72
  212. package/src/being/silence.ts +0 -46
  213. package/src/conformance/assert.ts +0 -100
  214. package/src/conformance/beings.ts +0 -188
  215. package/src/conformance/estate.ts +0 -412
  216. package/src/conformance/index.ts +0 -965
  217. package/src/conformance/reach.ts +0 -83
  218. package/src/conformance/store.ts +0 -125
  219. package/src/harbor/box.ts +0 -131
  220. package/src/harbor/core.ts +0 -699
  221. package/src/harbor/dial.ts +0 -112
  222. package/src/harbor/memory.ts +0 -123
  223. package/src/harbor/reach.ts +0 -221
  224. package/src/harbor/store.ts +0 -91
  225. package/src/vector/cases.ts +0 -257
  226. package/src/vector/index.ts +0 -11
  227. package/src/vector/stand.ts +0 -76
  228. package/src/vector/world.ts +0 -232
  229. package/src/ward/arithmetic.ts +0 -251
  230. package/src/ward/door.ts +0 -186
  231. package/src/ward/ground.ts +0 -142
  232. package/src/ward/heirs.ts +0 -116
  233. package/src/ward/json.ts +0 -144
  234. package/src/ward/owner.ts +0 -214
  235. package/src/ward/seal.ts +0 -178
@@ -0,0 +1,115 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The package: a harbor's memory, sealed under the harbor's seed. The
3
+ // terrain keeps its bytes and reads neither a ward's name, nor a being's
4
+ // key, nor anything a row holds.
5
+ //
6
+ // key HKDF-SHA-256 of the seed under `nervur-package`
7
+ // place 16 bytes under ["place", ward], as hex
8
+ // entry 16 bytes under ["entry", ward, row], as hex
9
+ // seal 32 bytes under ["seal", ward]
10
+ // entry bytes nonce (12) || AES-256-GCM( JSON { row, value } ),
11
+ // the entry's name as additional data
12
+ //
13
+ // A row is the head, under the empty name, or one being, under her key. An
14
+ // entry that does not open refuses the whole ward, so nothing unpacks from
15
+ // bytes the package did not seal.
16
+ import { concat, decrypt, encrypt, hex, hkdf, utf8 } from '../crypto/index.js';
17
+ import { HEAD_ROW } from '../ward/index.js';
18
+ const NONCE = 12;
19
+ const LABEL = utf8('nervur-package');
20
+ class PackageRows {
21
+ rows;
22
+ #ward;
23
+ #told = new Set();
24
+ #line = Promise.resolve(true);
25
+ constructor(ward, rows) {
26
+ this.#ward = ward;
27
+ this.rows = rows;
28
+ }
29
+ told(row) {
30
+ this.#told.add(row);
31
+ }
32
+ // Every row told since the last keep, sealed and written as one keep, one
33
+ // keep at a time.
34
+ kept() {
35
+ const rows = [...this.#told];
36
+ this.#told.clear();
37
+ this.#line = this.#line.then(() => this.#write(rows)).catch(() => false);
38
+ return this.#line;
39
+ }
40
+ async #write(told) {
41
+ const beings = (this.rows.beings ?? {});
42
+ const entries = new Map();
43
+ for (const row of told) {
44
+ const value = row === HEAD_ROW ? (this.rows.ward ?? null) : Object.hasOwn(beings, row) ? beings[row] : undefined;
45
+ entries.set(await this.#ward.entry(row), value === undefined ? null : await this.#ward.seal(row, value));
46
+ }
47
+ await this.#ward.write(entries);
48
+ return true;
49
+ }
50
+ }
51
+ class Ward {
52
+ #pack;
53
+ #name;
54
+ #seal;
55
+ place;
56
+ constructor(pack, name, seal, place) {
57
+ this.#pack = pack;
58
+ this.#name = name;
59
+ this.#seal = seal;
60
+ this.place = place;
61
+ }
62
+ entry(row) {
63
+ return this.#pack.derive(['entry', this.#name, row], 16).then(hex);
64
+ }
65
+ async seal(row, value) {
66
+ const nonce = this.#pack.entropy.draw(NONCE);
67
+ const text = utf8(JSON.stringify({ row, value }));
68
+ return concat(nonce, await encrypt(this.#seal, nonce, utf8(await this.entry(row)), text));
69
+ }
70
+ // The name is the additional data, so an entry moved under another name
71
+ // does not open either.
72
+ async open(name, bytes) {
73
+ const text = bytes.length > NONCE ? await decrypt(this.#seal, bytes.subarray(0, NONCE), utf8(name), bytes.subarray(NONCE)) : null;
74
+ if (text === null)
75
+ throw new Error('an entry the package did not seal');
76
+ return JSON.parse(new TextDecoder().decode(text));
77
+ }
78
+ write(entries) {
79
+ return this.#pack.memory.write(this.place, entries);
80
+ }
81
+ }
82
+ export class Package {
83
+ memory;
84
+ entropy;
85
+ #key;
86
+ constructor(memory, entropy, key) {
87
+ this.memory = memory;
88
+ this.entropy = entropy;
89
+ this.#key = key;
90
+ }
91
+ static async open(memory, entropy, seed) {
92
+ return new Package(memory, entropy, await hkdf(seed, LABEL, 32));
93
+ }
94
+ derive(info, length) {
95
+ return hkdf(this.#key, utf8(JSON.stringify(info)), length);
96
+ }
97
+ // One ward's rows, as the package kept them.
98
+ async rows(name) {
99
+ const ward = new Ward(this, name, await this.derive(['seal', name], 32), hex(await this.derive(['place', name], 16)));
100
+ const rows = {};
101
+ const beings = {};
102
+ let any = false;
103
+ for (const [entry, bytes] of await this.memory.read(ward.place)) {
104
+ const { row, value } = await ward.open(entry, bytes);
105
+ any = true;
106
+ if (row === HEAD_ROW)
107
+ rows.ward = value;
108
+ else
109
+ beings[row] = value;
110
+ }
111
+ if (any)
112
+ rows.beings = beings;
113
+ return new PackageRows(ward, rows);
114
+ }
115
+ }
@@ -0,0 +1,9 @@
1
+ import { type BeingClass } from '../being/index.ts';
2
+ import type { Module } from '../contract/index.ts';
3
+ import type { Catalogue } from '../ward/index.ts';
4
+ export declare class Registry implements Catalogue {
5
+ #private;
6
+ constructor(kit: readonly BeingClass[], modules: readonly Module[]);
7
+ classOf(kind: string): BeingClass | undefined;
8
+ kindsOf(module: string): string[];
9
+ }
@@ -0,0 +1,78 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The catalogue's index: every kind the harbor runs, from the kit's own
3
+ // classes and the modules the catalogue loaded. It resolves a kind a row
4
+ // keeps, and decides nothing about what stands. It refuses any set of
5
+ // modules two readings could split:
6
+ //
7
+ // a module whose name is no kind, or is the kit's, or two of one name
8
+ // a class with no kind of its own, or one outside its module's domain
9
+ // two classes of one kind, or one kind in two modules
10
+ // a contract with no kind of its own, or one kind for two contracts
11
+ // a kind that is a class and a contract
12
+ //
13
+ // A module's domain is its name's first two segments: `com.acme.shop`
14
+ // stands classes under `com.acme.` alone. A contract may be any domain's,
15
+ // so a faculty fulfils a contract another module declares. Two harbors hold
16
+ // two registries, and nothing between them names a class.
17
+ import { Faculty, isKind, KIT, kindOf } from '../being/index.js';
18
+ const domainOf = (name) => `${name.split('.').slice(0, 2).join('.')}.`;
19
+ export class Registry {
20
+ #classes = new Map();
21
+ #modules = new Map();
22
+ // `kit` holds the kit's own classes, which alone may be of its kinds.
23
+ constructor(kit, modules) {
24
+ const contracts = new Map();
25
+ const owners = new Map();
26
+ const add = (C, kind) => {
27
+ if (this.#classes.has(kind) && this.#classes.get(kind) !== C)
28
+ throw new Error(`two classes are of kind ${kind}`);
29
+ this.#classes.set(kind, C);
30
+ };
31
+ for (const C of kit)
32
+ add(C, kindOf(C));
33
+ for (const m of modules) {
34
+ if (!isKind(m.module) || m.module.startsWith(KIT))
35
+ throw new Error(`module ${String(m.module)} is no name a module may take`);
36
+ if (this.#modules.has(m.module))
37
+ throw new Error(`two modules are named ${m.module}`);
38
+ if (typeof m.version !== 'string' || m.version === '')
39
+ throw new Error(`module ${m.module} declares no version`);
40
+ const kinds = [];
41
+ for (const C of m.classes) {
42
+ if (typeof C !== 'function')
43
+ throw new Error(`module ${m.module} holds something that is no class`);
44
+ const kind = kindOf(C);
45
+ if (!kind.startsWith(domainOf(m.module)))
46
+ throw new Error(`kind ${kind} is outside module ${m.module}`);
47
+ const owner = owners.get(kind);
48
+ if (owner !== undefined && owner !== m.module)
49
+ throw new Error(`kind ${kind} is in modules ${owner} and ${m.module}`);
50
+ owners.set(kind, m.module);
51
+ add(C, kind);
52
+ kinds.push(kind);
53
+ if (!Faculty.fulfils(C))
54
+ continue;
55
+ for (let c = Object.getPrototypeOf(C); c !== Faculty; c = Object.getPrototypeOf(c)) {
56
+ const contract = kindOf(c);
57
+ if (contract.startsWith(KIT))
58
+ throw new Error(`kind ${contract} is the kit's`);
59
+ if (contracts.has(contract) && contracts.get(contract) !== c)
60
+ throw new Error(`two contracts are of kind ${contract}`);
61
+ contracts.set(contract, c);
62
+ }
63
+ }
64
+ this.#modules.set(m.module, kinds);
65
+ }
66
+ for (const kind of contracts.keys()) {
67
+ if (this.#classes.has(kind))
68
+ throw new Error(`kind ${kind} is a class and a contract`);
69
+ }
70
+ }
71
+ classOf(kind) {
72
+ return this.#classes.get(kind);
73
+ }
74
+ // The kinds a module stands, or none.
75
+ kindsOf(module) {
76
+ return [...(this.#modules.get(module) ?? [])];
77
+ }
78
+ }
@@ -0,0 +1,9 @@
1
+ import { type JsonObject } from '../being/index.ts';
2
+ import type { Harbor } from './harbor.ts';
3
+ export type RootRequest = {
4
+ ward?: string;
5
+ method?: string;
6
+ args?: JsonObject;
7
+ };
8
+ export declare const readRootRequest: (value: unknown) => RootRequest | null;
9
+ export declare const rootLine: (harbor: Harbor, value: unknown) => Promise<JsonObject>;
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The root line: one request, one answer, both plain JSON, for whatever
3
+ // carries the root's asks to a harbor in its own process. The command line
4
+ // carries it over a local socket, and an edge route carries it the same way.
5
+ //
6
+ // request { ward?, method?, args? } no ward is the box ward, no
7
+ // method the census
8
+ // answer { answer } what the ward-being said
9
+ // { silence: true } she said nothing
10
+ // { word } a kit word: unreached, late, ...
11
+ // { error } the request was not one, or the
12
+ // ward is none this harbor holds
13
+ import { isSilence, isWord, told } from '../being/index.js';
14
+ const object = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
15
+ export const readRootRequest = (value) => {
16
+ if (!object(value))
17
+ return null;
18
+ const { ward, method, args } = value;
19
+ if ((ward !== undefined && typeof ward !== 'string') || (method !== undefined && typeof method !== 'string') || (args !== undefined && !object(args)))
20
+ return null;
21
+ return { ...(ward === undefined ? {} : { ward }), ...(method === undefined ? {} : { method }), ...(args === undefined ? {} : { args }) };
22
+ };
23
+ export const rootLine = async (harbor, value) => {
24
+ const request = readRootRequest(value);
25
+ if (request === null)
26
+ return { error: 'not a root request' };
27
+ const ward = request.ward === undefined ? harbor.box : harbor.ward(request.ward);
28
+ if (ward === undefined)
29
+ return { error: 'no such ward' };
30
+ const out = await ward.root(request.method, request.args);
31
+ if (isSilence(out))
32
+ return { silence: true };
33
+ if (isWord(out))
34
+ return { word: told(out) };
35
+ return { answer: out };
36
+ };
@@ -0,0 +1,9 @@
1
+ import type { Carrier, Clock, Custody, Entropy, Loader, Memory } from '../contract/index.ts';
2
+ export declare abstract class Terrain {
3
+ abstract readonly entropy: Entropy;
4
+ abstract readonly clock: Clock;
5
+ abstract readonly custody: Custody;
6
+ abstract readonly memory: Memory;
7
+ abstract readonly loader: Loader;
8
+ abstract readonly carrier: Carrier;
9
+ }
@@ -0,0 +1,2 @@
1
+ export class Terrain {
2
+ }
@@ -0,0 +1,7 @@
1
+ export { Being, canonical, digest, Faculty, isSilence, isWord, OWNER, silence, told, WARD, word } from './being/index.ts';
2
+ export type { Answer, Ask, Asker, AskSpec, BeingClass, BeingLike, Blueprint, Invitation, Json, JsonObject, Occupants, Reply, Schema, Silence, Stance, Standing, Standings, Wanted, Word, WordName } from './being/index.ts';
3
+ export { readInvitation } from './quo/index.ts';
4
+ export { Carrier, Clock, Custody, Entropy, Loader, Memory, type Loaded, type Module, type Rows } from './contract/index.ts';
5
+ export { CEILING, DEFAULT, DEPTH, ownerAsk, Pilot, pilots, WardBeing, type Steward, type WardBeingStance } from './ward/index.ts';
6
+ export { BOX, Catalogue, Dock, Harbor, readRootRequest, Registry, rootLine, Terrain, type RootRequest } from './harbor/index.ts';
7
+ export { CryptoEntropy, HeldCustody, HeldLoader, NoCarrier, PointerCarrier, PointerTerrain, SystemClock, VolatileMemory, World, type PointerParts } from './pointer/index.ts';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // `nervur`: what a stranger writes a world with. It imports no platform, so
3
+ // it runs wherever JavaScript runs. A disk is `nervur/folder`.
4
+ // Beings, faculties, and what they are told.
5
+ export { Being, canonical, digest, Faculty, isSilence, isWord, OWNER, silence, told, WARD, word } from './being/index.js';
6
+ export { readInvitation } from './quo/index.js';
7
+ // What a terrain gives a harbor.
8
+ export { Carrier, Clock, Custody, Entropy, Loader, Memory } from './contract/index.js';
9
+ // Wards and the ward-being.
10
+ export { CEILING, DEFAULT, DEPTH, ownerAsk, Pilot, pilots, WardBeing } from './ward/index.js';
11
+ // The onion, and the one line its root's asks cross from any front.
12
+ export { BOX, Catalogue, Dock, Harbor, readRootRequest, Registry, rootLine, Terrain } from './harbor/index.js';
13
+ // The pointer dock: a whole world in one process.
14
+ export { CryptoEntropy, HeldCustody, HeldLoader, NoCarrier, PointerCarrier, PointerTerrain, SystemClock, VolatileMemory, World } from './pointer/index.js';
@@ -0,0 +1,26 @@
1
+ import { Clock, Custody, Entropy, Loader, Memory, type Loaded, type Module } from '../contract/index.ts';
2
+ export declare class CryptoEntropy extends Entropy {
3
+ draw(length: number): Uint8Array;
4
+ }
5
+ export declare class SystemClock extends Clock {
6
+ now(): number;
7
+ wait(ms: number): {
8
+ done: Promise<void>;
9
+ cancel(): void;
10
+ };
11
+ }
12
+ export declare class HeldCustody extends Custody {
13
+ #private;
14
+ constructor(entropy: Entropy);
15
+ seed(): Promise<Uint8Array>;
16
+ }
17
+ export declare class HeldLoader extends Loader {
18
+ #private;
19
+ constructor(modules?: readonly Module[]);
20
+ load(from: string): Promise<Loaded | null>;
21
+ }
22
+ export declare class VolatileMemory extends Memory {
23
+ #private;
24
+ read(place: string): Promise<Map<string, Uint8Array>>;
25
+ write(place: string, entries: ReadonlyMap<string, Uint8Array | null>): Promise<void>;
26
+ }
@@ -0,0 +1,64 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The pointer terrain's bodies: each contract fulfilled in one process,
3
+ // with nothing beyond JavaScript.
4
+ import { Clock, Custody, Entropy, Loader, Memory } from '../contract/index.js';
5
+ export class CryptoEntropy extends Entropy {
6
+ draw(length) {
7
+ return globalThis.crypto.getRandomValues(new Uint8Array(length));
8
+ }
9
+ }
10
+ export class SystemClock extends Clock {
11
+ now() {
12
+ return Date.now();
13
+ }
14
+ wait(ms) {
15
+ let timer;
16
+ const done = new Promise((resolve) => (timer = setTimeout(resolve, ms)));
17
+ return { done, cancel: () => clearTimeout(timer) };
18
+ }
19
+ }
20
+ // The harbor's seed, drawn once and held by this object.
21
+ export class HeldCustody extends Custody {
22
+ #seed;
23
+ constructor(entropy) {
24
+ super();
25
+ this.#seed = entropy.draw(32);
26
+ }
27
+ seed() {
28
+ return Promise.resolve(this.#seed.slice());
29
+ }
30
+ }
31
+ // Modules handed to this object, found by the name each declares.
32
+ export class HeldLoader extends Loader {
33
+ #modules = new Map();
34
+ constructor(modules = []) {
35
+ super();
36
+ for (const m of modules)
37
+ this.#modules.set(m.module, m);
38
+ }
39
+ load(from) {
40
+ const m = this.#modules.get(from);
41
+ return Promise.resolve(m ? { module: m.module, version: m.version, classes: m.classes, from } : null);
42
+ }
43
+ }
44
+ // Entries that live as long as this object, copied in and out, which is
45
+ // what a restart in one process finds.
46
+ export class VolatileMemory extends Memory {
47
+ #places = new Map();
48
+ read(place) {
49
+ const entries = this.#places.get(place) ?? new Map();
50
+ return Promise.resolve(new Map([...entries].map(([name, bytes]) => [name, bytes.slice()])));
51
+ }
52
+ write(place, entries) {
53
+ let kept = this.#places.get(place);
54
+ if (!kept)
55
+ this.#places.set(place, (kept = new Map()));
56
+ for (const [name, bytes] of entries) {
57
+ if (bytes === null)
58
+ kept.delete(name);
59
+ else
60
+ kept.set(name, bytes.slice());
61
+ }
62
+ return Promise.resolve();
63
+ }
64
+ }
@@ -0,0 +1,2 @@
1
+ export { CryptoEntropy, HeldCustody, HeldLoader, SystemClock, VolatileMemory } from './bodies.ts';
2
+ export { NoCarrier, PointerCarrier, PointerTerrain, World, type PointerParts } from './world.ts';
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The pointer dock: a whole world with `nervur` alone.
3
+ export { CryptoEntropy, HeldCustody, HeldLoader, SystemClock, VolatileMemory } from './bodies.js';
4
+ export { NoCarrier, PointerCarrier, PointerTerrain, World } from './world.js';
@@ -0,0 +1,35 @@
1
+ import { Carrier, type Clock, type Custody, type Entropy, type Loader, type Memory, type Module } from '../contract/index.ts';
2
+ import { Harbor, Terrain } from '../harbor/index.ts';
3
+ export declare class NoCarrier extends Carrier {
4
+ carry(): Promise<Uint8Array | null>;
5
+ }
6
+ export declare class PointerCarrier extends Carrier {
7
+ #private;
8
+ constructor(world: World);
9
+ carry(pk: string, bytes: Uint8Array): Promise<Uint8Array | null>;
10
+ }
11
+ export type PointerParts = {
12
+ entropy?: Entropy;
13
+ clock?: Clock;
14
+ custody?: Custody;
15
+ memory?: Memory;
16
+ carrier?: Carrier;
17
+ loader?: Loader;
18
+ };
19
+ export declare class PointerTerrain extends Terrain {
20
+ readonly entropy: Entropy;
21
+ readonly clock: Clock;
22
+ readonly custody: Custody;
23
+ readonly memory: Memory;
24
+ readonly carrier: Carrier;
25
+ readonly loader: Loader;
26
+ constructor(parts?: PointerParts);
27
+ }
28
+ export declare class World {
29
+ #private;
30
+ readonly cut: Set<string>;
31
+ harbor(name: string, modules?: readonly Module[], parts?: Omit<PointerParts, 'carrier'>): Promise<Harbor>;
32
+ get(name: string): Harbor;
33
+ restart(name: string, parts?: Omit<PointerParts, 'carrier'>): Promise<Harbor>;
34
+ carry(pk: string, bytes: Uint8Array): Promise<Uint8Array | null>;
35
+ }
@@ -0,0 +1,85 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The pointer world: harbors in one process, an address book from ward pk
3
+ // to harbor that stands in for the internet, and weather between them. A
4
+ // restart drops a harbor and opens a new one on the terrain the world
5
+ // keeps for it, so only what its memory kept comes back.
6
+ import { Carrier } from '../contract/index.js';
7
+ import { Harbor, Terrain } from '../harbor/index.js';
8
+ import { CryptoEntropy, HeldCustody, HeldLoader, SystemClock, VolatileMemory } from './bodies.js';
9
+ // A carrier that reaches no one: a harbor alone.
10
+ export class NoCarrier extends Carrier {
11
+ carry() {
12
+ return Promise.resolve(null);
13
+ }
14
+ }
15
+ // Bytes to whichever harbor of a world holds the ward pk.
16
+ export class PointerCarrier extends Carrier {
17
+ #world;
18
+ constructor(world) {
19
+ super();
20
+ this.#world = world;
21
+ }
22
+ carry(pk, bytes) {
23
+ return this.#world.carry(pk, bytes);
24
+ }
25
+ }
26
+ export class PointerTerrain extends Terrain {
27
+ entropy;
28
+ clock;
29
+ custody;
30
+ memory;
31
+ carrier;
32
+ loader;
33
+ constructor(parts = {}) {
34
+ super();
35
+ this.entropy = parts.entropy ?? new CryptoEntropy();
36
+ this.clock = parts.clock ?? new SystemClock();
37
+ this.custody = parts.custody ?? new HeldCustody(this.entropy);
38
+ this.memory = parts.memory ?? new VolatileMemory();
39
+ this.carrier = parts.carrier ?? new NoCarrier();
40
+ this.loader = parts.loader ?? new HeldLoader();
41
+ }
42
+ }
43
+ export class World {
44
+ #places = new Map();
45
+ // Harbors the world reaches no one in, nor anyone out of.
46
+ cut = new Set();
47
+ // A harbor of this world, whose loader holds `modules` unless `parts`
48
+ // names a loader. `parts` replaces the pointer bodies, a folder's memory
49
+ // and custody among them. The harbor runs only the modules its catalogue
50
+ // was told to add.
51
+ async harbor(name, modules = [], parts = {}) {
52
+ if (this.#places.has(name))
53
+ throw new Error(`a harbor named ${name} stands`);
54
+ const terrain = new PointerTerrain({ loader: new HeldLoader(modules), ...parts, carrier: new PointerCarrier(this) });
55
+ const harbor = await Harbor.open(terrain);
56
+ this.#places.set(name, { harbor, terrain });
57
+ return harbor;
58
+ }
59
+ get(name) {
60
+ const place = this.#places.get(name);
61
+ if (!place)
62
+ throw new Error(`no harbor named ${name}`);
63
+ return place.harbor;
64
+ }
65
+ // The harbor opened again on its own terrain. `parts` replaces bodies of
66
+ // the terrain, as a new process would build them over the same disk, or
67
+ // with other code.
68
+ async restart(name, parts) {
69
+ const place = this.#places.get(name);
70
+ if (!place)
71
+ throw new Error(`no harbor named ${name}`);
72
+ const t = place.terrain;
73
+ const terrain = parts ? new PointerTerrain({ entropy: t.entropy, clock: t.clock, custody: t.custody, memory: t.memory, loader: t.loader, ...parts, carrier: t.carrier }) : t;
74
+ const harbor = await Harbor.open(terrain);
75
+ this.#places.set(name, { harbor, terrain });
76
+ return harbor;
77
+ }
78
+ carry(pk, bytes) {
79
+ for (const [name, { harbor }] of this.#places) {
80
+ if (harbor.holds(pk))
81
+ return this.cut.has(name) ? Promise.resolve(null) : harbor.arrive(pk, bytes);
82
+ }
83
+ return Promise.resolve(null);
84
+ }
85
+ }
@@ -0,0 +1,34 @@
1
+ import { type Draw, type WardKey } from './keys.ts';
2
+ import type { Invitation } from './invitation.ts';
3
+ import { type Payload } from './payload.ts';
4
+ import type { Relations } from './relations.ts';
5
+ export declare const SPAN = 64;
6
+ export type Choice = {
7
+ readonly object: string;
8
+ readonly seen: string | null;
9
+ } | {
10
+ readonly silence: true;
11
+ };
12
+ export interface Behind {
13
+ readonly zero: boolean;
14
+ answer(heir: string | null, payload: Payload): Promise<Choice>;
15
+ }
16
+ export type Judged = {
17
+ bytes: Uint8Array;
18
+ case: number;
19
+ heard: boolean;
20
+ };
21
+ export declare class Door {
22
+ #private;
23
+ readonly key: WardKey;
24
+ readonly relations: Relations;
25
+ readonly behind: Behind;
26
+ readonly draw: Draw;
27
+ constructor(key: WardKey, relations: Relations, behind: Behind, draw: Draw);
28
+ invite(): Promise<{
29
+ heir: string;
30
+ invitation: Invitation;
31
+ }>;
32
+ remove(heir: string): boolean;
33
+ arrive(bytes: Uint8Array): Promise<Judged>;
34
+ }