@serfab/cadre-core 1.20.0 → 1.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 +294 -294
- package/dist/cadre-node.d.ts +329 -53
- package/dist/cadre-node.js +767 -85
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +32 -2
- package/dist/control-authorization.js +19 -0
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-database.d.ts +236 -23
- package/dist/control-database.js +601 -178
- package/dist/control-database.js.map +1 -1
- package/dist/control-schema.d.ts +3 -3
- package/dist/control-schema.js +71 -7
- package/dist/control-schema.js.map +1 -1
- package/dist/ed25519-key.d.ts +8 -0
- package/dist/ed25519-key.js +11 -1
- package/dist/ed25519-key.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/machine-removal.d.ts +51 -1
- package/dist/machine-removal.js +42 -1
- package/dist/machine-removal.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +8 -0
- package/dist/membership-connection-gater.js +13 -1
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/owner-keys.js +2 -1
- package/dist/owner-keys.js.map +1 -1
- package/dist/owner-signer.js +3 -4
- package/dist/owner-signer.js.map +1 -1
- package/dist/peer-authorization.d.ts +14 -2
- package/dist/peer-authorization.js +24 -1
- package/dist/peer-authorization.js.map +1 -1
- package/dist/relay-reservation.js +20 -1
- package/dist/relay-reservation.js.map +1 -1
- package/dist/sealed-party-key.d.ts +32 -0
- package/dist/sealed-party-key.js +162 -0
- package/dist/sealed-party-key.js.map +1 -0
- package/dist/seed-bootstrap.d.ts +10 -3
- package/dist/seed-bootstrap.js +12 -0
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +56 -6
- package/dist/strand-addr-protocol.js +57 -5
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-app-schema-report.d.ts +6 -3
- package/dist/strand-app-schema-report.js +13 -7
- package/dist/strand-app-schema-report.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +33 -2
- package/dist/strand-commit-durability.js +44 -4
- package/dist/strand-commit-durability.js.map +1 -1
- package/dist/strand-database.d.ts +36 -6
- package/dist/strand-database.js +35 -11
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +133 -9
- package/dist/strand-instance-manager.js +266 -42
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +250 -51
- package/dist/strand-membership-reconciler.js +410 -66
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +7 -0
- package/dist/strand-membership-writer.js +9 -0
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-party-key-rotation.d.ts +177 -0
- package/dist/strand-party-key-rotation.js +340 -0
- package/dist/strand-party-key-rotation.js.map +1 -0
- package/dist/strand-party-machines.d.ts +111 -0
- package/dist/strand-party-machines.js +258 -0
- package/dist/strand-party-machines.js.map +1 -0
- package/dist/strand-party-peers.d.ts +101 -0
- package/dist/strand-party-peers.js +49 -0
- package/dist/strand-party-peers.js.map +1 -0
- package/dist/strand-peer-redial.d.ts +34 -7
- package/dist/strand-peer-redial.js +46 -13
- package/dist/strand-peer-redial.js.map +1 -1
- package/dist/strand-revocation-enforcer.d.ts +15 -1
- package/dist/strand-revocation-enforcer.js +16 -9
- package/dist/strand-revocation-enforcer.js.map +1 -1
- package/dist/strand-transport-key.js +3 -0
- package/dist/strand-transport-key.js.map +1 -1
- package/dist/strand-watcher.d.ts +7 -4
- package/dist/strand-watcher.js +12 -7
- package/dist/strand-watcher.js.map +1 -1
- package/dist/types.d.ts +165 -17
- package/dist/types.js.map +1 -1
- package/package.json +9 -8
- package/src/cadre-node.ts +12252 -11528
- package/src/control-authorization.ts +41 -1
- package/src/control-database.ts +6123 -5594
- package/src/control-schema.ts +71 -7
- package/src/ed25519-key.ts +12 -1
- package/src/index.ts +957 -924
- package/src/machine-removal.ts +80 -1
- package/src/membership-connection-gater.ts +13 -1
- package/src/owner-keys.ts +2 -1
- package/src/owner-signer.ts +92 -94
- package/src/peer-authorization.ts +27 -3
- package/src/relay-reservation.ts +28 -1
- package/src/sealed-party-key.ts +190 -0
- package/src/seed-bootstrap.ts +17 -3
- package/src/strand-addr-protocol.ts +67 -6
- package/src/strand-app-schema-report.ts +17 -10
- package/src/strand-commit-durability.ts +54 -5
- package/src/strand-database.ts +48 -12
- package/src/strand-instance-manager.ts +330 -42
- package/src/strand-membership-reconciler.ts +1310 -942
- package/src/strand-membership-writer.ts +10 -0
- package/src/strand-party-key-rotation.ts +436 -0
- package/src/strand-party-machines.ts +293 -0
- package/src/strand-party-peers.ts +129 -0
- package/src/strand-peer-redial.ts +61 -14
- package/src/strand-revocation-enforcer.ts +27 -9
- package/src/strand-transport-key.ts +3 -0
- package/src/strand-watcher.ts +12 -7
- package/src/types.ts +3112 -2962
package/src/control-schema.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { Parser } from '@quereus/quereus';
|
|
|
10
10
|
* docs/architecture.md → "Control schema versions and migrations", enforced by
|
|
11
11
|
* `control-schema-versions.spec.ts`.
|
|
12
12
|
*/
|
|
13
|
-
export const CONTROL_SCHEMA_VERSION =
|
|
13
|
+
export const CONTROL_SCHEMA_VERSION = 4;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The first control schema version whose fixture is kept, and the oldest a store can be
|
|
@@ -48,9 +48,10 @@ export const CONTROL_SCHEMA_DECLARATION = `-- A Sereus party's cadre (its nodes)
|
|
|
48
48
|
-- an owner key never accept each other's approvals. FormationUsage is the exception, its
|
|
49
49
|
-- two digests scoped by the invitation token instead (FormationUsage.Authorized).
|
|
50
50
|
--
|
|
51
|
-
-- Rows of the guarded tables (OwnerKey, ValidationKey, Strand, StrandPartyKey,
|
|
52
|
-
-- JoinRequest, CadrePeer, DeviceToken, CadreInvite,
|
|
53
|
-
-- into their add and remove digests. \`unique\` holds
|
|
51
|
+
-- Rows of the guarded tables (OwnerKey, ValidationKey, Strand, StrandPartyKey,
|
|
52
|
+
-- PendingStrandPartyKey, JoinedStrand, JoinRequest, CadrePeer, DeviceToken, CadreInvite,
|
|
53
|
+
-- OwnerGrant) carry a one-off StampId bound into their add and remove digests. \`unique\` holds
|
|
54
|
+
-- over live rows only, so a delete retires
|
|
54
55
|
-- the stamp into Revocation in the same transaction (RevocationRecorded) and an insert refuses
|
|
55
56
|
-- a retired stamp (NotRevoked): the never-expiring add approval cannot re-seat a removed row.
|
|
56
57
|
-- A legitimate re-add mints a fresh stamp and a fresh signature. CadreInvite and OwnerGrant
|
|
@@ -272,6 +273,43 @@ declare schema CadreControl {
|
|
|
272
273
|
)
|
|
273
274
|
) with context (OwnerKey text, Signature text);
|
|
274
275
|
|
|
276
|
+
-- The key this party's membership in one closed strand is moving to, while the move is under
|
|
277
|
+
-- way. It is written before the strand is touched and swapped into StrandPartyKey only after
|
|
278
|
+
-- the strand-side work is done: seating a fresh key and crashing before the control row changes
|
|
279
|
+
-- would leave a manager seat nobody holds, and changing the control row first would delete the
|
|
280
|
+
-- only copy of the old key, which the seating needs. A table of its own because StrandPartyKey
|
|
281
|
+
-- is keyed on the strand id alone and NoUpdate. Guarded as StrandPartyKey is, with no reap
|
|
282
|
+
-- branch for the same reason: the key is stored nowhere else.
|
|
283
|
+
-- NOTE: unlike a tombstone (Revocation.ReissuedAt), a pending row committed while the remover
|
|
284
|
+
-- was alone has no re-issue path, so a remover that removes alone and is lost before its
|
|
285
|
+
-- rotations finish loses the rows with it. If that ever matters, give this table that idiom.
|
|
286
|
+
table PendingStrandPartyKey (
|
|
287
|
+
Id text primary key, -- the strand id
|
|
288
|
+
PublicKey text, -- the key being moved to, public half (base64url): the Strand.Member.Key it is seated as.
|
|
289
|
+
-- In the clear so a second removal lists it in Superseded without opening the row.
|
|
290
|
+
SealedKey text, -- its private half (StrandPartyKey.PrivateKey encoding), sealed to the identity keys of the
|
|
291
|
+
-- machines that remain (sealed-party-key.ts): the row is written in the removed machine's last
|
|
292
|
+
-- control transaction and reaches it, so what it carries must open only for the others.
|
|
293
|
+
Superseded text null, -- comma-joined public keys (base64url) of earlier pending keys this row replaced.
|
|
294
|
+
-- A second removal replaces the row because the old key may have reached the
|
|
295
|
+
-- machine it removes, and a seat that key already holds must then be revoked.
|
|
296
|
+
StampId text unique,
|
|
297
|
+
constraint NotRevoked check on insert (
|
|
298
|
+
not exists (select 1 from Revocation R where R.TableName = 'PendingStrandPartyKey' and R.StampId = new.StampId)
|
|
299
|
+
),
|
|
300
|
+
constraint RevocationRecorded check on delete (
|
|
301
|
+
exists (select 1 from Revocation R where R.TableName = 'PendingStrandPartyKey' and R.StampId = old.StampId and R.RowKey = old.Id)
|
|
302
|
+
),
|
|
303
|
+
constraint NoUpdate check on update (false),
|
|
304
|
+
-- Binding Superseded as well as the key: a captured approval cannot drop a key from the list.
|
|
305
|
+
constraint AuthorizedInsert check on insert (
|
|
306
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.PendingStrandPartyKey', 'add', party_id(), new.Id, new.PublicKey, new.SealedKey, coalesce(new.Superseded, ''), new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
307
|
+
),
|
|
308
|
+
constraint AuthorizedDelete check on delete (
|
|
309
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.PendingStrandPartyKey', 'remove', party_id(), old.Id, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
310
|
+
)
|
|
311
|
+
) with context (OwnerKey text, Signature text);
|
|
312
|
+
|
|
275
313
|
-- A strand this party joined from another party, whose control database holds the Strand
|
|
276
314
|
-- row. Every machine of the party reads it, so a replica host keeps a copy and the party's
|
|
277
315
|
-- other machines can attach. A separate table because every reader of Strand takes it to
|
|
@@ -559,6 +597,30 @@ declare schema CadreControl {
|
|
|
559
597
|
)
|
|
560
598
|
) with context (OwnerKey text null, Signature text);
|
|
561
599
|
|
|
600
|
+
-- Each machine's own signed statement of the peer id it uses in one strand. That id derives from
|
|
601
|
+
-- the machine's private identity seed (cadre-core strandTransportKey), so no other machine can
|
|
602
|
+
-- compute it, and a machine removal needs it to tell the removed machine's Strand.MemberPeer
|
|
603
|
+
-- binding from its siblings'. A row is a permanent fact: the derivation is deterministic, and a
|
|
604
|
+
-- removed machine's rows are how its orphaned bindings stay attributed to it. So no stamp, no
|
|
605
|
+
-- tombstone and no delete, and no Revocation.RowIsGone branch.
|
|
606
|
+
-- The check defers (it has a subquery), so a CadrePeer row written in the same transaction
|
|
607
|
+
-- counts. A node that does not hold the machine's CadrePeer row yet refuses the insert, and the
|
|
608
|
+
-- writer tries again later. The check runs only on the node that takes the insert, and it cannot
|
|
609
|
+
-- tell whether PublicKey is really the key behind PeerId, so a reader re-verifies Sig against the
|
|
610
|
+
-- key derived from PeerId (ControlDatabase.queryStrandPeers) and judges PeerId against the
|
|
611
|
+
-- membership views.
|
|
612
|
+
table StrandPeer (
|
|
613
|
+
StrandId text, -- a Strand.Id or JoinedStrand.Id
|
|
614
|
+
PeerId text, -- the machine's control peer id (CadrePeer.PeerId)
|
|
615
|
+
StrandPeerId text, -- that machine's peer id in the strand's own network
|
|
616
|
+
Sig text, -- the machine's signature over the 'add' digest
|
|
617
|
+
primary key (StrandId, PeerId),
|
|
618
|
+
constraint Immutable check on update, delete (false),
|
|
619
|
+
constraint Authorized check on insert (
|
|
620
|
+
exists (select 1 from CadrePeer P where P.PeerId = new.PeerId and verify(digest('CadreControl.StrandPeer', 'add', party_id(), new.StrandId, new.PeerId, new.StrandPeerId), new.Sig, P.PublicKey, 'ed25519'))
|
|
621
|
+
)
|
|
622
|
+
);
|
|
623
|
+
|
|
562
624
|
-- An open invitation to form a strand with this party.
|
|
563
625
|
table FormationInvite (
|
|
564
626
|
Token text primary key, -- a random string
|
|
@@ -909,9 +971,10 @@ declare schema CadreControl {
|
|
|
909
971
|
-- TableName, and queryRevocations skips it. A 'CadreInvite' or 'OwnerGrant' row withdraws
|
|
910
972
|
-- an invitation or a grant whose row stays (the table comments).
|
|
911
973
|
table Revocation (
|
|
912
|
-
TableName text, -- 'OwnerKey' | 'ValidationKey' | 'Strand' | 'StrandPartyKey' |
|
|
913
|
-
-- '
|
|
914
|
-
-- 'Revocation' for an older
|
|
974
|
+
TableName text, -- 'OwnerKey' | 'ValidationKey' | 'Strand' | 'StrandPartyKey' |
|
|
975
|
+
-- 'PendingStrandPartyKey' | 'JoinedStrand' | 'JoinRequest' | 'CadrePeer' |
|
|
976
|
+
-- 'DeviceToken' | 'CadreInvite' | 'OwnerGrant', or 'Revocation' for an older
|
|
977
|
+
-- party's marker
|
|
915
978
|
RowKey text, -- primary key of the removed row
|
|
916
979
|
StampId text, -- the retired stamp
|
|
917
980
|
ReissuedAt integer default 0, -- bumped by an owner-signed re-issue so a tombstone committed while the
|
|
@@ -950,6 +1013,7 @@ declare schema CadreControl {
|
|
|
950
1013
|
or (new.TableName = 'ValidationKey' and not exists (select 1 from ValidationKey V where V.StampId = new.StampId))
|
|
951
1014
|
or (new.TableName = 'Strand' and not exists (select 1 from Strand S where S.StampId = new.StampId))
|
|
952
1015
|
or (new.TableName = 'StrandPartyKey' and not exists (select 1 from StrandPartyKey K where K.StampId = new.StampId))
|
|
1016
|
+
or (new.TableName = 'PendingStrandPartyKey' and not exists (select 1 from PendingStrandPartyKey K where K.StampId = new.StampId))
|
|
953
1017
|
or (new.TableName = 'JoinedStrand' and not exists (select 1 from JoinedStrand J where J.StampId = new.StampId))
|
|
954
1018
|
or (new.TableName = 'JoinRequest' and not exists (select 1 from JoinRequest J where J.StampId = new.StampId))
|
|
955
1019
|
or (new.TableName = 'DeviceToken' and not exists (select 1 from DeviceToken D where D.StampId = new.StampId))
|
package/src/ed25519-key.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toString as uint8ArrayToString, fromString as uint8ArrayFromString } from 'uint8arrays';
|
|
2
|
-
import { getPublicKey } from '@optimystic/quereus-plugin-crypto';
|
|
2
|
+
import { getPublicKey, sign } from '@optimystic/quereus-plugin-crypto';
|
|
3
3
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
4
4
|
import type { PrivateKey } from '@libp2p/interface';
|
|
5
5
|
|
|
@@ -69,6 +69,17 @@ export function ed25519PublicKeyFromPrivate(privateKeyB64: string): string {
|
|
|
69
69
|
return getPublicKey(privateKeyB64, 'ed25519', 'base64url', 'base64url') as string;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* A signer over an in-memory Ed25519 seed, in the shape the control database's signing
|
|
74
|
+
* callbacks take (`ControlSign`, `OwnerSign`): raw message bytes in, a base64url signature out.
|
|
75
|
+
* The crypto plugin takes the bytes as they are (its input encoding applies to a string only).
|
|
76
|
+
*
|
|
77
|
+
* @param privateKeyB64 - The base64url-encoded 32-byte Ed25519 seed.
|
|
78
|
+
*/
|
|
79
|
+
export function ed25519MessageSigner(privateKeyB64: string): (message: Uint8Array) => string {
|
|
80
|
+
return (message) => sign(message, privateKeyB64, 'ed25519', 'base64url', 'base64url', 'base64url') as string;
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
/**
|
|
73
84
|
* Reject a value that isn't a base64url-encoded 32-byte Ed25519 seed, the private-key form
|
|
74
85
|
* {@link ed25519PublicKeyFromPrivate} and the crypto plugin's `sign` take. Unlike
|