@serfab/quereus-plugin-sereus 0.8.1 → 0.9.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/dist/compose-strand.js +1 -1
- package/dist/compose-strand.js.map +1 -1
- package/dist/plugin-browser.js +57672 -40849
- package/dist/plugin-browser.js.map +4 -4
- package/dist/strand-schema.d.ts +2 -2
- package/dist/strand-schema.js +22 -22
- package/package.json +2 -2
- package/src/compose-strand.ts +1 -1
- package/src/strand-schema.ts +22 -22
package/dist/strand-schema.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*
|
|
25
25
|
* Population note: this ticket applies the schema and makes its constraints
|
|
26
26
|
* active — it does NOT write membership rows at runtime. Inserting the `Header`,
|
|
27
|
-
* the founding `
|
|
27
|
+
* the founding `Manager`/`Member`, and the invite/peer flows is owned by
|
|
28
28
|
* `strand-membership-lifecycle-population`.
|
|
29
29
|
*/
|
|
30
|
-
export declare const STRAND_SCHEMA = " table Header (\n Id text, -- UUID of this network - generated at inception - immutable\n\n -- Types: 'o' = Open, 'c' = Closed\n -- Any peers can join an open network, but only members can join a closed network\n -- Open can still control writes in the app, but only Closed prevents reads\n Type text check (Type in ('o', 'c')),\n\n -- The app that this strand faciliates - public key from author to prevent tampering\n sAppId text,\n\n -- The version of the sApp that this strand faciliates\n sAppVersion text,\n\n -- The schema of the sApp that this strand faciliates\n sAppSchema text,\n\n -- The author's signature on the schema to guarantee authorship\n sAppSignature text,\n\n -- The engine (rules logic system) that is assumed to manage this strand\n Engine text,\n\n -- The version of the engine that is assumed to manage this strand\n EngineVersion text,\n\n primary key (/* empty - singleton */),\n constraint InsertOnly check on update, delete (false), -- One-time insert only for now - TODO: revisit for versioning\n );\n\n -- An invitation to join a strand as a member\n table Invite (\n Key text primary key,\n Expiration datetime null,\n -- TODO: ability to deactivate?\n constraint InsertOnly check on update, delete (false),\n constraint OnlyClosed check (\n exists (select 1 from Header H where H.Type = 'c')\n ),\n constraint InviteValid check on insert (\n -- Can only be inserted by
|
|
30
|
+
export declare const STRAND_SCHEMA = " table Header (\n Id text, -- UUID of this network - generated at inception - immutable\n\n -- Types: 'o' = Open, 'c' = Closed\n -- Any peers can join an open network, but only members can join a closed network\n -- Open can still control writes in the app, but only Closed prevents reads\n Type text check (Type in ('o', 'c')),\n\n -- The app that this strand faciliates - public key from author to prevent tampering\n sAppId text,\n\n -- The version of the sApp that this strand faciliates\n sAppVersion text,\n\n -- The schema of the sApp that this strand faciliates\n sAppSchema text,\n\n -- The author's signature on the schema to guarantee authorship\n sAppSignature text,\n\n -- The engine (rules logic system) that is assumed to manage this strand\n Engine text,\n\n -- The version of the engine that is assumed to manage this strand\n EngineVersion text,\n\n primary key (/* empty - singleton */),\n constraint InsertOnly check on update, delete (false), -- One-time insert only for now - TODO: revisit for versioning\n );\n\n -- An invitation to join a strand as a member\n table Invite (\n Key text primary key,\n Expiration datetime null,\n -- TODO: ability to deactivate?\n constraint InsertOnly check on update, delete (false),\n constraint OnlyClosed check (\n exists (select 1 from Header H where H.Type = 'c')\n ),\n constraint InviteValid check on insert (\n -- Can only be inserted by a manager,\n exists (select 1 from Manager A\n where A.MemberKey = context.ManagerKey\n and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.ManagerSignature, A.MemberKey, 'ed25519')\n )\n -- and must also prove invite private key held by issuing manager\n and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.InviteSignature, new.Key, 'ed25519')\n )\n ) with context (ManagerKey text null, ManagerSignature text null, InviteSignature text null);\n\n -- Invite [InviteKey] has been used to add [MemberKey] as a member\n table ConsumedInvite (\n InviteKey text primary key,\n MemberKey text,\n constraint InsertOnly check on update, delete (false),\n constraint InviteExists check (exists (select 1 from Invite I where I.Key = new.InviteKey)),\n constraint MemberExists check (exists (select 1 from Member M where M.Key = new.MemberKey)),\n constraint ValidUsage check on insert (\n exists (select 1 from Invite I where I.Key = new.InviteKey and verify(digest(new.InviteKey || '|' || new.MemberKey), context.InviteSignature, new.InviteKey, 'ed25519'))\n ),\n -- An invite with a non-null Expiration may only be consumed while it is still\n -- in the future. context.Now is the canonical-datetime \"now\" supplied by the\n -- consumeInvite writer (same canonicalDatetime() transform used to store\n -- Invite.Expiration), so both sides of the comparison are byte-identical\n -- canonical strings and the lexical \">\" comparison orders chronologically. A\n -- null Expiration never expires. Mirrors CadreControl.FormationUsage's\n -- \"FI.ExpiresAt is null or FI.ExpiresAt > context.Now\" gate.\n constraint NotExpired check on insert (\n exists (select 1 from Invite I where I.Key = new.InviteKey and (I.Expiration is null or I.Expiration > context.Now))\n ),\n constraint MemberValid check (exists (select 1 from Member M where M.Key = new.MemberKey))\n ) with context (InviteSignature text null, Now datetime null);\n\n -- A party in the closed strand network\n table Member (\n Key text primary key,\n constraint NoUpdate check on update (false),\n constraint OnlyClosed check (\n exists (select 1 from Header H where H.Type = 'c')\n ),\n constraint Authorized check on insert (\n -- There are no other records - first member needs no authorization\n (select count(1) from Member) <= 1\n\n -- or added directly by manager\n or exists (\n select 1 from Manager A\n where A.MemberKey = context.ManagerKey\n and verify(digest(new.Key), context.ManagerSignature, A.MemberKey, 'ed25519')\n )\n\n -- or added by invite\n or exists (\n select 1 from ConsumedInvite CI where CI.MemberKey = new.Key\n )\n ),\n -- TODO: handle member revocation constraint\n ) with context (ManagerKey text null, ManagerSignature text null);\n\n -- A member-associated peer (node)\n table MemberPeer (\n MemberKey text,\n PeerId text,\n primary key (MemberKey, PeerId),\n constraint MemberExists check (exists (select 1 from Member M where M.Key = new.MemberKey)),\n constraint Authorized check on insert, update, delete (\n verify(\n digest(coalesce(new.MemberKey, old.MemberKey) || '|' || coalesce(new.PeerId, old.PeerId)),\n context.Signature,\n coalesce(new.MemberKey, old.MemberKey),\n 'ed25519'\n )\n ),\n ) with context (Signature text null);\n\n -- A manager is a member that can issue invites, authorize members, and rotate managers\n table Manager (\n MemberKey text primary key,\n constraint OnlyClosed check (\n exists (select 1 from Header H where H.Type = 'c')\n ),\n constraint Authorized check on insert, update, delete (\n -- There are no existing records - first manager needs no authorization\n (select count(1) from Manager) <= 1\n\n -- or authorized by this former manager\n or (\n old.MemberKey is not null\n and old.MemberKey = context.ManagerKey\n and verify(digest(old.MemberKey), context.Signature, old.MemberKey, 'ed25519')\n )\n\n -- or authorized by another existing manager\n or exists (\n select 1 from Manager A\n where A.MemberKey = context.ManagerKey\n and verify(digest(coalesce(new.MemberKey, old.MemberKey)), context.Signature, A.MemberKey, 'ed25519')\n )\n )\n ) with context (ManagerKey text null, Signature text null);\n";
|
package/dist/strand-schema.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*
|
|
25
25
|
* Population note: this ticket applies the schema and makes its constraints
|
|
26
26
|
* active — it does NOT write membership rows at runtime. Inserting the `Header`,
|
|
27
|
-
* the founding `
|
|
27
|
+
* the founding `Manager`/`Member`, and the invite/peer flows is owned by
|
|
28
28
|
* `strand-membership-lifecycle-population`.
|
|
29
29
|
*/
|
|
30
30
|
export const STRAND_SCHEMA = ` table Header (
|
|
@@ -67,15 +67,15 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
67
67
|
exists (select 1 from Header H where H.Type = 'c')
|
|
68
68
|
),
|
|
69
69
|
constraint InviteValid check on insert (
|
|
70
|
-
-- Can only be inserted by
|
|
71
|
-
exists (select 1 from
|
|
72
|
-
where A.MemberKey = context.
|
|
73
|
-
and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.
|
|
70
|
+
-- Can only be inserted by a manager,
|
|
71
|
+
exists (select 1 from Manager A
|
|
72
|
+
where A.MemberKey = context.ManagerKey
|
|
73
|
+
and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.ManagerSignature, A.MemberKey, 'ed25519')
|
|
74
74
|
)
|
|
75
|
-
-- and must also prove invite private key held by issuing
|
|
75
|
+
-- and must also prove invite private key held by issuing manager
|
|
76
76
|
and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.InviteSignature, new.Key, 'ed25519')
|
|
77
77
|
)
|
|
78
|
-
) with context (
|
|
78
|
+
) with context (ManagerKey text null, ManagerSignature text null, InviteSignature text null);
|
|
79
79
|
|
|
80
80
|
-- Invite [InviteKey] has been used to add [MemberKey] as a member
|
|
81
81
|
table ConsumedInvite (
|
|
@@ -111,11 +111,11 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
111
111
|
-- There are no other records - first member needs no authorization
|
|
112
112
|
(select count(1) from Member) <= 1
|
|
113
113
|
|
|
114
|
-
-- or added directly by
|
|
114
|
+
-- or added directly by manager
|
|
115
115
|
or exists (
|
|
116
|
-
select 1 from
|
|
117
|
-
where A.MemberKey = context.
|
|
118
|
-
and verify(digest(new.Key), context.
|
|
116
|
+
select 1 from Manager A
|
|
117
|
+
where A.MemberKey = context.ManagerKey
|
|
118
|
+
and verify(digest(new.Key), context.ManagerSignature, A.MemberKey, 'ed25519')
|
|
119
119
|
)
|
|
120
120
|
|
|
121
121
|
-- or added by invite
|
|
@@ -124,7 +124,7 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
124
124
|
)
|
|
125
125
|
),
|
|
126
126
|
-- TODO: handle member revocation constraint
|
|
127
|
-
) with context (
|
|
127
|
+
) with context (ManagerKey text null, ManagerSignature text null);
|
|
128
128
|
|
|
129
129
|
-- A member-associated peer (node)
|
|
130
130
|
table MemberPeer (
|
|
@@ -142,30 +142,30 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
142
142
|
),
|
|
143
143
|
) with context (Signature text null);
|
|
144
144
|
|
|
145
|
-
--
|
|
146
|
-
table
|
|
145
|
+
-- A manager is a member that can issue invites, authorize members, and rotate managers
|
|
146
|
+
table Manager (
|
|
147
147
|
MemberKey text primary key,
|
|
148
148
|
constraint OnlyClosed check (
|
|
149
149
|
exists (select 1 from Header H where H.Type = 'c')
|
|
150
150
|
),
|
|
151
151
|
constraint Authorized check on insert, update, delete (
|
|
152
|
-
-- There are no existing records - first
|
|
153
|
-
(select count(1) from
|
|
152
|
+
-- There are no existing records - first manager needs no authorization
|
|
153
|
+
(select count(1) from Manager) <= 1
|
|
154
154
|
|
|
155
|
-
-- or authorized by this former
|
|
155
|
+
-- or authorized by this former manager
|
|
156
156
|
or (
|
|
157
157
|
old.MemberKey is not null
|
|
158
|
-
and old.MemberKey = context.
|
|
158
|
+
and old.MemberKey = context.ManagerKey
|
|
159
159
|
and verify(digest(old.MemberKey), context.Signature, old.MemberKey, 'ed25519')
|
|
160
160
|
)
|
|
161
161
|
|
|
162
|
-
-- or authorized by another existing
|
|
162
|
+
-- or authorized by another existing manager
|
|
163
163
|
or exists (
|
|
164
|
-
select 1 from
|
|
165
|
-
where A.MemberKey = context.
|
|
164
|
+
select 1 from Manager A
|
|
165
|
+
where A.MemberKey = context.ManagerKey
|
|
166
166
|
and verify(digest(coalesce(new.MemberKey, old.MemberKey)), context.Signature, A.MemberKey, 'ed25519')
|
|
167
167
|
)
|
|
168
168
|
)
|
|
169
|
-
) with context (
|
|
169
|
+
) with context (ManagerKey text null, Signature text null);
|
|
170
170
|
`;
|
|
171
171
|
//# sourceMappingURL=strand-schema.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serfab/quereus-plugin-sereus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Quereus plugin that connects to a Sereus strand for SQL access",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@optimystic/db-p2p-storage-web": "^0.14.1",
|
|
74
74
|
"@optimystic/quereus-plugin-crypto": "^0.14.1",
|
|
75
75
|
"@optimystic/quereus-plugin-optimystic": "^0.14.1",
|
|
76
|
-
"@quereus/quereus": "^4.
|
|
76
|
+
"@quereus/quereus": "^4.4.0",
|
|
77
77
|
"debug": "^4.4.3"
|
|
78
78
|
},
|
|
79
79
|
"quereus": {
|
package/src/compose-strand.ts
CHANGED
|
@@ -254,7 +254,7 @@ export async function composeStrand(
|
|
|
254
254
|
//
|
|
255
255
|
// This ticket only makes the tables present and their constraints active;
|
|
256
256
|
// nothing here writes membership rows. Founder bootstrap (Header, founding
|
|
257
|
-
//
|
|
257
|
+
// Manager/Member, invite/peer flows) is owned by the lifecycle ticket
|
|
258
258
|
// `strand-membership-lifecycle-population`.
|
|
259
259
|
log('Applying Strand membership schema for strand %s', strandId);
|
|
260
260
|
await db.exec(`
|
package/src/strand-schema.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*
|
|
25
25
|
* Population note: this ticket applies the schema and makes its constraints
|
|
26
26
|
* active — it does NOT write membership rows at runtime. Inserting the `Header`,
|
|
27
|
-
* the founding `
|
|
27
|
+
* the founding `Manager`/`Member`, and the invite/peer flows is owned by
|
|
28
28
|
* `strand-membership-lifecycle-population`.
|
|
29
29
|
*/
|
|
30
30
|
export const STRAND_SCHEMA = ` table Header (
|
|
@@ -67,15 +67,15 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
67
67
|
exists (select 1 from Header H where H.Type = 'c')
|
|
68
68
|
),
|
|
69
69
|
constraint InviteValid check on insert (
|
|
70
|
-
-- Can only be inserted by
|
|
71
|
-
exists (select 1 from
|
|
72
|
-
where A.MemberKey = context.
|
|
73
|
-
and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.
|
|
70
|
+
-- Can only be inserted by a manager,
|
|
71
|
+
exists (select 1 from Manager A
|
|
72
|
+
where A.MemberKey = context.ManagerKey
|
|
73
|
+
and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.ManagerSignature, A.MemberKey, 'ed25519')
|
|
74
74
|
)
|
|
75
|
-
-- and must also prove invite private key held by issuing
|
|
75
|
+
-- and must also prove invite private key held by issuing manager
|
|
76
76
|
and verify(digest(new.Key || '|' || coalesce(new.Expiration, '')), context.InviteSignature, new.Key, 'ed25519')
|
|
77
77
|
)
|
|
78
|
-
) with context (
|
|
78
|
+
) with context (ManagerKey text null, ManagerSignature text null, InviteSignature text null);
|
|
79
79
|
|
|
80
80
|
-- Invite [InviteKey] has been used to add [MemberKey] as a member
|
|
81
81
|
table ConsumedInvite (
|
|
@@ -111,11 +111,11 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
111
111
|
-- There are no other records - first member needs no authorization
|
|
112
112
|
(select count(1) from Member) <= 1
|
|
113
113
|
|
|
114
|
-
-- or added directly by
|
|
114
|
+
-- or added directly by manager
|
|
115
115
|
or exists (
|
|
116
|
-
select 1 from
|
|
117
|
-
where A.MemberKey = context.
|
|
118
|
-
and verify(digest(new.Key), context.
|
|
116
|
+
select 1 from Manager A
|
|
117
|
+
where A.MemberKey = context.ManagerKey
|
|
118
|
+
and verify(digest(new.Key), context.ManagerSignature, A.MemberKey, 'ed25519')
|
|
119
119
|
)
|
|
120
120
|
|
|
121
121
|
-- or added by invite
|
|
@@ -124,7 +124,7 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
124
124
|
)
|
|
125
125
|
),
|
|
126
126
|
-- TODO: handle member revocation constraint
|
|
127
|
-
) with context (
|
|
127
|
+
) with context (ManagerKey text null, ManagerSignature text null);
|
|
128
128
|
|
|
129
129
|
-- A member-associated peer (node)
|
|
130
130
|
table MemberPeer (
|
|
@@ -142,29 +142,29 @@ export const STRAND_SCHEMA = ` table Header (
|
|
|
142
142
|
),
|
|
143
143
|
) with context (Signature text null);
|
|
144
144
|
|
|
145
|
-
--
|
|
146
|
-
table
|
|
145
|
+
-- A manager is a member that can issue invites, authorize members, and rotate managers
|
|
146
|
+
table Manager (
|
|
147
147
|
MemberKey text primary key,
|
|
148
148
|
constraint OnlyClosed check (
|
|
149
149
|
exists (select 1 from Header H where H.Type = 'c')
|
|
150
150
|
),
|
|
151
151
|
constraint Authorized check on insert, update, delete (
|
|
152
|
-
-- There are no existing records - first
|
|
153
|
-
(select count(1) from
|
|
152
|
+
-- There are no existing records - first manager needs no authorization
|
|
153
|
+
(select count(1) from Manager) <= 1
|
|
154
154
|
|
|
155
|
-
-- or authorized by this former
|
|
155
|
+
-- or authorized by this former manager
|
|
156
156
|
or (
|
|
157
157
|
old.MemberKey is not null
|
|
158
|
-
and old.MemberKey = context.
|
|
158
|
+
and old.MemberKey = context.ManagerKey
|
|
159
159
|
and verify(digest(old.MemberKey), context.Signature, old.MemberKey, 'ed25519')
|
|
160
160
|
)
|
|
161
161
|
|
|
162
|
-
-- or authorized by another existing
|
|
162
|
+
-- or authorized by another existing manager
|
|
163
163
|
or exists (
|
|
164
|
-
select 1 from
|
|
165
|
-
where A.MemberKey = context.
|
|
164
|
+
select 1 from Manager A
|
|
165
|
+
where A.MemberKey = context.ManagerKey
|
|
166
166
|
and verify(digest(coalesce(new.MemberKey, old.MemberKey)), context.Signature, A.MemberKey, 'ed25519')
|
|
167
167
|
)
|
|
168
168
|
)
|
|
169
|
-
) with context (
|
|
169
|
+
) with context (ManagerKey text null, Signature text null);
|
|
170
170
|
`;
|