@serfab/cadre-core 1.23.0 → 1.24.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.
Files changed (313) hide show
  1. package/README.md +216 -294
  2. package/dist/arachnode-stub.d.ts +12 -4
  3. package/dist/arachnode-stub.js +15 -8
  4. package/dist/arachnode-stub.js.map +1 -1
  5. package/dist/cadre-invite-protocol.js +5 -4
  6. package/dist/cadre-invite-protocol.js.map +1 -1
  7. package/dist/cadre-node.d.ts +145 -44
  8. package/dist/cadre-node.js +239 -79
  9. package/dist/cadre-node.js.map +1 -1
  10. package/dist/control-authorization.d.ts +14 -2
  11. package/dist/control-authorization.js +8 -3
  12. package/dist/control-authorization.js.map +1 -1
  13. package/dist/control-cohort.d.ts +27 -13
  14. package/dist/control-cohort.js +21 -14
  15. package/dist/control-cohort.js.map +1 -1
  16. package/dist/control-database.d.ts +18 -16
  17. package/dist/control-database.js +57 -22
  18. package/dist/control-database.js.map +1 -1
  19. package/dist/control-protocol-guard.d.ts +1 -1
  20. package/dist/control-protocol-guard.js +7 -3
  21. package/dist/control-protocol-guard.js.map +1 -1
  22. package/dist/control-read-retry.d.ts +49 -11
  23. package/dist/control-read-retry.js +56 -15
  24. package/dist/control-read-retry.js.map +1 -1
  25. package/dist/control-retry.d.ts +32 -3
  26. package/dist/control-retry.js +35 -4
  27. package/dist/control-retry.js.map +1 -1
  28. package/dist/control-schema-version.d.ts +5 -5
  29. package/dist/control-schema-version.js +5 -5
  30. package/dist/control-schema-version.js.map +1 -1
  31. package/dist/control-schema.d.ts +5 -5
  32. package/dist/control-schema.js +1032 -1011
  33. package/dist/control-schema.js.map +1 -1
  34. package/dist/control-write-retry.d.ts +54 -65
  35. package/dist/control-write-retry.js +134 -158
  36. package/dist/control-write-retry.js.map +1 -1
  37. package/dist/delegate-admission.d.ts +1 -1
  38. package/dist/delegate-admission.js +1 -1
  39. package/dist/edge-node/config.d.ts +4 -3
  40. package/dist/edge-node/config.js +11 -9
  41. package/dist/edge-node/config.js.map +1 -1
  42. package/dist/edge-node/dissolve.d.ts +4 -4
  43. package/dist/edge-node/dissolve.js +4 -4
  44. package/dist/edge-node/edge-join.d.ts +1 -1
  45. package/dist/edge-node/edge-join.js +1 -1
  46. package/dist/edge-node/edge-node.js +2 -2
  47. package/dist/edge-node/edge-node.js.map +1 -1
  48. package/dist/edge-node/index.d.ts +1 -0
  49. package/dist/edge-node/index.js +1 -0
  50. package/dist/edge-node/index.js.map +1 -1
  51. package/dist/edge-node/join-credential.d.ts +1 -1
  52. package/dist/edge-node/join-credential.js +1 -1
  53. package/dist/edge-node/lazy-raw-storage.js +12 -0
  54. package/dist/edge-node/lazy-raw-storage.js.map +1 -1
  55. package/dist/edge-node/listen-addrs.d.ts +21 -0
  56. package/dist/edge-node/listen-addrs.js +25 -0
  57. package/dist/edge-node/listen-addrs.js.map +1 -0
  58. package/dist/edge-node/owner-grant.d.ts +1 -1
  59. package/dist/edge-node/owner-grant.js +1 -1
  60. package/dist/edge-node/platform.d.ts +5 -4
  61. package/dist/edge-node/platform.js.map +1 -1
  62. package/dist/edge-node/strand-move.d.ts +1 -1
  63. package/dist/edge-node/strand-move.js +1 -1
  64. package/dist/edge-node/strands.js +27 -11
  65. package/dist/edge-node/strands.js.map +1 -1
  66. package/dist/index.d.ts +7 -5
  67. package/dist/index.js +18 -7
  68. package/dist/index.js.map +1 -1
  69. package/dist/invitation-bootstrap.d.ts +28 -5
  70. package/dist/invitation-bootstrap.js +41 -8
  71. package/dist/invitation-bootstrap.js.map +1 -1
  72. package/dist/link-budget.d.ts +53 -4
  73. package/dist/link-budget.js +58 -5
  74. package/dist/link-budget.js.map +1 -1
  75. package/dist/machine-removal.d.ts +2 -2
  76. package/dist/machine-removal.js +4 -3
  77. package/dist/machine-removal.js.map +1 -1
  78. package/dist/membership-connection-gater.d.ts +2 -2
  79. package/dist/membership-connection-gater.js +2 -2
  80. package/dist/membership-view.d.ts +2 -2
  81. package/dist/membership-view.js +2 -2
  82. package/dist/node-claim-payload.d.ts +15 -7
  83. package/dist/node-claim-payload.js +25 -9
  84. package/dist/node-claim-payload.js.map +1 -1
  85. package/dist/node-class.d.ts +36 -0
  86. package/dist/node-class.js +26 -0
  87. package/dist/node-class.js.map +1 -0
  88. package/dist/node-default-transports.d.ts +50 -3
  89. package/dist/node-default-transports.js +48 -3
  90. package/dist/node-default-transports.js.map +1 -1
  91. package/dist/node-roles.d.ts +118 -0
  92. package/dist/node-roles.js +142 -0
  93. package/dist/node-roles.js.map +1 -0
  94. package/dist/node-transports.d.ts +6 -2
  95. package/dist/node-transports.js +39 -7
  96. package/dist/node-transports.js.map +1 -1
  97. package/dist/owner-anchor-sync.js +1 -1
  98. package/dist/owner-key-export.js +1 -1
  99. package/dist/owner-key-flows.d.ts +1 -1
  100. package/dist/owner-key-store.js +1 -1
  101. package/dist/owner-signer.js +1 -1
  102. package/dist/peer-authorization.d.ts +3 -1
  103. package/dist/peer-authorization.js +3 -1
  104. package/dist/peer-authorization.js.map +1 -1
  105. package/dist/peer-dial.d.ts +74 -10
  106. package/dist/peer-dial.js +89 -17
  107. package/dist/peer-dial.js.map +1 -1
  108. package/dist/peer-join-backfill.js +4 -4
  109. package/dist/peer-join-backfill.js.map +1 -1
  110. package/dist/peer-record.d.ts +34 -9
  111. package/dist/peer-record.js +66 -13
  112. package/dist/peer-record.js.map +1 -1
  113. package/dist/pending-join-runner.d.ts +1 -1
  114. package/dist/pending-join-runner.js +1 -1
  115. package/dist/provider/client.d.ts +6 -5
  116. package/dist/provider/client.js +3 -3
  117. package/dist/provider/client.js.map +1 -1
  118. package/dist/provider/descriptor.d.ts +1 -1
  119. package/dist/provider/descriptor.js +1 -1
  120. package/dist/provider/oauth.d.ts +1 -1
  121. package/dist/provider/oauth.js +1 -1
  122. package/dist/provider/rent-node.d.ts +4 -3
  123. package/dist/provider/rent-node.js +3 -3
  124. package/dist/provider/rent-node.js.map +1 -1
  125. package/dist/relay-addrs.d.ts +62 -7
  126. package/dist/relay-addrs.js +74 -11
  127. package/dist/relay-addrs.js.map +1 -1
  128. package/dist/relay-reservation.d.ts +1 -1
  129. package/dist/relay-reservation.js +1 -1
  130. package/dist/relay-server.d.ts +6 -5
  131. package/dist/relay-server.js +5 -5
  132. package/dist/relay-server.js.map +1 -1
  133. package/dist/schema-verification.d.ts +13 -10
  134. package/dist/schema-verification.js +32 -24
  135. package/dist/schema-verification.js.map +1 -1
  136. package/dist/sealed-party-key.js +1 -1
  137. package/dist/seed-bootstrap.d.ts +4 -3
  138. package/dist/seed-bootstrap.js +6 -7
  139. package/dist/seed-bootstrap.js.map +1 -1
  140. package/dist/strand-addr-protocol.d.ts +8 -6
  141. package/dist/strand-addr-protocol.js +12 -10
  142. package/dist/strand-addr-protocol.js.map +1 -1
  143. package/dist/strand-app-schema-report.d.ts +16 -2
  144. package/dist/strand-app-schema-report.js +15 -0
  145. package/dist/strand-app-schema-report.js.map +1 -1
  146. package/dist/strand-cohort.d.ts +1 -4
  147. package/dist/strand-cohort.js.map +1 -1
  148. package/dist/strand-commit-durability.d.ts +1 -1
  149. package/dist/strand-database.d.ts +13 -6
  150. package/dist/strand-database.js +17 -9
  151. package/dist/strand-database.js.map +1 -1
  152. package/dist/strand-first-sync-gate.d.ts +3 -2
  153. package/dist/strand-first-sync-gate.js +3 -2
  154. package/dist/strand-first-sync-gate.js.map +1 -1
  155. package/dist/strand-formation-deadlines.d.ts +2 -2
  156. package/dist/strand-formation-deadlines.js +2 -2
  157. package/dist/strand-formation-protocol.d.ts +1 -1
  158. package/dist/strand-formation-protocol.js +51 -16
  159. package/dist/strand-formation-protocol.js.map +1 -1
  160. package/dist/strand-instance-manager.d.ts +67 -33
  161. package/dist/strand-instance-manager.js +164 -55
  162. package/dist/strand-instance-manager.js.map +1 -1
  163. package/dist/strand-membership-reconciler.d.ts +8 -3
  164. package/dist/strand-membership-reconciler.js +8 -3
  165. package/dist/strand-membership-reconciler.js.map +1 -1
  166. package/dist/strand-membership-writer.d.ts +2 -2
  167. package/dist/strand-membership-writer.js +41 -39
  168. package/dist/strand-membership-writer.js.map +1 -1
  169. package/dist/strand-move.js +1 -1
  170. package/dist/strand-network-config.d.ts +15 -5
  171. package/dist/strand-network-config.js +7 -6
  172. package/dist/strand-network-config.js.map +1 -1
  173. package/dist/strand-party-key-rotation.d.ts +7 -3
  174. package/dist/strand-party-key-rotation.js +7 -3
  175. package/dist/strand-party-key-rotation.js.map +1 -1
  176. package/dist/strand-party-machines.d.ts +19 -8
  177. package/dist/strand-party-machines.js +26 -11
  178. package/dist/strand-party-machines.js.map +1 -1
  179. package/dist/strand-party-peers.d.ts +36 -14
  180. package/dist/strand-party-peers.js +24 -15
  181. package/dist/strand-party-peers.js.map +1 -1
  182. package/dist/strand-peer-redial.d.ts +1 -1
  183. package/dist/strand-peer-redial.js +1 -1
  184. package/dist/strand-reactivity.d.ts +20 -17
  185. package/dist/strand-reactivity.js +31 -18
  186. package/dist/strand-reactivity.js.map +1 -1
  187. package/dist/strand-revocation-enforcer.d.ts +3 -3
  188. package/dist/strand-revocation-enforcer.js +3 -3
  189. package/dist/strand-wake-protocol.d.ts +19 -7
  190. package/dist/strand-wake-protocol.js +22 -10
  191. package/dist/strand-wake-protocol.js.map +1 -1
  192. package/dist/strand-watcher.d.ts +1 -1
  193. package/dist/strand-watcher.js +1 -1
  194. package/dist/table-change-watch.js +1 -1
  195. package/dist/types.d.ts +116 -55
  196. package/dist/types.js.map +1 -1
  197. package/dist/webrtc-upgrade.d.ts +254 -0
  198. package/dist/webrtc-upgrade.js +355 -0
  199. package/dist/webrtc-upgrade.js.map +1 -0
  200. package/package.json +9 -9
  201. package/src/announce-addrs.ts +93 -93
  202. package/src/arachnode-stub.ts +18 -10
  203. package/src/bootstrap-peer-store-file.ts +44 -44
  204. package/src/bootstrap-peer-store.ts +214 -214
  205. package/src/cadre-invite-protocol.ts +741 -740
  206. package/src/cadre-node.ts +12462 -12280
  207. package/src/claim-proof.ts +147 -147
  208. package/src/control-authorization.ts +290 -276
  209. package/src/control-cohort.ts +223 -204
  210. package/src/control-database.ts +72 -28
  211. package/src/control-formation-recorder.ts +359 -359
  212. package/src/control-protocol-guard.ts +370 -366
  213. package/src/control-read-retry.ts +222 -180
  214. package/src/control-retry.ts +36 -4
  215. package/src/control-schema-version.ts +301 -301
  216. package/src/control-schema.ts +1108 -1087
  217. package/src/control-write-retry.ts +639 -669
  218. package/src/delegate-admission.ts +351 -351
  219. package/src/describe-thrown.ts +60 -60
  220. package/src/ed25519-key.ts +185 -185
  221. package/src/edge-node/config.ts +13 -10
  222. package/src/edge-node/dissolve.ts +252 -252
  223. package/src/edge-node/edge-join.ts +320 -320
  224. package/src/edge-node/edge-node.ts +1095 -1095
  225. package/src/edge-node/index.ts +60 -59
  226. package/src/edge-node/join-credential.ts +16 -16
  227. package/src/edge-node/lazy-raw-storage.ts +194 -178
  228. package/src/edge-node/listen-addrs.ts +26 -0
  229. package/src/edge-node/node-local.ts +84 -84
  230. package/src/edge-node/options.ts +195 -195
  231. package/src/edge-node/owner-grant.ts +63 -63
  232. package/src/edge-node/platform.ts +5 -4
  233. package/src/edge-node/strand-move.ts +266 -266
  234. package/src/edge-node/strands.ts +27 -12
  235. package/src/enrolled-machine-store-file.ts +43 -43
  236. package/src/enrolled-machine-store.ts +280 -280
  237. package/src/fetch-impl.ts +23 -23
  238. package/src/file-durable-slot.ts +64 -64
  239. package/src/file-safe-name.ts +32 -32
  240. package/src/formation-approval.ts +604 -604
  241. package/src/formation-token.ts +63 -63
  242. package/src/fs-atomic.ts +92 -92
  243. package/src/index.ts +987 -957
  244. package/src/invitation-bootstrap.ts +152 -118
  245. package/src/joined-strand-store.ts +553 -553
  246. package/src/key-store-file.ts +142 -142
  247. package/src/link-budget.ts +61 -5
  248. package/src/machine-removal.ts +211 -210
  249. package/src/member-redemption.ts +643 -643
  250. package/src/membership-connection-gater.ts +650 -650
  251. package/src/membership-view.ts +147 -147
  252. package/src/node-claim-payload.ts +34 -12
  253. package/src/node-class.ts +47 -0
  254. package/src/node-default-transports.ts +65 -3
  255. package/src/node-roles.ts +220 -0
  256. package/src/node-transports.ts +86 -49
  257. package/src/owner-anchor-sync.ts +172 -172
  258. package/src/owner-grant-protocol.ts +547 -547
  259. package/src/owner-key-export.ts +348 -348
  260. package/src/owner-key-flows.ts +109 -109
  261. package/src/owner-key-store.ts +1 -1
  262. package/src/owner-keys.ts +179 -179
  263. package/src/owner-signer.ts +92 -92
  264. package/src/peer-addr-book.ts +252 -252
  265. package/src/peer-authorization.ts +584 -582
  266. package/src/peer-dial.ts +698 -605
  267. package/src/peer-join-backfill.ts +961 -961
  268. package/src/peer-record.ts +71 -16
  269. package/src/pending-join-runner.ts +798 -798
  270. package/src/primary-lan-address.ts +47 -47
  271. package/src/provider/client.ts +327 -326
  272. package/src/provider/descriptor.ts +129 -129
  273. package/src/provider/index.ts +59 -59
  274. package/src/provider/oauth.ts +285 -285
  275. package/src/provider/rent-node.ts +276 -275
  276. package/src/relay-addrs.ts +90 -12
  277. package/src/relay-reservation.ts +1 -1
  278. package/src/relay-server.ts +99 -98
  279. package/src/schema-verification.ts +38 -23
  280. package/src/sealed-party-key.ts +190 -190
  281. package/src/seed-bootstrap.ts +8 -11
  282. package/src/seed-trust-policy.ts +353 -353
  283. package/src/self-address-update.ts +19 -19
  284. package/src/strand-addr-protocol.ts +17 -14
  285. package/src/strand-app-schema-report.ts +147 -122
  286. package/src/strand-cohort.ts +1 -5
  287. package/src/strand-commit-durability.ts +165 -165
  288. package/src/strand-database.ts +522 -510
  289. package/src/strand-first-sync-gate.ts +3 -2
  290. package/src/strand-formation-deadlines.ts +227 -227
  291. package/src/strand-formation-manager.ts +731 -731
  292. package/src/strand-formation-protocol.ts +1174 -1138
  293. package/src/strand-fret-addrs.ts +179 -179
  294. package/src/strand-instance-manager.ts +188 -63
  295. package/src/strand-membership-reconciler.ts +1315 -1310
  296. package/src/strand-membership-writer.ts +2152 -2150
  297. package/src/strand-move.ts +1 -1
  298. package/src/strand-network-config.ts +16 -6
  299. package/src/strand-offline.ts +178 -178
  300. package/src/strand-party-key-rotation.ts +440 -436
  301. package/src/strand-party-machines.ts +308 -293
  302. package/src/strand-party-peers.ts +151 -129
  303. package/src/strand-peer-redial.ts +1 -1
  304. package/src/strand-reactivity.ts +36 -19
  305. package/src/strand-revocation-enforcer.ts +758 -758
  306. package/src/strand-wake-protocol.ts +406 -394
  307. package/src/strand-watcher.ts +1 -1
  308. package/src/table-change-watch.ts +285 -285
  309. package/src/timed-step.ts +28 -28
  310. package/src/timeout-scheduler.ts +29 -29
  311. package/src/trusted-owner-store.ts +242 -242
  312. package/src/types.ts +3182 -3121
  313. package/src/webrtc-upgrade.ts +439 -0
@@ -53,8 +53,9 @@
53
53
  * other. A node with configured relays is built with that discovery switched off
54
54
  * altogether when it has a transport list to wrap (`node-transports.ts`), because it
55
55
  * CAN reach a relay-capable peer in its own namespace and take the configured relay's
56
- * slot. See `relay-reservation.ts`'s module doc and `docs/architecture.md`.
56
+ * slot. See `relay-reservation.ts`'s module doc and `docs/network/relay.md`.
57
57
  */
58
+ import { type StunServer } from './relay-stun.js';
58
59
  import type { NetworkConfig } from './types.js';
59
60
  import type { RelayReservationState } from './relay-reservation.js';
60
61
  /**
@@ -77,6 +78,18 @@ export declare const DEFAULT_DIRECT_LISTEN_ADDR = "/ip4/0.0.0.0/tcp/0";
77
78
  * each relay's supervisor has a slot of its own to fill.
78
79
  */
79
80
  export declare const RELAY_SEARCH_LISTEN_ADDR = "/p2p-circuit";
81
+ /**
82
+ * The WebRTC listen entry, for every host that offers one: the edge apps
83
+ * (`edge-node/listen-addrs.ts`) and `cadre-cli`'s `network.webrtc`. One home for the
84
+ * spelling {@link listenTransportKind} classifies, like the two constants around it —
85
+ * a host that mis-spells it gets a refusal naming the transport instead of a listener.
86
+ *
87
+ * It binds no socket: the transport registers libp2p's signalling handler and derives
88
+ * this node's address from each relay reservation it holds, which is why the entry is
89
+ * worth adding to a machine reachable only through a relay and worth nothing on one with
90
+ * a public address.
91
+ */
92
+ export declare const WEBRTC_LISTEN_ADDR = "/webrtc";
80
93
  /**
81
94
  * The circuit-listen multiaddr for each configured relay: `<relayAddr>/p2p-circuit`.
82
95
  * An entry that already carries `/p2p-circuit` is passed through unchanged.
@@ -120,7 +133,37 @@ export interface ListenTransportOptions {
120
133
  * {@link WS_TRANSPORT_SWITCH_PORT}.
121
134
  */
122
135
  wsPort?: number;
136
+ /**
137
+ * Present when some listen entry names `/webrtc` — the switch that makes
138
+ * `nodeDefaultTransports` add `@libp2p/webrtc`'s transport
139
+ * (`node-default-transports.ts`). Unlike {@link wsPort} the value is real: it is the
140
+ * ICE servers that transport needs, derived once here from `network.relayAddrs` and
141
+ * `network.stunUrls` (`relay-stun.ts` → `resolveStunServers`), so the factory reads one
142
+ * field instead of re-deriving them from a `NetworkConfig` it is not given.
143
+ *
144
+ * May be EMPTY, and an empty array is still the switch: WebRTC with no STUN server
145
+ * offers host and LAN candidates only, which is enough between two machines on one
146
+ * network. Absent is the only "no WebRTC" answer.
147
+ */
148
+ webrtcIceServers?: StunServer[];
123
149
  }
150
+ /**
151
+ * The subset of a resolved {@link ListenTransportOptions} that is a `createLibp2pNode` option,
152
+ * for the two sites that spread it into one (`cadre-node.ts`, `strand-instance-manager.ts`).
153
+ *
154
+ * `wsPort` is db-p2p's own switch, so it goes through. {@link ListenTransportOptions.webrtcIceServers}
155
+ * does not: it is read only by `network.defaultTransports`, and db-p2p knows no such key —
156
+ * handing it one is the drift the strand builder already avoids for `relayAddrs`. One home for
157
+ * that distinction rather than a correct spread at each site.
158
+ *
159
+ * NOTE: the allow-list is the destructuring, so a THIRD {@link ListenTransportOptions} field that
160
+ * is a db-p2p option has to be added here too or it is dropped in silence. Deliberate — the
161
+ * opposite default would leak a cadre-only field into db-p2p's options, which is the failure the
162
+ * function exists to prevent.
163
+ */
164
+ export declare function listenTransportNodeOptions({ wsPort }: ListenTransportOptions): {
165
+ wsPort?: number;
166
+ };
124
167
  /**
125
168
  * The transport-derived libp2p options `listenAddrs` implies, and the gate that stops a
126
169
  * listen address the node has no transport for from being SILENTLY dropped.
@@ -144,11 +187,18 @@ export interface ListenTransportOptions {
144
187
  * case where cadre passes the transport list itself (`node-transports.ts`, to switch
145
188
  * relay discovery off); when the embedder gave none, that list comes from
146
189
  * `network.defaultTransports`, which reads the same switch.
147
- * - **Everything else is REFUSED.** Deriving `/quic-v1`, `/webrtc` or `/webtransport`
148
- * would mean importing transport packages into every `cadre-core` consumer including
149
- * the React Native and browser bundles (against the cross-platform rule in
150
- * `AGENTS.md`) and duplicating policy `libp2p-node.ts` owns. So name the address, name
151
- * the transport it needs, and refuse to start — matching how `network.relayAddrs` and
190
+ * - **WebRTC is derived ONLY for a node that passed `network.defaultTransports`.** That
191
+ * field is a Node host's injected transport list
192
+ * (`@serfab/cadre-core/node-default-transports`), and it is the only thing in this repo
193
+ * that can supply `@libp2p/webrtc`'s Node build — whose module graph loads
194
+ * `node-datachannel`'s native addon, so this file's graph, which every React Native and
195
+ * browser bundle reaches, must not import it. Without that field a `/webrtc` entry is
196
+ * refused exactly as before.
197
+ * - **Everything else is REFUSED.** Deriving `/quic-v1` or `/webtransport` would mean
198
+ * importing transport packages into every `cadre-core` consumer including the React
199
+ * Native and browser bundles (against the cross-platform rule in `AGENTS.md`) and
200
+ * duplicating policy `libp2p-node.ts` owns. So name the address, name the transport it
201
+ * needs, and refuse to start — matching how `network.relayAddrs` and
152
202
  * `network.announceAddrs` already treat an operator typo.
153
203
  *
154
204
  * Returns `{}` unconditionally when `network.transports` is set: a programmatic embedder
@@ -172,7 +222,8 @@ export interface ListenTransportOptions {
172
222
  * {@link resolveListenAddrs}, or the strand derivation, after any per-node rewriting —
173
223
  * so the check reads what this node will actually bind.
174
224
  * @throws {UnbindableListenAddressError} when a listen entry names a transport outside
175
- * {tcp, ws/wss, p2p-circuit}.
225
+ * {tcp, ws/wss, p2p-circuit}, or names `/webrtc` on a node that passed no
226
+ * `network.defaultTransports`.
176
227
  */
177
228
  export declare function resolveTransportOptions(network: NetworkConfig | undefined, listenAddrs: readonly string[] | undefined): ListenTransportOptions;
178
229
  /**
@@ -180,6 +231,10 @@ export declare function resolveTransportOptions(network: NetworkConfig | undefin
180
231
  * default transports can bind. Names each offending address alongside the libp2p
181
232
  * transport package it would need — what the operator has without this is a node that
182
233
  * starts and silently never listens there.
234
+ *
235
+ * A `/webrtc` entry reaches this only on a node that passed no
236
+ * `network.defaultTransports`, so it gets the extra sentence naming the setting that
237
+ * does supply WebRTC on a Node host.
183
238
  */
184
239
  export declare class UnbindableListenAddressError extends Error {
185
240
  readonly listenAddrs: readonly string[];
@@ -53,10 +53,11 @@
53
53
  * other. A node with configured relays is built with that discovery switched off
54
54
  * altogether when it has a transport list to wrap (`node-transports.ts`), because it
55
55
  * CAN reach a relay-capable peer in its own namespace and take the configured relay's
56
- * slot. See `relay-reservation.ts`'s module doc and `docs/architecture.md`.
56
+ * slot. See `relay-reservation.ts`'s module doc and `docs/network/relay.md`.
57
57
  */
58
58
  import { multiaddr } from '@multiformats/multiaddr';
59
59
  import { circuitRelayTargetOrThrow } from './delegate-admission.js';
60
+ import { resolveStunServers } from './relay-stun.js';
60
61
  /**
61
62
  * The direct listener a node keeps when it configures `relayAddrs` but no
62
63
  * `listenAddrs`. Without this, naming a relay would silently REPLACE the node's
@@ -77,6 +78,18 @@ export const DEFAULT_DIRECT_LISTEN_ADDR = '/ip4/0.0.0.0/tcp/0';
77
78
  * each relay's supervisor has a slot of its own to fill.
78
79
  */
79
80
  export const RELAY_SEARCH_LISTEN_ADDR = '/p2p-circuit';
81
+ /**
82
+ * The WebRTC listen entry, for every host that offers one: the edge apps
83
+ * (`edge-node/listen-addrs.ts`) and `cadre-cli`'s `network.webrtc`. One home for the
84
+ * spelling {@link listenTransportKind} classifies, like the two constants around it —
85
+ * a host that mis-spells it gets a refusal naming the transport instead of a listener.
86
+ *
87
+ * It binds no socket: the transport registers libp2p's signalling handler and derives
88
+ * this node's address from each relay reservation it holds, which is why the entry is
89
+ * worth adding to a machine reachable only through a relay and worth nothing on one with
90
+ * a public address.
91
+ */
92
+ export const WEBRTC_LISTEN_ADDR = '/webrtc';
80
93
  /**
81
94
  * The circuit-listen multiaddr for each configured relay: `<relayAddr>/p2p-circuit`.
82
95
  * An entry that already carries `/p2p-circuit` is passed through unchanged.
@@ -119,11 +132,28 @@ export function resolveListenAddrs(network) {
119
132
  if (!listenAddrs && relayEntries.length === 0) {
120
133
  return undefined;
121
134
  }
122
- // An explicitly empty `listenAddrs` (the React Native "cannot listen" case) stays
135
+ // An explicitly empty `listenAddrs` (a device that names no listener of its own) stays
123
136
  // empty — but a relay named alongside it still gets its listen entry, since
124
137
  // acquiring a slot is the whole point of configuring a relay.
125
138
  return dedupe([...(listenAddrs ?? [DEFAULT_DIRECT_LISTEN_ADDR]), ...relayEntries]);
126
139
  }
140
+ /**
141
+ * The subset of a resolved {@link ListenTransportOptions} that is a `createLibp2pNode` option,
142
+ * for the two sites that spread it into one (`cadre-node.ts`, `strand-instance-manager.ts`).
143
+ *
144
+ * `wsPort` is db-p2p's own switch, so it goes through. {@link ListenTransportOptions.webrtcIceServers}
145
+ * does not: it is read only by `network.defaultTransports`, and db-p2p knows no such key —
146
+ * handing it one is the drift the strand builder already avoids for `relayAddrs`. One home for
147
+ * that distinction rather than a correct spread at each site.
148
+ *
149
+ * NOTE: the allow-list is the destructuring, so a THIRD {@link ListenTransportOptions} field that
150
+ * is a db-p2p option has to be added here too or it is dropped in silence. Deliberate — the
151
+ * opposite default would leak a cadre-only field into db-p2p's options, which is the failure the
152
+ * function exists to prevent.
153
+ */
154
+ export function listenTransportNodeOptions({ wsPort }) {
155
+ return wsPort === undefined ? {} : { wsPort };
156
+ }
127
157
  /**
128
158
  * The `wsPort` value passed purely to turn `@optimystic/db-p2p`'s WebSocket transport
129
159
  * ON. It is never bound, so it is deliberately `0` rather than a port scraped from a
@@ -177,11 +207,18 @@ const WS_TRANSPORT_SWITCH_PORT = 0;
177
207
  * case where cadre passes the transport list itself (`node-transports.ts`, to switch
178
208
  * relay discovery off); when the embedder gave none, that list comes from
179
209
  * `network.defaultTransports`, which reads the same switch.
180
- * - **Everything else is REFUSED.** Deriving `/quic-v1`, `/webrtc` or `/webtransport`
181
- * would mean importing transport packages into every `cadre-core` consumer including
182
- * the React Native and browser bundles (against the cross-platform rule in
183
- * `AGENTS.md`) and duplicating policy `libp2p-node.ts` owns. So name the address, name
184
- * the transport it needs, and refuse to start — matching how `network.relayAddrs` and
210
+ * - **WebRTC is derived ONLY for a node that passed `network.defaultTransports`.** That
211
+ * field is a Node host's injected transport list
212
+ * (`@serfab/cadre-core/node-default-transports`), and it is the only thing in this repo
213
+ * that can supply `@libp2p/webrtc`'s Node build — whose module graph loads
214
+ * `node-datachannel`'s native addon, so this file's graph, which every React Native and
215
+ * browser bundle reaches, must not import it. Without that field a `/webrtc` entry is
216
+ * refused exactly as before.
217
+ * - **Everything else is REFUSED.** Deriving `/quic-v1` or `/webtransport` would mean
218
+ * importing transport packages into every `cadre-core` consumer including the React
219
+ * Native and browser bundles (against the cross-platform rule in `AGENTS.md`) and
220
+ * duplicating policy `libp2p-node.ts` owns. So name the address, name the transport it
221
+ * needs, and refuse to start — matching how `network.relayAddrs` and
185
222
  * `network.announceAddrs` already treat an operator typo.
186
223
  *
187
224
  * Returns `{}` unconditionally when `network.transports` is set: a programmatic embedder
@@ -205,31 +242,49 @@ const WS_TRANSPORT_SWITCH_PORT = 0;
205
242
  * {@link resolveListenAddrs}, or the strand derivation, after any per-node rewriting —
206
243
  * so the check reads what this node will actually bind.
207
244
  * @throws {UnbindableListenAddressError} when a listen entry names a transport outside
208
- * {tcp, ws/wss, p2p-circuit}.
245
+ * {tcp, ws/wss, p2p-circuit}, or names `/webrtc` on a node that passed no
246
+ * `network.defaultTransports`.
209
247
  */
210
248
  export function resolveTransportOptions(network, listenAddrs) {
211
249
  if (network?.transports) {
212
250
  return {};
213
251
  }
214
252
  const kinds = (listenAddrs ?? []).map((addr) => [addr, listenTransportKind(addr)]);
215
- const unsupported = kinds.filter(([, kind]) => kind === 'unsupported').map(([addr]) => addr);
253
+ // A `/webrtc` entry is bindable only through an injected default transport list, so
254
+ // without one it joins the refusal rather than being accepted and silently unbound.
255
+ const webrtcBindable = network?.defaultTransports !== undefined;
256
+ const unsupported = kinds
257
+ .filter(([, kind]) => kind === 'unsupported' || (kind === 'webrtc' && !webrtcBindable))
258
+ .map(([addr]) => addr);
216
259
  if (unsupported.length > 0) {
217
260
  throw new UnbindableListenAddressError(unsupported);
218
261
  }
219
- return kinds.some(([, kind]) => kind === 'websockets') ? { wsPort: WS_TRANSPORT_SWITCH_PORT } : {};
262
+ return {
263
+ ...(kinds.some(([, kind]) => kind === 'websockets') && { wsPort: WS_TRANSPORT_SWITCH_PORT }),
264
+ ...(kinds.some(([, kind]) => kind === 'webrtc') && {
265
+ webrtcIceServers: resolveStunServers(network?.relayAddrs ?? [], network?.stunUrls)
266
+ })
267
+ };
220
268
  }
221
269
  /**
222
270
  * Thrown at config resolution when `network.listenAddrs` names an address none of the
223
271
  * default transports can bind. Names each offending address alongside the libp2p
224
272
  * transport package it would need — what the operator has without this is a node that
225
273
  * starts and silently never listens there.
274
+ *
275
+ * A `/webrtc` entry reaches this only on a node that passed no
276
+ * `network.defaultTransports`, so it gets the extra sentence naming the setting that
277
+ * does supply WebRTC on a Node host.
226
278
  */
227
279
  export class UnbindableListenAddressError extends Error {
228
280
  constructor(listenAddrs) {
229
281
  super('network.listenAddrs names an address this node has no transport for: ' +
230
282
  `${listenAddrs.map((a) => `${a} — ${unbindableReason(a)}`).join('; ')}. ` +
231
283
  'Default transports bind TCP (including /unix/<path>), WebSocket (/ws, /wss) and circuit-relay addresses only. ' +
232
- 'Either drop the address, or supply the transport programmatically via network.transports.');
284
+ 'Either drop the address, or supply the transport programmatically via network.transports.' +
285
+ (listenAddrs.some((a) => listenTransportKind(a) === 'webrtc')
286
+ ? ' A /webrtc listener needs a Node host that passes network.defaultTransports (cadre-cli: network.webrtc).'
287
+ : ''));
233
288
  this.listenAddrs = listenAddrs;
234
289
  this.name = 'UnbindableListenAddressError';
235
290
  }
@@ -267,6 +322,14 @@ function listenTransportKind(listenAddr) {
267
322
  if (outermost === 'ws' || outermost === 'wss') {
268
323
  return 'websockets';
269
324
  }
325
+ // Read from the outermost component like every other kind here, so `/webrtc` and a
326
+ // `…/p2p-circuit/webrtc` entry classify alike — they need the same transport, and the
327
+ // relayed form is the shape libp2p itself derives for a `/webrtc` listener once the
328
+ // reservation lands. `/webrtc-direct` is deliberately NOT this kind: it is a separate
329
+ // libp2p transport (`webRTCDirect`) that nothing here supplies.
330
+ if (outermost === 'webrtc') {
331
+ return 'webrtc';
332
+ }
270
333
  // Only a BARE tcp or unix stack is TCP. `@libp2p/tcp` binds both — its `listenFilter`
271
334
  // accepts an exact TCP match OR a `/unix/<path>` address (a named pipe on Windows) —
272
335
  // and nothing layered on top of either, which is why `/tcp/<port>/<anything else>` is
@@ -1 +1 @@
1
- {"version":3,"file":"relay-addrs.js","sourceRoot":"","sources":["../src/relay-addrs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,EAAE,SAAS,EAAkB,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAIpE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC;AAEvD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAA6B;IAC7D,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,MAA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,SAAS,CAAC,CAAC,aAAa,EAAE,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sDAAsD,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACrG,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,SAAS,MAAM,CAAC,KAAwB;IACtC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC"}
@@ -75,7 +75,7 @@
75
75
  *
76
76
  * ⚠️ WHY LIBP2P'S RELAY DISCOVERY IS SWITCHED OFF. Discovery does reach SOME
77
77
  * peers: every connected peer whose identify lists the relay-hop protocol, and a
78
- * storage-profile member's strand node runs the relay server in the same
78
+ * `'server'` member's strand node runs the relay server in the same
79
79
  * `/optimystic/strand-<id>/…` namespace as this node's strand node (control nodes
80
80
  * share `/optimystic/control-<partyId>/…` the same way). Discovery reserves on such
81
81
  * a peer as soon as it connects, and that takes one of the slots the configured
@@ -75,7 +75,7 @@
75
75
  *
76
76
  * ⚠️ WHY LIBP2P'S RELAY DISCOVERY IS SWITCHED OFF. Discovery does reach SOME
77
77
  * peers: every connected peer whose identify lists the relay-hop protocol, and a
78
- * storage-profile member's strand node runs the relay server in the same
78
+ * `'server'` member's strand node runs the relay server in the same
79
79
  * `/optimystic/strand-<id>/…` namespace as this node's strand node (control nodes
80
80
  * share `/optimystic/control-<partyId>/…` the same way). Discovery reserves on such
81
81
  * a peer as soon as it connects, and that takes one of the slots the configured
@@ -16,7 +16,8 @@
16
16
  * this is the same policy for the party-run kind.
17
17
  */
18
18
  import type { CircuitRelayServerInit, ServerReservationStoreInit } from '@libp2p/circuit-relay-v2';
19
- import type { NetworkConfig, NodeProfile } from './types.js';
19
+ import type { NetworkConfig } from './types.js';
20
+ import type { NodeRoles } from './node-roles.js';
20
21
  /**
21
22
  * Default size of a party-run relay's reservation store, raised from libp2p's 15.
22
23
  *
@@ -65,15 +66,15 @@ export interface ResolvedRelayServer {
65
66
  };
66
67
  }
67
68
  /**
68
- * Resolve the relay server for a node built from `network` with `profile`.
69
+ * Resolve the relay server for a node built from `network` with `roles`.
69
70
  *
70
- * `enabled`: an explicit `network.enableRelay` wins; otherwise storage-profile nodes run
71
- * the server (they are the machines with the connectivity and uptime to be a relay).
71
+ * `enabled`: an explicit `network.enableRelay` wins; otherwise an always-on node runs the
72
+ * server (those are the machines with the connectivity and uptime to be a relay).
72
73
  *
73
74
  * `init`: MERGED, not replaced. `reservations` is merged key by key over the party-run
74
75
  * defaults, so a caller who sets only `maxReservations` does not silently get the data
75
76
  * limit back; every other top-level key is taken from the caller as given. A key set to
76
77
  * `undefined` counts as unset, so the default beneath it holds.
77
78
  */
78
- export declare function resolveRelayServer(network: NetworkConfig | undefined, profile: NodeProfile): ResolvedRelayServer;
79
+ export declare function resolveRelayServer(network: NetworkConfig | undefined, roles: NodeRoles): ResolvedRelayServer;
79
80
  export {};
@@ -47,20 +47,20 @@ const PARTY_RELAY_RESERVATION_DEFAULTS = {
47
47
  reservationTtl: PARTY_RELAY_RESERVATION_TTL_MS
48
48
  };
49
49
  /**
50
- * Resolve the relay server for a node built from `network` with `profile`.
50
+ * Resolve the relay server for a node built from `network` with `roles`.
51
51
  *
52
- * `enabled`: an explicit `network.enableRelay` wins; otherwise storage-profile nodes run
53
- * the server (they are the machines with the connectivity and uptime to be a relay).
52
+ * `enabled`: an explicit `network.enableRelay` wins; otherwise an always-on node runs the
53
+ * server (those are the machines with the connectivity and uptime to be a relay).
54
54
  *
55
55
  * `init`: MERGED, not replaced. `reservations` is merged key by key over the party-run
56
56
  * defaults, so a caller who sets only `maxReservations` does not silently get the data
57
57
  * limit back; every other top-level key is taken from the caller as given. A key set to
58
58
  * `undefined` counts as unset, so the default beneath it holds.
59
59
  */
60
- export function resolveRelayServer(network, profile) {
60
+ export function resolveRelayServer(network, roles) {
61
61
  const override = network?.relayServerInit;
62
62
  return {
63
- enabled: network?.enableRelay ?? (profile === 'storage'),
63
+ enabled: network?.enableRelay ?? roles.alwaysOn,
64
64
  init: {
65
65
  ...override,
66
66
  reservations: { ...PARTY_RELAY_RESERVATION_DEFAULTS, ...definedEntries(override?.reservations) }
@@ -1 +1 @@
1
- {"version":3,"file":"relay-server.js","sourceRoot":"","sources":["../src/relay-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjE;;;;GAIG;AACH,MAAM,gCAAgC,GAAG;IACvC,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,4BAA4B;IAC7C,cAAc,EAAE,8BAA8B;CACD,CAAC;AAmBhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC,EAAE,OAAoB;IACzF,MAAM,QAAQ,GAAG,OAAO,EAAE,eAAe,CAAC;IAC1C,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,WAAW,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC;QACxD,IAAI,EAAE;YACJ,GAAG,QAAQ;YACX,YAAY,EAAE,EAAE,GAAG,gCAAgC,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;SACjG;KACF,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,SAAS,cAAc,CAAmB,GAAkB;IAC1D,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAe,CAAC;AAChH,CAAC"}
1
+ {"version":3,"file":"relay-server.js","sourceRoot":"","sources":["../src/relay-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjE;;;;GAIG;AACH,MAAM,gCAAgC,GAAG;IACvC,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,4BAA4B;IAC7C,cAAc,EAAE,8BAA8B;CACD,CAAC;AAmBhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC,EAAE,KAAgB;IACrF,MAAM,QAAQ,GAAG,OAAO,EAAE,eAAe,CAAC;IAC1C,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,WAAW,IAAI,KAAK,CAAC,QAAQ;QAC/C,IAAI,EAAE;YACJ,GAAG,QAAQ;YACX,YAAY,EAAE,EAAE,GAAG,gCAAgC,EAAE,GAAG,cAAc,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;SACjG;KACF,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,SAAS,cAAc,CAAmB,GAAkB;IAC1D,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAe,CAAC;AAChH,CAAC"}
@@ -1,36 +1,39 @@
1
1
  import type { SAppConfig } from './types.js';
2
+ /** The `SAppConfig` fields the author's signature covers. */
3
+ export type SignedSAppFields = Pick<SAppConfig, 'schema' | 'version' | 'schemaVersion'>;
2
4
  /**
3
5
  * Error thrown when sApp schema signature verification fails.
4
6
  */
5
7
  export declare class SchemaVerificationError extends Error {
6
8
  readonly sAppId: string;
7
9
  readonly version: string;
8
- constructor(sAppId: string, version: string, reason: string);
10
+ constructor(sAppId: string, version: string, schemaVersion: number, reason: string);
9
11
  }
10
12
  /**
11
- * Sign an sApp schema with the author's ed25519 private key.
12
- * Used by sApp authors when publishing their schema.
13
+ * Sign an sApp schema, its release version and its schema version with the author's ed25519
14
+ * private key. Used by sApp authors when publishing their schema.
13
15
  *
14
- * @param schema - The declarative schema DDL
15
- * @param version - Schema version string
16
+ * @param sApp - The declarative schema DDL, the release version string and the schema version
16
17
  * @param authorPrivateKey - Author's ed25519 private key (base64url)
17
18
  * @returns Signature (base64url)
18
19
  */
19
- export declare function signSchema(schema: string, version: string, authorPrivateKey: string): string;
20
+ export declare function signSchema(sApp: SignedSAppFields, authorPrivateKey: string): string;
20
21
  /**
21
22
  * Verify an sApp schema signature against the author's ed25519 public key.
22
23
  *
23
- * @param schema - The declarative schema DDL
24
- * @param version - Schema version string
24
+ * @param sApp - The declarative schema DDL, the release version string and the schema version
25
25
  * @param signature - Signature to verify (base64url)
26
26
  * @param authorPublicKey - Author's ed25519 public key (base64url)
27
27
  * @returns true if the signature is valid
28
28
  */
29
- export declare function verifySchema(schema: string, version: string, signature: string, authorPublicKey: string): boolean;
29
+ export declare function verifySchema(sApp: SignedSAppFields, signature: string, authorPublicKey: string): boolean;
30
30
  /**
31
31
  * Assert that an SAppConfig has a valid schema signature.
32
32
  * Throws SchemaVerificationError on failure.
33
33
  *
34
+ * A `schemaVersion` that is not a positive safe integer is refused with reason
35
+ * `'invalid schemaVersion'` under either policy.
36
+ *
34
37
  * Fail-closed by default: when `options.requireSignature` is not explicitly
35
38
  * `false`, an absent signature is rejected with reason `'missing signature'`,
36
39
  * distinct from the `'invalid signature'` (tampered/wrong-key) case. The
@@ -39,7 +42,7 @@ export declare function verifySchema(schema: string, version: string, signature:
39
42
  *
40
43
  * @param sAppConfig - The sApp configuration to verify
41
44
  * @param options - Verification policy; `requireSignature` defaults to `true`
42
- * @throws SchemaVerificationError if the signature is missing (when required) or invalid
45
+ * @throws SchemaVerificationError if the schema version is malformed, or the signature is missing (when required) or invalid
43
46
  */
44
47
  export declare function assertSchemaSignature(sAppConfig: SAppConfig, options?: {
45
48
  requireSignature?: boolean;
@@ -5,57 +5,61 @@ const log = debug('sereus:cadre:schema-verify');
5
5
  * Error thrown when sApp schema signature verification fails.
6
6
  */
7
7
  export class SchemaVerificationError extends Error {
8
- constructor(sAppId, version, reason) {
9
- super(`sApp schema verification failed for ${sAppId} v${version}: ${reason}`);
8
+ constructor(sAppId, version, schemaVersion, reason) {
9
+ super(`sApp schema verification failed for ${sAppId} v${version} (schema version ${String(schemaVersion)}): ${reason}`);
10
10
  this.sAppId = sAppId;
11
11
  this.version = version;
12
12
  this.name = 'SchemaVerificationError';
13
13
  }
14
14
  }
15
15
  /**
16
- * Compute the canonical digest of a schema + version for signing/verification.
17
- * The payload is deterministic JSON: `{"schema":"...","version":"..."}`.
16
+ * Compute the canonical digest of the signed sApp fields for signing/verification.
17
+ * The payload is deterministic JSON, keys in this order:
18
+ * `{"schema":"...","schemaVersion":N,"version":"..."}`.
18
19
  */
19
- function schemaDigest(schema, version) {
20
- const payload = JSON.stringify({ schema, version });
20
+ function schemaDigest({ schema, schemaVersion, version }) {
21
+ const payload = JSON.stringify({ schema, schemaVersion, version });
21
22
  return digest([payload], 'sha256', 'base64url');
22
23
  }
23
24
  /**
24
- * Sign an sApp schema with the author's ed25519 private key.
25
- * Used by sApp authors when publishing their schema.
25
+ * Sign an sApp schema, its release version and its schema version with the author's ed25519
26
+ * private key. Used by sApp authors when publishing their schema.
26
27
  *
27
- * @param schema - The declarative schema DDL
28
- * @param version - Schema version string
28
+ * @param sApp - The declarative schema DDL, the release version string and the schema version
29
29
  * @param authorPrivateKey - Author's ed25519 private key (base64url)
30
30
  * @returns Signature (base64url)
31
31
  */
32
- export function signSchema(schema, version, authorPrivateKey) {
33
- const d = schemaDigest(schema, version);
34
- return sign(d, authorPrivateKey, 'ed25519', 'base64url', 'base64url', 'base64url');
32
+ export function signSchema(sApp, authorPrivateKey) {
33
+ return sign(schemaDigest(sApp), authorPrivateKey, 'ed25519', 'base64url', 'base64url', 'base64url');
35
34
  }
36
35
  /**
37
36
  * Verify an sApp schema signature against the author's ed25519 public key.
38
37
  *
39
- * @param schema - The declarative schema DDL
40
- * @param version - Schema version string
38
+ * @param sApp - The declarative schema DDL, the release version string and the schema version
41
39
  * @param signature - Signature to verify (base64url)
42
40
  * @param authorPublicKey - Author's ed25519 public key (base64url)
43
41
  * @returns true if the signature is valid
44
42
  */
45
- export function verifySchema(schema, version, signature, authorPublicKey) {
43
+ export function verifySchema(sApp, signature, authorPublicKey) {
46
44
  try {
47
- const d = schemaDigest(schema, version);
48
- return verify(d, signature, authorPublicKey, 'ed25519', 'base64url', 'base64url', 'base64url');
45
+ return verify(schemaDigest(sApp), signature, authorPublicKey, 'ed25519', 'base64url', 'base64url', 'base64url');
49
46
  }
50
47
  catch (error) {
51
48
  log('Schema verification error: %o', error);
52
49
  return false;
53
50
  }
54
51
  }
52
+ /** A schema version is a positive safe integer; anything else could not be compared against a strand's. */
53
+ function isValidSchemaVersion(schemaVersion) {
54
+ return Number.isSafeInteger(schemaVersion) && schemaVersion >= 1;
55
+ }
55
56
  /**
56
57
  * Assert that an SAppConfig has a valid schema signature.
57
58
  * Throws SchemaVerificationError on failure.
58
59
  *
60
+ * A `schemaVersion` that is not a positive safe integer is refused with reason
61
+ * `'invalid schemaVersion'` under either policy.
62
+ *
59
63
  * Fail-closed by default: when `options.requireSignature` is not explicitly
60
64
  * `false`, an absent signature is rejected with reason `'missing signature'`,
61
65
  * distinct from the `'invalid signature'` (tampered/wrong-key) case. The
@@ -64,23 +68,27 @@ export function verifySchema(schema, version, signature, authorPublicKey) {
64
68
  *
65
69
  * @param sAppConfig - The sApp configuration to verify
66
70
  * @param options - Verification policy; `requireSignature` defaults to `true`
67
- * @throws SchemaVerificationError if the signature is missing (when required) or invalid
71
+ * @throws SchemaVerificationError if the schema version is malformed, or the signature is missing (when required) or invalid
68
72
  */
69
73
  export function assertSchemaSignature(sAppConfig, options) {
70
- const { id, version, schema, signature } = sAppConfig;
74
+ const { id, version, schemaVersion, signature } = sAppConfig;
71
75
  const requireSignature = options?.requireSignature ?? true;
76
+ const refuse = (reason) => new SchemaVerificationError(id ?? '', version, schemaVersion, reason);
77
+ if (!isValidSchemaVersion(schemaVersion)) {
78
+ throw refuse('invalid schemaVersion');
79
+ }
72
80
  if (!signature) {
73
81
  if (requireSignature) {
74
- throw new SchemaVerificationError(id ?? '', version, 'missing signature');
82
+ throw refuse('missing signature');
75
83
  }
76
84
  log('No signature provided for %s v%s — skipping verification (policy relaxed)', id, version);
77
85
  return;
78
86
  }
79
87
  if (!id) {
80
- throw new SchemaVerificationError(id ?? '', version, 'missing author public key');
88
+ throw refuse('missing author public key');
81
89
  }
82
- if (!verifySchema(schema, version, signature, id)) {
83
- throw new SchemaVerificationError(id, version, 'invalid signature');
90
+ if (!verifySchema(sAppConfig, signature, id)) {
91
+ throw refuse('invalid signature');
84
92
  }
85
93
  }
86
94
  //# sourceMappingURL=schema-verification.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-verification.js","sourceRoot":"","sources":["../src/schema-verification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAGzE,MAAM,GAAG,GAAG,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YACkB,MAAc,EACd,OAAe,EAC/B,MAAc;QAEd,KAAK,CAAC,uCAAuC,MAAM,KAAK,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC;QAJ9D,WAAM,GAAN,MAAM,CAAQ;QACd,YAAO,GAAP,OAAO,CAAQ;QAI/B,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED;;;GAG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B,CAAC,aAAa,CAAC,EAAE,CAAC;QACzC,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,IAAI,gBAAgB,EAAE,CAAC;YACrB,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QACD,GAAG,CAAC,2EAA2E,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAC9F,OAAO;IACT,CAAC;IAED,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC;QAC7C,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The pending party key, sealed to the machines that remain: how `PendingStrandPartyKey.SealedKey`
3
- * carries the key a party moves to after a machine removal (`docs/architecture.md` → "Removing a
3
+ * carries the key a party moves to after a machine removal (`docs/cadre/membership.md` → "Removing a
4
4
  * machine"). The row is written in the same control transaction as the removed machine's
5
5
  * tombstone, so it reaches that machine; what it carries must open only for the others.
6
6
  *
@@ -593,7 +593,7 @@ export declare class SeedBootstrapService {
593
593
  * A connection to `peerId` for {@link deliverSeed}, from {@link dialPeerAddrs}: one already
594
594
  * open without relay limits, or one dialed from `addrs` — each address on
595
595
  * `dialBudget.perAddressMs`, the whole peer within `dialBudget.totalMs`, direct addresses
596
- * before relayed ones and the given order otherwise.
596
+ * first, then relayed, then WebRTC, and the given order within each group.
597
597
  *
598
598
  * @throws {PeerUnreachableError} when no connection formed, with the dial's error as `cause`.
599
599
  */
@@ -621,8 +621,9 @@ export declare class SeedBootstrapService {
621
621
  */
622
622
  private readSeedAck;
623
623
  /**
624
- * Get this node's circuit relay address for inclusion in seeds.
625
- * Returns null if no relay address is available.
624
+ * This node's one relayed address for a seed, or null when it holds no reservation:
625
+ * {@link firstRelayedAddr} of its announced addresses, so the plain relayed address
626
+ * is named ahead of a WebRTC one that needs ICE after the same relay hop.
626
627
  */
627
628
  getRelayAddress(): Promise<string | null>;
628
629
  /**