@minca/core 0.1.14 → 0.1.16

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 (528) hide show
  1. package/README.md +4 -4
  2. package/dist/elements/auth-styles.d.ts +1 -1
  3. package/dist/elements/auth-styles.d.ts.map +1 -1
  4. package/dist/elements/auth-styles.js +21 -4
  5. package/dist/elements/auth-styles.js.map +1 -1
  6. package/dist/elements/minca-auth.d.ts.map +1 -1
  7. package/dist/elements/minca-auth.js +151 -57
  8. package/dist/elements/minca-auth.js.map +1 -1
  9. package/dist/files/space-files.d.ts +15 -3
  10. package/dist/files/space-files.d.ts.map +1 -1
  11. package/dist/files/space-files.js +225 -37
  12. package/dist/files/space-files.js.map +1 -1
  13. package/dist/identity/abilities.d.ts +2 -0
  14. package/dist/identity/abilities.d.ts.map +1 -1
  15. package/dist/identity/abilities.js +2 -0
  16. package/dist/identity/abilities.js.map +1 -1
  17. package/dist/identity/account-vault.d.ts +15 -71
  18. package/dist/identity/account-vault.d.ts.map +1 -1
  19. package/dist/identity/account-vault.js +45 -104
  20. package/dist/identity/account-vault.js.map +1 -1
  21. package/dist/identity/channel.d.ts +3 -9
  22. package/dist/identity/channel.d.ts.map +1 -1
  23. package/dist/identity/channel.js +42 -42
  24. package/dist/identity/channel.js.map +1 -1
  25. package/dist/identity/contact-key.d.ts +14 -29
  26. package/dist/identity/contact-key.d.ts.map +1 -1
  27. package/dist/identity/contact-key.js +31 -51
  28. package/dist/identity/contact-key.js.map +1 -1
  29. package/dist/identity/crypto-p256.d.ts.map +1 -1
  30. package/dist/identity/crypto-p256.js +39 -53
  31. package/dist/identity/crypto-p256.js.map +1 -1
  32. package/dist/identity/hpke.d.ts.map +1 -1
  33. package/dist/identity/hpke.js +19 -19
  34. package/dist/identity/hpke.js.map +1 -1
  35. package/dist/identity/identity-manager.d.ts.map +1 -1
  36. package/dist/identity/identity-manager.js +1 -2
  37. package/dist/identity/identity-manager.js.map +1 -1
  38. package/dist/identity/policy.d.ts.map +1 -1
  39. package/dist/identity/policy.js +35 -61
  40. package/dist/identity/policy.js.map +1 -1
  41. package/dist/identity/recovery-code.d.ts +2 -8
  42. package/dist/identity/recovery-code.d.ts.map +1 -1
  43. package/dist/identity/recovery-code.js +4 -11
  44. package/dist/identity/recovery-code.js.map +1 -1
  45. package/dist/identity/root-signer.d.ts +1 -6
  46. package/dist/identity/root-signer.d.ts.map +1 -1
  47. package/dist/identity/root-signer.js +12 -15
  48. package/dist/identity/root-signer.js.map +1 -1
  49. package/dist/identity/ucan.d.ts.map +1 -1
  50. package/dist/identity/ucan.js +48 -39
  51. package/dist/identity/ucan.js.map +1 -1
  52. package/dist/identity/webauthn.d.ts +6 -11
  53. package/dist/identity/webauthn.d.ts.map +1 -1
  54. package/dist/identity/webauthn.js +18 -30
  55. package/dist/identity/webauthn.js.map +1 -1
  56. package/dist/inbox/inbox.d.ts.map +1 -1
  57. package/dist/inbox/inbox.js +40 -30
  58. package/dist/inbox/inbox.js.map +1 -1
  59. package/dist/inbox/index.d.ts +2 -0
  60. package/dist/inbox/index.d.ts.map +1 -1
  61. package/dist/inbox/index.js +1 -0
  62. package/dist/inbox/index.js.map +1 -1
  63. package/dist/inbox/names.d.ts +54 -0
  64. package/dist/inbox/names.d.ts.map +1 -0
  65. package/dist/inbox/names.js +299 -0
  66. package/dist/inbox/names.js.map +1 -0
  67. package/dist/index.d.ts +3 -6
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +9 -12
  70. package/dist/index.js.map +1 -1
  71. package/dist/network/mesh.d.ts +7 -20
  72. package/dist/network/mesh.d.ts.map +1 -1
  73. package/dist/network/mesh.js +267 -245
  74. package/dist/network/mesh.js.map +1 -1
  75. package/dist/network/relay-link.d.ts +31 -0
  76. package/dist/network/relay-link.d.ts.map +1 -0
  77. package/dist/network/relay-link.js +62 -0
  78. package/dist/network/relay-link.js.map +1 -0
  79. package/dist/network/relay-minca.d.ts +12 -1
  80. package/dist/network/relay-minca.d.ts.map +1 -1
  81. package/dist/network/relay-minca.js +25 -55
  82. package/dist/network/relay-minca.js.map +1 -1
  83. package/dist/network/relay-nostr.d.ts +14 -3
  84. package/dist/network/relay-nostr.d.ts.map +1 -1
  85. package/dist/network/relay-nostr.js +34 -72
  86. package/dist/network/relay-nostr.js.map +1 -1
  87. package/dist/network/relay-socket.d.ts +1 -1
  88. package/dist/network/relay-socket.d.ts.map +1 -1
  89. package/dist/network/relay-socket.js +3 -1
  90. package/dist/network/relay-socket.js.map +1 -1
  91. package/dist/network/relays.d.ts +26 -17
  92. package/dist/network/relays.d.ts.map +1 -1
  93. package/dist/network/relays.js +21 -28
  94. package/dist/network/relays.js.map +1 -1
  95. package/dist/network/rendezvous.d.ts +1 -1
  96. package/dist/network/rendezvous.d.ts.map +1 -1
  97. package/dist/network/rendezvous.js +2 -2
  98. package/dist/network/rendezvous.js.map +1 -1
  99. package/dist/node/actions.d.ts.map +1 -1
  100. package/dist/node/actions.js +56 -39
  101. package/dist/node/actions.js.map +1 -1
  102. package/dist/node/api.d.ts +6 -0
  103. package/dist/node/api.d.ts.map +1 -1
  104. package/dist/node/api.js +6 -0
  105. package/dist/node/api.js.map +1 -1
  106. package/dist/node/carrier.d.ts +5 -0
  107. package/dist/node/carrier.d.ts.map +1 -1
  108. package/dist/node/carrier.js +94 -73
  109. package/dist/node/carrier.js.map +1 -1
  110. package/dist/node/copy.d.ts +8 -7
  111. package/dist/node/copy.d.ts.map +1 -1
  112. package/dist/node/copy.js +54 -56
  113. package/dist/node/copy.js.map +1 -1
  114. package/dist/node/host.d.ts +39 -65
  115. package/dist/node/host.d.ts.map +1 -1
  116. package/dist/node/host.js +362 -379
  117. package/dist/node/host.js.map +1 -1
  118. package/dist/node/index.d.ts +2 -2
  119. package/dist/node/index.d.ts.map +1 -1
  120. package/dist/node/index.js +1 -1
  121. package/dist/node/index.js.map +1 -1
  122. package/dist/node/node-carriers.d.ts +35 -0
  123. package/dist/node/node-carriers.d.ts.map +1 -0
  124. package/dist/node/node-carriers.js +562 -0
  125. package/dist/node/node-carriers.js.map +1 -0
  126. package/dist/node/node-contacts.d.ts +11 -0
  127. package/dist/node/node-contacts.d.ts.map +1 -0
  128. package/dist/node/node-contacts.js +808 -0
  129. package/dist/node/node-contacts.js.map +1 -0
  130. package/dist/node/node-context.d.ts +76 -0
  131. package/dist/node/node-context.d.ts.map +1 -0
  132. package/dist/node/node-context.js +54 -0
  133. package/dist/node/node-context.js.map +1 -0
  134. package/dist/node/node-hosting.d.ts +20 -0
  135. package/dist/node/node-hosting.d.ts.map +1 -0
  136. package/dist/node/node-hosting.js +449 -0
  137. package/dist/node/node-hosting.js.map +1 -0
  138. package/dist/node/node-records.d.ts +18 -0
  139. package/dist/node/node-records.d.ts.map +1 -0
  140. package/dist/node/node-records.js +262 -0
  141. package/dist/node/node-records.js.map +1 -0
  142. package/dist/node/node.d.ts.map +1 -1
  143. package/dist/node/node.js +197 -1989
  144. package/dist/node/node.js.map +1 -1
  145. package/dist/node/remote.d.ts +5 -6
  146. package/dist/node/remote.d.ts.map +1 -1
  147. package/dist/node/remote.js +272 -260
  148. package/dist/node/remote.js.map +1 -1
  149. package/dist/node/space-catalog.d.ts +40 -0
  150. package/dist/node/space-catalog.d.ts.map +1 -0
  151. package/dist/node/space-catalog.js +158 -0
  152. package/dist/node/space-catalog.js.map +1 -0
  153. package/dist/node/space-checks.d.ts +25 -0
  154. package/dist/node/space-checks.d.ts.map +1 -0
  155. package/dist/node/space-checks.js +343 -0
  156. package/dist/node/space-checks.js.map +1 -0
  157. package/dist/node/space-history.d.ts +37 -0
  158. package/dist/node/space-history.d.ts.map +1 -0
  159. package/dist/node/space-history.js +350 -0
  160. package/dist/node/space-history.js.map +1 -0
  161. package/dist/node/space-holding.d.ts +49 -0
  162. package/dist/node/space-holding.d.ts.map +1 -0
  163. package/dist/node/space-holding.js +267 -0
  164. package/dist/node/space-holding.js.map +1 -0
  165. package/dist/node/space-index.d.ts +41 -0
  166. package/dist/node/space-index.d.ts.map +1 -0
  167. package/dist/node/space-index.js +217 -0
  168. package/dist/node/space-index.js.map +1 -0
  169. package/dist/node/space-keys.d.ts +34 -0
  170. package/dist/node/space-keys.d.ts.map +1 -0
  171. package/dist/node/space-keys.js +309 -0
  172. package/dist/node/space-keys.js.map +1 -0
  173. package/dist/node/space-lines.d.ts +33 -0
  174. package/dist/node/space-lines.d.ts.map +1 -0
  175. package/dist/node/space-lines.js +145 -0
  176. package/dist/node/space-lines.js.map +1 -0
  177. package/dist/node/space-membership.d.ts +69 -0
  178. package/dist/node/space-membership.d.ts.map +1 -0
  179. package/dist/node/space-membership.js +242 -0
  180. package/dist/node/space-membership.js.map +1 -0
  181. package/dist/node/space-mirrors.d.ts +43 -0
  182. package/dist/node/space-mirrors.d.ts.map +1 -0
  183. package/dist/node/space-mirrors.js +125 -0
  184. package/dist/node/space-mirrors.js.map +1 -0
  185. package/dist/node/space-peers.d.ts +104 -0
  186. package/dist/node/space-peers.d.ts.map +1 -0
  187. package/dist/node/space-peers.js +595 -0
  188. package/dist/node/space-peers.js.map +1 -0
  189. package/dist/node/space-profiles.d.ts +18 -0
  190. package/dist/node/space-profiles.d.ts.map +1 -0
  191. package/dist/node/space-profiles.js +105 -0
  192. package/dist/node/space-profiles.js.map +1 -0
  193. package/dist/node/space-rules.d.ts +29 -0
  194. package/dist/node/space-rules.d.ts.map +1 -0
  195. package/dist/node/space-rules.js +144 -0
  196. package/dist/node/space-rules.js.map +1 -0
  197. package/dist/node/space-runtime.d.ts +104 -143
  198. package/dist/node/space-runtime.d.ts.map +1 -1
  199. package/dist/node/space-runtime.js +293 -3954
  200. package/dist/node/space-runtime.js.map +1 -1
  201. package/dist/node/space-standing.d.ts +20 -0
  202. package/dist/node/space-standing.d.ts.map +1 -0
  203. package/dist/node/space-standing.js +317 -0
  204. package/dist/node/space-standing.js.map +1 -0
  205. package/dist/node/space-versions.d.ts +104 -0
  206. package/dist/node/space-versions.d.ts.map +1 -0
  207. package/dist/node/space-versions.js +153 -0
  208. package/dist/node/space-versions.js.map +1 -0
  209. package/dist/node/space-warrants.d.ts +25 -0
  210. package/dist/node/space-warrants.d.ts.map +1 -0
  211. package/dist/node/space-warrants.js +214 -0
  212. package/dist/node/space-warrants.js.map +1 -0
  213. package/dist/node/space-writing.d.ts +72 -0
  214. package/dist/node/space-writing.d.ts.map +1 -0
  215. package/dist/node/space-writing.js +440 -0
  216. package/dist/node/space-writing.js.map +1 -0
  217. package/dist/node/stores.d.ts +19 -50
  218. package/dist/node/stores.d.ts.map +1 -1
  219. package/dist/node/stores.js +14 -33
  220. package/dist/node/stores.js.map +1 -1
  221. package/dist/node/types.d.ts +225 -305
  222. package/dist/node/types.d.ts.map +1 -1
  223. package/dist/node/usage.d.ts +2 -24
  224. package/dist/node/usage.d.ts.map +1 -1
  225. package/dist/node/usage.js +118 -102
  226. package/dist/node/usage.js.map +1 -1
  227. package/dist/node/watch-notifications.d.ts.map +1 -1
  228. package/dist/node/watch-notifications.js +32 -29
  229. package/dist/node/watch-notifications.js.map +1 -1
  230. package/dist/node/worker.d.ts +5 -6
  231. package/dist/node/worker.d.ts.map +1 -1
  232. package/dist/node/worker.js +80 -72
  233. package/dist/node/worker.js.map +1 -1
  234. package/dist/node/writer-keys.d.ts +5 -6
  235. package/dist/node/writer-keys.d.ts.map +1 -1
  236. package/dist/node/writer-keys.js +66 -57
  237. package/dist/node/writer-keys.js.map +1 -1
  238. package/dist/node/writers.d.ts +12 -19
  239. package/dist/node/writers.d.ts.map +1 -1
  240. package/dist/node/writers.js +7 -15
  241. package/dist/node/writers.js.map +1 -1
  242. package/dist/privacy/direct.d.ts.map +1 -1
  243. package/dist/privacy/direct.js +31 -27
  244. package/dist/privacy/direct.js.map +1 -1
  245. package/dist/privacy/space-encryption.d.ts.map +1 -1
  246. package/dist/privacy/space-encryption.js +5 -9
  247. package/dist/privacy/space-encryption.js.map +1 -1
  248. package/dist/query/computed.d.ts.map +1 -1
  249. package/dist/query/computed.js +78 -77
  250. package/dist/query/computed.js.map +1 -1
  251. package/dist/query/engine.d.ts +3 -4
  252. package/dist/query/engine.d.ts.map +1 -1
  253. package/dist/query/engine.js +93 -86
  254. package/dist/query/engine.js.map +1 -1
  255. package/dist/query/filter.d.ts +8 -10
  256. package/dist/query/filter.d.ts.map +1 -1
  257. package/dist/query/filter.js +144 -161
  258. package/dist/query/filter.js.map +1 -1
  259. package/dist/records/cel-types.d.ts.map +1 -1
  260. package/dist/records/cel-types.js +13 -27
  261. package/dist/records/cel-types.js.map +1 -1
  262. package/dist/records/cel.d.ts.map +1 -1
  263. package/dist/records/cel.js +177 -242
  264. package/dist/records/cel.js.map +1 -1
  265. package/dist/records/rules.d.ts.map +1 -1
  266. package/dist/records/rules.js +46 -50
  267. package/dist/records/rules.js.map +1 -1
  268. package/dist/records/topics.d.ts.map +1 -1
  269. package/dist/records/topics.js +18 -22
  270. package/dist/records/topics.js.map +1 -1
  271. package/dist/schema/collection-def.d.ts.map +1 -1
  272. package/dist/schema/collection-def.js +16 -5
  273. package/dist/schema/collection-def.js.map +1 -1
  274. package/dist/schemas/automations.d.ts +16 -15
  275. package/dist/schemas/automations.d.ts.map +1 -1
  276. package/dist/schemas/automations.js +203 -165
  277. package/dist/schemas/automations.js.map +1 -1
  278. package/dist/schemas/blueprints.d.ts.map +1 -1
  279. package/dist/schemas/blueprints.js +14 -13
  280. package/dist/schemas/blueprints.js.map +1 -1
  281. package/dist/schemas/connectors.d.ts +12 -0
  282. package/dist/schemas/connectors.d.ts.map +1 -1
  283. package/dist/schemas/connectors.js +16 -11
  284. package/dist/schemas/connectors.js.map +1 -1
  285. package/dist/schemas/contacts.d.ts +57 -0
  286. package/dist/schemas/contacts.d.ts.map +1 -1
  287. package/dist/schemas/contacts.js +32 -0
  288. package/dist/schemas/contacts.js.map +1 -1
  289. package/dist/schemas/cron.d.ts.map +1 -1
  290. package/dist/schemas/cron.js +27 -28
  291. package/dist/schemas/cron.js.map +1 -1
  292. package/dist/schemas/defined.d.ts +6 -0
  293. package/dist/schemas/defined.d.ts.map +1 -0
  294. package/dist/schemas/defined.js +7 -0
  295. package/dist/schemas/defined.js.map +1 -0
  296. package/dist/schemas/fragments.d.ts +22 -2
  297. package/dist/schemas/fragments.d.ts.map +1 -1
  298. package/dist/schemas/fragments.js +20 -12
  299. package/dist/schemas/fragments.js.map +1 -1
  300. package/dist/schemas/guides.d.ts +3 -1
  301. package/dist/schemas/guides.d.ts.map +1 -1
  302. package/dist/schemas/guides.js +13 -12
  303. package/dist/schemas/guides.js.map +1 -1
  304. package/dist/schemas/index.d.ts +2 -2
  305. package/dist/schemas/index.d.ts.map +1 -1
  306. package/dist/schemas/index.js +18 -14
  307. package/dist/schemas/index.js.map +1 -1
  308. package/dist/schemas/library/annotations.d.ts +30 -0
  309. package/dist/schemas/library/annotations.d.ts.map +1 -1
  310. package/dist/schemas/library/annotations.js +1 -0
  311. package/dist/schemas/library/annotations.js.map +1 -1
  312. package/dist/schemas/library/community.d.ts +28 -0
  313. package/dist/schemas/library/community.d.ts.map +1 -1
  314. package/dist/schemas/library/life.d.ts +62 -2
  315. package/dist/schemas/library/life.d.ts.map +1 -1
  316. package/dist/schemas/library/media.d.ts +36 -0
  317. package/dist/schemas/library/media.d.ts.map +1 -1
  318. package/dist/schemas/library/money.d.ts +74 -2
  319. package/dist/schemas/library/money.d.ts.map +1 -1
  320. package/dist/schemas/library/planning.d.ts +56 -0
  321. package/dist/schemas/library/planning.d.ts.map +1 -1
  322. package/dist/schemas/library/publishing.d.ts +80 -4
  323. package/dist/schemas/library/publishing.d.ts.map +1 -1
  324. package/dist/schemas/library/social.d.ts +44 -0
  325. package/dist/schemas/library/social.d.ts.map +1 -1
  326. package/dist/session/account-hint.d.ts.map +1 -1
  327. package/dist/session/account-hint.js +8 -5
  328. package/dist/session/account-hint.js.map +1 -1
  329. package/dist/session/auth.d.ts +36 -2
  330. package/dist/session/auth.d.ts.map +1 -1
  331. package/dist/session/auth.js +95 -2
  332. package/dist/session/auth.js.map +1 -1
  333. package/dist/session/connect.d.ts +1 -0
  334. package/dist/session/connect.d.ts.map +1 -1
  335. package/dist/session/connect.js +3 -1
  336. package/dist/session/connect.js.map +1 -1
  337. package/dist/session/credentials.d.ts +8 -26
  338. package/dist/session/credentials.d.ts.map +1 -1
  339. package/dist/session/credentials.js +14 -32
  340. package/dist/session/credentials.js.map +1 -1
  341. package/dist/session/index.d.ts +1 -0
  342. package/dist/session/index.d.ts.map +1 -1
  343. package/dist/session/index.js +1 -0
  344. package/dist/session/index.js.map +1 -1
  345. package/dist/session/pairing.d.ts.map +1 -1
  346. package/dist/session/pairing.js +92 -88
  347. package/dist/session/pairing.js.map +1 -1
  348. package/dist/session/password-strength.d.ts.map +1 -1
  349. package/dist/session/password-strength.js +37 -37
  350. package/dist/session/password-strength.js.map +1 -1
  351. package/dist/session/places.d.ts.map +1 -1
  352. package/dist/session/places.js +18 -13
  353. package/dist/session/places.js.map +1 -1
  354. package/dist/session/popup.d.ts +13 -0
  355. package/dist/session/popup.d.ts.map +1 -0
  356. package/dist/session/popup.js +23 -0
  357. package/dist/session/popup.js.map +1 -0
  358. package/dist/space/constitution.d.ts.map +1 -1
  359. package/dist/space/constitution.js +22 -29
  360. package/dist/space/constitution.js.map +1 -1
  361. package/dist/space/grants.d.ts.map +1 -1
  362. package/dist/space/grants.js +37 -39
  363. package/dist/space/grants.js.map +1 -1
  364. package/dist/space/invite-link.d.ts.map +1 -1
  365. package/dist/space/invite-link.js +33 -33
  366. package/dist/space/invite-link.js.map +1 -1
  367. package/dist/space/own-automations.d.ts +13 -24
  368. package/dist/space/own-automations.d.ts.map +1 -1
  369. package/dist/space/own-automations.js +47 -37
  370. package/dist/space/own-automations.js.map +1 -1
  371. package/dist/space/roles.d.ts +56 -80
  372. package/dist/space/roles.d.ts.map +1 -1
  373. package/dist/space/roles.js +448 -441
  374. package/dist/space/roles.js.map +1 -1
  375. package/dist/space/space-access.d.ts +3 -4
  376. package/dist/space/space-access.d.ts.map +1 -1
  377. package/dist/space/space-access.js +3 -8
  378. package/dist/space/space-access.js.map +1 -1
  379. package/dist/storage/blob/directory.d.ts.map +1 -1
  380. package/dist/storage/blob/directory.js +39 -32
  381. package/dist/storage/blob/directory.js.map +1 -1
  382. package/dist/storage/blob/s3.d.ts.map +1 -1
  383. package/dist/storage/blob/s3.js +21 -19
  384. package/dist/storage/blob/s3.js.map +1 -1
  385. package/dist/storage/blob-store.d.ts +0 -9
  386. package/dist/storage/blob-store.d.ts.map +1 -1
  387. package/dist/storage/directory-access.d.ts +8 -32
  388. package/dist/storage/directory-access.d.ts.map +1 -1
  389. package/dist/storage/directory-access.js +11 -36
  390. package/dist/storage/directory-access.js.map +1 -1
  391. package/dist/storage/encrypted-adapter.d.ts +12 -32
  392. package/dist/storage/encrypted-adapter.d.ts.map +1 -1
  393. package/dist/storage/encrypted-adapter.js +31 -54
  394. package/dist/storage/encrypted-adapter.js.map +1 -1
  395. package/dist/storage/folder-adapter.d.ts +12 -26
  396. package/dist/storage/folder-adapter.d.ts.map +1 -1
  397. package/dist/storage/folder-adapter.js +37 -54
  398. package/dist/storage/folder-adapter.js.map +1 -1
  399. package/dist/storage/folder-reconcile.d.ts +12 -26
  400. package/dist/storage/folder-reconcile.d.ts.map +1 -1
  401. package/dist/storage/folder-reconcile.js +39 -48
  402. package/dist/storage/folder-reconcile.js.map +1 -1
  403. package/dist/storage/indexeddb-adapter.d.ts +2 -6
  404. package/dist/storage/indexeddb-adapter.d.ts.map +1 -1
  405. package/dist/storage/indexeddb-adapter.js +60 -114
  406. package/dist/storage/indexeddb-adapter.js.map +1 -1
  407. package/dist/storage/mirror.d.ts +0 -29
  408. package/dist/storage/mirror.d.ts.map +1 -1
  409. package/dist/storage/mirror.js +153 -110
  410. package/dist/storage/mirror.js.map +1 -1
  411. package/dist/storage/segment.d.ts.map +1 -1
  412. package/dist/storage/segment.js +3 -7
  413. package/dist/storage/segment.js.map +1 -1
  414. package/dist/storage/storage-provider.d.ts +6 -11
  415. package/dist/storage/storage-provider.d.ts.map +1 -1
  416. package/dist/storage/storage-provider.js +112 -116
  417. package/dist/storage/storage-provider.js.map +1 -1
  418. package/dist/sync/sync-engine.d.ts +10 -44
  419. package/dist/sync/sync-engine.d.ts.map +1 -1
  420. package/dist/sync/sync-engine.js +245 -247
  421. package/dist/sync/sync-engine.js.map +1 -1
  422. package/dist/sync/sync-messages.d.ts +1 -1
  423. package/dist/sync/sync-messages.d.ts.map +1 -1
  424. package/dist/sync/sync-messages.js +1 -1
  425. package/dist/sync/sync-messages.js.map +1 -1
  426. package/dist/utils/guards.d.ts +1 -0
  427. package/dist/utils/guards.d.ts.map +1 -1
  428. package/dist/utils/guards.js +1 -0
  429. package/dist/utils/guards.js.map +1 -1
  430. package/dist/utils/hmac.d.ts +5 -0
  431. package/dist/utils/hmac.d.ts.map +1 -0
  432. package/dist/utils/hmac.js +20 -0
  433. package/dist/utils/hmac.js.map +1 -0
  434. package/dist/utils/map.d.ts +10 -0
  435. package/dist/utils/map.d.ts.map +1 -0
  436. package/dist/utils/map.js +30 -0
  437. package/dist/utils/map.js.map +1 -0
  438. package/dist/utils/serial.d.ts +2 -0
  439. package/dist/utils/serial.d.ts.map +1 -1
  440. package/dist/utils/serial.js +9 -0
  441. package/dist/utils/serial.js.map +1 -1
  442. package/dist/validation/capability-gate.d.ts +7 -15
  443. package/dist/validation/capability-gate.d.ts.map +1 -1
  444. package/dist/validation/capability-gate.js +32 -36
  445. package/dist/validation/capability-gate.js.map +1 -1
  446. package/dist/validation/crypto-gate.d.ts.map +1 -1
  447. package/dist/validation/crypto-gate.js +12 -21
  448. package/dist/validation/crypto-gate.js.map +1 -1
  449. package/docs/README.md +3 -2
  450. package/docs/actions.md +47 -20
  451. package/docs/automations.md +1 -1
  452. package/docs/blueprints-and-guides.md +57 -13
  453. package/docs/building-an-app.md +11 -8
  454. package/docs/collections.md +33 -5
  455. package/docs/contacts.md +34 -1
  456. package/docs/contracts.md +1 -1
  457. package/docs/direct-messages.md +1 -1
  458. package/docs/inbox.md +5 -11
  459. package/docs/node.md +36 -26
  460. package/docs/records-and-queries.md +1 -1
  461. package/docs/sign-in.md +54 -26
  462. package/docs/spaces.md +6 -6
  463. package/docs/standard-library.md +33 -31
  464. package/docs/storage.md +37 -15
  465. package/docs/usernames.md +161 -0
  466. package/docs/warrants.md +1 -1
  467. package/package.json +2 -21
  468. package/dist/calls/calls.d.ts +0 -140
  469. package/dist/calls/calls.d.ts.map +0 -1
  470. package/dist/calls/calls.js +0 -861
  471. package/dist/calls/calls.js.map +0 -1
  472. package/dist/calls/index.d.ts +0 -4
  473. package/dist/calls/index.d.ts.map +0 -1
  474. package/dist/calls/index.js +0 -3
  475. package/dist/calls/index.js.map +0 -1
  476. package/dist/react/context.d.ts +0 -81
  477. package/dist/react/context.d.ts.map +0 -1
  478. package/dist/react/context.js +0 -97
  479. package/dist/react/context.js.map +0 -1
  480. package/dist/react/follow.d.ts +0 -11
  481. package/dist/react/follow.d.ts.map +0 -1
  482. package/dist/react/follow.js +0 -7
  483. package/dist/react/follow.js.map +0 -1
  484. package/dist/react/index.d.ts +0 -44
  485. package/dist/react/index.d.ts.map +0 -1
  486. package/dist/react/index.js +0 -40
  487. package/dist/react/index.js.map +0 -1
  488. package/dist/react/minca-auth.d.ts +0 -19
  489. package/dist/react/minca-auth.d.ts.map +0 -1
  490. package/dist/react/minca-auth.js +0 -36
  491. package/dist/react/minca-auth.js.map +0 -1
  492. package/dist/react/use-calls.d.ts +0 -21
  493. package/dist/react/use-calls.d.ts.map +0 -1
  494. package/dist/react/use-calls.js +0 -39
  495. package/dist/react/use-calls.js.map +0 -1
  496. package/dist/react/use-invite-link.d.ts +0 -24
  497. package/dist/react/use-invite-link.d.ts.map +0 -1
  498. package/dist/react/use-invite-link.js +0 -62
  499. package/dist/react/use-invite-link.js.map +0 -1
  500. package/dist/react/use-live.d.ts +0 -16
  501. package/dist/react/use-live.d.ts.map +0 -1
  502. package/dist/react/use-live.js +0 -56
  503. package/dist/react/use-live.js.map +0 -1
  504. package/dist/react/use-my-name.d.ts +0 -12
  505. package/dist/react/use-my-name.d.ts.map +0 -1
  506. package/dist/react/use-my-name.js +0 -38
  507. package/dist/react/use-my-name.js.map +0 -1
  508. package/dist/react/use-names.d.ts +0 -7
  509. package/dist/react/use-names.d.ts.map +0 -1
  510. package/dist/react/use-names.js +0 -13
  511. package/dist/react/use-names.js.map +0 -1
  512. package/dist/react/use-network.d.ts +0 -9
  513. package/dist/react/use-network.d.ts.map +0 -1
  514. package/dist/react/use-network.js +0 -33
  515. package/dist/react/use-network.js.map +0 -1
  516. package/dist/react/use-query.d.ts +0 -14
  517. package/dist/react/use-query.d.ts.map +0 -1
  518. package/dist/react/use-query.js +0 -26
  519. package/dist/react/use-query.js.map +0 -1
  520. package/dist/react/use-space.d.ts +0 -29
  521. package/dist/react/use-space.d.ts.map +0 -1
  522. package/dist/react/use-space.js +0 -57
  523. package/dist/react/use-space.js.map +0 -1
  524. package/dist/react/use-spaces.d.ts +0 -29
  525. package/dist/react/use-spaces.d.ts.map +0 -1
  526. package/dist/react/use-spaces.js +0 -78
  527. package/dist/react/use-spaces.js.map +0 -1
  528. package/docs/calls.md +0 -189
@@ -1,38 +1,28 @@
1
1
  /**
2
2
  * Who may do what in a space: its roles and their grants, the accounts
3
- * assigned to them, its invites, and the history of changes to them —
4
- * replayed the same way on every peer, by `strong-remove/1`.
3
+ * assigned to them, its invites, and the history of changes to them, replayed
4
+ * the same way on every peer by `strong-remove/1`.
5
5
  *
6
- * This module knows people and grants. It knows nothing about polls or
7
- * todos: it answers one question, *may this account invoke this command with
8
- * these arguments here, as of this point in the space's history?*
6
+ * It answers one question: *may this account invoke this command with these
7
+ * arguments here, as of this point in the space's history?*
9
8
  *
10
- * **Grants.** A role holds grants (`space/grants.ts`): delegations to the
11
- * role of a command path under a UCAN policy. The constitution's grants for
12
- * a role are its first definition; a later definition replaces them. A
13
- * definition holds only what its author could do as of the definition, and
14
- * definitions written apart hold only the grants they share.
9
+ * **Grants.** A role holds grants (`space/grants.ts`). The constitution's
10
+ * grants are a role's first definition; a later one replaces them. A
11
+ * definition holds only what its author could do, and rival definitions hold
12
+ * only what they share.
15
13
  *
16
- * **Accounts.** An account holds power only through the roles assigned to
17
- * it, and invokes nothing with none. Under `top: { founders }` the founders
18
- * hold every command, and no one but each founder itself can remove one,
19
- * change its roles or make it step down. Under `top: "none"` there are no
20
- * founders, and anyone may be removed by whoever holds the grant.
14
+ * **Accounts.** An account holds power only through its roles. Under
15
+ * `top: { founders }` the founders hold every command, and only each founder
16
+ * itself can remove one, change its roles or make it step down.
21
17
  *
22
- * **The access history.** Every change to a role, an assignment, a removal,
23
- * an invite, a revoked key or a collection definition is a record whose
24
- * `seen` names the latest changes its author knew of. That makes a small
25
- * graph, and no order over it decides anything (spec 03 §4):
18
+ * **The access history.** Every change names in `seen` the latest changes its
19
+ * author knew of. No order over that graph decides anything (spec 03 §4):
26
20
  *
27
- * 1. A change is allowed when its author had the power in its own view: the
28
- * changes it saw that are valid among what it saw.
29
- * 2. A removal or an unassignment strikes what its account did that it
30
- * hadn't seen, whatever that needed. A revoke, a fork proof or a closed
31
- * invite strikes what it reaches. Changes that strike each other all
32
- * stand.
21
+ * 1. A change is allowed when its author had the power in its own view.
22
+ * 2. A removal or unassignment strikes what its account did that it hadn't
23
+ * seen. A revoke, a fork proof or a closed invite strikes what it reaches.
24
+ * Changes that strike each other all stand.
33
25
  * 3. The state is a merge of the valid changes: on each record the latest.
34
- * Rival definitions of a role hold what they share, an unassignment beats
35
- * an assignment, and a closed invite an open one.
36
26
  */
37
27
  import { commandCovers } from '../identity/ucan.js';
38
28
  import { canonicalize } from '../schema/version.js';
@@ -44,15 +34,15 @@ export const ASSIGN_COLLECTION = 'sys.assign';
44
34
  export const REMOVE_COLLECTION = 'sys.remove';
45
35
  export const INVITE_COLLECTION = 'sys.invite';
46
36
  export const REVOKE_COLLECTION = 'sys.revoke';
47
- /** Collection definitions are part of the access history too: what a version must keep to */
37
+ /** Collection definitions: what a version must keep to */
48
38
  export const DEFINITION_COLLECTION = 'sys.collection';
49
- /** Which of a private space's keys is current; the key itself travels sealed to each member (`sys.box`) */
39
+ /** Which of a private space's keys is current; the key itself travels sealed (`sys.box`) */
50
40
  export const KEY_COLLECTION = 'sys.key';
51
- /** The relays the space's members meet at, so people whose apps use different relays still find each other */
41
+ /** The relays the space's members meet at */
52
42
  export const RELAYS_COLLECTION = 'sys.relays';
53
- /** Nodes that hold the whole space, and how many a write should reach before a partial node lets go of it */
43
+ /** Nodes that hold the whole space, and how many a write should reach */
54
44
  export const KEEPERS_COLLECTION = 'sys.keepers';
55
- /** A fork proof: two versions one key signed at one place in its line (02 §4.10), checked by every peer */
45
+ /** A fork proof: two versions one key signed at one place in its line (02 §4.10) */
56
46
  export const FORK_COLLECTION = 'sys.fork';
57
47
  /** A founder stepping down: it keeps its roles, and is a founder no more */
58
48
  export const STEPDOWN_COLLECTION = 'sys.stepdown';
@@ -64,9 +54,9 @@ export const STRONG_REMOVE = 'strong-remove/1';
64
54
  export const RESOLVERS = new Set([STRONG_REMOVE]);
65
55
  const accessKind = (collection, prefix, clear = true) => Object.freeze({ collection, prefix, clear });
66
56
  /**
67
- * Each kind of change: its collection, where its line is counted too; its record keys' prefix; and
68
- * whether a private space keeps it in the clear, so a peer without the key can still judge who may
69
- * do what. Collection definitions stay sealed: only readers need their rules.
57
+ * Each kind of change: its collection, its record keys' prefix, and whether a
58
+ * private space keeps it in the clear so a peer without the key can judge it.
59
+ * Collection definitions stay sealed: only readers need their rules.
70
60
  */
71
61
  export const ACCESS_KINDS = Object.freeze({
72
62
  role: accessKind(ROLE_COLLECTION, 'role:'),
@@ -91,25 +81,21 @@ export function checkKeepers(keepers, copies = null) {
91
81
  if (!Array.isArray(keepers) || keepers.length > MAX_KEEPERS)
92
82
  return `A space names at most ${MAX_KEEPERS} keepers`;
93
83
  const list = keepers;
94
- const dids = new Set();
95
84
  for (const keeper of list) {
96
- if (!isObject(keeper) ||
97
- typeof keeper.did !== 'string' ||
98
- !keeper.did.startsWith('did:key:') ||
99
- keeper.did.length > 200)
85
+ if (!isObject(keeper) || !isKeeperDid(keeper.did))
100
86
  return 'A keeper is named by its did:key';
101
87
  if (typeof keeper.name !== 'string' || keeper.name.length > 80)
102
88
  return 'A keeper has a name of at most 80 characters';
103
- dids.add(keeper.did);
104
89
  }
90
+ const dids = new Set(list.map((keeper) => isObject(keeper) && keeper.did));
105
91
  if (dids.size !== list.length)
106
92
  return 'A keeper is named twice';
107
- if (copies !== null &&
108
- !(typeof copies === 'number' && Number.isSafeInteger(copies) && copies >= 1 && copies <= MAX_KEEPERS)) {
93
+ if (copies !== null && !isCopies(copies))
109
94
  return `Copies is a whole number from 1 to ${MAX_KEEPERS}`;
110
- }
111
95
  return null;
112
96
  }
97
+ const isKeeperDid = (did) => typeof did === 'string' && did.startsWith('did:key:') && did.length <= 200;
98
+ const isCopies = (copies) => typeof copies === 'number' && Number.isSafeInteger(copies) && copies >= 1 && copies <= MAX_KEEPERS;
113
99
  /** How many relays a space may name */
114
100
  export const MAX_RELAYS = 8;
115
101
  /** Why a list of relays can't be a space's, or null */
@@ -117,35 +103,42 @@ export function checkRelays(relays) {
117
103
  if (!Array.isArray(relays) || relays.length > MAX_RELAYS)
118
104
  return `A space names at most ${MAX_RELAYS} relays`;
119
105
  for (const url of relays) {
120
- if (typeof url !== 'string' || url.length > 200)
121
- return 'A relay is a URL of at most 200 characters';
122
- let parsed;
123
- try {
124
- parsed = new URL(url);
125
- }
126
- catch {
127
- return `"${url}" is not a URL`;
128
- }
129
- // A kind of relay other than Minca's own goes before the scheme (`nostr+wss://`). Plain ws://
130
- // only on this machine: anywhere else it would show the room to everyone on the way.
131
- const local = ['localhost', '127.0.0.1', '[::1]'].includes(parsed.hostname);
132
- const transport = /^(?:[a-z][a-z0-9-]*\+)?(wss?):$/.exec(parsed.protocol)?.[1];
133
- if (transport !== 'wss' && !(transport === 'ws' && local))
134
- return `"${url}" is not a wss:// relay`;
106
+ const problem = relayProblem(url);
107
+ if (problem)
108
+ return problem;
135
109
  }
136
110
  return new Set(relays).size === relays.length ? null : 'A relay is named twice';
137
111
  }
138
- /** The constitution's definition of a founding role */
139
- function founding(genesis, role) {
112
+ function relayProblem(url) {
113
+ if (typeof url !== 'string' || url.length > 200)
114
+ return 'A relay is a URL of at most 200 characters';
115
+ let parsed;
116
+ try {
117
+ parsed = new URL(url);
118
+ }
119
+ catch {
120
+ return `"${url}" is not a URL`;
121
+ }
122
+ // Another kind of relay goes before the scheme (`nostr+wss://`). Plain ws:// only on this
123
+ // machine: anywhere else it would show the room to everyone on the way.
124
+ const local = ['localhost', '127.0.0.1', '[::1]'].includes(parsed.hostname);
125
+ const transport = /^(?:[a-z][a-z0-9-]*\+)?(wss?):$/.exec(parsed.protocol)?.[1];
126
+ return transport === 'wss' || (transport === 'ws' && local) ? null : `"${url}" is not a wss:// relay`;
127
+ }
128
+ function roleDefinition(event, by, role, view) {
140
129
  return Object.freeze({
141
- event: genesis.id,
142
- by: null,
130
+ event,
131
+ by,
143
132
  ...(role.title !== undefined ? { title: role.title } : {}),
144
133
  grants: role.grants,
145
134
  nests: role.nests ?? [],
146
- view: null,
135
+ view,
147
136
  });
148
137
  }
138
+ /** A role's definition from a change, judged in `view` */
139
+ function definitionFrom(event, view) {
140
+ return event.kind === 'role' ? roleDefinition(event.id, event.root, event, view) : null;
141
+ }
149
142
  function startState(genesis) {
150
143
  // The constitution's assignments are as if made by the space itself: their id is the space's.
151
144
  const assigned = new Map();
@@ -153,7 +146,7 @@ function startState(genesis) {
153
146
  assigned.set(did, new Map(roles.map((role) => [role, genesis.id])));
154
147
  return {
155
148
  founders: new Set(genesis.founders),
156
- roles: new Map(genesis.roles.map((role) => [role.name, [founding(genesis, role)]])),
149
+ roles: new Map(genesis.roles.map((role) => [role.name, [roleDefinition(genesis.id, null, role, null)]])),
157
150
  assigned,
158
151
  invites: new Map(),
159
152
  definitions: new Map(),
@@ -174,7 +167,7 @@ export function rolesOf(state, did) {
174
167
  export function isMember(state, did) {
175
168
  return state.founders.has(did) || (state.assigned.get(did)?.size ?? 0) > 0;
176
169
  }
177
- /** Every member — who can read, as far as the history is concerned */
170
+ /** Every member: who can read, as far as the history is concerned */
178
171
  export function readers(state) {
179
172
  const out = new Set(state.founders);
180
173
  for (const [did, roles] of state.assigned)
@@ -194,14 +187,11 @@ export function headless(state) {
194
187
  return ![...readers(state)].some((did) => roles.some((role) => may(state, did, ROLE_DEFINE, { role }) ||
195
188
  may(state, did, ROLE_ASSIGN, { role, self: false, roles: [] })));
196
189
  }
197
- /** Answers already given in a state, which never changes once made */
198
- const answers = new WeakMap();
199
190
  /**
200
191
  * Whether an account may invoke a command with these arguments in a state:
201
192
  * a founder may invoke anything; anyone else, what a role assigned to it
202
- * holds. A role holds what its current definitions all hold, each only as far
203
- * as its author could invoke it, as of that definition (UCAN's attenuation),
204
- * and what the roles it nests hold.
193
+ * holds, each definition only as far as its author could invoke it (UCAN's
194
+ * attenuation), with what the roles it nests hold.
205
195
  */
206
196
  export function may(state, did, cmd, args, options = {}) {
207
197
  if (state.founders.has(did))
@@ -209,17 +199,22 @@ export function may(state, did, cmd, args, options = {}) {
209
199
  const roles = rolesOf(state, did);
210
200
  if (roles.length === 0)
211
201
  return false;
212
- const key = `${did}\n${cmd}\n${canonicalize(args)}\n${options.opaque ? 1 : 0}`;
213
- let cache = answers.get(state);
214
- if (!cache)
215
- answers.set(state, (cache = new Map()));
216
- const known = cache.get(key);
217
- if (known !== undefined)
218
- return known;
219
202
  const opaque = !!options.opaque;
220
- const answer = roles.some((role) => roleHolds(state, role, (grant) => grantFits(grant, cmd, args, opaque), (view, by) => may(view, by, cmd, args, { opaque })));
221
- cache.set(key, answer);
222
- return answer;
203
+ const question = `${did}\n${cmd}\n${canonicalize(args)}\n${opaque ? 1 : 0}`;
204
+ return remembered(state, question, () => roles.some((role) => roleHolds(state, role, (grant) => grantFits(grant, cmd, args, opaque), (view, by) => may(view, by, cmd, args, { opaque }))));
205
+ }
206
+ /** Answers already given in a state, which never changes once made */
207
+ const answers = new WeakMap();
208
+ function remembered(state, question, answer) {
209
+ let known = answers.get(state);
210
+ if (!known)
211
+ answers.set(state, (known = new Map()));
212
+ const given = known.get(question);
213
+ if (given !== undefined)
214
+ return given;
215
+ const result = answer();
216
+ known.set(question, result);
217
+ return result;
223
218
  }
224
219
  /** A role as its rival definitions leave it: what they all hold, and the authors whose power bounds it */
225
220
  function effectiveRole(state, role) {
@@ -243,18 +238,17 @@ function roleHolds(state, role, fits, authorHolds, visiting = new Set()) {
243
238
  const inner = new Set(visiting).add(role);
244
239
  const held = found.grants.some(fits) ||
245
240
  found.nests.some((nested) => nested !== role && roleHolds(state, nested, fits, authorHolds, inner));
246
- // Each definition holds only what its author could do itself, as of it.
247
241
  return held && found.authors.every(({ view, by }) => authorHolds(view, by));
248
242
  }
249
243
  /**
250
- * Whether an account holds every grant a role gives, each as wide or wider (its command covering,
251
- * its policy's statements among the other's): what it may hand a bot of its own. Only the policies'
252
- * words are compared, so it may say no where they would allow; never yes where they wouldn't.
244
+ * Whether an account holds every grant a role gives, each as wide or wider:
245
+ * what it may hand a bot of its own. Only the policies' words are compared, so
246
+ * it may say no where they would allow, never yes where they wouldn't.
253
247
  */
254
248
  export function holdsRole(state, did, role) {
255
249
  return grantsOfRole(state, role, new Set()).every((grant) => holdsGrant(state, did, grant));
256
250
  }
257
- /** What a role gives its members, as grants: its current definitions' shared ones, and its nested roles' */
251
+ /** What a role gives its members: its current definitions' shared grants, and its nested roles' */
258
252
  function grantsOfRole(state, role, visiting) {
259
253
  const found = effectiveRole(state, role);
260
254
  if (!found || visiting.has(role))
@@ -262,7 +256,7 @@ function grantsOfRole(state, role, visiting) {
262
256
  const inner = new Set(visiting).add(role);
263
257
  return [...found.grants, ...found.nests.flatMap((nested) => grantsOfRole(state, nested, inner))];
264
258
  }
265
- /** Whether an account holds a grant as wide as `wanted` or wider, in a state */
259
+ /** Whether an account holds a grant as wide as `wanted` or wider */
266
260
  function holdsGrant(state, did, wanted) {
267
261
  if (state.founders.has(did))
268
262
  return true;
@@ -277,7 +271,7 @@ const targetArgs = (state, invoker, target, role) => ({
277
271
  self: invoker === target,
278
272
  roles: rolesOf(state, target),
279
273
  });
280
- /** Whether any member holds `/space/succeed`, once per state: a state never changes */
274
+ /** Whether any member holds `/space/succeed`, once per state */
281
275
  const maySucceed = new WeakMap();
282
276
  function anyMaySucceed(state) {
283
277
  let found = maySucceed.get(state);
@@ -298,49 +292,12 @@ export function refusal(event, state) {
298
292
  return may(state, root, ROLE_DEFINE, { role: event.name })
299
293
  ? null
300
294
  : 'Its author may not define this role';
301
- case 'assign': {
302
- // Roles go to accounts: putting a role inside another is part of a definition, and grants.
303
- if (event.did.startsWith('role:'))
304
- return 'A role is assigned to accounts, not to roles';
305
- const holds = rolesOf(state, event.did).includes(event.role);
306
- // Joining with an invite: your own record, for the invite's role, judged as the assignment
307
- // its opener makes, with the joiner's own `self` and `roles`.
308
- if (event.viaInvite !== undefined) {
309
- const invite = state.invites.get(event.viaInvite);
310
- if (!event.assigned)
311
- return 'An invite only assigns';
312
- if (root !== event.did)
313
- return 'Only the person joining can use an invite for themselves';
314
- if (!invite?.open)
315
- return 'The invite is not open';
316
- if (invite.role !== event.role)
317
- return 'The invite is for another role';
318
- if (holds)
319
- return 'Already holds that role';
320
- if (!state.roles.has(event.role))
321
- return `There is no role "${event.role}"`;
322
- return invite.by.every((opener) => may(state, opener, ROLE_ASSIGN, targetArgs(state, opener, event.did, event.role)))
323
- ? null
324
- : 'Whoever opened the invite may not assign this role to them';
325
- }
326
- // Leaving a role is built in.
327
- if (!event.assigned && root === event.did)
328
- return holds ? null : 'It does not hold that role';
329
- if (state.founders.has(event.did) && root !== event.did)
330
- return "No one but a founder itself changes a founder's roles";
331
- if (!state.roles.has(event.role))
332
- return `There is no role "${event.role}"`;
333
- const args = targetArgs(state, root, event.did, event.role);
334
- if (event.assigned)
335
- return may(state, root, ROLE_ASSIGN, args) ? null : 'Its author may not assign them this role';
336
- if (!holds)
337
- return 'They do not hold that role';
338
- return may(state, root, ROLE_UNASSIGN, args) ? null : 'Its author may not take this role from them';
339
- }
295
+ case 'assign':
296
+ return assignRefusal(event, state);
340
297
  case 'remove': {
341
298
  if (!isMember(state, event.did))
342
299
  return 'Not a member';
343
- // Leaving the space is built in, for a founder too.
300
+ // Leaving is built in, for a founder too.
344
301
  if (root === event.did)
345
302
  return null;
346
303
  if (state.founders.has(event.did))
@@ -350,7 +307,7 @@ export function refusal(event, state) {
350
307
  : 'Its author may not remove them';
351
308
  }
352
309
  case 'invite': {
353
- // An invite is an assignment to whoever holds its secret: to someone else, holding nothing yet.
310
+ // An invite assigns to whoever holds its secret: someone else, holding nothing yet.
354
311
  const assigns = (role) => state.roles.has(role) && may(state, root, ROLE_ASSIGN, { role, self: false, roles: [] });
355
312
  const existing = state.invites.get(event.inviteKey);
356
313
  if (existing && !assigns(existing.role))
@@ -361,49 +318,32 @@ export function refusal(event, state) {
361
318
  return `There is no role "${event.role}"`;
362
319
  return assigns(event.role) ? null : 'Its author may not invite to this role';
363
320
  }
364
- // Stepping down is built in, and only a founder's own.
365
321
  case 'stepdown':
366
322
  if (root !== event.did)
367
323
  return 'Only a founder itself steps down';
368
324
  return state.founders.has(event.did) ? null : 'Not a founder';
369
- // A successor binds no one, so where no one holds the command, any member may name one.
370
325
  case 'succeed': {
326
+ // A successor binds no one, so where no one holds the command, any member may name one.
371
327
  if (!isMember(state, root))
372
328
  return 'Only a member may name a successor';
373
329
  if (may(state, root, SPACE_SUCCEED, {}))
374
330
  return null;
375
331
  return anyMaySucceed(state) ? 'Its author may not name a successor' : null;
376
332
  }
377
- // An account revokes its own keys: what a revoke takes away is only ever its own account's.
333
+ // A revoke only ever takes from its own account.
378
334
  case 'revoke':
379
335
  return isMember(state, root) ? null : 'Only a member may revoke a key here';
380
- // The proof stands on its own (checked before it got here); a member only has to bring it.
336
+ // The proof was checked before it got here; a member only has to bring it.
381
337
  case 'fork':
382
338
  return isMember(state, root) ? null : 'Only a member may report a fork';
383
- case 'definition': {
384
- const existing = state.definitions.get(event.name);
385
- const contested = state.contested.has(event.name);
386
- const defines = may(state, root, COLLECTION_DEFINE, { collection: event.name });
387
- if (!existing && !contested) {
388
- if (event.deleted)
389
- return 'There is no such definition to remove';
390
- return defines ? null : 'Its author may not define this collection';
391
- }
392
- if (defines)
393
- return null;
394
- // Rivals no one settled: no one first defined it, so only someone who may define it settles them.
395
- if (contested)
396
- return 'Rival definitions of it stand: only someone who may define it may settle them';
397
- return isMember(state, root) && existing?.definedBy === root
398
- ? null
399
- : 'Only whoever defined it, or someone who may define it, may change it';
400
- }
339
+ case 'definition':
340
+ return definitionRefusal(event, state);
401
341
  case 'key': {
402
342
  if (state.keys.length === 0)
403
343
  return 'A public space has no key to change';
404
344
  if (!may(state, root, KEY_CHANGE, {}))
405
345
  return "Its author may not change the space's key";
406
- // Going back to a key a removed member still holds would undo the point of changing it.
346
+ // Going back to a key a removed member still holds would undo the change.
407
347
  return state.keys.some((known) => known.keyId === event.keyId || known.readKey === event.readKey)
408
348
  ? 'That key was used before'
409
349
  : null;
@@ -418,10 +358,68 @@ export function refusal(event, state) {
418
358
  : 'Its author may not change who keeps the space';
419
359
  }
420
360
  }
361
+ function assignRefusal(event, state) {
362
+ const root = event.root;
363
+ // Roles go to accounts: putting one role inside another is part of a definition.
364
+ if (event.did.startsWith('role:'))
365
+ return 'A role is assigned to accounts, not to roles';
366
+ const holds = rolesOf(state, event.did).includes(event.role);
367
+ if (event.viaInvite !== undefined)
368
+ return inviteJoinRefusal(event, event.viaInvite, state, holds);
369
+ // Leaving a role is built in.
370
+ if (!event.assigned && root === event.did)
371
+ return holds ? null : 'It does not hold that role';
372
+ if (state.founders.has(event.did) && root !== event.did)
373
+ return "No one but a founder itself changes a founder's roles";
374
+ if (!state.roles.has(event.role))
375
+ return `There is no role "${event.role}"`;
376
+ const args = targetArgs(state, root, event.did, event.role);
377
+ if (event.assigned)
378
+ return may(state, root, ROLE_ASSIGN, args) ? null : 'Its author may not assign them this role';
379
+ if (!holds)
380
+ return 'They do not hold that role';
381
+ return may(state, root, ROLE_UNASSIGN, args) ? null : 'Its author may not take this role from them';
382
+ }
383
+ /** Joining with an invite: your own record, judged as the assignment its openers make */
384
+ function inviteJoinRefusal(event, inviteKey, state, holds) {
385
+ const invite = state.invites.get(inviteKey);
386
+ if (!event.assigned)
387
+ return 'An invite only assigns';
388
+ if (event.root !== event.did)
389
+ return 'Only the person joining can use an invite for themselves';
390
+ if (!invite?.open)
391
+ return 'The invite is not open';
392
+ if (invite.role !== event.role)
393
+ return 'The invite is for another role';
394
+ if (holds)
395
+ return 'Already holds that role';
396
+ if (!state.roles.has(event.role))
397
+ return `There is no role "${event.role}"`;
398
+ const openersMay = invite.by.every((opener) => may(state, opener, ROLE_ASSIGN, targetArgs(state, opener, event.did, event.role)));
399
+ return openersMay ? null : 'Whoever opened the invite may not assign this role to them';
400
+ }
401
+ function definitionRefusal(event, state) {
402
+ const root = event.root;
403
+ const existing = state.definitions.get(event.name);
404
+ const contested = state.contested.has(event.name);
405
+ const defines = may(state, root, COLLECTION_DEFINE, { collection: event.name });
406
+ if (!existing && !contested) {
407
+ if (event.deleted)
408
+ return 'There is no such definition to remove';
409
+ return defines ? null : 'Its author may not define this collection';
410
+ }
411
+ if (defines)
412
+ return null;
413
+ if (contested)
414
+ return 'Rival definitions of it stand: only someone who may define it may settle them';
415
+ return isMember(state, root) && existing?.definedBy === root
416
+ ? null
417
+ : 'Only whoever defined it, or someone who may define it, may change it';
418
+ }
421
419
  const NO_CUTOFF = new Map();
422
420
  /** Whether a reduction reaches its key's changes whatever either saw */
423
421
  const reachesBack = (reduction) => reduction.reach.kind === 'key' || reduction.reach.kind === 'line';
424
- /** What a change takes, in its own view: null when it takes nothing, and is no reduction */
422
+ /** What a change takes, in its own view: null when it takes nothing */
425
423
  function reductionOf(event, view) {
426
424
  const of = (reach, cutoff = event.cutoff) => ({ id: event.id, reach, cutoff });
427
425
  const account = (holds, did) => (holds ? of({ kind: 'account', root: did }) : null);
@@ -445,16 +443,12 @@ function reductionOf(event, view) {
445
443
  }
446
444
  /** Whether a reduction reaches a change or a record that its cutoff doesn't cover */
447
445
  function reaches(reduction, subject) {
448
- const { writer, collection, line } = subject;
449
- if (writer !== undefined &&
450
- collection !== undefined &&
451
- line !== undefined &&
452
- (reduction.cutoff.get(writer)?.get(collection) ?? -1) >= line)
446
+ if (coveredBy(reduction.cutoff, subject))
453
447
  return false;
448
+ const { writer, collection, line } = subject;
454
449
  const reach = reduction.reach;
455
450
  switch (reach.kind) {
456
- // A removal or an unassignment reaches everything its account did: what an action needed is
457
- // judged in a view its author chooses, so it can't decide what a strike leaves.
451
+ // Everything its account did: what an action needed is judged in a view its author chooses.
458
452
  case 'account':
459
453
  return subject.root === reach.root;
460
454
  case 'key':
@@ -465,6 +459,11 @@ function reaches(reduction, subject) {
465
459
  return subject.viaInvite === reach.invite;
466
460
  }
467
461
  }
462
+ function coveredBy(cutoff, { writer, collection, line }) {
463
+ if (writer === undefined || collection === undefined || line === undefined)
464
+ return false;
465
+ return (cutoff.get(writer)?.get(collection) ?? -1) >= line;
466
+ }
468
467
  /** Adds a valid reduction to what judging looks up: by the account or key it reaches, and each line's lowest fork */
469
468
  function indexReduction(taken, forks, reduction) {
470
469
  const reach = reduction.reach;
@@ -478,19 +477,6 @@ function indexReduction(taken, forks, reduction) {
478
477
  taken.set(who, [...(taken.get(who) ?? []), reduction]);
479
478
  }
480
479
  }
481
- /** A role's definition from a change, judged in `view` */
482
- function definitionFrom(event, view) {
483
- if (event.kind !== 'role')
484
- return null;
485
- return Object.freeze({
486
- event: event.id,
487
- by: event.root,
488
- ...(event.title !== undefined ? { title: event.title } : {}),
489
- grants: event.grants,
490
- nests: event.nests,
491
- view,
492
- });
493
- }
494
480
  function setAssigned(state, did, role, event) {
495
481
  const roles = new Map(state.assigned.get(did) ?? []);
496
482
  if (event === null)
@@ -512,7 +498,7 @@ function change(event, state, view) {
512
498
  setAssigned(state, event.did, event.role, event.assigned ? event.id : null);
513
499
  return;
514
500
  case 'remove':
515
- // It ends every assignment it saw, since none of them saw it; a founder who leaves steps down.
501
+ // It ends every assignment it saw; a founder who leaves steps down.
516
502
  state.assigned.delete(event.did);
517
503
  if (event.root === event.did)
518
504
  state.founders.delete(event.did);
@@ -521,7 +507,7 @@ function change(event, state, view) {
521
507
  state.founders.delete(event.did);
522
508
  return;
523
509
  case 'succeed':
524
- state.successors.set(event.space, [...new Set([...(state.successors.get(event.space) ?? []), event.root])].sort());
510
+ state.successors.set(event.space, sortedUnique([...(state.successors.get(event.space) ?? []), event.root]));
525
511
  return;
526
512
  case 'invite':
527
513
  state.invites.set(event.inviteKey, {
@@ -549,7 +535,7 @@ function change(event, state, view) {
549
535
  return;
550
536
  }
551
537
  case 'key':
552
- state.keys.push({ keyId: event.keyId, readKey: event.readKey, event: event.id });
538
+ state.keys.push(keyEpoch(event));
553
539
  return;
554
540
  case 'relays':
555
541
  state.relays = [...event.relays];
@@ -560,17 +546,6 @@ function change(event, state, view) {
560
546
  return;
561
547
  }
562
548
  }
563
- // ─── The convergent replay (spec/03-spaces.md §4) ──────────
564
- //
565
- // No order decides anything. A change is allowed when its author had the
566
- // power in the state its own view gives (the changes it saw that were
567
- // allowed, merged). A removal or an unassignment, judged in its own view, is
568
- // a reduction; it strikes every change of its account that it had not seen,
569
- // past its cutoff. Reductions that strike each other all stand. The state is a
570
- // merge of the valid changes: on each record, the latest wins, and of latest
571
- // changes that didn't see each other, the one that gives least.
572
- /** A key's line for one collection, as a map key */
573
- const lineOf = (writer, collection) => `${writer}\n${collection}`;
574
549
  /** What a change names in `seen`, once each, leaving out the space itself */
575
550
  const parentsOf = (event, genesisId) => [
576
551
  ...new Set(event.seen.filter((parent) => parent !== genesisId)),
@@ -603,50 +578,21 @@ function seenOf(parents, saw, order, index) {
603
578
  },
604
579
  };
605
580
  }
606
- const byId = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
607
581
  /** The state a set of changes gives, merged: no order, only what saw what (spec 03 §4.4) */
608
582
  function merge(genesis, events, saw, defViews) {
609
583
  const state = startState(genesis);
610
584
  const byKey = new Map();
611
- for (const event of events) {
612
- // A revoke or a fork proof changes no state.
613
- if (event.kind === 'revoke' || event.kind === 'fork')
614
- continue;
615
- (byKey.get(event.key) ?? byKey.set(event.key, []).get(event.key)).push(event);
616
- }
617
- // The latest on a key, those no other on it saw, in one pass: below another's prefix, or among its exceptions.
618
- const latest = (group) => {
619
- if (group.length <= 1)
620
- return group;
621
- let top = -1;
622
- let topBy = '';
623
- let second = -1;
624
- const exceptions = new Set();
625
- for (const event of group) {
626
- const seen = saw.get(event.id);
627
- if (seen.prefix > top) {
628
- second = top;
629
- top = seen.prefix;
630
- topBy = event.id;
631
- }
632
- else if (seen.prefix > second)
633
- second = seen.prefix;
634
- for (const n of seen.extra)
635
- exceptions.add(n);
636
- }
637
- return group.filter((event) => {
638
- const place = saw.get(event.id).placeOf(event.id);
639
- const below = event.id === topBy ? second : top;
640
- return !(place < below || exceptions.has(place));
641
- });
642
- };
585
+ // A revoke or a fork proof changes no state.
586
+ for (const event of events)
587
+ if (event.kind !== 'revoke' && event.kind !== 'fork')
588
+ pushTo(byKey, event.key, event);
643
589
  // Removals first: an assignment counts only if it saw every one of its account's.
644
590
  const removals = new Map();
645
591
  for (const group of byKey.values()) {
646
592
  if (group[0]?.kind !== 'remove')
647
593
  continue;
648
594
  const did = group[0].did;
649
- removals.set(did, latest(group));
595
+ removals.set(did, latestOf(group, saw));
650
596
  // A founder who leaves is one no more; no one else can remove one.
651
597
  if (group.some((event) => event.root === did))
652
598
  state.founders.delete(did);
@@ -656,7 +602,7 @@ function merge(genesis, events, saw, defViews) {
656
602
  let currentKey = null;
657
603
  const keyEvents = [];
658
604
  for (const group of byKey.values()) {
659
- const tops = [...latest(group)].sort(byId);
605
+ const tops = [...latestOf(group, saw)].sort(idOrder);
660
606
  const win = tops[0];
661
607
  if (!win)
662
608
  continue;
@@ -666,19 +612,16 @@ function merge(genesis, events, saw, defViews) {
666
612
  case 'stepdown':
667
613
  state.founders.delete(win.did);
668
614
  continue;
669
- case 'succeed': {
615
+ case 'succeed':
670
616
  // Every one stands, whoever named it: none is first.
671
- const space = win.space;
672
- state.successors.set(space, [...new Set(group.map((event) => event.root))].sort());
617
+ state.successors.set(win.space, sortedUnique(group.map((event) => event.root)));
673
618
  continue;
674
- }
675
619
  case 'role':
676
620
  // Rivals all stand: the role holds what they share.
677
621
  state.roles.set(win.name, tops.map((event) => definitionFrom(event, defViews.get(event.id))));
678
622
  continue;
679
623
  case 'assign': {
680
624
  // Taking a role away beats giving it; an assignment counts only if it saw its account's removals.
681
- // The changes on its key all saw the constitution, so they decide over its assignment too.
682
625
  const gone = removals.get(win.did) ?? [];
683
626
  const counted = tops.some((event) => event.kind === 'assign' && !event.assigned)
684
627
  ? undefined
@@ -686,25 +629,12 @@ function merge(genesis, events, saw, defViews) {
686
629
  setAssigned(state, win.did, win.role, counted ? counted.id : null);
687
630
  continue;
688
631
  }
689
- case 'invite': {
690
- // Closed beats open, and open ones that name different roles close it. Rival openers
691
- // all stand: a join must be one each of them could have made.
692
- const roles = new Set(tops.map((event) => (event.kind === 'invite' ? event.role : '')));
693
- const closed = tops.find((event) => event.kind === 'invite' && !event.open);
694
- const pick = closed ?? win;
695
- if (pick.kind === 'invite')
696
- state.invites.set(pick.inviteKey, {
697
- role: pick.role,
698
- open: !closed && roles.size === 1,
699
- event: pick.id,
700
- by: [...new Set(tops.map((event) => event.root))].sort(),
701
- });
632
+ case 'invite':
633
+ mergeInvites(tops, win, state);
702
634
  continue;
703
- }
704
635
  case 'key':
636
+ // Every key stands; an id picks which is current among keys any author could have made current alone.
705
637
  keyEvents.push(...group);
706
- // Only those granted it change the key, and every key stands: an id picks which is current
707
- // among keys any of them could have made current alone.
708
638
  currentKey = win;
709
639
  continue;
710
640
  case 'definition':
@@ -715,23 +645,65 @@ function merge(genesis, events, saw, defViews) {
715
645
  change(win, state, state);
716
646
  }
717
647
  }
718
- if (keyEvents.length > 0) {
719
- // Every key stands; the current one goes last, the rest by id: only which is current matters.
720
- const sorted = [...keyEvents].sort(byId);
648
+ if (currentKey) {
649
+ // The current key goes last, the rest by id: only which is current matters.
721
650
  const current = currentKey;
722
- for (const event of [...sorted.filter((e) => e !== current), current])
651
+ const rest = [...keyEvents].sort(idOrder).filter((event) => event !== current);
652
+ for (const event of [...rest, current])
723
653
  if (event.kind === 'key')
724
- state.keys.push({ keyId: event.keyId, readKey: event.readKey, event: event.id });
654
+ state.keys.push(keyEpoch(event));
725
655
  }
726
656
  return state;
727
657
  }
658
+ /** The latest changes on one record: those no other on it saw */
659
+ function latestOf(group, saw) {
660
+ if (group.length <= 1)
661
+ return group;
662
+ // In one pass: an event is seen when it is below another's prefix, or among its exceptions.
663
+ let top = -1;
664
+ let topBy = '';
665
+ let second = -1;
666
+ const exceptions = new Set();
667
+ for (const event of group) {
668
+ const seen = saw.get(event.id);
669
+ if (seen.prefix > top) {
670
+ second = top;
671
+ top = seen.prefix;
672
+ topBy = event.id;
673
+ }
674
+ else if (seen.prefix > second)
675
+ second = seen.prefix;
676
+ for (const n of seen.extra)
677
+ exceptions.add(n);
678
+ }
679
+ return group.filter((event) => {
680
+ const place = saw.get(event.id).placeOf(event.id);
681
+ const below = event.id === topBy ? second : top;
682
+ return !(place < below || exceptions.has(place));
683
+ });
684
+ }
685
+ /**
686
+ * Closed beats open, and open ones naming different roles close it. Rival
687
+ * openers all stand: a join must be one each of them could have made.
688
+ */
689
+ function mergeInvites(tops, win, state) {
690
+ const roles = new Set(tops.map((event) => (event.kind === 'invite' ? event.role : '')));
691
+ const closed = tops.find((event) => event.kind === 'invite' && !event.open);
692
+ const pick = closed ?? win;
693
+ if (pick.kind !== 'invite')
694
+ return;
695
+ state.invites.set(pick.inviteKey, {
696
+ role: pick.role,
697
+ open: !closed && roles.size === 1,
698
+ event: pick.id,
699
+ by: sortedUnique(tops.map((event) => event.root)),
700
+ });
701
+ }
728
702
  /**
729
703
  * A state with one change applied on top: the change saw all of it, so it is
730
- * the latest on its record. Who defined a collection is worked out among the
731
- * changes `counted`.
704
+ * the latest on its record. Who defined a collection is worked out among `counted`.
732
705
  */
733
706
  function applied(state, event, r, counted) {
734
- const genesisId = r.genesis.id;
735
707
  const next = {
736
708
  ...state,
737
709
  founders: new Set(state.founders),
@@ -744,15 +716,8 @@ function applied(state, event, r, counted) {
744
716
  successors: new Map(state.successors),
745
717
  };
746
718
  change(event, next, state);
747
- if (event.kind === 'key') {
748
- // The keys before it in the order a merge gives: the space's own first, the rest by id.
749
- const earlier = next.keys.slice(0, -1);
750
- const own = earlier.filter((key) => key.event === genesisId);
751
- const rest = earlier
752
- .filter((key) => key.event !== genesisId)
753
- .sort((a, b) => (a.event < b.event ? -1 : a.event > b.event ? 1 : 0));
754
- next.keys = [...own, ...rest, next.keys.at(-1)];
755
- }
719
+ if (event.kind === 'key')
720
+ next.keys = inMergeOrder(next.keys, r.genesis.id);
756
721
  if (event.kind === 'definition' && !event.deleted) {
757
722
  const group = [...r.saw.get(event.id)]
758
723
  .filter((other) => counted.has(other) && r.byId.get(other).key === event.key)
@@ -762,52 +727,54 @@ function applied(state, event, r, counted) {
762
727
  }
763
728
  return next;
764
729
  }
730
+ /** Keys in the order a merge gives: the space's own first, the rest by id, the newest last */
731
+ function inMergeOrder(keys, genesisId) {
732
+ const earlier = keys.slice(0, -1);
733
+ const own = earlier.filter((key) => key.event === genesisId);
734
+ const rest = earlier.filter((key) => key.event !== genesisId).sort((a, b) => compare(a.event, b.event));
735
+ return [...own, ...rest, keys.at(-1)];
736
+ }
765
737
  /**
766
738
  * The latest changes to one collection's definition, merged (02 §6.3). One
767
- * account's alone, or changes by accounts that may each change it (its first
768
- * definer and those who may define it, or only those once no one first
769
- * defined it), are picked between by id: each could have made its own the
770
- * latest alone. Anything else, rival first definitions by two accounts or a
771
- * delete beside another account's change, is contested: no id decides, since
772
- * an id can be ground, and readers judge the rivals by what they say.
739
+ * account's alone, or changes by accounts that may each change it, are picked
740
+ * between by id: each could have made its own the latest alone. Anything else
741
+ * (rival first definitions by two accounts, or a delete beside another
742
+ * account's change) is contested: an id can be ground, so no id decides.
773
743
  */
774
744
  function mergeDefinitions(tops, group, saw, state) {
775
- const sorted = [...tops].sort(byId);
745
+ const sorted = [...tops].sort(idOrder);
776
746
  const win = sorted[0];
777
747
  if (win.kind !== 'definition')
778
748
  return;
779
- // Who first defined it, as each latest definition sees the whole group: null where rivals stand.
780
749
  const definitions = sorted.filter((top) => !isDelete(top));
750
+ // Who first defined it, as each latest definition sees it: null where rivals stand.
781
751
  const definers = new Set(definitions.map((top) => definerOf(top, group, saw)));
782
- // No first definer is agreed on only once every latest change saw the rival firsts, which a
783
- // settling change did; rival firsts that are themselves latest are not agreement.
752
+ // Rival firsts are settled only once every latest change saw them all.
784
753
  const settled = definitions.every((top) => firstsOf(top, group, saw).every((first) => first === top || saw.get(top.id)?.has(first.id)));
785
754
  const oneAccount = new Set(sorted.map((top) => top.root)).size === 1;
786
755
  const agreed = sorted.length === 1 ||
787
756
  oneAccount ||
788
757
  (definers.size === 1 && !sorted.some(isDelete) && (!definers.has(null) || settled));
789
- if (agreed) {
790
- if (win.deleted)
791
- change(win, state, state);
792
- else
793
- state.definitions.set(win.name, { event: win.id, definedBy: definerOf(win, group, saw) });
794
- return;
758
+ if (!agreed) {
759
+ state.definitions.delete(win.name);
760
+ state.contested.set(win.name, sorted.map((top) => top.id));
795
761
  }
796
- state.definitions.delete(win.name);
797
- state.contested.set(win.name, sorted.map((top) => top.id));
762
+ else if (win.deleted)
763
+ change(win, state, state);
764
+ else
765
+ state.definitions.set(win.name, { event: win.id, definedBy: definerOf(win, group, saw) });
798
766
  }
799
767
  const isDelete = (event) => event.kind === 'definition' && event.deleted;
800
768
  /**
801
- * Whoever defined a collection this time (02 §6.3): of the definitions in
802
- * `group` that saw every removal the winning one saw, those that saw no
803
- * other, if they are all one account's. Rival first definitions by two
804
- * accounts give no one: no id decides it, since an id can be ground, so only
805
- * someone who may define it may change it.
769
+ * Whoever defined a collection this time (02 §6.3): the account of its first
770
+ * definitions, if they are all one account's. Rival firsts by two accounts
771
+ * give no one, so only someone who may define it may change it.
806
772
  */
807
773
  function definerOf(win, group, saw) {
808
- const firsts = firstsOf(win, group, saw);
809
- const roots = new Set(firsts.map((event) => event.root));
810
- return roots.size === 1 ? [...roots][0] : roots.size === 0 ? win.root : null;
774
+ const roots = new Set(firstsOf(win, group, saw).map((event) => event.root));
775
+ if (roots.size === 0)
776
+ return win.root;
777
+ return roots.size === 1 ? [...roots][0] : null;
811
778
  }
812
779
  /** The first definitions of the life `win` is in: those of `group` that saw every removal it saw, and no other */
813
780
  function firstsOf(win, group, saw) {
@@ -817,7 +784,10 @@ function firstsOf(win, group, saw) {
817
784
  (event === win || removals.every((removal) => saw.get(event.id)?.has(removal.id))));
818
785
  return life.filter((event) => !life.some((other) => other !== event && saw.get(event.id)?.has(other.id)));
819
786
  }
820
- /** A graph's strongly connected components, each after those with an edge into it (Tarjan's, without recursion: a long history must not overflow the stack) */
787
+ /**
788
+ * A graph's strongly connected components, each after those with an edge into
789
+ * it. Tarjan's, without recursion, so a long history can't overflow the stack.
790
+ */
821
791
  function componentsOf(nodes, edges) {
822
792
  let counter = 0;
823
793
  const indices = new Map();
@@ -825,7 +795,6 @@ function componentsOf(nodes, edges) {
825
795
  const stack = [];
826
796
  const onStack = new Set();
827
797
  const found = [];
828
- const of = new Map();
829
798
  const work = [];
830
799
  const visit = (id) => {
831
800
  indices.set(id, counter);
@@ -867,26 +836,87 @@ function componentsOf(nodes, edges) {
867
836
  }
868
837
  // Tarjan's finds components sinks first.
869
838
  const list = found.reverse();
839
+ const of = new Map();
870
840
  list.forEach((members, i) => members.forEach((id) => of.set(id, i)));
871
841
  return { of, list };
872
842
  }
873
843
  const STRUCK = "Its author's power was taken away by a change it had not seen, or rested on one that was";
874
844
  /** Replays a space's access history. */
875
845
  export function replayAccess(genesis, events) {
876
- // Another resolver would judge the same changes differently: this peer doesn't judge the space at all.
846
+ // Another resolver would judge the same changes differently, so this peer doesn't judge the space.
877
847
  if (!RESOLVERS.has(genesis.resolver))
878
848
  throw new Error(`This peer doesn't know the resolver ${genesis.resolver}, so it can't judge this space`);
879
- const byIdMap = new Map();
849
+ const byId = new Map();
880
850
  for (const event of events)
881
- if (!byIdMap.has(event.id))
882
- byIdMap.set(event.id, event);
883
- // A change waits until everything it saw is here, and so does anything that saw it.
851
+ if (!byId.has(event.id))
852
+ byId.set(event.id, event);
853
+ const waiting = waitingOf(genesis.id, byId);
854
+ const placeable = [...byId.values()].filter((event) => !waiting.has(event.id));
855
+ const order = ancestorsFirst(placeable, genesis.id);
856
+ const placed = new Set(order);
857
+ for (const event of placeable)
858
+ if (!placed.has(event.id))
859
+ waiting.add(event.id);
860
+ const index = new Map(order.map((id, i) => [id, i]));
861
+ const saw = new Map();
862
+ for (const id of order)
863
+ saw.set(id, seenOf(parentsOf(byId.get(id), genesis.id), saw, order, index));
864
+ const judged = judgeInOrder(order, { genesis, saw, byId });
865
+ const { allowedIds, taking, strikes, defViews } = judged;
866
+ const within = validWithin(order, { genesis, byId, saw, allowedIds, strikes, defViews });
867
+ const valid = within.valid;
868
+ const struck = new Map();
869
+ for (const id of order)
870
+ if (allowedIds.has(id) && !valid.has(id))
871
+ struck.set(id, STRUCK);
872
+ const taken = new Map();
873
+ const forks = new Map();
874
+ for (const id of order) {
875
+ const reduction = valid.has(id) && taking.get(id);
876
+ if (reduction)
877
+ indexReduction(taken, forks, reduction);
878
+ }
879
+ const named = new Set([...genesis.founders, ...Object.keys(genesis.assigned ?? {})]);
880
+ const invites = new Set();
881
+ for (const event of byId.values()) {
882
+ if (event.kind === 'assign' && event.assigned)
883
+ named.add(event.did);
884
+ if (event.kind === 'invite')
885
+ invites.add(event.inviteKey);
886
+ }
887
+ const state = merge(genesis, order.filter((id) => valid.has(id)).map((id) => byId.get(id)), saw, within.defViews);
888
+ state.keyDue = keyDue(state, { genesis, order, byId, saw, valid, ...judged });
889
+ return historyOf({
890
+ genesis,
891
+ byId,
892
+ waiting,
893
+ order,
894
+ saw,
895
+ index,
896
+ refused: judged.refused,
897
+ valid,
898
+ struck,
899
+ taking,
900
+ taken,
901
+ forks,
902
+ state,
903
+ named,
904
+ invites,
905
+ views: new Map(),
906
+ allowedIds,
907
+ defViews,
908
+ validDefViews: within.defViews,
909
+ strikes,
910
+ });
911
+ }
912
+ /** Changes that wait until everything they saw is here, and anything that saw them */
913
+ function waitingOf(genesisId, byId) {
884
914
  const waiting = new Set();
885
- const known = (id) => id === genesis.id || byIdMap.has(id);
915
+ const known = (id) => id === genesisId || byId.has(id);
886
916
  let changed = true;
887
917
  while (changed) {
888
918
  changed = false;
889
- for (const event of byIdMap.values()) {
919
+ for (const event of byId.values()) {
890
920
  if (waiting.has(event.id))
891
921
  continue;
892
922
  if (event.seen.some((parent) => parent === event.id || !known(parent) || waiting.has(parent))) {
@@ -895,15 +925,17 @@ export function replayAccess(genesis, events) {
895
925
  }
896
926
  }
897
927
  }
898
- // Ancestors first (Kahn's order, ties by id): a cycle can only be forged, and must not hang it.
899
- const placeable = [...byIdMap.values()].filter((event) => !waiting.has(event.id));
928
+ return waiting;
929
+ }
930
+ /** Kahn's order, ties by id. A cycle can only be forged: its changes are left out rather than hang it. */
931
+ function ancestorsFirst(placeable, genesisId) {
900
932
  const children = new Map();
901
933
  const pending = new Map();
902
934
  for (const event of placeable) {
903
- const parents = parentsOf(event, genesis.id);
935
+ const parents = parentsOf(event, genesisId);
904
936
  pending.set(event.id, parents.length);
905
937
  for (const parent of parents)
906
- (children.get(parent) ?? children.set(parent, []).get(parent)).push(event.id);
938
+ pushTo(children, parent, event.id);
907
939
  }
908
940
  const ready = placeable.filter((event) => pending.get(event.id) === 0).map((event) => event.id);
909
941
  const order = [];
@@ -918,30 +950,25 @@ export function replayAccess(genesis, events) {
918
950
  ready.push(child);
919
951
  }
920
952
  }
921
- const placed = new Set(order);
922
- for (const event of placeable)
923
- if (!placed.has(event.id))
924
- waiting.add(event.id);
925
- const index = new Map(order.map((id, i) => [id, i]));
926
- const saw = new Map();
927
- for (const id of order) {
928
- saw.set(id, seenOf(parentsOf(byIdMap.get(id), genesis.id), saw, order, index));
929
- }
930
- // In order, ancestors first: each change's own view (the allowed changes it saw), whether it is
931
- // allowed there, what it takes, and the strikes it is part of.
953
+ return order;
954
+ }
955
+ /**
956
+ * Each change in order, ancestors first: its own view (the allowed changes it
957
+ * saw), whether it is allowed there, what it takes, and the strikes it is part of.
958
+ */
959
+ function judgeInOrder(order, r) {
960
+ const { saw, byId } = r;
932
961
  const tookReading = new Set();
933
962
  const refused = new Map();
934
963
  const allowedIds = new Set();
935
964
  const strikes = new Map();
936
965
  const afterOf = new Map();
937
966
  const defViews = new Map();
938
- /** The allowed reductions, in order */
939
967
  const taking = new Map();
940
- const strike = (by, id) => (strikes.get(by) ?? strikes.set(by, []).get(by)).push(id);
941
- const allowedView = viewsAlong({ genesis, saw, byId: byIdMap }, (id) => allowedIds.has(id), afterOf, defViews);
968
+ const allowedView = viewsAlong(r, (id) => allowedIds.has(id), afterOf, defViews);
942
969
  for (const id of order) {
943
- const event = byIdMap.get(id);
944
- const result = step(event, allowedView(event), { genesis, saw, byId: byIdMap, allowedIds, taking });
970
+ const event = byId.get(id);
971
+ const result = step(event, allowedView(event), { ...r, allowedIds, taking });
945
972
  if (typeof result === 'string') {
946
973
  refused.set(id, result);
947
974
  continue;
@@ -950,10 +977,9 @@ export function replayAccess(genesis, events) {
950
977
  afterOf.set(id, result.after);
951
978
  if (result.tookReading)
952
979
  tookReading.add(id);
953
- // Strikes it is part of, with the allowed changes before it.
954
980
  for (const by of result.reachedBy)
955
981
  if (strikesOn(by, event, saw))
956
- strike(by.id, id);
982
+ pushTo(strikes, by.id, id);
957
983
  const reduction = result.reduction;
958
984
  if (!reduction)
959
985
  continue;
@@ -961,15 +987,15 @@ export function replayAccess(genesis, events) {
961
987
  for (const other of order) {
962
988
  if (other === id)
963
989
  break;
964
- if (allowedIds.has(other) && strikesOn(reduction, byIdMap.get(other), saw))
965
- strike(id, other);
990
+ if (allowedIds.has(other) && strikesOn(reduction, byId.get(other), saw))
991
+ pushTo(strikes, id, other);
966
992
  }
967
993
  }
968
- // A stepping down its key's revoke or fork proof reaches only ends founder status: it strikes
969
- // nothing, and withdraws nothing, as a reduction would.
994
+ // A stepping down that its key's revoke or fork proof reaches only ends founder status: it
995
+ // strikes nothing, and withdraws nothing.
970
996
  const back = [...taking.values()].filter(reachesBack);
971
997
  for (const id of order) {
972
- const event = byIdMap.get(id);
998
+ const event = byId.get(id);
973
999
  if (event.kind !== 'stepdown' || !allowedIds.has(id))
974
1000
  continue;
975
1001
  if (back.some((reduction) => reachedBy(reduction, event, saw))) {
@@ -977,74 +1003,34 @@ export function replayAccess(genesis, events) {
977
1003
  taking.delete(id);
978
1004
  }
979
1005
  }
980
- const within = validWithin(order, { genesis, byId: byIdMap, saw, allowedIds, strikes, defViews });
981
- const valid = within.valid;
982
- const struck = new Map();
983
- for (const id of order)
984
- if (allowedIds.has(id) && !valid.has(id))
985
- struck.set(id, STRUCK);
986
- const taken = new Map();
987
- const forks = new Map();
988
- for (const id of order) {
989
- const reduction = valid.has(id) && taking.get(id);
990
- if (reduction)
991
- indexReduction(taken, forks, reduction);
992
- }
993
- const named = new Set([...genesis.founders, ...Object.keys(genesis.assigned ?? {})]);
994
- const invites = new Set();
995
- for (const event of byIdMap.values()) {
996
- if (event.kind === 'assign' && event.assigned)
997
- named.add(event.did);
998
- if (event.kind === 'invite')
999
- invites.add(event.inviteKey);
1000
- }
1001
- const state = merge(genesis, order.filter((id) => valid.has(id)).map((id) => byIdMap.get(id)), saw, within.defViews);
1002
- // Due: someone lost reading in a valid change the current key had not seen. They may hold it.
1006
+ return { tookReading, refused, allowedIds, strikes, afterOf, defViews, taking };
1007
+ }
1008
+ /**
1009
+ * Whether a new key is due: someone lost reading in a valid change the current
1010
+ * key had not seen, or someone who held the current key reads no more, however
1011
+ * that came about (two changes together can take reading where neither did alone).
1012
+ */
1013
+ function keyDue(state, r) {
1003
1014
  const keyEvent = state.keys.at(-1)?.event;
1004
- const sawByKey = keyEvent === undefined ? undefined : saw.get(keyEvent);
1005
- state.keyDue =
1006
- keyEvent !== undefined &&
1007
- order.some((id) => valid.has(id) && tookReading.has(id) && id !== keyEvent && !sawByKey?.has(id));
1008
- // Due, too, when someone who held the current key reads no more, however that came about: two
1009
- // changes together can take reading where neither did alone. Whoever could read as the key was
1010
- // made held it, and so did whoever came to read after, by a change the key had not seen.
1011
- if (keyEvent !== undefined && !state.keyDue) {
1012
- const atKey = keyEvent === genesis.id ? startState(genesis) : afterOf.get(keyEvent);
1013
- const now = readers(state);
1014
- const held = new Set(atKey ? readers(atKey) : []);
1015
- for (const id of order) {
1016
- const event = byIdMap.get(id);
1017
- if (!valid.has(id) || event.kind !== 'assign' || sawByKey?.has(id))
1018
- continue;
1019
- const after = afterOf.get(id);
1020
- if (after && isMember(after, event.did))
1021
- held.add(event.did);
1022
- }
1023
- if ([...held].some((did) => !now.has(did)))
1024
- state.keyDue = true;
1015
+ if (keyEvent === undefined)
1016
+ return false;
1017
+ const sawByKey = r.saw.get(keyEvent);
1018
+ const unseen = (id) => r.valid.has(id) && id !== keyEvent && !sawByKey?.has(id);
1019
+ if (r.order.some((id) => r.tookReading.has(id) && unseen(id)))
1020
+ return true;
1021
+ // Whoever could read as the key was made held it, and so did whoever came to read after.
1022
+ const atKey = keyEvent === r.genesis.id ? startState(r.genesis) : r.afterOf.get(keyEvent);
1023
+ const held = new Set(atKey ? readers(atKey) : []);
1024
+ for (const id of r.order) {
1025
+ const event = r.byId.get(id);
1026
+ if (!r.valid.has(id) || event.kind !== 'assign' || sawByKey?.has(id))
1027
+ continue;
1028
+ const after = r.afterOf.get(id);
1029
+ if (after && isMember(after, event.did))
1030
+ held.add(event.did);
1025
1031
  }
1026
- return historyOf({
1027
- genesis,
1028
- byId: byIdMap,
1029
- waiting,
1030
- order,
1031
- saw,
1032
- index,
1033
- refused,
1034
- valid,
1035
- struck,
1036
- taking,
1037
- taken,
1038
- forks,
1039
- state,
1040
- named,
1041
- invites,
1042
- views: new Map(),
1043
- allowedIds,
1044
- defViews,
1045
- validDefViews: within.defViews,
1046
- strikes,
1047
- });
1032
+ const now = readers(state);
1033
+ return [...held].some((did) => !now.has(did));
1048
1034
  }
1049
1035
  // Revokes and fork proofs are never struck: every allowed one applies.
1050
1036
  const reachedBy = (reduction, event, saw) => reduction.id !== event.id &&
@@ -1053,8 +1039,7 @@ const reachedBy = (reduction, event, saw) => reduction.id !== event.id &&
1053
1039
  (reachesBack(reduction) ||
1054
1040
  (!saw.get(event.id).has(reduction.id) && !saw.get(reduction.id).has(event.id))) &&
1055
1041
  reaches(reduction, { ...event, writer: event.author, collection: ACCESS_KINDS[event.kind].collection });
1056
- // A stepping down is never struck (`validWithin`): founder status can't be given again. One a
1057
- // revoke or a fork proof reaches ends founder status and does nothing more.
1042
+ // A stepping down is never struck: founder status can't be given again.
1058
1043
  const strikesOn = (reduction, event, saw) => !(reachesBack(reduction) && event.kind === 'stepdown') && reachedBy(reduction, event, saw);
1059
1044
  /**
1060
1045
  * One change judged in its own view, as replaying and extending both do: why it is refused, or the
@@ -1076,21 +1061,23 @@ function step(event, view, r) {
1076
1061
  };
1077
1062
  }
1078
1063
  /**
1079
- * Each change's view over the changes `counts` keeps among what it saw. Along a chain, the one
1064
+ * Each change's view over the changes `counts` keeps among what it saw: along a chain, the one
1080
1065
  * before's view, with it on top when kept; where branches meet, a merge. Asked in order. A role
1081
1066
  * definition's view is kept in `defViews`, where its grants are judged.
1082
1067
  */
1083
1068
  function viewsAlong({ genesis, saw, byId }, counts, afterOf, defViews) {
1084
1069
  const viewOf = new Map();
1085
- return (event) => {
1070
+ const viewFor = (event) => {
1086
1071
  const parents = parentsOf(event, genesis.id);
1087
- let view;
1088
1072
  if (parents.length === 0)
1089
- view = startState(genesis);
1090
- else if (parents.length === 1)
1091
- view = counts(parents[0]) ? afterOf.get(parents[0]) : viewOf.get(parents[0]);
1092
- else
1093
- view = merge(genesis, [...saw.get(event.id)].filter(counts).map((other) => byId.get(other)), saw, defViews);
1073
+ return startState(genesis);
1074
+ if (parents.length === 1)
1075
+ return counts(parents[0]) ? afterOf.get(parents[0]) : viewOf.get(parents[0]);
1076
+ const counted = [...saw.get(event.id)].filter(counts).map((other) => byId.get(other));
1077
+ return merge(genesis, counted, saw, defViews);
1078
+ };
1079
+ return (event) => {
1080
+ const view = viewFor(event);
1094
1081
  viewOf.set(event.id, view);
1095
1082
  if (event.kind === 'role')
1096
1083
  defViews.set(event.id, view);
@@ -1100,34 +1087,11 @@ function viewsAlong({ genesis, saw, byId }, counts, afterOf, defViews) {
1100
1087
  /**
1101
1088
  * The valid changes among `cut` (in replay order, closed under what they saw), and the views their
1102
1089
  * role definitions are judged in. First the strikes: an allowed change is struck by an unstruck one
1103
- * from another component of the strikes inside the cut, visited strikers first. Then, ancestors
1104
- * first, a change stays valid only if the valid changes it saw still give its author the power.
1090
+ * from another component of the strikes inside the cut. Then, ancestors first, a change stays
1091
+ * valid only if the valid changes it saw still give its author the power.
1105
1092
  */
1106
1093
  function validWithin(cut, r) {
1107
- const inCut = new Set(cut);
1108
- const out = new Set(cut.filter((id) => !r.allowedIds.has(id)));
1109
- const edges = new Map();
1110
- for (const [from, targets] of r.strikes) {
1111
- if (!inCut.has(from) || !r.allowedIds.has(from))
1112
- continue;
1113
- const kept = targets.filter((to) => inCut.has(to) && r.allowedIds.has(to));
1114
- if (kept.length > 0)
1115
- edges.set(from, kept);
1116
- }
1117
- if (edges.size > 0) {
1118
- const nodes = [...new Set([...edges.keys(), ...[...edges.values()].flat()])].sort();
1119
- const { of, list } = componentsOf(nodes, edges);
1120
- const strikers = new Map();
1121
- for (const [from, targets] of edges)
1122
- for (const to of targets)
1123
- if (of.get(from) !== of.get(to))
1124
- (strikers.get(to) ?? strikers.set(to, []).get(to)).push(from);
1125
- // A stepping down is never struck: founder status can't be given back.
1126
- for (const members of list)
1127
- for (const id of members)
1128
- if (r.byId.get(id)?.kind !== 'stepdown' && (strikers.get(id) ?? []).some((from) => !out.has(from)))
1129
- out.add(id);
1130
- }
1094
+ const out = struckWithin(cut, r);
1131
1095
  const valid = new Set(cut.filter((id) => !out.has(id)));
1132
1096
  if (cut.every((id) => !r.allowedIds.has(id) || valid.has(id)))
1133
1097
  return { valid, defViews: r.defViews };
@@ -1147,6 +1111,34 @@ function validWithin(cut, r) {
1147
1111
  }
1148
1112
  return { valid, defViews };
1149
1113
  }
1114
+ /** The changes in `cut` that are not allowed, or that an unstruck change from another component strikes */
1115
+ function struckWithin(cut, r) {
1116
+ const inCut = new Set(cut);
1117
+ const out = new Set(cut.filter((id) => !r.allowedIds.has(id)));
1118
+ const edges = new Map();
1119
+ for (const [from, targets] of r.strikes) {
1120
+ if (!inCut.has(from) || !r.allowedIds.has(from))
1121
+ continue;
1122
+ const kept = targets.filter((to) => inCut.has(to) && r.allowedIds.has(to));
1123
+ if (kept.length > 0)
1124
+ edges.set(from, kept);
1125
+ }
1126
+ if (edges.size === 0)
1127
+ return out;
1128
+ const nodes = [...new Set([...edges.keys(), ...[...edges.values()].flat()])].sort();
1129
+ const { of, list } = componentsOf(nodes, edges);
1130
+ const strikers = new Map();
1131
+ for (const [from, targets] of edges)
1132
+ for (const to of targets)
1133
+ if (of.get(from) !== of.get(to))
1134
+ pushTo(strikers, to, from);
1135
+ // Visited strikers first. A stepping down is never struck: founder status can't be given back.
1136
+ for (const members of list)
1137
+ for (const id of members)
1138
+ if (r.byId.get(id)?.kind !== 'stepdown' && (strikers.get(id) ?? []).some((from) => !out.has(from)))
1139
+ out.add(id);
1140
+ return out;
1141
+ }
1150
1142
  /**
1151
1143
  * The replay with one more change that saw every change placed, or null for any other. Such a change
1152
1144
  * strikes nothing and only a revoke or fork can strike it; its view is every allowed change, and it
@@ -1157,8 +1149,8 @@ function extended(r, event) {
1157
1149
  // A revoke or a fork proof reaches back, whatever it saw: only replaying whole can say what it strikes.
1158
1150
  if (event.kind === 'revoke' || event.kind === 'fork')
1159
1151
  return null;
1160
- // Where something allowed is not valid, its view (the allowed changes) is not the state; and
1161
- // whether a key change is due rests on everyone who held the key. Both are worked out whole.
1152
+ // With something allowed but not valid, the allowed changes are not the state; and whether a key
1153
+ // change is due rests on everyone who held the key. Both are worked out whole.
1162
1154
  if (r.struck.size > 0 || r.state.keyDue)
1163
1155
  return null;
1164
1156
  const parents = parentsOf(event, genesis.id);
@@ -1170,7 +1162,7 @@ function extended(r, event) {
1170
1162
  if (mine.prefix !== r.order.length || mine.extra.size > 0 || r.waiting.size > 0)
1171
1163
  return null;
1172
1164
  const saw = new Map(r.saw).set(event.id, mine);
1173
- const byIdMap = new Map(r.byId).set(event.id, event);
1165
+ const byId = new Map(r.byId).set(event.id, event);
1174
1166
  const named = new Set(r.named);
1175
1167
  if (event.kind === 'assign' && event.assigned)
1176
1168
  named.add(event.did);
@@ -1179,11 +1171,10 @@ function extended(r, event) {
1179
1171
  invites.add(event.inviteKey);
1180
1172
  // It saw everything: its view is the current state.
1181
1173
  const view = r.state;
1182
- const defViews = event.kind === 'role' ? new Map(r.defViews).set(event.id, view) : r.defViews;
1183
- const validDefViews = event.kind === 'role' ? new Map(r.validDefViews).set(event.id, view) : r.validDefViews;
1174
+ const withView = (views) => event.kind === 'role' ? new Map(views).set(event.id, view) : views;
1184
1175
  const base = {
1185
1176
  genesis,
1186
- byId: byIdMap,
1177
+ byId,
1187
1178
  waiting: r.waiting,
1188
1179
  order,
1189
1180
  saw,
@@ -1191,15 +1182,14 @@ function extended(r, event) {
1191
1182
  named,
1192
1183
  invites,
1193
1184
  views: new Map(),
1194
- defViews,
1185
+ defViews: withView(r.defViews),
1195
1186
  };
1196
- const result = step(event, view, { ...r, saw, byId: byIdMap });
1187
+ const result = step(event, view, { ...r, saw, byId });
1197
1188
  if (typeof result === 'string')
1198
1189
  return { ...r, ...base, refused: new Map(r.refused).set(event.id, result) };
1199
- // Valid, besides allowed, when no revoke or fork of its key reaches it, whatever it saw: no other
1200
- // reduction can, since it saw them all.
1190
+ // It saw every reduction, so only a revoke or fork of its key can strike it.
1201
1191
  const strikers = result.reachedBy;
1202
- // A stepping down its key's revoke reaches ends founder status and does nothing else: only a whole replay says.
1192
+ // A stepping down its key's revoke reaches only ends founder status: only a whole replay says.
1203
1193
  if (strikers.length > 0 && event.kind === 'stepdown')
1204
1194
  return null;
1205
1195
  const taking = result.reduction ? new Map(r.taking).set(event.id, result.reduction) : r.taking;
@@ -1210,9 +1200,9 @@ function extended(r, event) {
1210
1200
  strikes.set(id, [...(strikes.get(id) ?? []), event.id]);
1211
1201
  return { ...r, ...base, strikes, struck: new Map(r.struck).set(event.id, STRUCK), allowedIds, taking };
1212
1202
  }
1213
- // Its view is every allowed change, and those are the valid ones: it is the state with it on top.
1203
+ // Every allowed change is valid: the state is it on top of the current one.
1214
1204
  const state = result.after;
1215
- // Due once it takes reading from someone: the key saw everything else, and no one else lost it.
1205
+ // Due once it takes reading from someone: the key saw everything else.
1216
1206
  state.keyDue = result.tookReading && state.keys.length > 0 && event.kind !== 'key';
1217
1207
  const taken = new Map(r.taken);
1218
1208
  const forks = new Map(r.forks);
@@ -1221,7 +1211,7 @@ function extended(r, event) {
1221
1211
  return {
1222
1212
  ...r,
1223
1213
  ...base,
1224
- validDefViews,
1214
+ validDefViews: withView(r.validDefViews),
1225
1215
  valid: new Set(r.valid).add(event.id),
1226
1216
  allowedIds,
1227
1217
  taking,
@@ -1288,8 +1278,7 @@ function historyOf(r) {
1288
1278
  const sawOrIs = (head, id) => head === id || r.saw.get(head).has(id);
1289
1279
  const chosen = [];
1290
1280
  for (const key of keys) {
1291
- const mine = r.order.filter((id) => r.valid.has(id) && r.byId.get(id).key === key);
1292
- const latest = mine.at(-1);
1281
+ const latest = r.order.filter((id) => r.valid.has(id) && r.byId.get(id).key === key).at(-1);
1293
1282
  if (!latest || chosen.some((head) => sawOrIs(head, latest)))
1294
1283
  continue;
1295
1284
  const head = recent.find((id) => sawOrIs(id, latest));
@@ -1323,7 +1312,7 @@ function historyOf(r) {
1323
1312
  return { ok: false, reason: 'Its writer’s log forked at or before it', withdrawn: true };
1324
1313
  if (!needs(at(record.seen, record.seen)))
1325
1314
  return { ok: false, reason: 'Its author was not allowed to, as of what it had seen' };
1326
- // What it had not seen of its author's standing: a removal or an unassignment takes everything.
1315
+ // A removal or an unassignment it had not seen takes everything.
1327
1316
  const cut = cutOf(record.seen);
1328
1317
  const reduced = (reduction) => reduction.reach.kind === 'account' && !cut.has(reduction.id) && takes(reduction);
1329
1318
  if ((r.taken.get(record.root) ?? []).some(reduced))
@@ -1360,4 +1349,22 @@ function historyOf(r) {
1360
1349
  });
1361
1350
  return history;
1362
1351
  }
1352
+ // ─── Plumbing ─────────────────────────────────────────────────────────
1353
+ /** A key's line for one collection, as a map key */
1354
+ const lineOf = (writer, collection) => `${writer}\n${collection}`;
1355
+ const keyEpoch = (event) => ({
1356
+ keyId: event.keyId,
1357
+ readKey: event.readKey,
1358
+ event: event.id,
1359
+ });
1360
+ const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
1361
+ const idOrder = (a, b) => compare(a.id, b.id);
1362
+ const sortedUnique = (values) => [...new Set(values)].sort();
1363
+ function pushTo(map, key, value) {
1364
+ const list = map.get(key);
1365
+ if (list)
1366
+ list.push(value);
1367
+ else
1368
+ map.set(key, [value]);
1369
+ }
1363
1370
  //# sourceMappingURL=roles.js.map