@serfab/cadre-core 0.6.0 → 0.8.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 (166) hide show
  1. package/README.md +9 -8
  2. package/dist/authority-key.d.ts +41 -0
  3. package/dist/authority-key.js +52 -0
  4. package/dist/authority-key.js.map +1 -0
  5. package/dist/cadre-node.d.ts +777 -11
  6. package/dist/cadre-node.js +1912 -82
  7. package/dist/cadre-node.js.map +1 -1
  8. package/dist/canonical-datetime.d.ts +33 -0
  9. package/dist/canonical-datetime.js +38 -0
  10. package/dist/canonical-datetime.js.map +1 -0
  11. package/dist/canonical-json.d.ts +12 -0
  12. package/dist/canonical-json.js +33 -0
  13. package/dist/canonical-json.js.map +1 -0
  14. package/dist/control-cohort.d.ts +63 -0
  15. package/dist/control-cohort.js +80 -0
  16. package/dist/control-cohort.js.map +1 -0
  17. package/dist/control-database.d.ts +259 -5
  18. package/dist/control-database.js +541 -128
  19. package/dist/control-database.js.map +1 -1
  20. package/dist/control-formation-recorder.d.ts +89 -0
  21. package/dist/control-formation-recorder.js +139 -0
  22. package/dist/control-formation-recorder.js.map +1 -0
  23. package/dist/control-schema.d.ts +12 -0
  24. package/dist/control-schema.js +199 -0
  25. package/dist/control-schema.js.map +1 -0
  26. package/dist/control-stream.d.ts +54 -0
  27. package/dist/control-stream.js +104 -0
  28. package/dist/control-stream.js.map +1 -0
  29. package/dist/device-token.d.ts +50 -0
  30. package/dist/device-token.js +66 -0
  31. package/dist/device-token.js.map +1 -0
  32. package/dist/diagnostics/connection-path.d.ts +118 -0
  33. package/dist/diagnostics/connection-path.js +204 -0
  34. package/dist/diagnostics/connection-path.js.map +1 -0
  35. package/dist/diagnostics/webrtc-turn-tracker.d.ts +50 -0
  36. package/dist/diagnostics/webrtc-turn-tracker.js +196 -0
  37. package/dist/diagnostics/webrtc-turn-tracker.js.map +1 -0
  38. package/dist/hibernation-manager.d.ts +79 -0
  39. package/dist/hibernation-manager.js +173 -23
  40. package/dist/hibernation-manager.js.map +1 -1
  41. package/dist/index.d.ts +25 -4
  42. package/dist/index.js +59 -4
  43. package/dist/index.js.map +1 -1
  44. package/dist/key-store-file.d.ts +52 -0
  45. package/dist/key-store-file.js +194 -0
  46. package/dist/key-store-file.js.map +1 -0
  47. package/dist/key-store.d.ts +75 -0
  48. package/dist/key-store.js +66 -0
  49. package/dist/key-store.js.map +1 -0
  50. package/dist/peer-authorization.d.ts +26 -0
  51. package/dist/peer-authorization.js +40 -0
  52. package/dist/peer-authorization.js.map +1 -0
  53. package/dist/peer-record.d.ts +89 -0
  54. package/dist/peer-record.js +117 -0
  55. package/dist/peer-record.js.map +1 -0
  56. package/dist/push-credentials.d.ts +34 -0
  57. package/dist/push-credentials.js +81 -0
  58. package/dist/push-credentials.js.map +1 -0
  59. package/dist/push-fanout.d.ts +137 -0
  60. package/dist/push-fanout.js +197 -0
  61. package/dist/push-fanout.js.map +1 -0
  62. package/dist/push-notifier-apns.d.ts +53 -0
  63. package/dist/push-notifier-apns.js +195 -0
  64. package/dist/push-notifier-apns.js.map +1 -0
  65. package/dist/push-notifier-fcm.d.ts +38 -0
  66. package/dist/push-notifier-fcm.js +183 -0
  67. package/dist/push-notifier-fcm.js.map +1 -0
  68. package/dist/push-notifier-shared.d.ts +18 -0
  69. package/dist/push-notifier-shared.js +25 -0
  70. package/dist/push-notifier-shared.js.map +1 -0
  71. package/dist/push-notifier.d.ts +71 -0
  72. package/dist/push-notifier.js +50 -0
  73. package/dist/push-notifier.js.map +1 -0
  74. package/dist/schema-verification.d.ts +11 -2
  75. package/dist/schema-verification.js +15 -4
  76. package/dist/schema-verification.js.map +1 -1
  77. package/dist/seed-bootstrap.d.ts +210 -7
  78. package/dist/seed-bootstrap.js +429 -131
  79. package/dist/seed-bootstrap.js.map +1 -1
  80. package/dist/seed-trust-policy.d.ts +63 -0
  81. package/dist/seed-trust-policy.js +56 -0
  82. package/dist/seed-trust-policy.js.map +1 -0
  83. package/dist/strand-addr-protocol.d.ts +132 -0
  84. package/dist/strand-addr-protocol.js +313 -0
  85. package/dist/strand-addr-protocol.js.map +1 -0
  86. package/dist/strand-cohort.d.ts +54 -0
  87. package/dist/strand-cohort.js +38 -0
  88. package/dist/strand-cohort.js.map +1 -0
  89. package/dist/strand-database.d.ts +54 -6
  90. package/dist/strand-database.js +88 -89
  91. package/dist/strand-database.js.map +1 -1
  92. package/dist/strand-formation-manager.d.ts +79 -19
  93. package/dist/strand-formation-manager.js +196 -104
  94. package/dist/strand-formation-manager.js.map +1 -1
  95. package/dist/strand-formation-protocol.d.ts +162 -0
  96. package/dist/strand-formation-protocol.js +279 -0
  97. package/dist/strand-formation-protocol.js.map +1 -0
  98. package/dist/strand-instance-manager.d.ts +73 -4
  99. package/dist/strand-instance-manager.js +167 -41
  100. package/dist/strand-instance-manager.js.map +1 -1
  101. package/dist/strand-member-key.d.ts +29 -0
  102. package/dist/strand-member-key.js +38 -0
  103. package/dist/strand-member-key.js.map +1 -0
  104. package/dist/strand-member-registry.d.ts +98 -0
  105. package/dist/strand-member-registry.js +129 -0
  106. package/dist/strand-member-registry.js.map +1 -0
  107. package/dist/strand-membership-writer.d.ts +361 -0
  108. package/dist/strand-membership-writer.js +449 -0
  109. package/dist/strand-membership-writer.js.map +1 -0
  110. package/dist/strand-solicitation.d.ts +77 -2
  111. package/dist/strand-solicitation.js +25 -4
  112. package/dist/strand-solicitation.js.map +1 -1
  113. package/dist/strand-wake-payload.d.ts +30 -0
  114. package/dist/strand-wake-payload.js +20 -0
  115. package/dist/strand-wake-payload.js.map +1 -0
  116. package/dist/strand-wake-protocol.d.ts +114 -0
  117. package/dist/strand-wake-protocol.js +257 -0
  118. package/dist/strand-wake-protocol.js.map +1 -0
  119. package/dist/strand-watcher.d.ts +6 -2
  120. package/dist/strand-watcher.js +57 -17
  121. package/dist/strand-watcher.js.map +1 -1
  122. package/dist/types.d.ts +413 -23
  123. package/dist/types.js +22 -5
  124. package/dist/types.js.map +1 -1
  125. package/package.json +14 -8
  126. package/src/authority-key.ts +68 -0
  127. package/src/cadre-node.ts +2937 -929
  128. package/src/canonical-datetime.ts +39 -0
  129. package/src/canonical-json.ts +30 -0
  130. package/src/control-cohort.ts +103 -0
  131. package/src/control-database.ts +931 -383
  132. package/src/control-formation-recorder.ts +151 -0
  133. package/src/control-schema.ts +198 -0
  134. package/src/control-stream.ts +128 -0
  135. package/src/device-token.ts +89 -0
  136. package/src/diagnostics/connection-path.ts +277 -0
  137. package/src/diagnostics/webrtc-turn-tracker.ts +222 -0
  138. package/src/hibernation-manager.ts +197 -28
  139. package/src/index.ts +273 -79
  140. package/src/key-store-file.ts +203 -0
  141. package/src/key-store.ts +99 -0
  142. package/src/peer-authorization.ts +53 -0
  143. package/src/peer-record.ts +146 -0
  144. package/src/push-credentials.ts +84 -0
  145. package/src/push-fanout.ts +272 -0
  146. package/src/push-notifier-apns.ts +243 -0
  147. package/src/push-notifier-fcm.ts +221 -0
  148. package/src/push-notifier-shared.ts +28 -0
  149. package/src/push-notifier.ts +93 -0
  150. package/src/schema-verification.ts +18 -4
  151. package/src/seed-bootstrap.ts +504 -171
  152. package/src/seed-trust-policy.ts +107 -0
  153. package/src/strand-addr-protocol.ts +410 -0
  154. package/src/strand-cohort.ts +77 -0
  155. package/src/strand-database.ts +113 -126
  156. package/src/strand-formation-manager.ts +233 -142
  157. package/src/strand-formation-protocol.ts +391 -0
  158. package/src/strand-instance-manager.ts +207 -56
  159. package/src/strand-member-key.ts +39 -0
  160. package/src/strand-member-registry.ts +177 -0
  161. package/src/strand-membership-writer.ts +640 -0
  162. package/src/strand-solicitation.ts +93 -4
  163. package/src/strand-wake-payload.ts +32 -0
  164. package/src/strand-wake-protocol.ts +331 -0
  165. package/src/strand-watcher.ts +61 -17
  166. package/src/types.ts +1012 -575
package/README.md CHANGED
@@ -91,12 +91,14 @@ await node.stop();
91
91
 
92
92
  ## Node Profiles
93
93
 
94
- | Profile | Storage Role | Use Case | Ring Participation |
95
- |---------|--------------|----------|-------------------|
96
- | **transaction** | Ring Zulu only | Mobile devices, intermittent connectivity | Transaction verification, caching |
97
- | **storage** | Ring Zulu + Storage Rings | Servers, NAS, always-on nodes | Full archival storage |
94
+ | Profile | Storage Role | Use Case | Ring Zulu |
95
+ |---------|--------------|----------|-----------|
96
+ | **transaction** | Arachnode disabled; transaction verification via FRET only | Mobile devices, intermittent connectivity | No |
97
+ | **storage** | Ring Zulu + storage rings (storage rings not yet implemented — stub) | Servers, NAS, always-on nodes | Yes |
98
98
 
99
- Both profiles participate in transaction consensus. The distinction is long-term storage commitment.
99
+ Transaction-profile nodes verify transactions via FRET only, with Arachnode disabled. Storage-profile nodes additionally join Ring Zulu and (when implemented) the concentric storage rings.
100
+
101
+ > **Note:** The storage-ring subsystem is currently a no-op stub (`arachnode-stub.ts`). See [Node Profiles in `docs/architecture.md`](../../docs/architecture.md#node-profiles) for the full design.
100
102
 
101
103
  ## Strand Filtering
102
104
 
@@ -104,7 +106,7 @@ Mobile apps typically shouldn't participate in all strands. Use filters to contr
104
106
 
105
107
  ```typescript
106
108
  // Only participate in strands for a specific app
107
- strandFilter: { mode: 'appId', appId: 'com.example.chat' }
109
+ strandFilter: { mode: 'sAppId', sAppId: 'com.example.chat' }
108
110
 
109
111
  // Only participate in one specific strand
110
112
  strandFilter: { mode: 'strandId', strandId: 'strand-abc123' }
@@ -151,7 +153,7 @@ const { seed, encodedSeed } = await node.addDrone({
151
153
  });
152
154
 
153
155
  // Send to provider for drone initialization
154
- await provider.applySeed(droneInfo.containerId, encodedSeed);
156
+ await provider.initializeNode(droneInfo.containerId, encodedSeed);
155
157
  ```
156
158
 
157
159
  ## API Reference
@@ -240,7 +242,6 @@ Available storage implementations:
240
242
 
241
243
  ## Related Packages
242
244
 
243
- - **[@serfab/strand-proto](../strand-proto/)** - Strand initialization protocol
244
245
  - **[@optimystic/db-core](https://github.com/gotchoices/optimystic)** - Distributed database core
245
246
  - **[@optimystic/db-p2p](https://github.com/gotchoices/optimystic)** - libp2p integration for Optimystic
246
247
  - **[@optimystic/db-p2p-storage-fs](https://github.com/gotchoices/optimystic)** - File system storage (Node.js)
@@ -0,0 +1,41 @@
1
+ import type { PrivateKey } from '@libp2p/interface';
2
+ /**
3
+ * A household authority keypair expressed in the base64url Ed25519 form that
4
+ * `@optimystic/quereus-plugin-crypto` (`sign`/`verify`/`getPublicKey`) consumes.
5
+ */
6
+ export interface AuthorityKeyPair {
7
+ /** 32-byte Ed25519 seed, base64url-encoded — the crypto-plugin private key. */
8
+ privateKeyB64: string;
9
+ /** 32-byte Ed25519 public key, base64url-encoded. */
10
+ publicKeyB64: string;
11
+ }
12
+ /**
13
+ * Bridge a libp2p Ed25519 private key into the base64url keypair used by the
14
+ * control-database authority constraints.
15
+ *
16
+ * libp2p stores an Ed25519 private key as 64 raw bytes: the first 32 are the
17
+ * seed (the actual scalar source), the last 32 are the public key — see
18
+ * `@libp2p/crypto`'s `Ed25519PrivateKey`. `@optimystic/quereus-plugin-crypto`
19
+ * (via `@noble/curves`) treats the 32-byte seed *as* the private key and
20
+ * derives the public key from it with standard Ed25519. The two derivations
21
+ * agree, so the node's peer identity and its authority key are one keypair:
22
+ * `getPublicKey(privateKeyB64)` === `publicKeyB64`.
23
+ *
24
+ * @param privateKey - The node's libp2p Ed25519 private key.
25
+ * @returns The base64url seed/public-key pair for authority operations.
26
+ * @throws If the key is not Ed25519 or the raw bytes aren't the expected length.
27
+ */
28
+ export declare function authorityKeyFromLibp2p(privateKey: PrivateKey): AuthorityKeyPair;
29
+ /**
30
+ * Derive the base64url Ed25519 public key from a base64url 32-byte private seed
31
+ * — the same derivation the seed-bootstrap signer uses internally
32
+ * (`SeedBootstrapService` constructor). Use this to enroll a standalone
33
+ * (non-libp2p) authority key into the control DB via
34
+ * `ControlDatabase.ensureAuthorityKey` before minting an invite, when the
35
+ * authority key is *not* the node's peer identity (so `authorityKeyFromLibp2p`,
36
+ * which needs a libp2p key object, does not apply).
37
+ *
38
+ * @param privateKeyB64 - The base64url-encoded 32-byte Ed25519 seed.
39
+ * @returns The base64url-encoded Ed25519 public key.
40
+ */
41
+ export declare function authorityPublicKeyFromPrivate(privateKeyB64: string): string;
@@ -0,0 +1,52 @@
1
+ import { toString as uint8ArrayToString } from 'uint8arrays';
2
+ import { getPublicKey } from '@optimystic/quereus-plugin-crypto';
3
+ /**
4
+ * Bridge a libp2p Ed25519 private key into the base64url keypair used by the
5
+ * control-database authority constraints.
6
+ *
7
+ * libp2p stores an Ed25519 private key as 64 raw bytes: the first 32 are the
8
+ * seed (the actual scalar source), the last 32 are the public key — see
9
+ * `@libp2p/crypto`'s `Ed25519PrivateKey`. `@optimystic/quereus-plugin-crypto`
10
+ * (via `@noble/curves`) treats the 32-byte seed *as* the private key and
11
+ * derives the public key from it with standard Ed25519. The two derivations
12
+ * agree, so the node's peer identity and its authority key are one keypair:
13
+ * `getPublicKey(privateKeyB64)` === `publicKeyB64`.
14
+ *
15
+ * @param privateKey - The node's libp2p Ed25519 private key.
16
+ * @returns The base64url seed/public-key pair for authority operations.
17
+ * @throws If the key is not Ed25519 or the raw bytes aren't the expected length.
18
+ */
19
+ export function authorityKeyFromLibp2p(privateKey) {
20
+ if (privateKey.type !== 'Ed25519') {
21
+ throw new Error(`authorityKeyFromLibp2p requires an Ed25519 key, got ${privateKey.type}`);
22
+ }
23
+ const raw = privateKey.raw;
24
+ if (raw.length !== 64) {
25
+ throw new Error(`Expected a 64-byte Ed25519 raw private key (seed||public), got ${raw.length} bytes`);
26
+ }
27
+ const seed = raw.subarray(0, 32);
28
+ const publicKeyRaw = privateKey.publicKey.raw;
29
+ if (publicKeyRaw.length !== 32) {
30
+ throw new Error(`Expected a 32-byte Ed25519 public key, got ${publicKeyRaw.length} bytes`);
31
+ }
32
+ return {
33
+ privateKeyB64: uint8ArrayToString(seed, 'base64url'),
34
+ publicKeyB64: uint8ArrayToString(publicKeyRaw, 'base64url'),
35
+ };
36
+ }
37
+ /**
38
+ * Derive the base64url Ed25519 public key from a base64url 32-byte private seed
39
+ * — the same derivation the seed-bootstrap signer uses internally
40
+ * (`SeedBootstrapService` constructor). Use this to enroll a standalone
41
+ * (non-libp2p) authority key into the control DB via
42
+ * `ControlDatabase.ensureAuthorityKey` before minting an invite, when the
43
+ * authority key is *not* the node's peer identity (so `authorityKeyFromLibp2p`,
44
+ * which needs a libp2p key object, does not apply).
45
+ *
46
+ * @param privateKeyB64 - The base64url-encoded 32-byte Ed25519 seed.
47
+ * @returns The base64url-encoded Ed25519 public key.
48
+ */
49
+ export function authorityPublicKeyFromPrivate(privateKeyB64) {
50
+ return getPublicKey(privateKeyB64, 'ed25519', 'base64url', 'base64url');
51
+ }
52
+ //# sourceMappingURL=authority-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority-key.js","sourceRoot":"","sources":["../src/authority-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAcjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAsB;IAC3D,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,uDAAuD,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;IAC3B,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,kEAAkE,GAAG,CAAC,MAAM,QAAQ,CAAC,CAAC;IACxG,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC;IAC9C,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,8CAA8C,YAAY,CAAC,MAAM,QAAQ,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO;QACL,aAAa,EAAE,kBAAkB,CAAC,IAAI,EAAE,WAAW,CAAC;QACpD,YAAY,EAAE,kBAAkB,CAAC,YAAY,EAAE,WAAW,CAAC;KAC5D,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,6BAA6B,CAAC,aAAqB;IACjE,OAAO,YAAY,CAAC,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,CAAW,CAAC;AACpF,CAAC"}