nervur 0.7.2 → 0.7.6

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 (3) hide show
  1. package/being.mjs +44 -9
  2. package/ground.mjs +10 -7
  3. package/package.json +1 -1
package/being.mjs CHANGED
@@ -39,15 +39,42 @@ const Compartment = ({ memory, voice, address, root, classOf }) => {
39
39
  });
40
40
  };
41
41
 
42
+ const grantable = (program) =>
43
+ (program?.rights ?? [...STRUCTURAL, 'MEMBER']).filter((one) => !STRUCTURAL.includes(one));
44
+
45
+ const referable = (mine, key, plain, program) => {
46
+ const rights = plain.rights ?? 'MEMBER';
47
+ if (!grantable(program).includes(rights)) {
48
+ return undefined;
49
+ }
50
+ if (key.startsWith('refs/pending/')) {
51
+ return { ...plain, rights };
52
+ }
53
+ const held = mine.read(key);
54
+ return {
55
+ ...plain,
56
+ nextPkHash: plain.nextPkHash ?? held?.nextPkHash ?? null,
57
+ rights,
58
+ seen: Math.max(plain.seen ?? 0, held?.seen ?? 0),
59
+ };
60
+ };
61
+
42
62
  const scoped = (mine, program) =>
43
63
  Object.freeze({
44
64
  classOf: mine.classOf,
45
65
  list: mine.list,
46
66
  read: mine.read,
47
- write: (key, plain) =>
48
- key.startsWith('refs/') || key.startsWith('handles/') || program?.declares(key) !== undefined
67
+ write: (key, plain) => {
68
+ if (key.startsWith('refs/') && plain !== undefined) {
69
+ const guarded = referable(mine, key, plain, program);
70
+ return guarded === undefined ? undefined : mine.write(key, guarded);
71
+ }
72
+ return key.startsWith('refs/') ||
73
+ key.startsWith('handles/') ||
74
+ program?.declares(key) !== undefined
49
75
  ? mine.write(key, plain)
50
- : undefined,
76
+ : undefined;
77
+ },
51
78
  });
52
79
 
53
80
  const rootFor = ({ memory, voice, address }) => {
@@ -56,13 +83,13 @@ const rootFor = ({ memory, voice, address }) => {
56
83
  return opened === undefined ? undefined : Buffer.from(opened, 'base64');
57
84
  };
58
85
 
59
- const Port = ({ voice, mine, modules, rights }) => {
86
+ const Port = ({ voice, mine, deliver, rights }) => {
60
87
  const stamp = Stamp();
61
88
  const lanes = new Map();
62
89
  const send = async (to, op) => {
63
90
  const turn = (lanes.get(to) ?? Promise.resolve()).then(() => {
64
91
  const handle = mine.read(`handles/${to}`);
65
- return modules.deliver(
92
+ return deliver(
66
93
  Tools.envelope(handle === undefined ? voice : Voice.revive(handle.face), to, op, stamp()),
67
94
  );
68
95
  });
@@ -112,7 +139,7 @@ const rotates = ({ mine }, from, nextPkHash) => {
112
139
  return from;
113
140
  };
114
141
 
115
- const Being = ({ voice, address, modules, registry, vouched, watch }) => {
142
+ const Being = ({ voice, address, deliver, modules, registry, vouched, watch }) => {
116
143
  const memory = modules.memory;
117
144
  const root = rootFor({ memory, voice, address });
118
145
  const source = memory.read(address, 'program')?.value;
@@ -214,7 +241,7 @@ const Being = ({ voice, address, modules, registry, vouched, watch }) => {
214
241
  const asked = await program.ask({
215
242
  context: {
216
243
  modules: Object.freeze({ ...modules, memory: scoped(mine, program) }),
217
- port: Port({ voice, mine, modules, rights }),
244
+ port: Port({ voice, mine, deliver, rights }),
218
245
  registry,
219
246
  rights,
220
247
  },
@@ -258,6 +285,7 @@ const Registry = ({
258
285
  memory,
259
286
  adminMine,
260
287
  address,
288
+ deliver,
261
289
  modules,
262
290
  modulesFor,
263
291
  announce,
@@ -276,7 +304,14 @@ const Registry = ({
276
304
  if (voice === undefined) {
277
305
  return undefined;
278
306
  }
279
- const door = Being({ voice, address: at, modules: modulesFor(voice), vouched, watch });
307
+ const door = Being({
308
+ address: at,
309
+ deliver,
310
+ modules: modulesFor(voice),
311
+ vouched,
312
+ voice,
313
+ watch,
314
+ });
280
315
  live.set(at, door);
281
316
  return door;
282
317
  };
@@ -297,7 +332,7 @@ const Registry = ({
297
332
  if (written !== undefined && (brought === undefined || settings === undefined)) {
298
333
  return undefined;
299
334
  }
300
- const allowed = written?.rights ?? [...STRUCTURAL, 'MEMBER'];
335
+ const allowed = grantable(written);
301
336
  if (refs.some((ref) => !allowed.includes(ref.rights ?? 'MEMBER'))) {
302
337
  return undefined;
303
338
  }
package/ground.mjs CHANGED
@@ -94,10 +94,7 @@ const Ground = (modules = {}) => {
94
94
  {
95
95
  ...extra,
96
96
  ...boundFor(voice),
97
- deliver: (envelope) => deliver(envelope),
98
97
  memory,
99
- paths,
100
- wire,
101
98
  },
102
99
  Tools.address(voice.pk),
103
100
  ),
@@ -148,6 +145,7 @@ const Ground = (modules = {}) => {
148
145
  memory,
149
146
  adminMine,
150
147
  address,
148
+ deliver: (envelope) => deliver(envelope),
151
149
  modules: adminModules,
152
150
  modulesFor,
153
151
  announce,
@@ -157,10 +155,15 @@ const Ground = (modules = {}) => {
157
155
  watch,
158
156
  });
159
157
  const admin = (envelope, token) =>
160
- Being({ voice: adminVoice, address, modules: adminModules, registry, vouched, watch })(
161
- envelope,
162
- token,
163
- );
158
+ Being({
159
+ address,
160
+ deliver: (envelope) => deliver(envelope),
161
+ modules: adminModules,
162
+ registry,
163
+ vouched,
164
+ voice: adminVoice,
165
+ watch,
166
+ })(envelope, token);
164
167
 
165
168
  announce(address);
166
169
  for (const key of adminMine.list('identity/custody/')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nervur",
3
- "version": "0.7.2",
3
+ "version": "0.7.6",
4
4
  "description": "A distributed system of sovereign beings — one door, one question: by whose authority.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Razvan Gherghina",