@dxos/client-services 0.1.13 → 0.1.16

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