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