@dxos/client-services 0.1.13 → 0.1.14

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 (316) hide show
  1. package/dist/lib/browser/index.mjs +2747 -0
  2. package/dist/lib/browser/index.mjs.map +7 -0
  3. package/dist/lib/browser/meta.json +1 -0
  4. package/dist/lib/node/index.cjs +2823 -0
  5. package/dist/lib/node/index.cjs.map +7 -0
  6. package/dist/lib/node/meta.json +1 -0
  7. package/dist/{src → types/src}/index.d.ts +0 -0
  8. package/dist/types/src/index.d.ts.map +1 -0
  9. package/dist/{src → types/src}/packlets/deprecated/index.d.ts +0 -0
  10. package/dist/types/src/packlets/deprecated/index.d.ts.map +1 -0
  11. package/dist/{src → types/src}/packlets/deprecated/invitations.d.ts +4 -4
  12. package/dist/types/src/packlets/deprecated/invitations.d.ts.map +1 -0
  13. package/dist/{src → types/src}/packlets/deprecated/profile.d.ts +0 -0
  14. package/dist/types/src/packlets/deprecated/profile.d.ts.map +1 -0
  15. package/dist/{src → types/src}/packlets/deprecated/space.d.ts +0 -0
  16. package/dist/types/src/packlets/deprecated/space.d.ts.map +1 -0
  17. package/dist/{src → types/src}/packlets/deprecated/system.d.ts +0 -0
  18. package/dist/types/src/packlets/deprecated/system.d.ts.map +1 -0
  19. package/dist/{src → types/src}/packlets/deprecated/tracing.d.ts +0 -0
  20. package/dist/types/src/packlets/deprecated/tracing.d.ts.map +1 -0
  21. package/dist/{src → types/src}/packlets/devtools/devtools.d.ts +1 -1
  22. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -0
  23. package/dist/{src → types/src}/packlets/devtools/feeds.d.ts +0 -0
  24. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -0
  25. package/dist/{src → types/src}/packlets/devtools/index.d.ts +0 -0
  26. package/dist/types/src/packlets/devtools/index.d.ts.map +1 -0
  27. package/dist/types/src/packlets/devtools/keys.d.ts +7 -0
  28. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -0
  29. package/dist/{src → types/src}/packlets/devtools/network.d.ts +0 -0
  30. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -0
  31. package/dist/{src → types/src}/packlets/devtools/spaces.d.ts +0 -0
  32. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -0
  33. package/dist/{src → types/src}/packlets/identity/authenticator.d.ts +0 -0
  34. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -0
  35. package/dist/{src → types/src}/packlets/identity/authenticator.test.d.ts +0 -0
  36. package/dist/types/src/packlets/identity/authenticator.test.d.ts.map +1 -0
  37. package/dist/{src → types/src}/packlets/identity/devices-service-impl.d.ts +0 -0
  38. package/dist/types/src/packlets/identity/devices-service-impl.d.ts.map +1 -0
  39. package/dist/{src → types/src}/packlets/identity/identity-manager.d.ts +3 -3
  40. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -0
  41. package/dist/{src → types/src}/packlets/identity/identity-manager.test.d.ts +0 -0
  42. package/dist/types/src/packlets/identity/identity-manager.test.d.ts.map +1 -0
  43. package/dist/{src → types/src}/packlets/identity/identity.d.ts +2 -2
  44. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -0
  45. package/dist/{src → types/src}/packlets/identity/identity.test.d.ts +0 -0
  46. package/dist/types/src/packlets/identity/identity.test.d.ts.map +1 -0
  47. package/dist/{src → types/src}/packlets/identity/index.d.ts +0 -0
  48. package/dist/types/src/packlets/identity/index.d.ts.map +1 -0
  49. package/dist/{src → types/src}/packlets/invitations/encoder.d.ts +0 -0
  50. package/dist/types/src/packlets/invitations/encoder.d.ts.map +1 -0
  51. package/dist/{src → types/src}/packlets/invitations/encoder.test.d.ts +0 -0
  52. package/dist/types/src/packlets/invitations/encoder.test.d.ts.map +1 -0
  53. package/dist/{src → types/src}/packlets/invitations/halo-invitations-handler.d.ts +0 -0
  54. package/dist/types/src/packlets/invitations/halo-invitations-handler.d.ts.map +1 -0
  55. package/dist/{src → types/src}/packlets/invitations/halo-invitations-handler.test.d.ts +0 -0
  56. package/dist/types/src/packlets/invitations/halo-invitations-handler.test.d.ts.map +1 -0
  57. package/dist/{src → types/src}/packlets/invitations/halo-invitations-proxy.d.ts +0 -0
  58. package/dist/types/src/packlets/invitations/halo-invitations-proxy.d.ts.map +1 -0
  59. package/dist/{src → types/src}/packlets/invitations/halo-invitations-service.d.ts +0 -0
  60. package/dist/types/src/packlets/invitations/halo-invitations-service.d.ts.map +1 -0
  61. package/dist/{src → types/src}/packlets/invitations/halo-invitations-service.test.d.ts +0 -0
  62. package/dist/types/src/packlets/invitations/halo-invitations-service.test.d.ts.map +1 -0
  63. package/dist/{src → types/src}/packlets/invitations/index.d.ts +0 -0
  64. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -0
  65. package/dist/{src → types/src}/packlets/invitations/invitations-handler.d.ts +10 -10
  66. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -0
  67. package/dist/{src → types/src}/packlets/invitations/invitations-proxy.d.ts +0 -0
  68. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts.map +1 -0
  69. package/dist/{src → types/src}/packlets/invitations/invitations-service.d.ts +0 -0
  70. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -0
  71. package/dist/{src → types/src}/packlets/invitations/invitations.d.ts +0 -0
  72. package/dist/types/src/packlets/invitations/invitations.d.ts.map +1 -0
  73. package/dist/types/src/packlets/invitations/rpc-extension.d.ts +17 -0
  74. package/dist/types/src/packlets/invitations/rpc-extension.d.ts.map +1 -0
  75. package/dist/{src → types/src}/packlets/invitations/space-invitations-handler.d.ts +3 -1
  76. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -0
  77. package/dist/{src → types/src}/packlets/invitations/space-invitations-handler.test.d.ts +0 -0
  78. package/dist/types/src/packlets/invitations/space-invitations-handler.test.d.ts.map +1 -0
  79. package/dist/{src → types/src}/packlets/invitations/space-invitations-proxy.d.ts +0 -0
  80. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts.map +1 -0
  81. package/dist/{src → types/src}/packlets/invitations/space-invitations-service.d.ts +0 -0
  82. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts.map +1 -0
  83. package/dist/{src → types/src}/packlets/invitations/space-invitations-service.test.d.ts +0 -0
  84. package/dist/types/src/packlets/invitations/space-invitations-service.test.d.ts.map +1 -0
  85. package/dist/{src → types/src}/packlets/services/index.d.ts +0 -0
  86. package/dist/types/src/packlets/services/index.d.ts.map +1 -0
  87. package/dist/{src → types/src}/packlets/services/service-context.d.ts +0 -0
  88. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -0
  89. package/dist/{src → types/src}/packlets/services/service-definitions.d.ts +1 -1
  90. package/dist/types/src/packlets/services/service-definitions.d.ts.map +1 -0
  91. package/dist/{src → types/src}/packlets/services/service-host.d.ts +1 -1
  92. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -0
  93. package/dist/{src → types/src}/packlets/services/service-proxy.d.ts +0 -0
  94. package/dist/types/src/packlets/services/service-proxy.d.ts.map +1 -0
  95. package/dist/{src → types/src}/packlets/services/service-registry.d.ts +0 -0
  96. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -0
  97. package/dist/{src → types/src}/packlets/services/service-registry.test.d.ts +0 -0
  98. package/dist/types/src/packlets/services/service-registry.test.d.ts.map +1 -0
  99. package/dist/{src → types/src}/packlets/services/signer.d.ts +0 -0
  100. package/dist/types/src/packlets/services/signer.d.ts.map +1 -0
  101. package/dist/{src → types/src}/packlets/spaces/index.d.ts +0 -0
  102. package/dist/types/src/packlets/spaces/index.d.ts.map +1 -0
  103. package/dist/{src → types/src}/packlets/spaces/spaces-service.d.ts +0 -0
  104. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -0
  105. package/dist/{src → types/src}/packlets/storage/index.d.ts +0 -0
  106. package/dist/types/src/packlets/storage/index.d.ts.map +1 -0
  107. package/dist/{src → types/src}/packlets/storage/storage.d.ts +1 -1
  108. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -0
  109. package/dist/{src → types/src}/packlets/testing/index.d.ts +0 -0
  110. package/dist/types/src/packlets/testing/index.d.ts.map +1 -0
  111. package/dist/{src → types/src}/packlets/testing/test-builder.d.ts +0 -0
  112. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -0
  113. package/dist/{src → types/src}/packlets/vault/iframe-runtime.d.ts +1 -1
  114. package/dist/types/src/packlets/vault/iframe-runtime.d.ts.map +1 -0
  115. package/dist/{src → types/src}/packlets/vault/index.d.ts +0 -0
  116. package/dist/types/src/packlets/vault/index.d.ts.map +1 -0
  117. package/dist/{src → types/src}/packlets/vault/services.d.ts +2 -2
  118. package/dist/types/src/packlets/vault/services.d.ts.map +1 -0
  119. package/dist/{src → types/src}/packlets/vault/worker-runtime.d.ts +1 -1
  120. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -0
  121. package/dist/{src → types/src}/packlets/vault/worker-session.d.ts +1 -1
  122. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -0
  123. package/package.json +32 -30
  124. package/src/packlets/devtools/devtools.ts +2 -1
  125. package/src/packlets/devtools/keys.ts +19 -0
  126. package/src/packlets/identity/authenticator.test.ts +5 -8
  127. package/src/packlets/identity/identity-manager.test.ts +5 -5
  128. package/src/packlets/identity/identity-manager.ts +6 -4
  129. package/src/packlets/identity/identity.test.ts +4 -4
  130. package/src/packlets/identity/identity.ts +1 -1
  131. package/src/packlets/invitations/encoder.test.ts +3 -2
  132. package/src/packlets/invitations/halo-invitations-handler.test.ts +5 -5
  133. package/src/packlets/invitations/halo-invitations-handler.ts +232 -135
  134. package/src/packlets/invitations/halo-invitations-service.test.ts +4 -4
  135. package/src/packlets/invitations/invitations-handler.ts +9 -9
  136. package/src/packlets/invitations/invitations-proxy.ts +1 -1
  137. package/src/packlets/invitations/invitations-service.ts +1 -1
  138. package/src/packlets/invitations/invitations.ts +1 -1
  139. package/src/packlets/invitations/rpc-extension.ts +56 -0
  140. package/src/packlets/invitations/space-invitations-handler.test.ts +15 -9
  141. package/src/packlets/invitations/space-invitations-handler.ts +293 -152
  142. package/src/packlets/invitations/space-invitations-service.test.ts +5 -5
  143. package/src/packlets/invitations/space-invitations-service.ts +1 -1
  144. package/src/packlets/services/service-context.ts +6 -1
  145. package/src/packlets/services/service-registry.test.ts +4 -3
  146. package/src/packlets/vault/worker-session.ts +8 -3
  147. package/testing.d.ts +1 -1
  148. package/testing.js +1 -1
  149. package/dist/src/index.d.ts.map +0 -1
  150. package/dist/src/index.js +0 -27
  151. package/dist/src/index.js.map +0 -1
  152. package/dist/src/packlets/deprecated/index.d.ts.map +0 -1
  153. package/dist/src/packlets/deprecated/index.js +0 -24
  154. package/dist/src/packlets/deprecated/index.js.map +0 -1
  155. package/dist/src/packlets/deprecated/invitations.d.ts.map +0 -1
  156. package/dist/src/packlets/deprecated/invitations.js +0 -12
  157. package/dist/src/packlets/deprecated/invitations.js.map +0 -1
  158. package/dist/src/packlets/deprecated/profile.d.ts.map +0 -1
  159. package/dist/src/packlets/deprecated/profile.js +0 -60
  160. package/dist/src/packlets/deprecated/profile.js.map +0 -1
  161. package/dist/src/packlets/deprecated/space.d.ts.map +0 -1
  162. package/dist/src/packlets/deprecated/space.js +0 -209
  163. package/dist/src/packlets/deprecated/space.js.map +0 -1
  164. package/dist/src/packlets/deprecated/system.d.ts.map +0 -1
  165. package/dist/src/packlets/deprecated/system.js +0 -33
  166. package/dist/src/packlets/deprecated/system.js.map +0 -1
  167. package/dist/src/packlets/deprecated/tracing.d.ts.map +0 -1
  168. package/dist/src/packlets/deprecated/tracing.js +0 -22
  169. package/dist/src/packlets/deprecated/tracing.js.map +0 -1
  170. package/dist/src/packlets/devtools/devtools.d.ts.map +0 -1
  171. package/dist/src/packlets/devtools/devtools.js +0 -88
  172. package/dist/src/packlets/devtools/devtools.js.map +0 -1
  173. package/dist/src/packlets/devtools/feeds.d.ts.map +0 -1
  174. package/dist/src/packlets/devtools/feeds.js +0 -77
  175. package/dist/src/packlets/devtools/feeds.js.map +0 -1
  176. package/dist/src/packlets/devtools/index.d.ts.map +0 -1
  177. package/dist/src/packlets/devtools/index.js +0 -24
  178. package/dist/src/packlets/devtools/index.js.map +0 -1
  179. package/dist/src/packlets/devtools/network.d.ts.map +0 -1
  180. package/dist/src/packlets/devtools/network.js +0 -79
  181. package/dist/src/packlets/devtools/network.js.map +0 -1
  182. package/dist/src/packlets/devtools/spaces.d.ts.map +0 -1
  183. package/dist/src/packlets/devtools/spaces.js +0 -39
  184. package/dist/src/packlets/devtools/spaces.js.map +0 -1
  185. package/dist/src/packlets/identity/authenticator.d.ts.map +0 -1
  186. package/dist/src/packlets/identity/authenticator.js +0 -40
  187. package/dist/src/packlets/identity/authenticator.js.map +0 -1
  188. package/dist/src/packlets/identity/authenticator.test.d.ts.map +0 -1
  189. package/dist/src/packlets/identity/authenticator.test.js +0 -32
  190. package/dist/src/packlets/identity/authenticator.test.js.map +0 -1
  191. package/dist/src/packlets/identity/devices-service-impl.d.ts.map +0 -1
  192. package/dist/src/packlets/identity/devices-service-impl.js +0 -47
  193. package/dist/src/packlets/identity/devices-service-impl.js.map +0 -1
  194. package/dist/src/packlets/identity/identity-manager.d.ts.map +0 -1
  195. package/dist/src/packlets/identity/identity-manager.js +0 -156
  196. package/dist/src/packlets/identity/identity-manager.js.map +0 -1
  197. package/dist/src/packlets/identity/identity-manager.test.d.ts.map +0 -1
  198. package/dist/src/packlets/identity/identity-manager.test.js +0 -88
  199. package/dist/src/packlets/identity/identity-manager.test.js.map +0 -1
  200. package/dist/src/packlets/identity/identity.d.ts.map +0 -1
  201. package/dist/src/packlets/identity/identity.js +0 -133
  202. package/dist/src/packlets/identity/identity.js.map +0 -1
  203. package/dist/src/packlets/identity/identity.test.d.ts.map +0 -1
  204. package/dist/src/packlets/identity/identity.test.js +0 -257
  205. package/dist/src/packlets/identity/identity.test.js.map +0 -1
  206. package/dist/src/packlets/identity/index.d.ts.map +0 -1
  207. package/dist/src/packlets/identity/index.js +0 -23
  208. package/dist/src/packlets/identity/index.js.map +0 -1
  209. package/dist/src/packlets/invitations/encoder.d.ts.map +0 -1
  210. package/dist/src/packlets/invitations/encoder.js +0 -27
  211. package/dist/src/packlets/invitations/encoder.js.map +0 -1
  212. package/dist/src/packlets/invitations/encoder.test.d.ts.map +0 -1
  213. package/dist/src/packlets/invitations/encoder.test.js +0 -19
  214. package/dist/src/packlets/invitations/encoder.test.js.map +0 -1
  215. package/dist/src/packlets/invitations/halo-invitations-handler.d.ts.map +0 -1
  216. package/dist/src/packlets/invitations/halo-invitations-handler.js +0 -231
  217. package/dist/src/packlets/invitations/halo-invitations-handler.js.map +0 -1
  218. package/dist/src/packlets/invitations/halo-invitations-handler.test.d.ts.map +0 -1
  219. package/dist/src/packlets/invitations/halo-invitations-handler.test.js +0 -69
  220. package/dist/src/packlets/invitations/halo-invitations-handler.test.js.map +0 -1
  221. package/dist/src/packlets/invitations/halo-invitations-proxy.d.ts.map +0 -1
  222. package/dist/src/packlets/invitations/halo-invitations-proxy.js +0 -17
  223. package/dist/src/packlets/invitations/halo-invitations-proxy.js.map +0 -1
  224. package/dist/src/packlets/invitations/halo-invitations-service.d.ts.map +0 -1
  225. package/dist/src/packlets/invitations/halo-invitations-service.js +0 -20
  226. package/dist/src/packlets/invitations/halo-invitations-service.js.map +0 -1
  227. package/dist/src/packlets/invitations/halo-invitations-service.test.d.ts.map +0 -1
  228. package/dist/src/packlets/invitations/halo-invitations-service.test.js +0 -83
  229. package/dist/src/packlets/invitations/halo-invitations-service.test.js.map +0 -1
  230. package/dist/src/packlets/invitations/index.d.ts.map +0 -1
  231. package/dist/src/packlets/invitations/index.js +0 -31
  232. package/dist/src/packlets/invitations/index.js.map +0 -1
  233. package/dist/src/packlets/invitations/invitations-handler.d.ts.map +0 -1
  234. package/dist/src/packlets/invitations/invitations-handler.js +0 -18
  235. package/dist/src/packlets/invitations/invitations-handler.js.map +0 -1
  236. package/dist/src/packlets/invitations/invitations-proxy.d.ts.map +0 -1
  237. package/dist/src/packlets/invitations/invitations-proxy.js +0 -121
  238. package/dist/src/packlets/invitations/invitations-proxy.js.map +0 -1
  239. package/dist/src/packlets/invitations/invitations-service.d.ts.map +0 -1
  240. package/dist/src/packlets/invitations/invitations-service.js +0 -174
  241. package/dist/src/packlets/invitations/invitations-service.js.map +0 -1
  242. package/dist/src/packlets/invitations/invitations.d.ts.map +0 -1
  243. package/dist/src/packlets/invitations/invitations.js +0 -59
  244. package/dist/src/packlets/invitations/invitations.js.map +0 -1
  245. package/dist/src/packlets/invitations/space-invitations-handler.d.ts.map +0 -1
  246. package/dist/src/packlets/invitations/space-invitations-handler.js +0 -239
  247. package/dist/src/packlets/invitations/space-invitations-handler.js.map +0 -1
  248. package/dist/src/packlets/invitations/space-invitations-handler.test.d.ts.map +0 -1
  249. package/dist/src/packlets/invitations/space-invitations-handler.test.js +0 -131
  250. package/dist/src/packlets/invitations/space-invitations-handler.test.js.map +0 -1
  251. package/dist/src/packlets/invitations/space-invitations-proxy.d.ts.map +0 -1
  252. package/dist/src/packlets/invitations/space-invitations-proxy.js +0 -17
  253. package/dist/src/packlets/invitations/space-invitations-proxy.js.map +0 -1
  254. package/dist/src/packlets/invitations/space-invitations-service.d.ts.map +0 -1
  255. package/dist/src/packlets/invitations/space-invitations-service.js +0 -31
  256. package/dist/src/packlets/invitations/space-invitations-service.js.map +0 -1
  257. package/dist/src/packlets/invitations/space-invitations-service.test.d.ts.map +0 -1
  258. package/dist/src/packlets/invitations/space-invitations-service.test.js +0 -100
  259. package/dist/src/packlets/invitations/space-invitations-service.test.js.map +0 -1
  260. package/dist/src/packlets/services/index.d.ts.map +0 -1
  261. package/dist/src/packlets/services/index.js +0 -26
  262. package/dist/src/packlets/services/index.js.map +0 -1
  263. package/dist/src/packlets/services/service-context.d.ts.map +0 -1
  264. package/dist/src/packlets/services/service-context.js +0 -103
  265. package/dist/src/packlets/services/service-context.js.map +0 -1
  266. package/dist/src/packlets/services/service-definitions.d.ts.map +0 -1
  267. package/dist/src/packlets/services/service-definitions.js +0 -25
  268. package/dist/src/packlets/services/service-definitions.js.map +0 -1
  269. package/dist/src/packlets/services/service-host.d.ts.map +0 -1
  270. package/dist/src/packlets/services/service-host.js +0 -88
  271. package/dist/src/packlets/services/service-host.js.map +0 -1
  272. package/dist/src/packlets/services/service-proxy.d.ts.map +0 -1
  273. package/dist/src/packlets/services/service-proxy.js +0 -48
  274. package/dist/src/packlets/services/service-proxy.js.map +0 -1
  275. package/dist/src/packlets/services/service-registry.d.ts.map +0 -1
  276. package/dist/src/packlets/services/service-registry.js +0 -24
  277. package/dist/src/packlets/services/service-registry.js.map +0 -1
  278. package/dist/src/packlets/services/service-registry.test.d.ts.map +0 -1
  279. package/dist/src/packlets/services/service-registry.test.js +0 -75
  280. package/dist/src/packlets/services/service-registry.test.js.map +0 -1
  281. package/dist/src/packlets/services/signer.d.ts.map +0 -1
  282. package/dist/src/packlets/services/signer.js +0 -6
  283. package/dist/src/packlets/services/signer.js.map +0 -1
  284. package/dist/src/packlets/spaces/index.d.ts.map +0 -1
  285. package/dist/src/packlets/spaces/index.js +0 -21
  286. package/dist/src/packlets/spaces/index.js.map +0 -1
  287. package/dist/src/packlets/spaces/spaces-service.d.ts.map +0 -1
  288. package/dist/src/packlets/spaces/spaces-service.js +0 -22
  289. package/dist/src/packlets/spaces/spaces-service.js.map +0 -1
  290. package/dist/src/packlets/storage/index.d.ts.map +0 -1
  291. package/dist/src/packlets/storage/index.js +0 -21
  292. package/dist/src/packlets/storage/index.js.map +0 -1
  293. package/dist/src/packlets/storage/storage.d.ts.map +0 -1
  294. package/dist/src/packlets/storage/storage.js +0 -89
  295. package/dist/src/packlets/storage/storage.js.map +0 -1
  296. package/dist/src/packlets/testing/index.d.ts.map +0 -1
  297. package/dist/src/packlets/testing/index.js +0 -21
  298. package/dist/src/packlets/testing/index.js.map +0 -1
  299. package/dist/src/packlets/testing/test-builder.d.ts.map +0 -1
  300. package/dist/src/packlets/testing/test-builder.js +0 -66
  301. package/dist/src/packlets/testing/test-builder.js.map +0 -1
  302. package/dist/src/packlets/vault/iframe-runtime.d.ts.map +0 -1
  303. package/dist/src/packlets/vault/iframe-runtime.js +0 -46
  304. package/dist/src/packlets/vault/iframe-runtime.js.map +0 -1
  305. package/dist/src/packlets/vault/index.d.ts.map +0 -1
  306. package/dist/src/packlets/vault/index.js +0 -23
  307. package/dist/src/packlets/vault/index.js.map +0 -1
  308. package/dist/src/packlets/vault/services.d.ts.map +0 -1
  309. package/dist/src/packlets/vault/services.js +0 -15
  310. package/dist/src/packlets/vault/services.js.map +0 -1
  311. package/dist/src/packlets/vault/worker-runtime.d.ts.map +0 -1
  312. package/dist/src/packlets/vault/worker-runtime.js +0 -99
  313. package/dist/src/packlets/vault/worker-runtime.js.map +0 -1
  314. package/dist/src/packlets/vault/worker-session.d.ts.map +0 -1
  315. package/dist/src/packlets/vault/worker-session.js +0 -106
  316. package/dist/src/packlets/vault/worker-session.js.map +0 -1
@@ -0,0 +1,2747 @@
1
+ // packages/sdk/client-services/src/packlets/deprecated/space.ts
2
+ import assert from "@dxos/node-std/assert";
3
+ import { EventSubscriptions } from "@dxos/async";
4
+ import { Stream } from "@dxos/codec-protobuf";
5
+ import { todo } from "@dxos/debug";
6
+ import { log } from "@dxos/log";
7
+ import { humanize } from "@dxos/util";
8
+ var SpaceServiceImpl = class {
9
+ constructor(serviceContext) {
10
+ this.serviceContext = serviceContext;
11
+ this.inviteeInvitations = /* @__PURE__ */ new Map();
12
+ }
13
+ subscribeToSpace(request) {
14
+ return new Stream(({ next }) => {
15
+ next({
16
+ space: {
17
+ publicKey: request.spaceKey,
18
+ isOpen: true,
19
+ isActive: true,
20
+ members: []
21
+ }
22
+ });
23
+ });
24
+ }
25
+ subscribeSpaces() {
26
+ return new Stream(({ next }) => {
27
+ const subscriptions = new EventSubscriptions();
28
+ const onUpdate = () => {
29
+ const spaces = Array.from(this.serviceContext.spaceManager.spaces.values()).map((space) => ({
30
+ publicKey: space.key,
31
+ isOpen: true,
32
+ isActive: true,
33
+ members: Array.from(space.spaceState.members.values()).map((member) => {
34
+ var _a, _b;
35
+ return {
36
+ identityKey: member.key,
37
+ profile: {
38
+ identityKey: member.key,
39
+ displayName: (_b = (_a = member.assertion.profile) == null ? void 0 : _a.displayName) != null ? _b : humanize(member.key)
40
+ }
41
+ };
42
+ })
43
+ }));
44
+ log("update", {
45
+ spaces
46
+ }, {
47
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/deprecated/space.ts",
48
+ line: 114,
49
+ scope: this,
50
+ callSite: (f, a) => f(...a)
51
+ });
52
+ next({
53
+ spaces
54
+ });
55
+ };
56
+ setTimeout(async () => {
57
+ if (!this.serviceContext.spaceManager) {
58
+ next({
59
+ spaces: []
60
+ });
61
+ }
62
+ await this.serviceContext.initialized.wait();
63
+ subscriptions.add(this.serviceContext.spaceManager.updated.on(() => {
64
+ this.serviceContext.spaceManager.spaces.forEach((space) => {
65
+ subscriptions.add(space.stateUpdate.on(onUpdate));
66
+ });
67
+ onUpdate();
68
+ }));
69
+ this.serviceContext.spaceManager.spaces.forEach((space) => {
70
+ subscriptions.add(space.stateUpdate.on(onUpdate));
71
+ });
72
+ onUpdate();
73
+ });
74
+ return () => subscriptions.clear();
75
+ });
76
+ }
77
+ async getSpaceDetails(request) {
78
+ return todo();
79
+ }
80
+ async createSpace() {
81
+ await this.serviceContext.initialized.wait();
82
+ const space = await this.serviceContext.spaceManager.createSpace();
83
+ return {
84
+ publicKey: space.key,
85
+ isOpen: true,
86
+ isActive: true
87
+ };
88
+ }
89
+ async cloneSpace(snapshot) {
90
+ return todo();
91
+ }
92
+ async setSpaceState(request) {
93
+ return todo();
94
+ }
95
+ async authenticateInvitation(request) {
96
+ var _a;
97
+ assert(request.processId, "Process ID is missing.");
98
+ const invitation = this.inviteeInvitations.get(request.processId);
99
+ assert(invitation, "Invitation not found.");
100
+ assert(request.secret, "Secret not provided.");
101
+ invitation.secret = request.secret;
102
+ (_a = invitation.secretTrigger) == null ? void 0 : _a.call(invitation);
103
+ }
104
+ subscribeMembers(request) {
105
+ return todo();
106
+ }
107
+ async createSnapshot(request) {
108
+ return todo();
109
+ }
110
+ };
111
+
112
+ // packages/sdk/client-services/src/packlets/deprecated/profile.ts
113
+ import { Stream as Stream2 } from "@dxos/codec-protobuf";
114
+ import { todo as todo2 } from "@dxos/debug";
115
+ var ProfileServiceImpl = class {
116
+ constructor(context) {
117
+ this.context = context;
118
+ this.inviteeInvitations = /* @__PURE__ */ new Map();
119
+ }
120
+ subscribeProfile() {
121
+ return new Stream2(({ next }) => {
122
+ const emitNext = () => {
123
+ var _a;
124
+ return next({
125
+ profile: this.context.identityManager.identity ? {
126
+ identityKey: this.context.identityManager.identity.identityKey,
127
+ deviceKey: this.context.identityManager.identity.deviceKey,
128
+ displayName: (_a = this.context.identityManager.identity.profileDocument) == null ? void 0 : _a.displayName
129
+ } : void 0
130
+ });
131
+ };
132
+ emitNext();
133
+ return this.context.identityManager.stateUpdate.on(emitNext);
134
+ });
135
+ }
136
+ async createProfile(request) {
137
+ var _a;
138
+ await this.context.createIdentity({
139
+ displayName: request.displayName
140
+ });
141
+ return {
142
+ identityKey: this.context.identityManager.identity.identityKey,
143
+ deviceKey: this.context.identityManager.identity.deviceKey,
144
+ displayName: (_a = this.context.identityManager.identity.profileDocument) == null ? void 0 : _a.displayName
145
+ };
146
+ }
147
+ async recoverProfile(request) {
148
+ return todo2();
149
+ if (!request.seedPhrase) {
150
+ throw new Error("Recovery SeedPhrase not provided.");
151
+ }
152
+ }
153
+ };
154
+
155
+ // packages/sdk/client-services/src/packlets/deprecated/system.ts
156
+ var SystemServiceImpl = class {
157
+ constructor(_config, _serviceContext) {
158
+ this._config = _config;
159
+ this._serviceContext = _serviceContext;
160
+ }
161
+ async initSession() {
162
+ }
163
+ async getConfig(request) {
164
+ return this._config.values;
165
+ }
166
+ async getStatus(request) {
167
+ return {
168
+ message: `ok: ${Date.now()}`
169
+ };
170
+ }
171
+ async reset(request) {
172
+ await this._serviceContext.reset();
173
+ }
174
+ };
175
+
176
+ // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
177
+ var TracingServiceImpl = class {
178
+ constructor(_config) {
179
+ this._config = _config;
180
+ }
181
+ async setTracingOptions() {
182
+ throw new Error("Tracing not available.");
183
+ }
184
+ subscribeToRpcTrace() {
185
+ throw new Error("Tracing not available.");
186
+ }
187
+ };
188
+
189
+ // packages/sdk/client-services/src/packlets/devtools/devtools.ts
190
+ import { Event as AsyncEvent } from "@dxos/async";
191
+ import { Stream as Stream7 } from "@dxos/codec-protobuf";
192
+
193
+ // packages/sdk/client-services/src/packlets/devtools/feeds.ts
194
+ import { EventSubscriptions as EventSubscriptions2 } from "@dxos/async";
195
+ import { Stream as Stream3 } from "@dxos/codec-protobuf";
196
+ import { FeedIterator } from "@dxos/feed-store";
197
+ import { PublicKey } from "@dxos/keys";
198
+ import { ComplexMap } from "@dxos/util";
199
+ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => new Stream3(({ next }) => {
200
+ if ((feedKeys == null ? void 0 : feedKeys.length) === 0) {
201
+ return;
202
+ }
203
+ const feedMap = new ComplexMap(PublicKey.hash);
204
+ const subscriptions = new EventSubscriptions2();
205
+ const update = () => {
206
+ const feeds = feedStore.feeds;
207
+ feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
208
+ if (!feedMap.has(feed.key)) {
209
+ feedMap.set(feed.key, feed);
210
+ feed.on("close", update);
211
+ subscriptions.add(feed.off("close", update));
212
+ }
213
+ });
214
+ next({
215
+ feeds: Array.from(feedMap.values()).map((feed) => ({
216
+ feedKey: feed.key,
217
+ length: feed.properties.length
218
+ }))
219
+ });
220
+ };
221
+ subscriptions.add(feedStore.feedOpened.on(update));
222
+ update();
223
+ return () => {
224
+ subscriptions.clear();
225
+ };
226
+ });
227
+ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => new Stream3(({ next }) => {
228
+ if (!feedKey) {
229
+ return;
230
+ }
231
+ const subscriptions = new EventSubscriptions2();
232
+ const timeout = setTimeout(async () => {
233
+ const feed = feedStore.getFeed(feedKey);
234
+ if (!feed) {
235
+ return;
236
+ }
237
+ const update = async () => {
238
+ const iterator = new FeedIterator(feed);
239
+ await iterator.open();
240
+ const blocks = [];
241
+ for await (const block of iterator) {
242
+ blocks.push(block);
243
+ if (blocks.length >= feed.properties.length) {
244
+ break;
245
+ }
246
+ }
247
+ next({
248
+ blocks: blocks.slice(-maxBlocks)
249
+ });
250
+ await iterator.close();
251
+ };
252
+ feed.on("append", update);
253
+ subscriptions.add(() => feed.off("append", update));
254
+ feed.on("truncate", update);
255
+ subscriptions.add(() => feed.off("truncate", update));
256
+ await update();
257
+ });
258
+ return () => {
259
+ subscriptions.clear();
260
+ clearTimeout(timeout);
261
+ };
262
+ });
263
+
264
+ // packages/sdk/client-services/src/packlets/devtools/keys.ts
265
+ import { Stream as Stream4 } from "@dxos/codec-protobuf";
266
+ var subscribeToKeyringKeys = ({ keyring }) => new Stream4(({ next }) => {
267
+ const update = () => {
268
+ next({
269
+ keys: keyring.list()
270
+ });
271
+ };
272
+ const unsubscribe = keyring.keysUpdate.on(update);
273
+ update();
274
+ return unsubscribe;
275
+ });
276
+
277
+ // packages/sdk/client-services/src/packlets/devtools/network.ts
278
+ import { Stream as Stream5 } from "@dxos/codec-protobuf";
279
+ import { PublicKey as PublicKey2 } from "@dxos/keys";
280
+ var subscribeToNetworkStatus = ({ networkManager }) => new Stream5(({ next, close }) => {
281
+ const update = () => {
282
+ try {
283
+ const status = networkManager.signalManager.getStatus();
284
+ next({
285
+ servers: status
286
+ });
287
+ } catch (err) {
288
+ close(err);
289
+ }
290
+ };
291
+ networkManager.signalManager.statusChanged.on(update);
292
+ update();
293
+ });
294
+ var subscribeToSignalTrace = ({ networkManager }) => new Stream5(({ next }) => {
295
+ next({
296
+ events: []
297
+ });
298
+ const trace = [];
299
+ networkManager.signalManager.commandTrace.on((msg) => {
300
+ trace.push(msg);
301
+ next({
302
+ events: trace.map((msg2) => JSON.stringify(msg2))
303
+ });
304
+ });
305
+ });
306
+ var subscribeToNetworkTopics = ({ networkManager }) => new Stream5(({ next, close }) => {
307
+ const update = () => {
308
+ try {
309
+ const topics = networkManager.topics;
310
+ const labeledTopics = topics.map((topic) => {
311
+ var _a, _b;
312
+ return {
313
+ topic,
314
+ label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
315
+ };
316
+ });
317
+ next({
318
+ topics: labeledTopics
319
+ });
320
+ } catch (err) {
321
+ close(err);
322
+ }
323
+ };
324
+ networkManager.topicsUpdated.on(update);
325
+ update();
326
+ });
327
+ var subscribeToSwarmInfo = ({ networkManager }) => new Stream5(({ next }) => {
328
+ var _a;
329
+ const update = () => {
330
+ var _a2;
331
+ const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
332
+ if (info) {
333
+ next({
334
+ data: info
335
+ });
336
+ }
337
+ };
338
+ (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
339
+ update();
340
+ });
341
+ var getNetworkPeers = ({ networkManager }, request) => {
342
+ if (!request.topic) {
343
+ throw new Error("Expected a network topic");
344
+ }
345
+ const map = networkManager.getSwarmMap(PublicKey2.from(request.topic));
346
+ return {
347
+ peers: map == null ? void 0 : map.peers.map((peer) => ({
348
+ ...peer,
349
+ connections: peer.connections.map((connection) => connection.asUint8Array())
350
+ }))
351
+ };
352
+ };
353
+
354
+ // packages/sdk/client-services/src/packlets/devtools/spaces.ts
355
+ import { Stream as Stream6 } from "@dxos/codec-protobuf";
356
+ var subscribeToSpaces = (context, { spaceKeys = [] }) => new Stream6(({ next }) => {
357
+ let unsubscribe;
358
+ const update = async () => {
359
+ const spaces = [
360
+ ...context.spaceManager.spaces.values()
361
+ ];
362
+ const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
363
+ next({
364
+ spaces: filteredSpaces.map((space) => {
365
+ const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
366
+ return {
367
+ key: space.key,
368
+ isOpen: space.isOpen,
369
+ timeframe: spaceMetadata.latestTimeframe,
370
+ genesisFeed: space.genesisFeedKey,
371
+ controlFeed: space.controlFeedKey,
372
+ dataFeed: space.dataFeedKey
373
+ };
374
+ })
375
+ });
376
+ };
377
+ const timeout = setTimeout(async () => {
378
+ await context.initialized.wait();
379
+ unsubscribe = context.spaceManager.updated.on(() => update());
380
+ await update();
381
+ });
382
+ return () => {
383
+ unsubscribe == null ? void 0 : unsubscribe();
384
+ clearTimeout(timeout);
385
+ };
386
+ });
387
+
388
+ // packages/sdk/client-services/src/packlets/devtools/devtools.ts
389
+ var DevtoolsHostEvents = class {
390
+ constructor() {
391
+ this.ready = new AsyncEvent();
392
+ }
393
+ };
394
+ var DevtoolsServiceImpl = class {
395
+ constructor(params) {
396
+ this.params = params;
397
+ }
398
+ events(request) {
399
+ return new Stream7(({ next }) => {
400
+ this.params.events.ready.on(() => {
401
+ next({
402
+ ready: {}
403
+ });
404
+ });
405
+ });
406
+ }
407
+ getConfig(request) {
408
+ throw new Error();
409
+ }
410
+ resetStorage(request) {
411
+ throw new Error();
412
+ }
413
+ enableDebugLogging(request) {
414
+ throw new Error();
415
+ }
416
+ disableDebugLogging(request) {
417
+ throw new Error();
418
+ }
419
+ subscribeToKeyringKeys(request) {
420
+ return subscribeToKeyringKeys({
421
+ keyring: this.params.context.keyring
422
+ });
423
+ }
424
+ subscribeToCredentialMessages(request) {
425
+ throw new Error();
426
+ }
427
+ subscribeToSpaces(request) {
428
+ return subscribeToSpaces(this.params.context, request);
429
+ }
430
+ subscribeToItems(request) {
431
+ throw new Error();
432
+ }
433
+ subscribeToFeeds(request) {
434
+ return subscribeToFeeds({
435
+ feedStore: this.params.context.feedStore
436
+ }, request);
437
+ }
438
+ subscribeToFeedBlocks(request) {
439
+ return subscribeToFeedBlocks({
440
+ feedStore: this.params.context.feedStore
441
+ }, request);
442
+ }
443
+ getSpaceSnapshot(request) {
444
+ throw new Error();
445
+ }
446
+ saveSpaceSnapshot(request) {
447
+ throw new Error();
448
+ }
449
+ clearSnapshots(request) {
450
+ throw new Error();
451
+ }
452
+ getNetworkPeers(request) {
453
+ throw new Error();
454
+ }
455
+ subscribeToNetworkTopics(request) {
456
+ throw new Error();
457
+ }
458
+ subscribeToSignalStatus(request) {
459
+ return subscribeToNetworkStatus({
460
+ networkManager: this.params.context.networkManager
461
+ });
462
+ }
463
+ subscribeToSignalTrace() {
464
+ return subscribeToSignalTrace({
465
+ networkManager: this.params.context.networkManager
466
+ });
467
+ }
468
+ subscribeToSwarmInfo() {
469
+ return subscribeToSwarmInfo({
470
+ networkManager: this.params.context.networkManager
471
+ });
472
+ }
473
+ };
474
+
475
+ // packages/sdk/client-services/src/packlets/identity/authenticator.ts
476
+ import { verifyCredential } from "@dxos/credentials";
477
+ import { log as log2 } from "@dxos/log";
478
+ import { schema } from "@dxos/protocols";
479
+ var createHaloAuthProvider = (signer) => async (nonce) => {
480
+ const credential = await signer.createCredential({
481
+ assertion: {
482
+ "@type": "dxos.halo.credentials.Auth"
483
+ },
484
+ subject: signer.getIssuer(),
485
+ nonce
486
+ });
487
+ return schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
488
+ };
489
+ var createHaloAuthVerifier = (getDeviceSet) => async (nonce, auth) => {
490
+ const credential = schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
491
+ const deviceSet = getDeviceSet();
492
+ const result = await verifyCredential(credential);
493
+ if (result.kind === "fail") {
494
+ log2("Invalid credential", {
495
+ result
496
+ }, {
497
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts",
498
+ line: 34,
499
+ scope: void 0,
500
+ callSite: (f, a) => f(...a)
501
+ });
502
+ return false;
503
+ }
504
+ if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
505
+ log2("Invalid nonce", {
506
+ nonce,
507
+ credential
508
+ }, {
509
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts",
510
+ line: 39,
511
+ scope: void 0,
512
+ callSite: (f, a) => f(...a)
513
+ });
514
+ return false;
515
+ }
516
+ if (!deviceSet.has(credential.issuer)) {
517
+ log2("Device not in allowed set", {}, {
518
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts",
519
+ line: 44,
520
+ scope: void 0,
521
+ callSite: (f, a) => f(...a)
522
+ });
523
+ return false;
524
+ }
525
+ return true;
526
+ };
527
+
528
+ // packages/sdk/client-services/src/packlets/identity/identity.ts
529
+ import assert2 from "@dxos/node-std/assert";
530
+ import { Event } from "@dxos/async";
531
+ import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSignerWithChain, ProfileStateMachine } from "@dxos/credentials";
532
+ import { failUndefined } from "@dxos/debug";
533
+ import { writeMessages } from "@dxos/feed-store";
534
+ import { log as log3 } from "@dxos/log";
535
+ import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
536
+ var Identity = class {
537
+ constructor({ space, signer, identityKey, deviceKey }) {
538
+ this.stateUpdate = new Event();
539
+ this._space = space;
540
+ this._signer = signer;
541
+ this.identityKey = identityKey;
542
+ this.deviceKey = deviceKey;
543
+ this._deviceStateMachine = new DeviceStateMachine(this.identityKey, this.deviceKey);
544
+ this._profileStateMachine = new ProfileStateMachine(this.identityKey);
545
+ this._space.onCredentialProcessed.set(async (credential) => {
546
+ await this._deviceStateMachine.process(credential);
547
+ await this._profileStateMachine.process(credential);
548
+ this.stateUpdate.emit();
549
+ });
550
+ }
551
+ get authorizedDeviceKeys() {
552
+ return this._deviceStateMachine.authorizedDeviceKeys;
553
+ }
554
+ async open() {
555
+ await this._space.open();
556
+ }
557
+ async close() {
558
+ await this._space.close();
559
+ }
560
+ async ready() {
561
+ await this._deviceStateMachine.deviceChainReady.wait();
562
+ }
563
+ get profileDocument() {
564
+ return this._profileStateMachine.profile;
565
+ }
566
+ get controlPipeline() {
567
+ return this._space.controlPipeline;
568
+ }
569
+ get haloSpaceKey() {
570
+ return this._space.key;
571
+ }
572
+ get haloGenesisFeedKey() {
573
+ return this._space.genesisFeedKey;
574
+ }
575
+ get haloDatabase() {
576
+ var _a;
577
+ return (_a = this._space.database) != null ? _a : failUndefined();
578
+ }
579
+ getAdmissionCredentials() {
580
+ return {
581
+ deviceKey: this.deviceKey,
582
+ controlFeedKey: this._space.controlFeedKey,
583
+ dataFeedKey: this._space.dataFeedKey
584
+ };
585
+ }
586
+ getIdentityCredentialSigner() {
587
+ assert2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
588
+ return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
589
+ }
590
+ getDeviceCredentialSigner() {
591
+ return createCredentialSignerWithKey(this._signer, this.deviceKey);
592
+ }
593
+ async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
594
+ log3("Admitting device:", {
595
+ identityKey: this.identityKey,
596
+ hostDevice: this.deviceKey,
597
+ deviceKey,
598
+ controlFeedKey,
599
+ dataFeedKey
600
+ }, {
601
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts",
602
+ line: 137,
603
+ scope: this,
604
+ callSite: (f, a) => f(...a)
605
+ });
606
+ const signer = this.getIdentityCredentialSigner();
607
+ await writeMessages(this.controlPipeline.writer, [
608
+ await signer.createCredential({
609
+ subject: deviceKey,
610
+ assertion: {
611
+ "@type": "dxos.halo.credentials.AuthorizedDevice",
612
+ identityKey: this.identityKey,
613
+ deviceKey
614
+ }
615
+ }),
616
+ await signer.createCredential({
617
+ subject: controlFeedKey,
618
+ assertion: {
619
+ "@type": "dxos.halo.credentials.AdmittedFeed",
620
+ spaceKey: this.haloSpaceKey,
621
+ deviceKey,
622
+ identityKey: this.identityKey,
623
+ designation: AdmittedFeed.Designation.CONTROL
624
+ }
625
+ }),
626
+ await signer.createCredential({
627
+ subject: dataFeedKey,
628
+ assertion: {
629
+ "@type": "dxos.halo.credentials.AdmittedFeed",
630
+ spaceKey: this.haloSpaceKey,
631
+ deviceKey,
632
+ identityKey: this.identityKey,
633
+ designation: AdmittedFeed.Designation.DATA
634
+ }
635
+ })
636
+ ].map((credential) => ({
637
+ "@type": "dxos.echo.feed.CredentialsMessage",
638
+ credential
639
+ })));
640
+ }
641
+ };
642
+
643
+ // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
644
+ import assert3 from "@dxos/node-std/assert";
645
+ import { Event as Event2 } from "@dxos/async";
646
+ import { CredentialGenerator } from "@dxos/credentials";
647
+ import { MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, Space, Database, SpaceProtocol } from "@dxos/echo-db";
648
+ import { log as log4 } from "@dxos/log";
649
+ import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
650
+ var IdentityManager = class {
651
+ constructor(_metadataStore, _feedStore, _keyring, _networkManager, _modelFactory) {
652
+ this._metadataStore = _metadataStore;
653
+ this._feedStore = _feedStore;
654
+ this._keyring = _keyring;
655
+ this._networkManager = _networkManager;
656
+ this._modelFactory = _modelFactory;
657
+ this.stateUpdate = new Event2();
658
+ }
659
+ get identity() {
660
+ return this._identity;
661
+ }
662
+ async open() {
663
+ await this._metadataStore.load();
664
+ const identityRecord = this._metadataStore.getIdentityRecord();
665
+ if (identityRecord) {
666
+ this._identity = await this._constructIdentity(identityRecord);
667
+ await this._identity.open();
668
+ await this._identity.ready();
669
+ this.stateUpdate.emit();
670
+ }
671
+ }
672
+ async close() {
673
+ var _a;
674
+ await ((_a = this._identity) == null ? void 0 : _a.close());
675
+ }
676
+ async createIdentity({ displayName } = {}) {
677
+ assert3(!this._identity, "Identity already exists.");
678
+ log4("creating identity...", {}, {
679
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts",
680
+ line: 83,
681
+ scope: this,
682
+ callSite: (f, a) => f(...a)
683
+ });
684
+ const controlFeedKey = await this._keyring.createKey();
685
+ const identityRecord = {
686
+ identityKey: await this._keyring.createKey(),
687
+ deviceKey: await this._keyring.createKey(),
688
+ haloSpace: {
689
+ spaceKey: await this._keyring.createKey(),
690
+ genesisFeedKey: controlFeedKey,
691
+ writeControlFeedKey: controlFeedKey,
692
+ writeDataFeedKey: await this._keyring.createKey()
693
+ }
694
+ };
695
+ const identity = await this._constructIdentity(identityRecord);
696
+ await identity.open();
697
+ {
698
+ const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
699
+ const credentials = [
700
+ ...await generator.createSpaceGenesis(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.genesisFeedKey),
701
+ await generator.createFeedAdmission(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.writeDataFeedKey, AdmittedFeed2.Designation.DATA)
702
+ ];
703
+ if (displayName) {
704
+ credentials.push(await generator.createProfileCredential({
705
+ displayName
706
+ }));
707
+ }
708
+ credentials.push(await generator.createDeviceAuthorization(identityRecord.deviceKey));
709
+ for (const credential of credentials) {
710
+ await identity.controlPipeline.writer.write({
711
+ "@type": "dxos.echo.feed.CredentialsMessage",
712
+ credential
713
+ });
714
+ }
715
+ }
716
+ await this._metadataStore.setIdentityRecord(identityRecord);
717
+ this._identity = identity;
718
+ await this._identity.ready();
719
+ this.stateUpdate.emit();
720
+ log4("created identity", {
721
+ identityKey: identity.identityKey,
722
+ deviceKey: identity.deviceKey
723
+ }, {
724
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts",
725
+ line: 142,
726
+ scope: this,
727
+ callSite: (f, a) => f(...a)
728
+ });
729
+ return identity;
730
+ }
731
+ async acceptIdentity(params) {
732
+ log4("accepting identity", {
733
+ params
734
+ }, {
735
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts",
736
+ line: 150,
737
+ scope: this,
738
+ callSite: (f, a) => f(...a)
739
+ });
740
+ assert3(!this._identity, "Identity already exists.");
741
+ const identityRecord = {
742
+ identityKey: params.identityKey,
743
+ deviceKey: await this._keyring.createKey(),
744
+ haloSpace: {
745
+ spaceKey: params.haloSpaceKey,
746
+ genesisFeedKey: params.haloGenesisFeedKey,
747
+ writeControlFeedKey: await this._keyring.createKey(),
748
+ writeDataFeedKey: await this._keyring.createKey()
749
+ }
750
+ };
751
+ const identity = await this._constructIdentity(identityRecord);
752
+ await identity.open();
753
+ this._identity = identity;
754
+ await this._metadataStore.setIdentityRecord(identityRecord);
755
+ this.stateUpdate.emit();
756
+ return identity;
757
+ }
758
+ async _constructIdentity(identityRecord) {
759
+ assert3(!this._identity);
760
+ log4("constructing identity", {
761
+ identityRecord
762
+ }, {
763
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts",
764
+ line: 174,
765
+ scope: this,
766
+ callSite: (f, a) => f(...a)
767
+ });
768
+ const space = await this._constructSpace({
769
+ spaceRecord: identityRecord.haloSpace,
770
+ swarmIdentity: {
771
+ peerKey: identityRecord.deviceKey,
772
+ credentialProvider: MOCK_AUTH_PROVIDER,
773
+ credentialAuthenticator: MOCK_AUTH_VERIFIER
774
+ }
775
+ });
776
+ log4("done", {
777
+ identityKey: identityRecord.identityKey
778
+ }, {
779
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts",
780
+ line: 185,
781
+ scope: this,
782
+ callSite: (f, a) => f(...a)
783
+ });
784
+ return new Identity({
785
+ space,
786
+ signer: this._keyring,
787
+ identityKey: identityRecord.identityKey,
788
+ deviceKey: identityRecord.deviceKey
789
+ });
790
+ }
791
+ async _constructSpace({ spaceRecord, swarmIdentity }) {
792
+ const controlFeed = await this._feedStore.openFeed(spaceRecord.writeControlFeedKey, {
793
+ writable: true
794
+ });
795
+ const dataFeed = await this._feedStore.openFeed(spaceRecord.writeDataFeedKey, {
796
+ writable: true
797
+ });
798
+ const genesisFeed = await this._feedStore.openFeed(spaceRecord.genesisFeedKey);
799
+ const protocol = new SpaceProtocol({
800
+ topic: spaceRecord.spaceKey,
801
+ identity: swarmIdentity,
802
+ networkManager: this._networkManager
803
+ });
804
+ return new Space({
805
+ spaceKey: spaceRecord.spaceKey,
806
+ protocol,
807
+ genesisFeed,
808
+ controlFeed,
809
+ dataFeed,
810
+ feedProvider: (feedKey) => this._feedStore.openFeed(feedKey),
811
+ databaseFactory: async ({ databaseBackend }) => new Database(this._modelFactory, databaseBackend, swarmIdentity.peerKey)
812
+ });
813
+ }
814
+ };
815
+
816
+ // packages/sdk/client-services/src/packlets/invitations/encoder.ts
817
+ import base from "base-x";
818
+ import { schema as schema2 } from "@dxos/protocols";
819
+ var base62 = base("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
820
+ var codec = schema2.getCodecForType("dxos.client.services.Invitation");
821
+ var InvitationEncoder = class {
822
+ static decode(text) {
823
+ return codec.decode(base62.decode(text));
824
+ }
825
+ static encode(invitation) {
826
+ return base62.encode(codec.encode(invitation));
827
+ }
828
+ };
829
+
830
+ // packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts
831
+ import assert5 from "@dxos/node-std/assert";
832
+ import { scheduleTask, sleep, Trigger } from "@dxos/async";
833
+ import { Context } from "@dxos/context";
834
+ import { generatePasscode } from "@dxos/credentials";
835
+ import { failUndefined as failUndefined2 } from "@dxos/debug";
836
+ import { PublicKey as PublicKey3 } from "@dxos/keys";
837
+ import { log as log5 } from "@dxos/log";
838
+ import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
839
+ import { schema as schema3 } from "@dxos/protocols";
840
+ import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
841
+ import { AuthenticationResponse } from "@dxos/protocols/proto/dxos/halo/invitations";
842
+
843
+ // packages/sdk/client-services/src/packlets/invitations/invitations.ts
844
+ import assert4 from "@dxos/node-std/assert";
845
+ import { CancellableObservableProvider } from "@dxos/async";
846
+ import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
847
+ var AUTHENTICATION_CODE_LENGTH = 6;
848
+ var INVITATION_TIMEOUT = 3 * 6e4;
849
+ var ON_CLOSE_DELAY = 500;
850
+ var InvitationObservableProvider = class extends CancellableObservableProvider {
851
+ get invitation() {
852
+ return this._invitation;
853
+ }
854
+ setInvitation(invitation) {
855
+ this._invitation = invitation;
856
+ }
857
+ };
858
+ var AuthenticatingInvitationProvider = class extends InvitationObservableProvider {
859
+ constructor(_actions) {
860
+ super(() => this._actions.onCancel());
861
+ this._actions = _actions;
862
+ }
863
+ async authenticate(authenticationCode) {
864
+ return this._actions.onAuthenticate(authenticationCode);
865
+ }
866
+ };
867
+ var wrapObservable = async (observable) => {
868
+ return new Promise((resolve, reject) => {
869
+ const unsubscribe = observable.subscribe({
870
+ onSuccess: (invitation) => {
871
+ assert4(invitation.state === Invitation.State.SUCCESS);
872
+ unsubscribe();
873
+ resolve(invitation);
874
+ },
875
+ onError: (err) => {
876
+ unsubscribe();
877
+ reject(err);
878
+ }
879
+ });
880
+ });
881
+ };
882
+
883
+ // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
884
+ var AbstractInvitationsHandler = class {
885
+ constructor(_networkManager) {
886
+ this._networkManager = _networkManager;
887
+ }
888
+ };
889
+
890
+ // packages/sdk/client-services/src/packlets/invitations/rpc-extension.ts
891
+ import { createProtoRpcPeer } from "@dxos/rpc";
892
+ var RpcExtension = class {
893
+ constructor(_params) {
894
+ this._params = _params;
895
+ }
896
+ get initiator() {
897
+ return this._extensionContext.initiator;
898
+ }
899
+ get localPeerId() {
900
+ return this._extensionContext.localPeerId;
901
+ }
902
+ get remotePeerId() {
903
+ return this._extensionContext.remotePeerId;
904
+ }
905
+ get rpc() {
906
+ return this._rpc.rpc;
907
+ }
908
+ async onOpen(context) {
909
+ this._extensionContext = context;
910
+ const handlers = await this.getHandlers();
911
+ const port = context.createPort("rpc", {
912
+ contentType: 'application/x-protobuf; messageType="dxos.rpc.Message"'
913
+ });
914
+ this._rpc = createProtoRpcPeer({
915
+ ...this._params,
916
+ handlers,
917
+ port
918
+ });
919
+ await this._rpc.open();
920
+ }
921
+ async onClose(err) {
922
+ await this._rpc.close();
923
+ }
924
+ close() {
925
+ this._extensionContext.close();
926
+ }
927
+ };
928
+
929
+ // packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts
930
+ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
931
+ constructor(networkManager, _identityManager) {
932
+ super(networkManager);
933
+ this._identityManager = _identityManager;
934
+ }
935
+ createInvitation(context, options) {
936
+ var _a;
937
+ const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
938
+ assert5(type !== Invitation2.Type.OFFLINE);
939
+ const identity = (_a = this._identityManager.identity) != null ? _a : failUndefined2();
940
+ const invitation = {
941
+ type,
942
+ invitationId: PublicKey3.random().toHex(),
943
+ swarmKey: swarmKey != null ? swarmKey : PublicKey3.random(),
944
+ authenticationCode: generatePasscode(AUTHENTICATION_CODE_LENGTH)
945
+ };
946
+ const ctx = new Context({
947
+ onError: (err) => {
948
+ void ctx.dispose();
949
+ observable.callback.onError(err);
950
+ }
951
+ });
952
+ const observable = new InvitationObservableProvider(async () => {
953
+ await ctx.dispose();
954
+ });
955
+ let authenticationCode;
956
+ const complete = new Trigger();
957
+ const createExtension = () => {
958
+ const hostInvitationExtension = new HostHaloInvitationExtension({
959
+ requestAdmission: async () => {
960
+ var _a2, _b;
961
+ log5("responding with admission offer", {
962
+ host: identity.deviceKey
963
+ }, {
964
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
965
+ line: 85,
966
+ scope: this,
967
+ callSite: (f, a) => f(...a)
968
+ });
969
+ (_b = (_a2 = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a2, invitation);
970
+ return {
971
+ identityKey: identity.identityKey,
972
+ haloSpaceKey: identity.haloSpaceKey,
973
+ genesisFeedKey: identity.haloGenesisFeedKey
974
+ };
975
+ },
976
+ authenticate: async ({ authenticationCode: code }) => {
977
+ log5("received authentication request", {
978
+ authenticationCode: code
979
+ }, {
980
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
981
+ line: 99,
982
+ scope: this,
983
+ callSite: (f, a) => f(...a)
984
+ });
985
+ authenticationCode = code;
986
+ return {
987
+ status: AuthenticationResponse.Status.OK
988
+ };
989
+ },
990
+ presentAdmissionCredentials: async (credentials) => {
991
+ try {
992
+ if (invitation.type !== Invitation2.Type.INTERACTIVE_TESTING) {
993
+ if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
994
+ throw new Error(`invalid authentication code: ${authenticationCode}`);
995
+ }
996
+ }
997
+ log5("writing guest credentials", {
998
+ host: identity.deviceKey,
999
+ guest: credentials.deviceKey
1000
+ }, {
1001
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1002
+ line: 114,
1003
+ scope: this,
1004
+ callSite: (f, a) => f(...a)
1005
+ });
1006
+ await identity.admitDevice(credentials);
1007
+ complete.wake(credentials.deviceKey);
1008
+ } catch (err) {
1009
+ observable.callback.onError(err);
1010
+ throw err;
1011
+ }
1012
+ },
1013
+ onOpen: () => {
1014
+ scheduleTask(ctx, async () => {
1015
+ var _a2, _b;
1016
+ try {
1017
+ log5("connected", {
1018
+ host: identity.deviceKey
1019
+ }, {
1020
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1021
+ line: 130,
1022
+ scope: this,
1023
+ callSite: (f, a) => f(...a)
1024
+ });
1025
+ (_b = (_a2 = observable.callback).onConnected) == null ? void 0 : _b.call(_a2, invitation);
1026
+ const deviceKey = await complete.wait({
1027
+ timeout
1028
+ });
1029
+ log5("admitted guest", {
1030
+ host: identity.deviceKey,
1031
+ guest: deviceKey
1032
+ }, {
1033
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1034
+ line: 133,
1035
+ scope: this,
1036
+ callSite: (f, a) => f(...a)
1037
+ });
1038
+ observable.callback.onSuccess(invitation);
1039
+ } catch (err) {
1040
+ if (!observable.cancelled) {
1041
+ log5.error("failed", err, {
1042
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1043
+ line: 137,
1044
+ scope: this,
1045
+ callSite: (f, a) => f(...a)
1046
+ });
1047
+ observable.callback.onError(err);
1048
+ }
1049
+ } finally {
1050
+ await sleep(ON_CLOSE_DELAY);
1051
+ await ctx.dispose();
1052
+ }
1053
+ });
1054
+ }
1055
+ });
1056
+ return hostInvitationExtension;
1057
+ };
1058
+ scheduleTask(ctx, async () => {
1059
+ var _a2, _b;
1060
+ const topic = invitation.swarmKey;
1061
+ const swarmConnection = await this._networkManager.joinSwarm({
1062
+ topic,
1063
+ peerId: topic,
1064
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1065
+ teleport.addExtension("dxos.halo.invitations", createExtension());
1066
+ }),
1067
+ topology: new StarTopology(topic)
1068
+ });
1069
+ ctx.onDispose(() => swarmConnection.close());
1070
+ (_b = (_a2 = observable.callback).onConnecting) == null ? void 0 : _b.call(_a2, invitation);
1071
+ });
1072
+ return observable;
1073
+ }
1074
+ acceptInvitation(invitation, options) {
1075
+ const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1076
+ const ctx = new Context({
1077
+ onError: (err) => {
1078
+ void ctx.dispose();
1079
+ observable.callback.onError(err);
1080
+ }
1081
+ });
1082
+ const authenticated = new Trigger();
1083
+ const observable = new AuthenticatingInvitationProvider({
1084
+ onCancel: async () => {
1085
+ await ctx.dispose();
1086
+ },
1087
+ onAuthenticate: async (code) => {
1088
+ authenticated.wake(code);
1089
+ }
1090
+ });
1091
+ let connectionCount = 0;
1092
+ const complete = new Trigger();
1093
+ const createExtension = () => {
1094
+ const extension = new GuestHaloInvitationExtension({
1095
+ onOpen: () => {
1096
+ scheduleTask(ctx, async () => {
1097
+ var _a, _b, _c, _d;
1098
+ try {
1099
+ if (++connectionCount > 1) {
1100
+ throw new Error(`multiple connections detected: ${connectionCount}`);
1101
+ }
1102
+ log5("connected", {}, {
1103
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1104
+ line: 210,
1105
+ scope: this,
1106
+ callSite: (f, a) => f(...a)
1107
+ });
1108
+ (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1109
+ log5("sending admission request", {}, {
1110
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1111
+ line: 214,
1112
+ scope: this,
1113
+ callSite: (f, a) => f(...a)
1114
+ });
1115
+ const { identityKey, haloSpaceKey, genesisFeedKey } = await extension.rpc.HaloHostService.requestAdmission();
1116
+ if (invitation.type === void 0 || invitation.type === Invitation2.Type.INTERACTIVE) {
1117
+ log5("guest waiting for authentication code...", {}, {
1118
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1119
+ line: 221,
1120
+ scope: this,
1121
+ callSite: (f, a) => f(...a)
1122
+ });
1123
+ (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1124
+ const authenticationCode = await authenticated.wait({
1125
+ timeout
1126
+ });
1127
+ log5("sending authentication request", {}, {
1128
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1129
+ line: 224,
1130
+ scope: this,
1131
+ callSite: (f, a) => f(...a)
1132
+ });
1133
+ await extension.rpc.HaloHostService.authenticate({
1134
+ authenticationCode
1135
+ });
1136
+ }
1137
+ const identity = await this._identityManager.acceptIdentity({
1138
+ identityKey,
1139
+ haloSpaceKey,
1140
+ haloGenesisFeedKey: genesisFeedKey
1141
+ });
1142
+ log5("presenting admission credentials", {
1143
+ guest: identity.deviceKey,
1144
+ identityKey
1145
+ }, {
1146
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1147
+ line: 237,
1148
+ scope: this,
1149
+ callSite: (f, a) => f(...a)
1150
+ });
1151
+ await extension.rpc.HaloHostService.presentAdmissionCredentials(identity.getAdmissionCredentials());
1152
+ log5("admitted by host", {
1153
+ guest: identity.deviceKey,
1154
+ identityKey
1155
+ }, {
1156
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1157
+ line: 241,
1158
+ scope: this,
1159
+ callSite: (f, a) => f(...a)
1160
+ });
1161
+ complete.wake(identityKey);
1162
+ } catch (err) {
1163
+ if (!observable.cancelled) {
1164
+ log5.warn("auth failed", err, {
1165
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts",
1166
+ line: 245,
1167
+ scope: this,
1168
+ callSite: (f, a) => f(...a)
1169
+ });
1170
+ observable.callback.onError(err);
1171
+ }
1172
+ } finally {
1173
+ await ctx.dispose();
1174
+ }
1175
+ });
1176
+ }
1177
+ });
1178
+ return extension;
1179
+ };
1180
+ scheduleTask(ctx, async () => {
1181
+ var _a, _b;
1182
+ assert5(invitation.swarmKey);
1183
+ const topic = invitation.swarmKey;
1184
+ const swarmConnection = await this._networkManager.joinSwarm({
1185
+ topic,
1186
+ peerId: PublicKey3.random(),
1187
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1188
+ teleport.addExtension("dxos.halo.invitations", createExtension());
1189
+ }),
1190
+ topology: new StarTopology(topic)
1191
+ });
1192
+ ctx.onDispose(() => swarmConnection.close());
1193
+ (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1194
+ invitation.identityKey = await complete.wait();
1195
+ observable.callback.onSuccess(invitation);
1196
+ await ctx.dispose();
1197
+ });
1198
+ return observable;
1199
+ }
1200
+ };
1201
+ var HostHaloInvitationExtension = class extends RpcExtension {
1202
+ constructor(_callbacks) {
1203
+ super({
1204
+ exposed: {
1205
+ HaloHostService: schema3.getService("dxos.halo.invitations.HaloHostService")
1206
+ }
1207
+ });
1208
+ this._callbacks = _callbacks;
1209
+ }
1210
+ async getHandlers() {
1211
+ return {
1212
+ HaloHostService: {
1213
+ requestAdmission: async () => {
1214
+ return this._callbacks.requestAdmission();
1215
+ },
1216
+ authenticate: async (credentials) => {
1217
+ return this._callbacks.authenticate(credentials);
1218
+ },
1219
+ presentAdmissionCredentials: async (credentials) => {
1220
+ return this._callbacks.presentAdmissionCredentials(credentials);
1221
+ }
1222
+ }
1223
+ };
1224
+ }
1225
+ async onOpen(context) {
1226
+ await super.onOpen(context);
1227
+ this._callbacks.onOpen();
1228
+ }
1229
+ };
1230
+ var GuestHaloInvitationExtension = class extends RpcExtension {
1231
+ constructor(_callbacks) {
1232
+ super({
1233
+ requested: {
1234
+ HaloHostService: schema3.getService("dxos.halo.invitations.HaloHostService")
1235
+ }
1236
+ });
1237
+ this._callbacks = _callbacks;
1238
+ }
1239
+ async getHandlers() {
1240
+ return {};
1241
+ }
1242
+ async onOpen(context) {
1243
+ await super.onOpen(context);
1244
+ this._callbacks.onOpen();
1245
+ }
1246
+ };
1247
+
1248
+ // packages/sdk/client-services/src/packlets/invitations/invitations-proxy.ts
1249
+ import assert6 from "@dxos/node-std/assert";
1250
+ import { observableError } from "@dxos/async";
1251
+ import { log as log6 } from "@dxos/log";
1252
+ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1253
+ var AbstractInvitationsProxy = class {
1254
+ constructor(_invitationsService) {
1255
+ this._invitationsService = _invitationsService;
1256
+ }
1257
+ createInvitation(context, options) {
1258
+ let invitationId;
1259
+ const observable = new InvitationObservableProvider(async () => {
1260
+ if (invitationId) {
1261
+ await this._invitationsService.cancelInvitation({
1262
+ invitationId
1263
+ });
1264
+ }
1265
+ });
1266
+ const invitation = {
1267
+ ...this.getInvitationOptions(context),
1268
+ ...options
1269
+ };
1270
+ const stream = this._invitationsService.createInvitation(invitation);
1271
+ stream.subscribe((invitation2) => {
1272
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1273
+ observable.setInvitation(invitation2);
1274
+ switch (invitation2.state) {
1275
+ case Invitation3.State.CONNECTING: {
1276
+ assert6(invitation2.invitationId);
1277
+ invitationId = invitation2.invitationId;
1278
+ (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation2);
1279
+ break;
1280
+ }
1281
+ case Invitation3.State.CONNECTED: {
1282
+ (_d = (_c = observable.callback).onConnected) == null ? void 0 : _d.call(_c, invitation2);
1283
+ break;
1284
+ }
1285
+ case Invitation3.State.AUTHENTICATING: {
1286
+ (_f = (_e = observable.callback).onAuthenticating) == null ? void 0 : _f.call(_e, invitation2);
1287
+ break;
1288
+ }
1289
+ case Invitation3.State.SUCCESS: {
1290
+ (_h = (_g = observable.callback).onSuccess) == null ? void 0 : _h.call(_g, invitation2);
1291
+ break;
1292
+ }
1293
+ case Invitation3.State.CANCELLED: {
1294
+ (_j = (_i = observable.callback).onCancelled) == null ? void 0 : _j.call(_i);
1295
+ break;
1296
+ }
1297
+ default: {
1298
+ log6.error(`Invalid state: ${invitation2.state}`, {}, {
1299
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-proxy.ts",
1300
+ line: 81,
1301
+ scope: this,
1302
+ callSite: (f, a) => f(...a)
1303
+ });
1304
+ }
1305
+ }
1306
+ }, (err) => {
1307
+ if (err) {
1308
+ observableError(observable, err);
1309
+ }
1310
+ });
1311
+ return observable;
1312
+ }
1313
+ acceptInvitation(invitation, options) {
1314
+ assert6(invitation && invitation.swarmKey);
1315
+ const observable = new AuthenticatingInvitationProvider({
1316
+ onCancel: async () => {
1317
+ var _a;
1318
+ const invitationId = (_a = observable.invitation) == null ? void 0 : _a.invitationId;
1319
+ assert6(invitationId);
1320
+ await this._invitationsService.cancelInvitation({
1321
+ invitationId
1322
+ });
1323
+ },
1324
+ onAuthenticate: async (authenticationCode) => {
1325
+ var _a;
1326
+ const invitationId = (_a = observable.invitation) == null ? void 0 : _a.invitationId;
1327
+ assert6(invitationId);
1328
+ await this._invitationsService.authenticate({
1329
+ invitationId,
1330
+ authenticationCode
1331
+ });
1332
+ }
1333
+ });
1334
+ const stream = this._invitationsService.acceptInvitation({
1335
+ ...invitation,
1336
+ ...options
1337
+ });
1338
+ stream.subscribe((invitation2) => {
1339
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1340
+ assert6(invitation2.invitationId);
1341
+ observable.setInvitation(invitation2);
1342
+ switch (invitation2.state) {
1343
+ case Invitation3.State.CONNECTING: {
1344
+ (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation2);
1345
+ break;
1346
+ }
1347
+ case Invitation3.State.CONNECTED: {
1348
+ (_d = (_c = observable.callback).onConnected) == null ? void 0 : _d.call(_c, invitation2);
1349
+ break;
1350
+ }
1351
+ case Invitation3.State.AUTHENTICATING: {
1352
+ (_f = (_e = observable.callback).onAuthenticating) == null ? void 0 : _f.call(_e, invitation2);
1353
+ break;
1354
+ }
1355
+ case Invitation3.State.SUCCESS: {
1356
+ (_h = (_g = observable.callback).onSuccess) == null ? void 0 : _h.call(_g, invitation2);
1357
+ break;
1358
+ }
1359
+ case Invitation3.State.CANCELLED: {
1360
+ (_j = (_i = observable.callback).onCancelled) == null ? void 0 : _j.call(_i);
1361
+ break;
1362
+ }
1363
+ default: {
1364
+ log6.error(`Invalid state: ${invitation2.state}`, {}, {
1365
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-proxy.ts",
1366
+ line: 146,
1367
+ scope: this,
1368
+ callSite: (f, a) => f(...a)
1369
+ });
1370
+ }
1371
+ }
1372
+ }, (err) => {
1373
+ if (err) {
1374
+ observableError(observable, err);
1375
+ }
1376
+ });
1377
+ return observable;
1378
+ }
1379
+ };
1380
+
1381
+ // packages/sdk/client-services/src/packlets/invitations/halo-invitations-proxy.ts
1382
+ var HaloInvitationsProxy = class extends AbstractInvitationsProxy {
1383
+ getInvitationOptions() {
1384
+ return {};
1385
+ }
1386
+ };
1387
+
1388
+ // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1389
+ import assert7 from "@dxos/node-std/assert";
1390
+ import { Stream as Stream8 } from "@dxos/codec-protobuf";
1391
+ import { log as log7 } from "@dxos/log";
1392
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
1393
+ var AbstractInvitationsService = class {
1394
+ constructor(_identityManager, _getInvitationsHandler) {
1395
+ this._identityManager = _identityManager;
1396
+ this._getInvitationsHandler = _getInvitationsHandler;
1397
+ this._createInvitations = /* @__PURE__ */ new Map();
1398
+ this._acceptInvitations = /* @__PURE__ */ new Map();
1399
+ }
1400
+ getLoggingContext() {
1401
+ var _a;
1402
+ return {
1403
+ deviceKey: (_a = this._identityManager.identity) == null ? void 0 : _a.deviceKey
1404
+ };
1405
+ }
1406
+ createInvitation(invitation) {
1407
+ return new Stream8(({ next, close }) => {
1408
+ const invitationsHandler = this._getInvitationsHandler();
1409
+ const context = this.getContext(invitation);
1410
+ log7("stream opened", this.getLoggingContext(), {
1411
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1412
+ line: 43,
1413
+ scope: this,
1414
+ callSite: (f, a) => f(...a)
1415
+ });
1416
+ let invitationId;
1417
+ const { type, swarmKey } = invitation;
1418
+ const observable = invitationsHandler.createInvitation(context, {
1419
+ type,
1420
+ swarmKey
1421
+ });
1422
+ observable.subscribe({
1423
+ onConnecting: (invitation2) => {
1424
+ assert7(invitation2.invitationId);
1425
+ invitationId = invitation2.invitationId;
1426
+ this._createInvitations.set(invitation2.invitationId, observable);
1427
+ invitation2.state = Invitation4.State.CONNECTING;
1428
+ next(invitation2);
1429
+ },
1430
+ onConnected: (invitation2) => {
1431
+ assert7(invitation2.invitationId);
1432
+ invitation2.state = Invitation4.State.CONNECTED;
1433
+ next(invitation2);
1434
+ },
1435
+ onAuthenticating: (invitation2) => {
1436
+ assert7(invitation2.invitationId);
1437
+ invitation2.state = Invitation4.State.AUTHENTICATING;
1438
+ next(invitation2);
1439
+ },
1440
+ onSuccess: (invitation2) => {
1441
+ assert7(invitation2.invitationId);
1442
+ invitation2.state = Invitation4.State.SUCCESS;
1443
+ next(invitation2);
1444
+ close();
1445
+ },
1446
+ onCancelled: () => {
1447
+ assert7(invitationId);
1448
+ invitation.invitationId = invitationId;
1449
+ invitation.state = Invitation4.State.CANCELLED;
1450
+ next(invitation);
1451
+ close();
1452
+ },
1453
+ onTimeout: (err) => {
1454
+ invitation.state = Invitation4.State.TIMEOUT;
1455
+ close(err);
1456
+ },
1457
+ onError: (err) => {
1458
+ invitation.state = Invitation4.State.ERROR;
1459
+ close(err);
1460
+ }
1461
+ });
1462
+ return (err) => {
1463
+ const context2 = this.getLoggingContext();
1464
+ if (err) {
1465
+ log7.warn("stream closed", {
1466
+ ...context2,
1467
+ err
1468
+ }, {
1469
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1470
+ line: 92,
1471
+ scope: this,
1472
+ callSite: (f, a) => f(...a)
1473
+ });
1474
+ } else {
1475
+ log7("stream closed", context2, {
1476
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1477
+ line: 94,
1478
+ scope: this,
1479
+ callSite: (f, a) => f(...a)
1480
+ });
1481
+ }
1482
+ this._createInvitations.delete(invitation.invitationId);
1483
+ };
1484
+ });
1485
+ }
1486
+ acceptInvitation(invitation, options) {
1487
+ return new Stream8(({ next, close }) => {
1488
+ log7("stream opened", this.getLoggingContext(), {
1489
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1490
+ line: 104,
1491
+ scope: this,
1492
+ callSite: (f, a) => f(...a)
1493
+ });
1494
+ const invitationsHandler = this._getInvitationsHandler();
1495
+ let invitationId;
1496
+ const observable = invitationsHandler.acceptInvitation(invitation, options);
1497
+ observable.subscribe({
1498
+ onConnecting: (invitation2) => {
1499
+ assert7(invitation2.invitationId);
1500
+ invitationId = invitation2.invitationId;
1501
+ this._acceptInvitations.set(invitation2.invitationId, observable);
1502
+ invitation2.state = Invitation4.State.CONNECTING;
1503
+ next(invitation2);
1504
+ },
1505
+ onConnected: (invitation2) => {
1506
+ assert7(invitation2.invitationId);
1507
+ invitation2.state = Invitation4.State.CONNECTED;
1508
+ next(invitation2);
1509
+ },
1510
+ onAuthenticating: (invitation2) => {
1511
+ assert7(invitation2.invitationId);
1512
+ invitation2.state = Invitation4.State.AUTHENTICATING;
1513
+ next(invitation2);
1514
+ },
1515
+ onSuccess: (invitation2) => {
1516
+ invitation2.state = Invitation4.State.SUCCESS;
1517
+ next(invitation2);
1518
+ close();
1519
+ },
1520
+ onCancelled: () => {
1521
+ assert7(invitationId);
1522
+ invitation.invitationId = invitationId;
1523
+ invitation.state = Invitation4.State.CANCELLED;
1524
+ next(invitation);
1525
+ close();
1526
+ },
1527
+ onTimeout: (err) => {
1528
+ invitation.state = Invitation4.State.TIMEOUT;
1529
+ close(err);
1530
+ },
1531
+ onError: (err) => {
1532
+ invitation.state = Invitation4.State.ERROR;
1533
+ close(err);
1534
+ }
1535
+ });
1536
+ return (err) => {
1537
+ const context = this.getLoggingContext();
1538
+ if (err) {
1539
+ log7.warn("stream closed", {
1540
+ ...context,
1541
+ err
1542
+ }, {
1543
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1544
+ line: 152,
1545
+ scope: this,
1546
+ callSite: (f, a) => f(...a)
1547
+ });
1548
+ } else {
1549
+ log7("stream closed", context, {
1550
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1551
+ line: 154,
1552
+ scope: this,
1553
+ callSite: (f, a) => f(...a)
1554
+ });
1555
+ }
1556
+ this._acceptInvitations.delete(invitation.invitationId);
1557
+ };
1558
+ });
1559
+ }
1560
+ async authenticate({ invitationId, authenticationCode }) {
1561
+ log7("authenticating...", {}, {
1562
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1563
+ line: 163,
1564
+ scope: this,
1565
+ callSite: (f, a) => f(...a)
1566
+ });
1567
+ assert7(invitationId);
1568
+ const observable = this._acceptInvitations.get(invitationId);
1569
+ if (!observable) {
1570
+ log7.warn("invalid invitation", {
1571
+ invitationId
1572
+ }, {
1573
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1574
+ line: 167,
1575
+ scope: this,
1576
+ callSite: (f, a) => f(...a)
1577
+ });
1578
+ } else {
1579
+ await observable.authenticate(authenticationCode);
1580
+ }
1581
+ }
1582
+ async cancelInvitation(invitation) {
1583
+ var _a;
1584
+ log7("cancelling...", {}, {
1585
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1586
+ line: 174,
1587
+ scope: this,
1588
+ callSite: (f, a) => f(...a)
1589
+ });
1590
+ assert7(invitation.invitationId);
1591
+ const observable = (_a = this._createInvitations.get(invitation.invitationId)) != null ? _a : this._acceptInvitations.get(invitation.invitationId);
1592
+ if (!observable) {
1593
+ log7.warn("invalid invitation", {
1594
+ invitationId: invitation.invitationId
1595
+ }, {
1596
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts",
1597
+ line: 179,
1598
+ scope: this,
1599
+ callSite: (f, a) => f(...a)
1600
+ });
1601
+ } else {
1602
+ await (observable == null ? void 0 : observable.cancel());
1603
+ }
1604
+ }
1605
+ };
1606
+
1607
+ // packages/sdk/client-services/src/packlets/invitations/halo-invitations-service.ts
1608
+ var HaloInvitationsServiceImpl = class extends AbstractInvitationsService {
1609
+ constructor(identityManager, invitationsHandler) {
1610
+ super(identityManager, () => invitationsHandler);
1611
+ this.invitationsHandler = invitationsHandler;
1612
+ }
1613
+ getContext(invitation) {
1614
+ }
1615
+ };
1616
+
1617
+ // packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts
1618
+ import assert8 from "@dxos/node-std/assert";
1619
+ import { scheduleTask as scheduleTask2, sleep as sleep2, Trigger as Trigger2 } from "@dxos/async";
1620
+ import { Context as Context2 } from "@dxos/context";
1621
+ import { createAdmissionCredentials, generatePasscode as generatePasscode2, getCredentialAssertion } from "@dxos/credentials";
1622
+ import { writeMessages as writeMessages2 } from "@dxos/feed-store";
1623
+ import { PublicKey as PublicKey4 } from "@dxos/keys";
1624
+ import { log as log8 } from "@dxos/log";
1625
+ import { createTeleportProtocolFactory as createTeleportProtocolFactory2, StarTopology as StarTopology2 } from "@dxos/network-manager";
1626
+ import { schema as schema4 } from "@dxos/protocols";
1627
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
1628
+ import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
1629
+ var MAX_OTP_ATTEMPTS = 3;
1630
+ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1631
+ constructor(networkManager, _spaceManager, _signingContext, _keyring) {
1632
+ super(networkManager);
1633
+ this._spaceManager = _spaceManager;
1634
+ this._signingContext = _signingContext;
1635
+ this._keyring = _keyring;
1636
+ }
1637
+ createInvitation(space, options) {
1638
+ let swarmConnection;
1639
+ const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
1640
+ assert8(type !== Invitation5.Type.OFFLINE);
1641
+ assert8(space);
1642
+ const invitation = {
1643
+ type,
1644
+ invitationId: PublicKey4.random().toHex(),
1645
+ swarmKey: swarmKey != null ? swarmKey : PublicKey4.random(),
1646
+ spaceKey: space.key,
1647
+ authenticationCode: generatePasscode2(AUTHENTICATION_CODE_LENGTH)
1648
+ };
1649
+ const ctx = new Context2({
1650
+ onError: (err) => {
1651
+ void ctx.dispose();
1652
+ observable.callback.onError(err);
1653
+ }
1654
+ });
1655
+ const observable = new InvitationObservableProvider(async () => {
1656
+ await (swarmConnection == null ? void 0 : swarmConnection.close());
1657
+ });
1658
+ let authenticationCode;
1659
+ let authenticationRetry = 0;
1660
+ const complete = new Trigger2();
1661
+ const createExtension = () => {
1662
+ let guestProfile;
1663
+ const hostInvitationExtension = new HostSpaceInvitationExtension({
1664
+ introduce: async ({ profile }) => {
1665
+ var _a, _b;
1666
+ log8("guest introduced itself", {
1667
+ guestProfile: profile,
1668
+ host: this._signingContext.deviceKey,
1669
+ spaceKey: space.key
1670
+ }, {
1671
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1672
+ line: 97,
1673
+ scope: this,
1674
+ callSite: (f, a) => f(...a)
1675
+ });
1676
+ guestProfile = profile;
1677
+ (_b = (_a = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a, invitation);
1678
+ },
1679
+ authenticate: async ({ authenticationCode: code }) => {
1680
+ log8("received authentication request", {
1681
+ authenticationCode: code
1682
+ }, {
1683
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1684
+ line: 111,
1685
+ scope: this,
1686
+ callSite: (f, a) => f(...a)
1687
+ });
1688
+ let status = AuthenticationResponse2.Status.OK;
1689
+ if (invitation.authenticationCode) {
1690
+ if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1691
+ status = AuthenticationResponse2.Status.INVALID_OPT_ATTEMPTS;
1692
+ } else if (code !== invitation.authenticationCode) {
1693
+ status = AuthenticationResponse2.Status.INVALID_OTP;
1694
+ } else {
1695
+ authenticationCode = code;
1696
+ }
1697
+ }
1698
+ return {
1699
+ status
1700
+ };
1701
+ },
1702
+ requestAdmission: async ({ identityKey, deviceKey, controlFeedKey, dataFeedKey }) => {
1703
+ try {
1704
+ if (invitation.type !== Invitation5.Type.INTERACTIVE_TESTING) {
1705
+ if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
1706
+ throw new Error(`invalid authentication code: ${authenticationCode}`);
1707
+ }
1708
+ }
1709
+ log8("writing guest credentials", {
1710
+ host: this._signingContext.deviceKey,
1711
+ guest: deviceKey
1712
+ }, {
1713
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1714
+ line: 135,
1715
+ scope: this,
1716
+ callSite: (f, a) => f(...a)
1717
+ });
1718
+ const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, deviceKey, space.key, controlFeedKey, dataFeedKey, space.genesisFeedKey, guestProfile);
1719
+ assert8(credentials[0]["@type"] === "dxos.echo.feed.CredentialsMessage");
1720
+ const spaceMemberCredential = credentials[0].credential;
1721
+ assert8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1722
+ await writeMessages2(space.controlPipeline.writer, credentials);
1723
+ complete.wake(deviceKey);
1724
+ return {
1725
+ credential: spaceMemberCredential
1726
+ };
1727
+ } catch (err) {
1728
+ observable.callback.onError(err);
1729
+ throw err;
1730
+ }
1731
+ },
1732
+ onOpen: () => {
1733
+ scheduleTask2(ctx, async () => {
1734
+ var _a, _b;
1735
+ try {
1736
+ log8("connected", {
1737
+ host: this._signingContext.deviceKey
1738
+ }, {
1739
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1740
+ line: 169,
1741
+ scope: this,
1742
+ callSite: (f, a) => f(...a)
1743
+ });
1744
+ (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1745
+ const deviceKey = await complete.wait({
1746
+ timeout
1747
+ });
1748
+ log8("admitted guest", {
1749
+ host: this._signingContext.deviceKey,
1750
+ guest: deviceKey
1751
+ }, {
1752
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1753
+ line: 172,
1754
+ scope: this,
1755
+ callSite: (f, a) => f(...a)
1756
+ });
1757
+ observable.callback.onSuccess(invitation);
1758
+ } catch (err) {
1759
+ if (!observable.cancelled) {
1760
+ log8.error("failed", err, {
1761
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1762
+ line: 176,
1763
+ scope: this,
1764
+ callSite: (f, a) => f(...a)
1765
+ });
1766
+ observable.callback.onError(err);
1767
+ }
1768
+ } finally {
1769
+ await sleep2(ON_CLOSE_DELAY);
1770
+ await ctx.dispose();
1771
+ }
1772
+ });
1773
+ }
1774
+ });
1775
+ return hostInvitationExtension;
1776
+ };
1777
+ scheduleTask2(ctx, async () => {
1778
+ var _a, _b;
1779
+ const topic = invitation.swarmKey;
1780
+ const swarmConnection2 = await this._networkManager.joinSwarm({
1781
+ topic,
1782
+ peerId: topic,
1783
+ protocolProvider: createTeleportProtocolFactory2(async (teleport) => {
1784
+ teleport.addExtension("dxos.halo.invitations", createExtension());
1785
+ }),
1786
+ topology: new StarTopology2(topic)
1787
+ });
1788
+ ctx.onDispose(() => swarmConnection2.close());
1789
+ (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1790
+ });
1791
+ return observable;
1792
+ }
1793
+ acceptInvitation(invitation, options) {
1794
+ const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1795
+ const ctx = new Context2({
1796
+ onError: (err) => {
1797
+ void ctx.dispose();
1798
+ observable.callback.onError(err);
1799
+ }
1800
+ });
1801
+ const authenticated = new Trigger2();
1802
+ const observable = new AuthenticatingInvitationProvider({
1803
+ onCancel: async () => {
1804
+ await ctx.dispose();
1805
+ },
1806
+ onAuthenticate: async (code) => {
1807
+ authenticated.wake(code);
1808
+ }
1809
+ });
1810
+ let connectionCount = 0;
1811
+ const complete = new Trigger2();
1812
+ const createExtension = () => {
1813
+ const extension = new GuestSpaceInvitationExtension({
1814
+ onOpen: () => {
1815
+ scheduleTask2(ctx, async () => {
1816
+ var _a, _b, _c, _d;
1817
+ try {
1818
+ if (++connectionCount > 1) {
1819
+ throw new Error(`multiple connections detected: ${connectionCount}`);
1820
+ }
1821
+ log8("connected", {
1822
+ guest: this._signingContext.deviceKey
1823
+ }, {
1824
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1825
+ line: 247,
1826
+ scope: this,
1827
+ callSite: (f, a) => f(...a)
1828
+ });
1829
+ (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1830
+ log8("introduce", {
1831
+ guest: this._signingContext.deviceKey
1832
+ }, {
1833
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1834
+ line: 251,
1835
+ scope: this,
1836
+ callSite: (f, a) => f(...a)
1837
+ });
1838
+ await extension.rpc.SpaceHostService.introduce({
1839
+ profile: this._signingContext.profile
1840
+ });
1841
+ if (invitation.type === void 0 || invitation.type === Invitation5.Type.INTERACTIVE) {
1842
+ for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1843
+ log8("guest waiting for authentication code...", {}, {
1844
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1845
+ line: 260,
1846
+ scope: this,
1847
+ callSite: (f, a) => f(...a)
1848
+ });
1849
+ (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1850
+ const authenticationCode = await authenticated.wait({
1851
+ timeout
1852
+ });
1853
+ log8("sending authentication request", {}, {
1854
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1855
+ line: 264,
1856
+ scope: this,
1857
+ callSite: (f, a) => f(...a)
1858
+ });
1859
+ const response = await extension.rpc.SpaceHostService.authenticate({
1860
+ authenticationCode
1861
+ });
1862
+ if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
1863
+ break;
1864
+ }
1865
+ if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
1866
+ if (attempt === MAX_OTP_ATTEMPTS) {
1867
+ throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1868
+ } else {
1869
+ log8("retrying invalid code", {
1870
+ attempt
1871
+ }, {
1872
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1873
+ line: 274,
1874
+ scope: this,
1875
+ callSite: (f, a) => f(...a)
1876
+ });
1877
+ authenticated.reset();
1878
+ }
1879
+ }
1880
+ }
1881
+ }
1882
+ const controlFeedKey = await this._keyring.createKey();
1883
+ const dataFeedKey = await this._keyring.createKey();
1884
+ log8("request admission", {
1885
+ guest: this._signingContext.deviceKey
1886
+ }, {
1887
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1888
+ line: 285,
1889
+ scope: this,
1890
+ callSite: (f, a) => f(...a)
1891
+ });
1892
+ const { credential } = await extension.rpc.SpaceHostService.requestAdmission({
1893
+ identityKey: this._signingContext.identityKey,
1894
+ deviceKey: this._signingContext.deviceKey,
1895
+ controlFeedKey,
1896
+ dataFeedKey
1897
+ });
1898
+ const assertion = getCredentialAssertion(credential);
1899
+ assert8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1900
+ assert8(credential.subject.id.equals(this._signingContext.identityKey));
1901
+ const space = await this._spaceManager.acceptSpace({
1902
+ spaceKey: assertion.spaceKey,
1903
+ genesisFeedKey: assertion.genesisFeedKey,
1904
+ controlFeedKey,
1905
+ dataFeedKey
1906
+ });
1907
+ log8("admitted by host", {
1908
+ guest: this._signingContext.deviceKey,
1909
+ spaceKey: space.key
1910
+ }, {
1911
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1912
+ line: 308,
1913
+ scope: this,
1914
+ callSite: (f, a) => f(...a)
1915
+ });
1916
+ complete.wake();
1917
+ } catch (err) {
1918
+ if (!observable.cancelled) {
1919
+ log8.warn("auth failed", err, {
1920
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts",
1921
+ line: 312,
1922
+ scope: this,
1923
+ callSite: (f, a) => f(...a)
1924
+ });
1925
+ observable.callback.onError(err);
1926
+ }
1927
+ } finally {
1928
+ await ctx.dispose();
1929
+ }
1930
+ });
1931
+ }
1932
+ });
1933
+ return extension;
1934
+ };
1935
+ scheduleTask2(ctx, async () => {
1936
+ var _a, _b;
1937
+ assert8(invitation.swarmKey);
1938
+ const topic = invitation.swarmKey;
1939
+ const swarmConnection = await this._networkManager.joinSwarm({
1940
+ topic,
1941
+ peerId: PublicKey4.random(),
1942
+ protocolProvider: createTeleportProtocolFactory2(async (teleport) => {
1943
+ teleport.addExtension("dxos.halo.invitations", createExtension());
1944
+ }),
1945
+ topology: new StarTopology2(topic)
1946
+ });
1947
+ ctx.onDispose(() => swarmConnection.close());
1948
+ (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1949
+ await complete.wait();
1950
+ observable.callback.onSuccess(invitation);
1951
+ await ctx.dispose();
1952
+ });
1953
+ return observable;
1954
+ }
1955
+ };
1956
+ var HostSpaceInvitationExtension = class extends RpcExtension {
1957
+ constructor(_callbacks) {
1958
+ super({
1959
+ exposed: {
1960
+ SpaceHostService: schema4.getService("dxos.halo.invitations.SpaceHostService")
1961
+ }
1962
+ });
1963
+ this._callbacks = _callbacks;
1964
+ }
1965
+ async getHandlers() {
1966
+ return {
1967
+ SpaceHostService: {
1968
+ introduce: async (params) => {
1969
+ return this._callbacks.introduce(params);
1970
+ },
1971
+ authenticate: async (credentials) => {
1972
+ return this._callbacks.authenticate(credentials);
1973
+ },
1974
+ requestAdmission: async (credentials) => {
1975
+ return this._callbacks.requestAdmission(credentials);
1976
+ }
1977
+ }
1978
+ };
1979
+ }
1980
+ async onOpen(context) {
1981
+ await super.onOpen(context);
1982
+ this._callbacks.onOpen();
1983
+ }
1984
+ };
1985
+ var GuestSpaceInvitationExtension = class extends RpcExtension {
1986
+ constructor(_callbacks) {
1987
+ super({
1988
+ requested: {
1989
+ SpaceHostService: schema4.getService("dxos.halo.invitations.SpaceHostService")
1990
+ }
1991
+ });
1992
+ this._callbacks = _callbacks;
1993
+ }
1994
+ async getHandlers() {
1995
+ return {};
1996
+ }
1997
+ async onOpen(context) {
1998
+ await super.onOpen(context);
1999
+ this._callbacks.onOpen();
2000
+ }
2001
+ };
2002
+
2003
+ // packages/sdk/client-services/src/packlets/invitations/space-invitations-proxy.ts
2004
+ var SpaceInvitationsProxy = class extends AbstractInvitationsProxy {
2005
+ getInvitationOptions(context) {
2006
+ return {
2007
+ spaceKey: context
2008
+ };
2009
+ }
2010
+ };
2011
+
2012
+ // packages/sdk/client-services/src/packlets/invitations/space-invitations-service.ts
2013
+ import assert9 from "@dxos/node-std/assert";
2014
+ var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
2015
+ constructor(identityManager, invitationsHandler, _getSpaceManager) {
2016
+ super(identityManager, invitationsHandler);
2017
+ this.invitationsHandler = invitationsHandler;
2018
+ this._getSpaceManager = _getSpaceManager;
2019
+ }
2020
+ getContext(invitation) {
2021
+ assert9(invitation.spaceKey);
2022
+ const spaceManager = this._getSpaceManager();
2023
+ const space = spaceManager.spaces.get(invitation.spaceKey);
2024
+ assert9(space);
2025
+ return space;
2026
+ }
2027
+ };
2028
+
2029
+ // packages/sdk/client-services/src/packlets/services/service-context.ts
2030
+ import { Trigger as Trigger3 } from "@dxos/async";
2031
+ import { failUndefined as failUndefined3 } from "@dxos/debug";
2032
+ import { MOCK_AUTH_PROVIDER as MOCK_AUTH_PROVIDER2, MOCK_AUTH_VERIFIER as MOCK_AUTH_VERIFIER2, valueEncoding, DataServiceSubscriptions, MetadataStore, SpaceManager } from "@dxos/echo-db";
2033
+ import { FeedFactory, FeedStore } from "@dxos/feed-store";
2034
+ import { Keyring } from "@dxos/keyring";
2035
+ import { log as log9 } from "@dxos/log";
2036
+ var ServiceContext = class {
2037
+ constructor(storage, networkManager, modelFactory) {
2038
+ this.storage = storage;
2039
+ this.networkManager = networkManager;
2040
+ this.modelFactory = modelFactory;
2041
+ this.initialized = new Trigger3();
2042
+ this.dataServiceSubscriptions = new DataServiceSubscriptions();
2043
+ this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
2044
+ this.keyring = new Keyring(storage.createDirectory("keyring"));
2045
+ this.feedStore = new FeedStore({
2046
+ factory: new FeedFactory({
2047
+ root: storage.createDirectory("feeds"),
2048
+ signer: this.keyring,
2049
+ hypercore: {
2050
+ valueEncoding
2051
+ }
2052
+ })
2053
+ });
2054
+ this.identityManager = new IdentityManager(this.metadataStore, this.feedStore, this.keyring, networkManager, modelFactory);
2055
+ this.haloInvitations = new HaloInvitationsHandler(this.networkManager, this.identityManager);
2056
+ }
2057
+ async open() {
2058
+ log9("opening...", {}, {
2059
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts",
2060
+ line: 78,
2061
+ scope: this,
2062
+ callSite: (f, a) => f(...a)
2063
+ });
2064
+ await this.identityManager.open();
2065
+ if (this.identityManager.identity) {
2066
+ await this._initialize();
2067
+ }
2068
+ log9("opened", {}, {
2069
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts",
2070
+ line: 83,
2071
+ scope: this,
2072
+ callSite: (f, a) => f(...a)
2073
+ });
2074
+ }
2075
+ async close() {
2076
+ var _a;
2077
+ log9("closing...", {}, {
2078
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts",
2079
+ line: 87,
2080
+ scope: this,
2081
+ callSite: (f, a) => f(...a)
2082
+ });
2083
+ await this.identityManager.close();
2084
+ await ((_a = this.spaceManager) == null ? void 0 : _a.close());
2085
+ await this.feedStore.close();
2086
+ await this.networkManager.close();
2087
+ this.dataServiceSubscriptions.clear();
2088
+ log9("closed", {}, {
2089
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts",
2090
+ line: 93,
2091
+ scope: this,
2092
+ callSite: (f, a) => f(...a)
2093
+ });
2094
+ }
2095
+ async reset() {
2096
+ log9("resetting...", {}, {
2097
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts",
2098
+ line: 97,
2099
+ scope: this,
2100
+ callSite: (f, a) => f(...a)
2101
+ });
2102
+ await this.close();
2103
+ await this.storage.reset();
2104
+ log9("reset", {}, {
2105
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts",
2106
+ line: 100,
2107
+ scope: this,
2108
+ callSite: (f, a) => f(...a)
2109
+ });
2110
+ }
2111
+ async createIdentity(params = {}) {
2112
+ const identity = await this.identityManager.createIdentity(params);
2113
+ this.dataServiceSubscriptions.registerSpace(identity.haloSpaceKey, identity.haloDatabase.createDataServiceHost());
2114
+ await this._initialize();
2115
+ return identity;
2116
+ }
2117
+ async _initialize() {
2118
+ var _a;
2119
+ const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
2120
+ const signingContext = {
2121
+ credentialProvider: MOCK_AUTH_PROVIDER2,
2122
+ credentialAuthenticator: MOCK_AUTH_VERIFIER2,
2123
+ credentialSigner: identity.getIdentityCredentialSigner(),
2124
+ identityKey: identity.identityKey,
2125
+ deviceKey: identity.deviceKey,
2126
+ profile: identity.profileDocument
2127
+ };
2128
+ const spaceManager = new SpaceManager({
2129
+ metadataStore: this.metadataStore,
2130
+ feedStore: this.feedStore,
2131
+ networkManager: this.networkManager,
2132
+ keyring: this.keyring,
2133
+ dataServiceSubscriptions: this.dataServiceSubscriptions,
2134
+ modelFactory: this.modelFactory,
2135
+ signingContext
2136
+ });
2137
+ await spaceManager.open();
2138
+ this.spaceManager = spaceManager;
2139
+ this.spaceInvitations = new SpaceInvitationsHandler(this.networkManager, this.spaceManager, signingContext, this.keyring);
2140
+ this.initialized.wake();
2141
+ }
2142
+ };
2143
+
2144
+ // packages/sdk/client-services/src/packlets/services/service-definitions.ts
2145
+ import { schema as schema5 } from "@dxos/protocols";
2146
+ import { createServiceBundle } from "@dxos/rpc";
2147
+ var clientServiceBundle = createServiceBundle({
2148
+ HaloInvitationsService: schema5.getService("dxos.client.services.HaloInvitationsService"),
2149
+ DevicesService: schema5.getService("dxos.client.services.DevicesService"),
2150
+ SpaceInvitationsService: schema5.getService("dxos.client.services.SpaceInvitationsService"),
2151
+ SpacesService: schema5.getService("dxos.client.services.SpacesService"),
2152
+ SpaceService: schema5.getService("dxos.client.SpaceService"),
2153
+ DataService: schema5.getService("dxos.echo.service.DataService"),
2154
+ ProfileService: schema5.getService("dxos.client.ProfileService"),
2155
+ SystemService: schema5.getService("dxos.client.SystemService"),
2156
+ DevtoolsHost: schema5.getService("dxos.devtools.host.DevtoolsHost"),
2157
+ TracingService: schema5.getService("dxos.devtools.host.TracingService")
2158
+ });
2159
+
2160
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
2161
+ import { raise } from "@dxos/debug";
2162
+ import { DataServiceImpl } from "@dxos/echo-db";
2163
+ import { log as log10 } from "@dxos/log";
2164
+ import { ModelFactory } from "@dxos/model-factory";
2165
+ import { ObjectModel } from "@dxos/object-model";
2166
+ import { TextModel } from "@dxos/text-model";
2167
+
2168
+ // packages/sdk/client-services/src/packlets/identity/devices-service-impl.ts
2169
+ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
2170
+ import { Stream as Stream9 } from "@dxos/codec-protobuf";
2171
+ var DevicesServiceImpl = class {
2172
+ constructor(_identityManager) {
2173
+ this._identityManager = _identityManager;
2174
+ }
2175
+ updateDevice() {
2176
+ throw new Error("Method not implemented.");
2177
+ }
2178
+ queryDevices() {
2179
+ return new Stream9(({ next }) => {
2180
+ const update = () => {
2181
+ var _a;
2182
+ const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
2183
+ if (!deviceKeys) {
2184
+ next({
2185
+ devices: []
2186
+ });
2187
+ } else {
2188
+ next({
2189
+ devices: Array.from(deviceKeys.values()).map((key) => ({
2190
+ deviceKey: key
2191
+ }))
2192
+ });
2193
+ }
2194
+ };
2195
+ const dispose = new EventSubscriptions3();
2196
+ dispose.add(this._identityManager.stateUpdate.on(() => {
2197
+ update();
2198
+ if (this._identityManager.identity) {
2199
+ dispose.add(this._identityManager.identity.stateUpdate.on(() => {
2200
+ update();
2201
+ }));
2202
+ }
2203
+ }));
2204
+ update();
2205
+ return () => dispose.clear();
2206
+ });
2207
+ }
2208
+ };
2209
+
2210
+ // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2211
+ var SpacesServiceImpl = class {
2212
+ async createSpace() {
2213
+ throw new Error();
2214
+ }
2215
+ querySpaces() {
2216
+ throw new Error();
2217
+ }
2218
+ queryMembers(query) {
2219
+ throw new Error();
2220
+ }
2221
+ };
2222
+
2223
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
2224
+ import jsondown from "jsondown";
2225
+ import leveljs from "level-js";
2226
+ import memdown from "memdown";
2227
+ import { InvalidConfigError } from "@dxos/errors";
2228
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
2229
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
2230
+ import { isNode } from "@dxos/util";
2231
+ var StorageDriver = Runtime.Client.Storage.StorageDriver;
2232
+ var createStorageObjects = (config) => {
2233
+ const { path = "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
2234
+ if (persistent && storageType === StorageDriver.RAM) {
2235
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
2236
+ }
2237
+ if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
2238
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
2239
+ }
2240
+ if (persistent && keyStorage === StorageDriver.RAM) {
2241
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
2242
+ }
2243
+ if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
2244
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
2245
+ }
2246
+ return {
2247
+ storage: createStorage({
2248
+ type: persistent ? toStorageType(storageType) : StorageType.RAM,
2249
+ root: `${path}/`
2250
+ }),
2251
+ keyStorage: createKeyStorage(`${path}/keystore`, persistent ? toKeyStorageType(keyStorage) : "ram")
2252
+ };
2253
+ };
2254
+ var createKeyStorage = (path, type) => {
2255
+ const defaultedType = type != null ? type : isNode() ? "jsondown" : "leveljs";
2256
+ switch (defaultedType) {
2257
+ case "leveljs":
2258
+ return leveljs(path);
2259
+ case "jsondown":
2260
+ return jsondown(path);
2261
+ case "ram":
2262
+ return memdown();
2263
+ default:
2264
+ throw new InvalidConfigError(`Invalid key storage type: ${defaultedType}`);
2265
+ }
2266
+ };
2267
+ var toStorageType = (type) => {
2268
+ switch (type) {
2269
+ case void 0:
2270
+ return void 0;
2271
+ case StorageDriver.RAM:
2272
+ return StorageType.RAM;
2273
+ case StorageDriver.CHROME:
2274
+ return StorageType.CHROME;
2275
+ case StorageDriver.FIREFOX:
2276
+ return StorageType.FIREFOX;
2277
+ case StorageDriver.IDB:
2278
+ return StorageType.IDB;
2279
+ case StorageDriver.NODE:
2280
+ return StorageType.NODE;
2281
+ default:
2282
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
2283
+ }
2284
+ };
2285
+ var toKeyStorageType = (type) => {
2286
+ switch (type) {
2287
+ case void 0:
2288
+ return void 0;
2289
+ case StorageDriver.RAM:
2290
+ return "ram";
2291
+ case StorageDriver.LEVELJS:
2292
+ return "leveljs";
2293
+ case StorageDriver.JSONDOWN:
2294
+ return "jsondown";
2295
+ default:
2296
+ throw new Error(`Invalid key storage type: ${StorageDriver[type]}`);
2297
+ }
2298
+ };
2299
+
2300
+ // packages/sdk/client-services/src/packlets/services/service-registry.ts
2301
+ var ServiceRegistry = class {
2302
+ constructor(_serviceBundle, _handlers) {
2303
+ this._serviceBundle = _serviceBundle;
2304
+ this._handlers = _handlers;
2305
+ }
2306
+ get descriptors() {
2307
+ return this._serviceBundle;
2308
+ }
2309
+ get services() {
2310
+ return this._handlers;
2311
+ }
2312
+ };
2313
+
2314
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
2315
+ var createDefaultModelFactory = () => {
2316
+ return new ModelFactory().registerModel(ObjectModel).registerModel(TextModel);
2317
+ };
2318
+ var ClientServicesHost = class {
2319
+ constructor({
2320
+ config,
2321
+ modelFactory = createDefaultModelFactory(),
2322
+ networkManager
2323
+ }) {
2324
+ this._config = config;
2325
+ this._modelFactory = modelFactory;
2326
+ this._networkManager = networkManager;
2327
+ }
2328
+ get descriptors() {
2329
+ return this._serviceRegistry.descriptors;
2330
+ }
2331
+ get services() {
2332
+ return this._serviceRegistry.services;
2333
+ }
2334
+ async open() {
2335
+ var _a;
2336
+ await this._initialize();
2337
+ const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
2338
+ log10("opening...", {
2339
+ deviceKey
2340
+ }, {
2341
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts",
2342
+ line: 69,
2343
+ scope: this,
2344
+ callSite: (f, a) => f(...a)
2345
+ });
2346
+ await this._initialize();
2347
+ await this._serviceContext.open();
2348
+ log10("opened", {
2349
+ deviceKey
2350
+ }, {
2351
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts",
2352
+ line: 72,
2353
+ scope: this,
2354
+ callSite: (f, a) => f(...a)
2355
+ });
2356
+ }
2357
+ async close() {
2358
+ var _a;
2359
+ const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
2360
+ log10("closing...", {
2361
+ deviceKey
2362
+ }, {
2363
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts",
2364
+ line: 77,
2365
+ scope: this,
2366
+ callSite: (f, a) => f(...a)
2367
+ });
2368
+ await this._serviceContext.close();
2369
+ log10("closed", {
2370
+ deviceKey
2371
+ }, {
2372
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts",
2373
+ line: 79,
2374
+ scope: this,
2375
+ callSite: (f, a) => f(...a)
2376
+ });
2377
+ }
2378
+ async _initialize() {
2379
+ const { storage } = createStorageObjects(this._config.get("runtime.client.storage", {}));
2380
+ this._serviceContext = new ServiceContext(storage, this._networkManager, this._modelFactory);
2381
+ this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
2382
+ HaloInvitationsService: new HaloInvitationsServiceImpl(this._serviceContext.identityManager, this._serviceContext.haloInvitations),
2383
+ DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
2384
+ SpaceInvitationsService: new SpaceInvitationsServiceImpl(this._serviceContext.identityManager, () => {
2385
+ var _a;
2386
+ return (_a = this._serviceContext.spaceInvitations) != null ? _a : raise(new Error("SpaceInvitations not initialized"));
2387
+ }, () => {
2388
+ var _a;
2389
+ return (_a = this._serviceContext.spaceManager) != null ? _a : raise(new Error("SpaceManager not initialized"));
2390
+ }),
2391
+ SpacesService: new SpacesServiceImpl(),
2392
+ DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
2393
+ ProfileService: new ProfileServiceImpl(this._serviceContext),
2394
+ SpaceService: new SpaceServiceImpl(this._serviceContext),
2395
+ SystemService: new SystemServiceImpl(this._config, this._serviceContext),
2396
+ TracingService: new TracingServiceImpl(this._config),
2397
+ DevtoolsHost: new DevtoolsServiceImpl({
2398
+ events: new DevtoolsHostEvents(),
2399
+ config: this._config,
2400
+ context: this._serviceContext
2401
+ })
2402
+ });
2403
+ }
2404
+ };
2405
+
2406
+ // packages/sdk/client-services/src/packlets/services/service-proxy.ts
2407
+ import { asyncTimeout } from "@dxos/async";
2408
+ import { RemoteServiceConnectionTimeout } from "@dxos/errors";
2409
+ import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
2410
+ var ClientServicesProxy = class {
2411
+ constructor(port, _timeout = 3e4) {
2412
+ this._timeout = _timeout;
2413
+ this._proxy = createProtoRpcPeer2({
2414
+ requested: clientServiceBundle,
2415
+ exposed: {},
2416
+ handlers: {},
2417
+ port
2418
+ });
2419
+ }
2420
+ get proxy() {
2421
+ return this._proxy;
2422
+ }
2423
+ get descriptors() {
2424
+ return clientServiceBundle;
2425
+ }
2426
+ get services() {
2427
+ return this._proxy.rpc;
2428
+ }
2429
+ async open() {
2430
+ await asyncTimeout(this._proxy.open(), this._timeout, new RemoteServiceConnectionTimeout());
2431
+ }
2432
+ async close() {
2433
+ await this._proxy.close();
2434
+ }
2435
+ };
2436
+
2437
+ // packages/sdk/client-services/src/packlets/vault/iframe-runtime.ts
2438
+ import { WebRTCTransportService } from "@dxos/network-manager";
2439
+ import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
2440
+
2441
+ // packages/sdk/client-services/src/packlets/vault/services.ts
2442
+ import { schema as schema6 } from "@dxos/protocols";
2443
+ var iframeServiceBundle = {
2444
+ IframeService: schema6.getService("dxos.iframe.IframeService"),
2445
+ BridgeService: schema6.getService("dxos.mesh.bridge.BridgeService")
2446
+ };
2447
+ var workerServiceBundle = {
2448
+ WorkerService: schema6.getService("dxos.iframe.WorkerService")
2449
+ };
2450
+
2451
+ // packages/sdk/client-services/src/packlets/vault/iframe-runtime.ts
2452
+ var IFrameRuntime = class {
2453
+ constructor({ systemPort, workerAppPort, windowAppPort }) {
2454
+ this._transportService = new WebRTCTransportService();
2455
+ this._systemPort = systemPort;
2456
+ this._windowAppPort = windowAppPort;
2457
+ this._workerAppPort = workerAppPort;
2458
+ this._systemRpc = createProtoRpcPeer3({
2459
+ requested: workerServiceBundle,
2460
+ exposed: iframeServiceBundle,
2461
+ handlers: {
2462
+ BridgeService: this._transportService,
2463
+ IframeService: {
2464
+ async heartbeat() {
2465
+ }
2466
+ }
2467
+ },
2468
+ port: this._systemPort,
2469
+ timeout: 200
2470
+ });
2471
+ this._workerAppPort.subscribe((msg) => this._windowAppPort.send(msg));
2472
+ this._windowAppPort.subscribe((msg) => this._workerAppPort.send(msg));
2473
+ }
2474
+ async open(origin) {
2475
+ await this._systemRpc.open();
2476
+ await this._systemRpc.rpc.WorkerService.start({
2477
+ origin
2478
+ });
2479
+ }
2480
+ async close() {
2481
+ await this._systemRpc.rpc.WorkerService.stop();
2482
+ await this._systemRpc.close();
2483
+ }
2484
+ };
2485
+
2486
+ // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
2487
+ import { Trigger as Trigger5 } from "@dxos/async";
2488
+ import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
2489
+ import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manager";
2490
+
2491
+ // packages/sdk/client-services/src/packlets/vault/worker-session.ts
2492
+ import assert10 from "@dxos/node-std/assert";
2493
+ import { Trigger as Trigger4 } from "@dxos/async";
2494
+ import { log as log11, logInfo } from "@dxos/log";
2495
+ import { createProtoRpcPeer as createProtoRpcPeer4 } from "@dxos/rpc";
2496
+ import { Callback } from "@dxos/util";
2497
+ var __decorate = function(decorators, target, key, desc) {
2498
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2499
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2500
+ r = Reflect.decorate(decorators, target, key, desc);
2501
+ else
2502
+ for (var i = decorators.length - 1; i >= 0; i--)
2503
+ if (d = decorators[i])
2504
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2505
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2506
+ };
2507
+ var WorkerSession = class {
2508
+ constructor({ getServices, systemPort, appPort, options = {
2509
+ heartbeatInterval: 1e3
2510
+ } }) {
2511
+ this._startTrigger = new Trigger4();
2512
+ this.onClose = new Callback();
2513
+ assert10(options);
2514
+ assert10(getServices);
2515
+ this._options = options;
2516
+ this._getServices = getServices;
2517
+ this._clientRpc = createProtoRpcPeer4({
2518
+ exposed: clientServiceBundle,
2519
+ handlers: {
2520
+ HaloInvitationsService: async () => (await this._getServices()).services.HaloInvitationsService,
2521
+ DevicesService: async () => (await this._getServices()).services.DevicesService,
2522
+ SpaceInvitationsService: async () => (await this._getServices()).services.SpaceInvitationsService,
2523
+ SpacesService: async () => (await this._getServices()).services.SpacesService,
2524
+ SpaceService: async () => (await this._getServices()).services.SpaceService,
2525
+ DataService: async () => (await this._getServices()).services.DataService,
2526
+ ProfileService: async () => (await this._getServices()).services.ProfileService,
2527
+ SystemService: async () => (await this._getServices()).services.SystemService,
2528
+ DevtoolsHost: async () => (await this._getServices()).services.DevtoolsHost,
2529
+ TracingService: async () => (await this._getServices()).services.TracingService
2530
+ },
2531
+ port: appPort
2532
+ });
2533
+ this._iframeRpc = createProtoRpcPeer4({
2534
+ requested: iframeServiceBundle,
2535
+ exposed: workerServiceBundle,
2536
+ handlers: {
2537
+ WorkerService: {
2538
+ start: async (request) => {
2539
+ this.origin = request.origin;
2540
+ this._startTrigger.wake();
2541
+ },
2542
+ stop: async () => {
2543
+ setTimeout(async () => {
2544
+ try {
2545
+ await this.close();
2546
+ } catch (err) {
2547
+ log11.catch(err, {}, {
2548
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts",
2549
+ line: 89,
2550
+ scope: this,
2551
+ callSite: (f, a) => f(...a)
2552
+ });
2553
+ }
2554
+ });
2555
+ }
2556
+ }
2557
+ },
2558
+ port: systemPort,
2559
+ timeout: 1e3
2560
+ });
2561
+ this.bridgeService = this._iframeRpc.rpc.BridgeService;
2562
+ }
2563
+ async open() {
2564
+ log11.info("opening..", {}, {
2565
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts",
2566
+ line: 103,
2567
+ scope: this,
2568
+ callSite: (f, a) => f(...a)
2569
+ });
2570
+ await Promise.all([
2571
+ this._clientRpc.open(),
2572
+ this._iframeRpc.open()
2573
+ ]);
2574
+ await this._startTrigger.wait({
2575
+ timeout: 3e3
2576
+ });
2577
+ this._heartbeatTimer = setInterval(async () => {
2578
+ try {
2579
+ await this._iframeRpc.rpc.IframeService.heartbeat();
2580
+ } catch (err1) {
2581
+ log11.warn("Heartbeat failed", {
2582
+ err: err1
2583
+ }, {
2584
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts",
2585
+ line: 115,
2586
+ scope: this,
2587
+ callSite: (f, a) => f(...a)
2588
+ });
2589
+ try {
2590
+ await this.close();
2591
+ } catch (err) {
2592
+ log11.catch(err, {}, {
2593
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts",
2594
+ line: 119,
2595
+ scope: this,
2596
+ callSite: (f, a) => f(...a)
2597
+ });
2598
+ }
2599
+ }
2600
+ }, this._options.heartbeatInterval);
2601
+ }
2602
+ async close() {
2603
+ log11.info("closing..", {}, {
2604
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts",
2605
+ line: 126,
2606
+ scope: this,
2607
+ callSite: (f, a) => f(...a)
2608
+ });
2609
+ try {
2610
+ await this.onClose.callIfSet();
2611
+ } catch (err) {
2612
+ log11.catch(err, {}, {
2613
+ file: "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/vault/worker-session.ts",
2614
+ line: 130,
2615
+ scope: this,
2616
+ callSite: (f, a) => f(...a)
2617
+ });
2618
+ }
2619
+ if (this._heartbeatTimer !== void 0) {
2620
+ clearInterval(this._heartbeatTimer);
2621
+ }
2622
+ await Promise.all([
2623
+ this._clientRpc.close(),
2624
+ this._iframeRpc.close()
2625
+ ]);
2626
+ }
2627
+ };
2628
+ __decorate([
2629
+ logInfo
2630
+ ], WorkerSession.prototype, "origin", void 0);
2631
+
2632
+ // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
2633
+ var WorkerRuntime = class {
2634
+ constructor(_configProvider) {
2635
+ this._configProvider = _configProvider;
2636
+ this._transportFactory = new WebRTCTransportProxyFactory();
2637
+ this._ready = new Trigger5();
2638
+ this.sessions = /* @__PURE__ */ new Set();
2639
+ }
2640
+ async start() {
2641
+ try {
2642
+ this._config = await this._configProvider();
2643
+ const signalServer = this._config.get("runtime.services.signal.server");
2644
+ this._clientServices = new ClientServicesHost({
2645
+ config: this._config,
2646
+ networkManager: new NetworkManager({
2647
+ log: true,
2648
+ signalManager: signalServer ? new WebsocketSignalManager([
2649
+ signalServer
2650
+ ]) : new MemorySignalManager(new MemorySignalManagerContext()),
2651
+ transportFactory: this._transportFactory
2652
+ })
2653
+ });
2654
+ await this._clientServices.open();
2655
+ this._ready.wake(void 0);
2656
+ } catch (err) {
2657
+ this._ready.wake(err);
2658
+ }
2659
+ }
2660
+ async stop() {
2661
+ await this._clientServices.close();
2662
+ }
2663
+ async createSession({ appPort, systemPort }) {
2664
+ const session = new WorkerSession({
2665
+ getServices: async () => {
2666
+ const error = await this._ready.wait();
2667
+ if (error !== void 0) {
2668
+ throw error;
2669
+ }
2670
+ return this._clientServices;
2671
+ },
2672
+ appPort,
2673
+ systemPort,
2674
+ readySignal: this._ready
2675
+ });
2676
+ session.onClose.set(async () => {
2677
+ this.sessions.delete(session);
2678
+ this._reconnectWebrtc();
2679
+ });
2680
+ await session.open();
2681
+ this.sessions.add(session);
2682
+ this._reconnectWebrtc();
2683
+ }
2684
+ _reconnectWebrtc() {
2685
+ if (this._sessionForNetworking) {
2686
+ if (!this.sessions.has(this._sessionForNetworking)) {
2687
+ this._sessionForNetworking = void 0;
2688
+ }
2689
+ }
2690
+ if (!this._sessionForNetworking) {
2691
+ const selected = Array.from(this.sessions).find((session) => session.bridgeService);
2692
+ if (selected) {
2693
+ this._sessionForNetworking = selected;
2694
+ this._transportFactory.setBridgeService(selected.bridgeService);
2695
+ } else {
2696
+ this._transportFactory.setBridgeService(void 0);
2697
+ }
2698
+ }
2699
+ }
2700
+ };
2701
+ export {
2702
+ AUTHENTICATION_CODE_LENGTH,
2703
+ AbstractInvitationsHandler,
2704
+ AbstractInvitationsProxy,
2705
+ AbstractInvitationsService,
2706
+ AuthenticatingInvitationProvider,
2707
+ ClientServicesHost,
2708
+ ClientServicesProxy,
2709
+ DevtoolsHostEvents,
2710
+ DevtoolsServiceImpl,
2711
+ HaloInvitationsHandler,
2712
+ HaloInvitationsProxy,
2713
+ HaloInvitationsServiceImpl,
2714
+ IFrameRuntime,
2715
+ INVITATION_TIMEOUT,
2716
+ Identity,
2717
+ IdentityManager,
2718
+ InvitationEncoder,
2719
+ InvitationObservableProvider,
2720
+ ON_CLOSE_DELAY,
2721
+ ProfileServiceImpl,
2722
+ ServiceContext,
2723
+ ServiceRegistry,
2724
+ SpaceInvitationsHandler,
2725
+ SpaceInvitationsProxy,
2726
+ SpaceInvitationsServiceImpl,
2727
+ SpaceServiceImpl,
2728
+ SystemServiceImpl,
2729
+ TracingServiceImpl,
2730
+ WorkerRuntime,
2731
+ WorkerSession,
2732
+ clientServiceBundle,
2733
+ createDefaultModelFactory,
2734
+ createHaloAuthProvider,
2735
+ createHaloAuthVerifier,
2736
+ createStorageObjects,
2737
+ getNetworkPeers,
2738
+ subscribeToFeedBlocks,
2739
+ subscribeToFeeds,
2740
+ subscribeToNetworkStatus,
2741
+ subscribeToNetworkTopics,
2742
+ subscribeToSignalTrace,
2743
+ subscribeToSpaces,
2744
+ subscribeToSwarmInfo,
2745
+ wrapObservable
2746
+ };
2747
+ //# sourceMappingURL=index.mjs.map