@dxos/client-services 0.1.35 → 0.1.36

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 (95) hide show
  1. package/dist/lib/browser/{chunk-H5IXSSI7.mjs → chunk-2AYYVPWN.mjs} +835 -950
  2. package/dist/lib/browser/chunk-2AYYVPWN.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +9 -11
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +212 -74
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +942 -1058
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +1089 -1067
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/identity/identity-manager.d.ts +1 -0
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  14. package/dist/types/src/packlets/identity/identity.d.ts +3 -3
  15. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +18 -0
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -0
  18. package/dist/types/src/packlets/invitations/device-invitation-protocol.test.d.ts +2 -0
  19. package/dist/types/src/packlets/invitations/device-invitation-protocol.test.d.ts.map +1 -0
  20. package/dist/types/src/packlets/invitations/index.d.ts +4 -4
  21. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +12 -0
  23. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -0
  24. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +38 -0
  25. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -0
  26. package/dist/types/src/packlets/invitations/invitations-service.d.ts +13 -15
  27. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  28. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +22 -0
  29. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -0
  30. package/dist/types/src/packlets/invitations/space-invitation-protocol.test.d.ts +2 -0
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.test.d.ts.map +1 -0
  32. package/dist/types/src/packlets/services/service-context.d.ts +6 -4
  33. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  35. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -0
  36. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  37. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  38. package/dist/types/src/packlets/testing/invitation-utils.d.ts +31 -2
  39. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  40. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -3
  41. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  42. package/dist/types/src/packlets/tests/invitations.test.d.ts +2 -0
  43. package/dist/types/src/packlets/tests/invitations.test.d.ts.map +1 -0
  44. package/dist/types/src/packlets/vault/worker-runtime.d.ts +2 -0
  45. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  46. package/package.json +30 -30
  47. package/src/packlets/identity/identity-manager.ts +2 -1
  48. package/src/packlets/identity/identity.ts +3 -3
  49. package/src/packlets/invitations/{device-invitations-handler.test.ts → device-invitation-protocol.test.ts} +3 -3
  50. package/src/packlets/invitations/device-invitation-protocol.ts +83 -0
  51. package/src/packlets/invitations/index.ts +4 -4
  52. package/src/packlets/invitations/invitation-protocol.ts +21 -0
  53. package/src/packlets/invitations/invitations-handler.ts +462 -0
  54. package/src/packlets/invitations/invitations-service.ts +127 -104
  55. package/src/packlets/invitations/space-invitation-protocol.test.ts +221 -0
  56. package/src/packlets/invitations/space-invitation-protocol.ts +117 -0
  57. package/src/packlets/services/service-context.test.ts +11 -4
  58. package/src/packlets/services/service-context.ts +40 -19
  59. package/src/packlets/services/service-host.ts +4 -12
  60. package/src/packlets/services/service-registry.test.ts +23 -25
  61. package/src/packlets/spaces/data-space-manager.ts +5 -0
  62. package/src/packlets/spaces/spaces-service.ts +7 -2
  63. package/src/packlets/storage/storage.ts +2 -0
  64. package/src/packlets/testing/invitation-utils.ts +219 -31
  65. package/src/packlets/testing/test-builder.ts +33 -22
  66. package/src/packlets/tests/client-services.test.ts +33 -76
  67. package/src/packlets/tests/halo-profile.test.ts +2 -28
  68. package/src/packlets/tests/invitations.test.ts +389 -0
  69. package/src/packlets/tests/spaces-invitations.test.ts +12 -30
  70. package/src/packlets/tests/spaces.test.ts +30 -28
  71. package/src/packlets/vault/worker-runtime.ts +4 -0
  72. package/dist/lib/browser/chunk-H5IXSSI7.mjs.map +0 -7
  73. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts +0 -30
  74. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts.map +0 -1
  75. package/dist/types/src/packlets/invitations/device-invitations-handler.test.d.ts +0 -2
  76. package/dist/types/src/packlets/invitations/device-invitations-handler.test.d.ts.map +0 -1
  77. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts +0 -13
  78. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts.map +0 -1
  79. package/dist/types/src/packlets/invitations/device-invitations-service.test.d.ts +0 -2
  80. package/dist/types/src/packlets/invitations/device-invitations-service.test.d.ts.map +0 -1
  81. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts +0 -26
  82. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +0 -1
  83. package/dist/types/src/packlets/invitations/space-invitations-handler.test.d.ts +0 -2
  84. package/dist/types/src/packlets/invitations/space-invitations-handler.test.d.ts.map +0 -1
  85. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts +0 -16
  86. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts.map +0 -1
  87. package/dist/types/src/packlets/invitations/space-invitations-service.test.d.ts +0 -2
  88. package/dist/types/src/packlets/invitations/space-invitations-service.test.d.ts.map +0 -1
  89. package/src/packlets/invitations/device-invitations-handler.ts +0 -370
  90. package/src/packlets/invitations/device-invitations-service.test.ts +0 -96
  91. package/src/packlets/invitations/device-invitations-service.ts +0 -24
  92. package/src/packlets/invitations/space-invitations-handler.test.ts +0 -246
  93. package/src/packlets/invitations/space-invitations-handler.ts +0 -463
  94. package/src/packlets/invitations/space-invitations-service.test.ts +0 -129
  95. package/src/packlets/invitations/space-invitations-service.ts +0 -35
@@ -586,10 +586,11 @@ var IdentityManager = class {
586
586
  async open() {
587
587
  var _a;
588
588
  log3.trace("dxos.halo.identity-manager", trace.begin({
589
- id: this._instanceId
589
+ id: this._instanceId,
590
+ parentId: this._traceParent
590
591
  }), {
591
592
  file: "identity-manager.ts",
592
- line: 71,
593
+ line: 72,
593
594
  scope: this,
594
595
  callSite: (f, a) => f(...a)
595
596
  });
@@ -599,7 +600,7 @@ var IdentityManager = class {
599
600
  identityRecord
600
601
  }, {
601
602
  file: "identity-manager.ts",
602
- line: 75,
603
+ line: 76,
603
604
  scope: this,
604
605
  callSite: (f, a) => f(...a)
605
606
  });
@@ -612,7 +613,7 @@ var IdentityManager = class {
612
613
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
613
614
  }, {
614
615
  file: "identity-manager.ts",
615
- line: 80,
616
+ line: 81,
616
617
  scope: this,
617
618
  callSite: (f, a) => f(...a)
618
619
  });
@@ -626,7 +627,7 @@ var IdentityManager = class {
626
627
  id: this._instanceId
627
628
  }), {
628
629
  file: "identity-manager.ts",
629
- line: 90,
630
+ line: 91,
630
631
  scope: this,
631
632
  callSite: (f, a) => f(...a)
632
633
  });
@@ -636,7 +637,7 @@ var IdentityManager = class {
636
637
  assert2(!this._identity, "Identity already exists.");
637
638
  log3("creating identity...", {}, {
638
639
  file: "identity-manager.ts",
639
- line: 95,
640
+ line: 96,
640
641
  scope: this,
641
642
  callSite: (f, a) => f(...a)
642
643
  });
@@ -685,7 +686,7 @@ var IdentityManager = class {
685
686
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
686
687
  }, {
687
688
  file: "identity-manager.ts",
688
- line: 150,
689
+ line: 151,
689
690
  scope: this,
690
691
  callSite: (f, a) => f(...a)
691
692
  });
@@ -695,7 +696,7 @@ var IdentityManager = class {
695
696
  deviceKey: identity.deviceKey
696
697
  }, {
697
698
  file: "identity-manager.ts",
698
- line: 156,
699
+ line: 157,
699
700
  scope: this,
700
701
  callSite: (f, a) => f(...a)
701
702
  });
@@ -710,7 +711,7 @@ var IdentityManager = class {
710
711
  params
711
712
  }, {
712
713
  file: "identity-manager.ts",
713
- line: 164,
714
+ line: 165,
714
715
  scope: this,
715
716
  callSite: (f, a) => f(...a)
716
717
  });
@@ -736,7 +737,7 @@ var IdentityManager = class {
736
737
  displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
737
738
  }, {
738
739
  file: "identity-manager.ts",
739
- line: 184,
740
+ line: 185,
740
741
  scope: this,
741
742
  callSite: (f, a) => f(...a)
742
743
  });
@@ -746,7 +747,7 @@ var IdentityManager = class {
746
747
  deviceKey: identity.deviceKey
747
748
  }, {
748
749
  file: "identity-manager.ts",
749
- line: 190,
750
+ line: 191,
750
751
  scope: this,
751
752
  callSite: (f, a) => f(...a)
752
753
  });
@@ -758,7 +759,7 @@ var IdentityManager = class {
758
759
  identityRecord
759
760
  }, {
760
761
  file: "identity-manager.ts",
761
- line: 196,
762
+ line: 197,
762
763
  scope: this,
763
764
  callSite: (f, a) => f(...a)
764
765
  });
@@ -791,7 +792,7 @@ var IdentityManager = class {
791
792
  identityKey: identityRecord.identityKey
792
793
  }, {
793
794
  file: "identity-manager.ts",
794
- line: 224,
795
+ line: 225,
795
796
  scope: this,
796
797
  callSite: (f, a) => f(...a)
797
798
  });
@@ -861,696 +862,176 @@ var IdentityServiceImpl = class {
861
862
  }
862
863
  };
863
864
 
864
- // packages/sdk/client-services/src/packlets/invitations/device-invitations-handler.ts
865
+ // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
865
866
  import assert4 from "@dxos/node-std/assert";
866
- import { scheduleTask, sleep, Trigger as Trigger2 } from "@dxos/async";
867
- import { AbstractInvitationsHandler, AuthenticatingInvitationProvider, AUTHENTICATION_CODE_LENGTH, InvitationObservableProvider, INVITATION_TIMEOUT, ON_CLOSE_DELAY } from "@dxos/client";
868
- import { Context as Context3 } from "@dxos/context";
869
- import { generatePasscode } from "@dxos/credentials";
870
- import { PublicKey as PublicKey4 } from "@dxos/keys";
871
- import { log as log4 } from "@dxos/log";
872
- import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
873
- import { schema as schema2 } from "@dxos/protocols";
874
867
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
875
- import { AuthenticationResponse } from "@dxos/protocols/proto/dxos/halo/invitations";
876
- import { RpcExtension } from "@dxos/teleport";
877
- var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
878
- // prettier-ignore
879
- constructor(_params) {
880
- super(_params.networkManager);
881
- this._params = _params;
868
+ var DeviceInvitationProtocol = class {
869
+ constructor(_keyring, _getIdentity, _acceptIdentity) {
870
+ this._keyring = _keyring;
871
+ this._getIdentity = _getIdentity;
872
+ this._acceptIdentity = _acceptIdentity;
882
873
  }
883
- /**
884
- * Creates an invitation and listens for a join request from the invited (guest) peer.
885
- */
886
- createInvitation(context, options) {
887
- const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
888
- assert4(type !== Invitation.Type.OFFLINE);
889
- const identity = this._params.getIdentity();
890
- const invitation = {
891
- type,
892
- invitationId: PublicKey4.random().toHex(),
893
- swarmKey: swarmKey != null ? swarmKey : PublicKey4.random(),
894
- authenticationCode: generatePasscode(AUTHENTICATION_CODE_LENGTH)
895
- };
896
- const ctx = new Context3({
897
- onError: (err) => {
898
- void ctx.dispose();
899
- observable.callback.onError(err);
900
- }
901
- });
902
- const observable = new InvitationObservableProvider(async () => {
903
- await ctx.dispose();
904
- });
905
- let authenticationCode;
906
- const complete = new Trigger2();
907
- const createExtension = () => new HostHaloInvitationExtension({
908
- requestAdmission: async () => {
909
- var _a, _b;
910
- log4("responding with admission offer", {
911
- host: identity.deviceKey
912
- }, {
913
- file: "device-invitations-handler.ts",
914
- line: 92,
915
- scope: this,
916
- callSite: (f, a) => f(...a)
917
- });
918
- (_b = (_a = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a, invitation);
919
- return {
920
- identityKey: identity.identityKey,
921
- haloSpaceKey: identity.haloSpaceKey,
922
- genesisFeedKey: identity.haloGenesisFeedKey,
923
- controlTimeframe: identity.controlPipeline.state.timeframe
924
- };
925
- },
926
- authenticate: async ({ authenticationCode: code }) => {
927
- log4("received authentication request", {
928
- authenticationCode: code
929
- }, {
930
- file: "device-invitations-handler.ts",
931
- line: 107,
932
- scope: this,
933
- callSite: (f, a) => f(...a)
934
- });
935
- authenticationCode = code;
936
- return {
937
- status: AuthenticationResponse.Status.OK
938
- };
939
- },
940
- // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
941
- presentAdmissionCredentials: async (credentials) => {
942
- try {
943
- if (invitation.type !== Invitation.Type.INTERACTIVE_TESTING) {
944
- if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
945
- throw new Error(`invalid authentication code: ${authenticationCode}`);
946
- }
947
- }
948
- log4("writing guest credentials", {
949
- host: identity.deviceKey,
950
- guest: credentials.deviceKey
951
- }, {
952
- file: "device-invitations-handler.ts",
953
- line: 122,
954
- scope: this,
955
- callSite: (f, a) => f(...a)
956
- });
957
- await identity.admitDevice(credentials);
958
- complete.wake(credentials.deviceKey);
959
- } catch (err) {
960
- observable.callback.onError(err);
961
- throw err;
962
- }
963
- },
964
- onOpen: () => {
965
- scheduleTask(ctx, async () => {
966
- var _a, _b;
967
- try {
968
- log4("connected", {
969
- host: identity.deviceKey
970
- }, {
971
- file: "device-invitations-handler.ts",
972
- line: 138,
973
- scope: this,
974
- callSite: (f, a) => f(...a)
975
- });
976
- (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
977
- const deviceKey = await complete.wait({
978
- timeout
979
- });
980
- log4("admitted guest", {
981
- host: identity.deviceKey,
982
- guest: deviceKey
983
- }, {
984
- file: "device-invitations-handler.ts",
985
- line: 141,
986
- scope: this,
987
- callSite: (f, a) => f(...a)
988
- });
989
- observable.callback.onSuccess(invitation);
990
- } catch (err) {
991
- if (!observable.cancelled) {
992
- log4.error("failed", err, {
993
- file: "device-invitations-handler.ts",
994
- line: 145,
995
- scope: this,
996
- callSite: (f, a) => f(...a)
997
- });
998
- observable.callback.onError(err);
999
- }
1000
- } finally {
1001
- await sleep(ON_CLOSE_DELAY);
1002
- await ctx.dispose();
1003
- }
1004
- });
1005
- }
1006
- });
1007
- scheduleTask(ctx, async () => {
1008
- var _a, _b;
1009
- const topic = invitation.swarmKey;
1010
- const swarmConnection = await this._networkManager.joinSwarm({
1011
- topic,
1012
- peerId: topic,
1013
- protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1014
- teleport.addExtension("dxos.halo.invitations", createExtension());
1015
- }),
1016
- topology: new StarTopology(topic)
1017
- });
1018
- ctx.onDispose(() => swarmConnection.close());
1019
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1020
- });
1021
- return observable;
874
+ toJSON() {
875
+ return {};
1022
876
  }
1023
- /**
1024
- * Waits for the host peer (inviter) to accept our join request.
1025
- * The local guest peer (invitee) then sends the local halo invitation to the host,
1026
- * which then writes the guest's credentials to the halo.
1027
- */
1028
- acceptInvitation(invitation, options) {
1029
- const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1030
- const ctx = new Context3({
1031
- onError: (err) => {
1032
- void ctx.dispose();
1033
- observable.callback.onError(err);
1034
- }
1035
- });
1036
- const authenticated = new Trigger2();
1037
- const observable = new AuthenticatingInvitationProvider({
1038
- onCancel: async () => {
1039
- await ctx.dispose();
1040
- },
1041
- // TODO(burdon): Consider retry.
1042
- onAuthenticate: async (code) => {
1043
- authenticated.wake(code);
1044
- }
1045
- });
1046
- let connectionCount = 0;
1047
- const complete = new Trigger2();
1048
- const createExtension = () => {
1049
- const extension = new GuestHaloInvitationExtension({
1050
- onOpen: () => {
1051
- scheduleTask(ctx, async () => {
1052
- var _a, _b, _c, _d;
1053
- try {
1054
- if (++connectionCount > 1) {
1055
- throw new Error(`multiple connections detected: ${connectionCount}`);
1056
- }
1057
- log4("connected", {}, {
1058
- file: "device-invitations-handler.ts",
1059
- line: 216,
1060
- scope: this,
1061
- callSite: (f, a) => f(...a)
1062
- });
1063
- (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1064
- log4("sending admission request", {}, {
1065
- file: "device-invitations-handler.ts",
1066
- line: 220,
1067
- scope: this,
1068
- callSite: (f, a) => f(...a)
1069
- });
1070
- const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = await extension.rpc.HaloHostService.requestAdmission();
1071
- if (invitation.type === void 0 || invitation.type === Invitation.Type.INTERACTIVE) {
1072
- log4("guest waiting for authentication code...", {}, {
1073
- file: "device-invitations-handler.ts",
1074
- line: 227,
1075
- scope: this,
1076
- callSite: (f, a) => f(...a)
1077
- });
1078
- (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1079
- const authenticationCode = await authenticated.wait({
1080
- timeout
1081
- });
1082
- log4("sending authentication request", {}, {
1083
- file: "device-invitations-handler.ts",
1084
- line: 230,
1085
- scope: this,
1086
- callSite: (f, a) => f(...a)
1087
- });
1088
- await extension.rpc.HaloHostService.authenticate({
1089
- authenticationCode
1090
- });
1091
- }
1092
- const deviceKey = await this._params.keyring.createKey();
1093
- const controlFeedKey = await this._params.keyring.createKey();
1094
- const dataFeedKey = await this._params.keyring.createKey();
1095
- log4("presenting admission credentials", {
1096
- identityKey,
1097
- deviceKey,
1098
- controlFeedKey,
1099
- dataFeedKey
1100
- }, {
1101
- file: "device-invitations-handler.ts",
1102
- line: 239,
1103
- scope: this,
1104
- callSite: (f, a) => f(...a)
1105
- });
1106
- await extension.rpc.HaloHostService.presentAdmissionCredentials({
1107
- deviceKey,
1108
- controlFeedKey,
1109
- dataFeedKey
1110
- });
1111
- const identity = await this._params.acceptIdentity({
1112
- identityKey,
1113
- deviceKey,
1114
- haloSpaceKey,
1115
- haloGenesisFeedKey: genesisFeedKey,
1116
- controlFeedKey,
1117
- dataFeedKey,
1118
- controlTimeframe
1119
- });
1120
- log4("admitted by host", {
1121
- guest: identity.deviceKey,
1122
- identityKey
1123
- }, {
1124
- file: "device-invitations-handler.ts",
1125
- line: 259,
1126
- scope: this,
1127
- callSite: (f, a) => f(...a)
1128
- });
1129
- complete.wake(identityKey);
1130
- } catch (err) {
1131
- if (!observable.cancelled) {
1132
- log4.warn("auth failed", err, {
1133
- file: "device-invitations-handler.ts",
1134
- line: 263,
1135
- scope: this,
1136
- callSite: (f, a) => f(...a)
1137
- });
1138
- observable.callback.onError(err);
1139
- }
1140
- } finally {
1141
- await ctx.dispose();
1142
- }
1143
- });
1144
- }
1145
- });
1146
- return extension;
877
+ getInvitationContext() {
878
+ return {
879
+ kind: Invitation.Kind.DEVICE
1147
880
  };
1148
- scheduleTask(ctx, async () => {
1149
- var _a, _b;
1150
- assert4(invitation.swarmKey);
1151
- const topic = invitation.swarmKey;
1152
- const swarmConnection = await this._networkManager.joinSwarm({
1153
- topic,
1154
- peerId: PublicKey4.random(),
1155
- protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1156
- teleport.addExtension("dxos.halo.invitations", createExtension());
1157
- }),
1158
- topology: new StarTopology(topic)
1159
- });
1160
- ctx.onDispose(() => swarmConnection.close());
1161
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1162
- invitation.identityKey = await complete.wait();
1163
- observable.callback.onSuccess(invitation);
1164
- await ctx.dispose();
1165
- });
1166
- return observable;
1167
881
  }
1168
- };
1169
- var HostHaloInvitationExtension = class extends RpcExtension {
1170
- constructor(_callbacks) {
1171
- super({
1172
- exposed: {
1173
- HaloHostService: schema2.getService("dxos.halo.invitations.HaloHostService")
1174
- }
1175
- });
1176
- this._callbacks = _callbacks;
1177
- }
1178
- async getHandlers() {
882
+ async admit(request) {
883
+ assert4(request.device);
884
+ const identity = this._getIdentity();
885
+ await identity.admitDevice(request.device);
1179
886
  return {
1180
- // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1181
- // Perhaps in the future we will have more complex logic here.
1182
- HaloHostService: {
1183
- requestAdmission: async () => {
1184
- return this._callbacks.requestAdmission();
1185
- },
1186
- authenticate: async (credentials) => {
1187
- return this._callbacks.authenticate(credentials);
1188
- },
1189
- // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
1190
- presentAdmissionCredentials: async (credentials) => {
1191
- return this._callbacks.presentAdmissionCredentials(credentials);
1192
- }
887
+ device: {
888
+ identityKey: identity.identityKey,
889
+ haloSpaceKey: identity.haloSpaceKey,
890
+ genesisFeedKey: identity.haloGenesisFeedKey,
891
+ controlTimeframe: identity.controlPipeline.state.timeframe
1193
892
  }
1194
893
  };
1195
894
  }
1196
- async onOpen(context) {
1197
- await super.onOpen(context);
1198
- this._callbacks.onOpen();
1199
- }
1200
- };
1201
- var GuestHaloInvitationExtension = class extends RpcExtension {
1202
- constructor(_callbacks) {
1203
- super({
1204
- requested: {
1205
- HaloHostService: schema2.getService("dxos.halo.invitations.HaloHostService")
1206
- }
1207
- });
1208
- this._callbacks = _callbacks;
1209
- }
1210
- async getHandlers() {
895
+ createIntroduction() {
1211
896
  return {};
1212
897
  }
1213
- async onOpen(context) {
1214
- await super.onOpen(context);
1215
- this._callbacks.onOpen();
1216
- }
1217
- };
1218
-
1219
- // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1220
- import assert5 from "@dxos/node-std/assert";
1221
- import { Stream as Stream7 } from "@dxos/codec-protobuf";
1222
- import { log as log5 } from "@dxos/log";
1223
- import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
1224
- var AbstractInvitationsService = class {
1225
- // prettier-ignore
1226
- constructor(_identityManager, _getInvitationsHandler) {
1227
- this._identityManager = _identityManager;
1228
- this._getInvitationsHandler = _getInvitationsHandler;
1229
- this._createInvitations = /* @__PURE__ */ new Map();
1230
- this._acceptInvitations = /* @__PURE__ */ new Map();
1231
- }
1232
- // TODO(burdon): Guest/host label.
1233
- getLoggingContext() {
1234
- var _a;
898
+ async createAdmissionRequest() {
899
+ const deviceKey = await this._keyring.createKey();
900
+ const controlFeedKey = await this._keyring.createKey();
901
+ const dataFeedKey = await this._keyring.createKey();
1235
902
  return {
1236
- deviceKey: (_a = this._identityManager.identity) == null ? void 0 : _a.deviceKey
903
+ device: {
904
+ deviceKey,
905
+ controlFeedKey,
906
+ dataFeedKey
907
+ }
1237
908
  };
1238
909
  }
1239
- createInvitation(invitation) {
1240
- return new Stream7(({ next, close }) => {
1241
- const invitationsHandler = this._getInvitationsHandler();
1242
- const context = this.getContext(invitation);
1243
- log5("stream opened", this.getLoggingContext(), {
1244
- file: "invitations-service.ts",
1245
- line: 48,
1246
- scope: this,
1247
- callSite: (f, a) => f(...a)
1248
- });
1249
- let invitationId;
1250
- const { type, swarmKey, authMethod } = invitation;
1251
- const observable = invitationsHandler.createInvitation(context, {
1252
- type,
1253
- swarmKey,
1254
- authMethod
1255
- });
1256
- observable.subscribe({
1257
- onConnecting: (invitation2) => {
1258
- assert5(invitation2.invitationId);
1259
- invitationId = invitation2.invitationId;
1260
- this._createInvitations.set(invitation2.invitationId, observable);
1261
- invitation2.state = Invitation2.State.CONNECTING;
1262
- next(invitation2);
1263
- },
1264
- onConnected: (invitation2) => {
1265
- assert5(invitation2.invitationId);
1266
- invitation2.state = Invitation2.State.CONNECTED;
1267
- next(invitation2);
1268
- },
1269
- onAuthenticating: (invitation2) => {
1270
- assert5(invitation2.invitationId);
1271
- invitation2.state = Invitation2.State.AUTHENTICATING;
1272
- next(invitation2);
1273
- },
1274
- onSuccess: (invitation2) => {
1275
- assert5(invitation2.invitationId);
1276
- invitation2.state = Invitation2.State.SUCCESS;
1277
- next(invitation2);
1278
- close();
1279
- },
1280
- onCancelled: () => {
1281
- assert5(invitationId);
1282
- invitation.invitationId = invitationId;
1283
- invitation.state = Invitation2.State.CANCELLED;
1284
- next(invitation);
1285
- close();
1286
- },
1287
- onTimeout: (err) => {
1288
- invitation.state = Invitation2.State.TIMEOUT;
1289
- close(err);
1290
- },
1291
- onError: (err) => {
1292
- invitation.state = Invitation2.State.ERROR;
1293
- close(err);
1294
- }
1295
- });
1296
- return (err) => {
1297
- const context2 = this.getLoggingContext();
1298
- if (err) {
1299
- log5.warn("stream closed", {
1300
- ...context2,
1301
- err
1302
- }, {
1303
- file: "invitations-service.ts",
1304
- line: 97,
1305
- scope: this,
1306
- callSite: (f, a) => f(...a)
1307
- });
1308
- } else {
1309
- log5("stream closed", context2, {
1310
- file: "invitations-service.ts",
1311
- line: 99,
1312
- scope: this,
1313
- callSite: (f, a) => f(...a)
1314
- });
1315
- }
1316
- this._createInvitations.delete(invitation.invitationId);
1317
- };
1318
- });
1319
- }
1320
- acceptInvitation(invitation, options) {
1321
- return new Stream7(({ next, close }) => {
1322
- log5("stream opened", this.getLoggingContext(), {
1323
- file: "invitations-service.ts",
1324
- line: 109,
1325
- scope: this,
1326
- callSite: (f, a) => f(...a)
1327
- });
1328
- const invitationsHandler = this._getInvitationsHandler();
1329
- let invitationId;
1330
- const observable = invitationsHandler.acceptInvitation(invitation, options);
1331
- observable.subscribe({
1332
- onConnecting: (invitation2) => {
1333
- assert5(invitation2.invitationId);
1334
- invitationId = invitation2.invitationId;
1335
- this._acceptInvitations.set(invitation2.invitationId, observable);
1336
- invitation2.state = Invitation2.State.CONNECTING;
1337
- next(invitation2);
1338
- },
1339
- onConnected: (invitation2) => {
1340
- assert5(invitation2.invitationId);
1341
- invitation2.state = Invitation2.State.CONNECTED;
1342
- next(invitation2);
1343
- },
1344
- onAuthenticating: (invitation2) => {
1345
- assert5(invitation2.invitationId);
1346
- invitation2.state = Invitation2.State.AUTHENTICATING;
1347
- next(invitation2);
1348
- },
1349
- onSuccess: (invitation2) => {
1350
- invitation2.state = Invitation2.State.SUCCESS;
1351
- next(invitation2);
1352
- close();
1353
- },
1354
- onCancelled: () => {
1355
- assert5(invitationId);
1356
- invitation.invitationId = invitationId;
1357
- invitation.state = Invitation2.State.CANCELLED;
1358
- next(invitation);
1359
- close();
1360
- },
1361
- onTimeout: (err) => {
1362
- invitation.state = Invitation2.State.TIMEOUT;
1363
- close(err);
1364
- },
1365
- onError: (err) => {
1366
- invitation.state = Invitation2.State.ERROR;
1367
- close(err);
1368
- }
1369
- });
1370
- return (err) => {
1371
- const context = this.getLoggingContext();
1372
- if (err) {
1373
- log5.warn("stream closed", {
1374
- ...context,
1375
- err
1376
- }, {
1377
- file: "invitations-service.ts",
1378
- line: 157,
1379
- scope: this,
1380
- callSite: (f, a) => f(...a)
1381
- });
1382
- } else {
1383
- log5("stream closed", context, {
1384
- file: "invitations-service.ts",
1385
- line: 159,
1386
- scope: this,
1387
- callSite: (f, a) => f(...a)
1388
- });
1389
- }
1390
- this._acceptInvitations.delete(invitation.invitationId);
1391
- };
1392
- });
1393
- }
1394
- async authenticate({ invitationId, authenticationCode }) {
1395
- log5("authenticating...", {}, {
1396
- file: "invitations-service.ts",
1397
- line: 168,
1398
- scope: this,
1399
- callSite: (f, a) => f(...a)
1400
- });
1401
- assert5(invitationId);
1402
- const observable = this._acceptInvitations.get(invitationId);
1403
- if (!observable) {
1404
- log5.warn("invalid invitation", {
1405
- invitationId
1406
- }, {
1407
- file: "invitations-service.ts",
1408
- line: 172,
1409
- scope: this,
1410
- callSite: (f, a) => f(...a)
1411
- });
1412
- } else {
1413
- await observable.authenticate(authenticationCode);
1414
- }
1415
- }
1416
- async cancelInvitation(invitation) {
1417
- var _a;
1418
- log5("cancelling...", {}, {
1419
- file: "invitations-service.ts",
1420
- line: 179,
1421
- scope: this,
1422
- callSite: (f, a) => f(...a)
910
+ async accept(response, request) {
911
+ assert4(response.device);
912
+ const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
913
+ assert4(request.device);
914
+ const { deviceKey, controlFeedKey, dataFeedKey } = request.device;
915
+ await this._acceptIdentity({
916
+ identityKey,
917
+ deviceKey,
918
+ haloSpaceKey,
919
+ haloGenesisFeedKey: genesisFeedKey,
920
+ controlFeedKey,
921
+ dataFeedKey,
922
+ controlTimeframe
1423
923
  });
1424
- assert5(invitation.invitationId);
1425
- const observable = (_a = this._createInvitations.get(invitation.invitationId)) != null ? _a : this._acceptInvitations.get(invitation.invitationId);
1426
- if (!observable) {
1427
- log5.warn("invalid invitation", {
1428
- invitationId: invitation.invitationId
1429
- }, {
1430
- file: "invitations-service.ts",
1431
- line: 184,
1432
- scope: this,
1433
- callSite: (f, a) => f(...a)
1434
- });
1435
- } else {
1436
- await (observable == null ? void 0 : observable.cancel());
1437
- }
1438
- }
1439
- };
1440
-
1441
- // packages/sdk/client-services/src/packlets/invitations/device-invitations-service.ts
1442
- var DeviceInvitationsServiceImpl = class extends AbstractInvitationsService {
1443
- // prettier-ignore
1444
- constructor(identityManager, invitationsHandler) {
1445
- super(identityManager, () => invitationsHandler);
1446
- this.invitationsHandler = invitationsHandler;
1447
- }
1448
- getContext(invitation) {
924
+ return {
925
+ identityKey
926
+ };
1449
927
  }
1450
928
  };
1451
929
 
1452
- // packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts
1453
- import assert6 from "@dxos/node-std/assert";
1454
- import { scheduleTask as scheduleTask2, sleep as sleep2, Trigger as Trigger3 } from "@dxos/async";
1455
- import { AuthenticatingInvitationProvider as AuthenticatingInvitationProvider2, AUTHENTICATION_CODE_LENGTH as AUTHENTICATION_CODE_LENGTH2, InvitationObservableProvider as InvitationObservableProvider2, INVITATION_TIMEOUT as INVITATION_TIMEOUT2, ON_CLOSE_DELAY as ON_CLOSE_DELAY2, AbstractInvitationsHandler as AbstractInvitationsHandler2 } from "@dxos/client";
1456
- import { Context as Context4 } from "@dxos/context";
1457
- import { createAdmissionCredentials, generatePasscode as generatePasscode2, getCredentialAssertion } from "@dxos/credentials";
1458
- import { writeMessages as writeMessages2 } from "@dxos/feed-store";
1459
- import { PublicKey as PublicKey5 } from "@dxos/keys";
1460
- import { log as log6 } from "@dxos/log";
1461
- import { createTeleportProtocolFactory as createTeleportProtocolFactory2, StarTopology as StarTopology2 } from "@dxos/network-manager";
1462
- import { schema as schema3 } from "@dxos/protocols";
1463
- import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1464
- import { AuthenticationResponse as AuthenticationResponse2, AuthMethod } from "@dxos/protocols/proto/dxos/halo/invitations";
1465
- import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
930
+ // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
931
+ import assert5 from "@dxos/node-std/assert";
932
+ import { PushStream, scheduleTask, sleep, TimeoutError, Trigger as Trigger2 } from "@dxos/async";
933
+ import { AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT, ON_CLOSE_DELAY, AuthenticatingInvitationObservable } from "@dxos/client";
934
+ import { Context as Context3 } from "@dxos/context";
935
+ import { generatePasscode } from "@dxos/credentials";
936
+ import { PublicKey as PublicKey4 } from "@dxos/keys";
937
+ import { log as log4 } from "@dxos/log";
938
+ import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
939
+ import { schema as schema2 } from "@dxos/protocols";
940
+ import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
941
+ import { AuthenticationResponse } from "@dxos/protocols/proto/dxos/halo/invitations";
942
+ import { RpcExtension } from "@dxos/teleport";
1466
943
  var MAX_OTP_ATTEMPTS = 3;
1467
- var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1468
- constructor(networkManager, _spaceManager, _signingContext, _keyring) {
1469
- super(networkManager);
1470
- this._spaceManager = _spaceManager;
1471
- this._signingContext = _signingContext;
1472
- this._keyring = _keyring;
944
+ var InvitationsHandler = class {
945
+ constructor(_networkManager) {
946
+ this._networkManager = _networkManager;
1473
947
  }
1474
- /**
1475
- * Creates an invitation and listens for a join request from the invited (guest) peer.
1476
- */
1477
- createInvitation(space, options) {
948
+ createInvitation(protocol, options) {
1478
949
  var _a;
1479
- let swarmConnection;
1480
- const { type, timeout = INVITATION_TIMEOUT2, swarmKey } = options != null ? options : {};
1481
- assert6(type !== Invitation3.Type.OFFLINE);
1482
- assert6(space);
950
+ const { invitationId = PublicKey4.random().toHex(), type = Invitation2.Type.INTERACTIVE, authMethod = Invitation2.AuthMethod.SHARED_SECRET, state = Invitation2.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey4.random() } = options != null ? options : {};
951
+ const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation2.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
952
+ assert5(protocol);
1483
953
  const invitation = {
954
+ invitationId,
1484
955
  type,
1485
- invitationId: PublicKey5.random().toHex(),
1486
- swarmKey: swarmKey != null ? swarmKey : PublicKey5.random(),
1487
- spaceKey: space.key,
1488
- authMethod: (_a = options == null ? void 0 : options.authMethod) != null ? _a : AuthMethod.SHARED_SECRET,
1489
- authenticationCode: generatePasscode2(AUTHENTICATION_CODE_LENGTH2)
1490
- // TODO(dmaretskyi): Don't generate if authMethod === NONE .
956
+ authMethod,
957
+ state,
958
+ swarmKey,
959
+ authCode,
960
+ timeout,
961
+ ...protocol.getInvitationContext()
1491
962
  };
1492
- const ctx = new Context4({
963
+ const stream = new PushStream();
964
+ const ctx = new Context3({
1493
965
  onError: (err) => {
1494
966
  void ctx.dispose();
1495
- observable.callback.onError(err);
967
+ stream.error(err);
1496
968
  }
1497
969
  });
1498
- const observable = new InvitationObservableProvider2(async () => {
1499
- await (swarmConnection == null ? void 0 : swarmConnection.close());
970
+ ctx.onDispose(() => {
971
+ log4("complete", {
972
+ ...protocol.toJSON()
973
+ }, {
974
+ file: "invitations-handler.ts",
975
+ line: 102,
976
+ scope: this,
977
+ callSite: (f, a) => f(...a)
978
+ });
979
+ stream.complete();
1500
980
  });
1501
- let authenticationPassed = false;
1502
- let authenticationRetry = 0;
1503
981
  const createExtension = () => {
1504
- const complete = new Trigger3();
982
+ const success = new Trigger2();
1505
983
  let guestProfile;
1506
- const hostInvitationExtension = new HostSpaceInvitationExtension({
984
+ let authenticationPassed = false;
985
+ let authenticationRetry = 0;
986
+ const extension = new InvitationHostExtension({
1507
987
  introduce: async ({ profile }) => {
1508
- var _a2, _b;
1509
- log6("guest introduced itself", {
988
+ log4("guest introduced itself", {
1510
989
  guestProfile: profile,
1511
- host: this._signingContext.deviceKey,
1512
- spaceKey: space.key
990
+ ...protocol.toJSON()
1513
991
  }, {
1514
- file: "space-invitations-handler.ts",
1515
- line: 101,
992
+ file: "invitations-handler.ts",
993
+ line: 115,
1516
994
  scope: this,
1517
995
  callSite: (f, a) => f(...a)
1518
996
  });
1519
997
  guestProfile = profile;
1520
- (_b = (_a2 = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a2, invitation);
998
+ stream.next({
999
+ ...invitation,
1000
+ state: Invitation2.State.READY_FOR_AUTHENTICATION
1001
+ });
1521
1002
  return {
1522
- spaceKey: type === Invitation3.Type.INTERACTIVE_TESTING || type === Invitation3.Type.MULTIUSE_TESTING ? space.key : void 0,
1523
- authMethod: invitation.authMethod
1003
+ spaceKey: authMethod === Invitation2.AuthMethod.NONE ? protocol.getInvitationContext().spaceKey : void 0,
1004
+ authMethod
1524
1005
  };
1525
1006
  },
1526
- authenticate: async ({ authenticationCode: code }) => {
1527
- log6("received authentication request", {
1528
- authenticationCode: code
1007
+ authenticate: async ({ authCode: code }) => {
1008
+ log4("received authentication request", {
1009
+ authCode: code
1529
1010
  }, {
1530
- file: "space-invitations-handler.ts",
1531
- line: 123,
1011
+ file: "invitations-handler.ts",
1012
+ line: 134,
1532
1013
  scope: this,
1533
1014
  callSite: (f, a) => f(...a)
1534
1015
  });
1535
- let status = AuthenticationResponse2.Status.OK;
1016
+ let status = AuthenticationResponse.Status.OK;
1536
1017
  switch (invitation.authMethod) {
1537
- case AuthMethod.NONE: {
1538
- log6("authentication not required", {}, {
1539
- file: "space-invitations-handler.ts",
1540
- line: 128,
1018
+ case Invitation2.AuthMethod.NONE: {
1019
+ log4("authentication not required", {}, {
1020
+ file: "invitations-handler.ts",
1021
+ line: 139,
1541
1022
  scope: this,
1542
1023
  callSite: (f, a) => f(...a)
1543
1024
  });
1544
1025
  return {
1545
- status: AuthenticationResponse2.Status.OK
1026
+ status: AuthenticationResponse.Status.OK
1546
1027
  };
1547
1028
  }
1548
- case AuthMethod.SHARED_SECRET: {
1549
- if (invitation.authenticationCode) {
1029
+ case Invitation2.AuthMethod.SHARED_SECRET: {
1030
+ if (invitation.authCode) {
1550
1031
  if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1551
- status = AuthenticationResponse2.Status.INVALID_OPT_ATTEMPTS;
1552
- } else if (code !== invitation.authenticationCode) {
1553
- status = AuthenticationResponse2.Status.INVALID_OTP;
1032
+ status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1033
+ } else if (code !== invitation.authCode) {
1034
+ status = AuthenticationResponse.Status.INVALID_OTP;
1554
1035
  } else {
1555
1036
  authenticationPassed = true;
1556
1037
  }
@@ -1558,15 +1039,15 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1558
1039
  break;
1559
1040
  }
1560
1041
  default: {
1561
- log6.error("invalid authentication method", {
1042
+ log4.error("invalid authentication method", {
1562
1043
  authMethod: invitation.authMethod
1563
1044
  }, {
1564
- file: "space-invitations-handler.ts",
1565
- line: 144,
1045
+ file: "invitations-handler.ts",
1046
+ line: 157,
1566
1047
  scope: this,
1567
1048
  callSite: (f, a) => f(...a)
1568
1049
  });
1569
- status = AuthenticationResponse2.Status.INTERNAL_ERROR;
1050
+ status = AuthenticationResponse.Status.INTERNAL_ERROR;
1570
1051
  break;
1571
1052
  }
1572
1053
  }
@@ -1574,159 +1055,196 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1574
1055
  status
1575
1056
  };
1576
1057
  },
1577
- requestAdmission: async ({ identityKey, deviceKey, controlFeedKey, dataFeedKey }) => {
1578
- var _a2;
1058
+ admit: async (admissionRequest) => {
1059
+ var _a2, _b, _c;
1579
1060
  try {
1580
1061
  if (isAuthenticationRequired(invitation) && !authenticationPassed) {
1581
1062
  throw new Error("Not authenticated");
1582
1063
  }
1583
- log6("writing guest credentials", {
1584
- host: this._signingContext.deviceKey,
1585
- guest: deviceKey
1586
- }, {
1587
- file: "space-invitations-handler.ts",
1588
- line: 160,
1589
- scope: this,
1590
- callSite: (f, a) => f(...a)
1591
- });
1592
- const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1593
- assert6(credentials[0].credential);
1594
- const spaceMemberCredential = credentials[0].credential.credential;
1595
- assert6(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1596
- await writeMessages2(space.inner.controlPipeline.writer, credentials);
1597
- complete.wake(deviceKey);
1598
- return {
1599
- credential: spaceMemberCredential,
1600
- controlTimeframe: space.inner.controlPipeline.state.timeframe,
1601
- dataTimeframe: (_a2 = space.dataPipeline.pipelineState) == null ? void 0 : _a2.timeframe
1602
- };
1064
+ const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1065
+ assert5(deviceKey);
1066
+ const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
1067
+ success.wake(deviceKey);
1068
+ return admissionResponse;
1603
1069
  } catch (err) {
1604
- observable.callback.onError(err);
1070
+ stream.error(err);
1605
1071
  throw err;
1606
1072
  }
1607
1073
  },
1608
1074
  onOpen: () => {
1609
- scheduleTask2(ctx, async () => {
1610
- var _a2, _b;
1075
+ scheduleTask(ctx, async () => {
1611
1076
  try {
1612
- log6("connected", {
1613
- host: this._signingContext.deviceKey
1077
+ log4("connected", {
1078
+ ...protocol.toJSON()
1614
1079
  }, {
1615
- file: "space-invitations-handler.ts",
1616
- line: 195,
1080
+ file: "invitations-handler.ts",
1081
+ line: 191,
1617
1082
  scope: this,
1618
1083
  callSite: (f, a) => f(...a)
1619
1084
  });
1620
- (_b = (_a2 = observable.callback).onConnected) == null ? void 0 : _b.call(_a2, invitation);
1621
- const deviceKey = await complete.wait({
1085
+ stream.next({
1086
+ ...invitation,
1087
+ state: Invitation2.State.CONNECTED
1088
+ });
1089
+ const deviceKey = await success.wait({
1622
1090
  timeout
1623
1091
  });
1624
- log6("admitted guest", {
1625
- host: this._signingContext.deviceKey,
1626
- guest: deviceKey
1092
+ log4("admitted guest", {
1093
+ guest: deviceKey,
1094
+ ...protocol.toJSON()
1627
1095
  }, {
1628
- file: "space-invitations-handler.ts",
1629
- line: 198,
1096
+ file: "invitations-handler.ts",
1097
+ line: 194,
1630
1098
  scope: this,
1631
1099
  callSite: (f, a) => f(...a)
1632
1100
  });
1633
- observable.callback.onSuccess(invitation);
1101
+ stream.next({
1102
+ ...invitation,
1103
+ state: Invitation2.State.SUCCESS
1104
+ });
1634
1105
  } catch (err) {
1635
- if (!observable.cancelled) {
1636
- log6.error("failed", err, {
1637
- file: "space-invitations-handler.ts",
1638
- line: 202,
1106
+ if (err instanceof TimeoutError) {
1107
+ log4("timeout", {
1108
+ ...protocol.toJSON()
1109
+ }, {
1110
+ file: "invitations-handler.ts",
1111
+ line: 198,
1639
1112
  scope: this,
1640
1113
  callSite: (f, a) => f(...a)
1641
1114
  });
1642
- observable.callback.onError(err);
1115
+ stream.next({
1116
+ ...invitation,
1117
+ state: Invitation2.State.TIMEOUT
1118
+ });
1119
+ } else {
1120
+ log4.error("failed", err, {
1121
+ file: "invitations-handler.ts",
1122
+ line: 201,
1123
+ scope: this,
1124
+ callSite: (f, a) => f(...a)
1125
+ });
1126
+ stream.error(err);
1643
1127
  }
1644
1128
  } finally {
1645
- if (type !== Invitation3.Type.MULTIUSE_TESTING) {
1646
- await sleep2(ON_CLOSE_DELAY2);
1129
+ if (type !== Invitation2.Type.MULTIUSE) {
1130
+ await sleep(ON_CLOSE_DELAY);
1647
1131
  await ctx.dispose();
1648
1132
  }
1649
1133
  }
1650
1134
  });
1651
1135
  }
1652
1136
  });
1653
- return hostInvitationExtension;
1137
+ return extension;
1654
1138
  };
1655
- scheduleTask2(ctx, async () => {
1656
- var _a2, _b;
1139
+ scheduleTask(ctx, async () => {
1657
1140
  const topic = invitation.swarmKey;
1658
- const swarmConnection2 = await this._networkManager.joinSwarm({
1141
+ const swarmConnection = await this._networkManager.joinSwarm({
1659
1142
  topic,
1660
1143
  peerId: topic,
1661
- protocolProvider: createTeleportProtocolFactory2(async (teleport) => {
1144
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1662
1145
  teleport.addExtension("dxos.halo.invitations", createExtension());
1663
1146
  }),
1664
- topology: new StarTopology2(topic)
1147
+ topology: new StarTopology(topic)
1148
+ });
1149
+ ctx.onDispose(() => swarmConnection.close());
1150
+ stream.next({
1151
+ ...invitation,
1152
+ state: Invitation2.State.CONNECTING
1665
1153
  });
1666
- ctx.onDispose(() => swarmConnection2.close());
1667
- (_b = (_a2 = observable.callback).onConnecting) == null ? void 0 : _b.call(_a2, invitation);
1154
+ });
1155
+ const observable = new CancellableInvitationObservable({
1156
+ initialInvitation: invitation,
1157
+ subscriber: stream.observable,
1158
+ onCancel: async () => {
1159
+ stream.next({
1160
+ ...invitation,
1161
+ state: Invitation2.State.CANCELLED
1162
+ });
1163
+ await ctx.dispose();
1164
+ }
1668
1165
  });
1669
1166
  return observable;
1670
1167
  }
1671
- /**
1672
- * Waits for the host peer (inviter) to accept our join request.
1673
- * The local guest peer (invitee) then sends the local space invitation to the host,
1674
- * which then writes the guest's credentials to the space.
1675
- */
1676
- acceptInvitation(invitation, options) {
1677
- const { timeout = INVITATION_TIMEOUT2 } = options != null ? options : {};
1678
- const ctx = new Context4({
1168
+ acceptInvitation(protocol, invitation) {
1169
+ const { timeout = INVITATION_TIMEOUT } = invitation;
1170
+ assert5(protocol);
1171
+ const authenticated = new Trigger2();
1172
+ const stream = new PushStream();
1173
+ const ctx = new Context3({
1679
1174
  onError: (err) => {
1175
+ if (err instanceof TimeoutError) {
1176
+ log4("timeout", {
1177
+ ...protocol.toJSON()
1178
+ }, {
1179
+ file: "invitations-handler.ts",
1180
+ line: 255,
1181
+ scope: this,
1182
+ callSite: (f, a) => f(...a)
1183
+ });
1184
+ stream.next({
1185
+ ...invitation,
1186
+ state: Invitation2.State.TIMEOUT
1187
+ });
1188
+ } else {
1189
+ log4.warn("auth failed", err, {
1190
+ file: "invitations-handler.ts",
1191
+ line: 258,
1192
+ scope: this,
1193
+ callSite: (f, a) => f(...a)
1194
+ });
1195
+ stream.error(err);
1196
+ }
1680
1197
  void ctx.dispose();
1681
- observable.callback.onError(err);
1682
1198
  }
1683
1199
  });
1684
- const authenticated = new Trigger3();
1685
- const observable = new AuthenticatingInvitationProvider2({
1686
- onCancel: async () => {
1687
- await ctx.dispose();
1688
- },
1689
- onAuthenticate: async (code) => {
1690
- authenticated.wake(code);
1691
- }
1200
+ ctx.onDispose(() => {
1201
+ log4("complete", {
1202
+ ...protocol.toJSON()
1203
+ }, {
1204
+ file: "invitations-handler.ts",
1205
+ line: 266,
1206
+ scope: this,
1207
+ callSite: (f, a) => f(...a)
1208
+ });
1209
+ stream.complete();
1692
1210
  });
1693
- let connectionCount = 0;
1694
- const complete = new Trigger3();
1695
1211
  const createExtension = () => {
1696
- const extension = new GuestSpaceInvitationExtension({
1212
+ let connectionCount = 0;
1213
+ const extension = new InvitationGuestExtension({
1697
1214
  onOpen: () => {
1698
- scheduleTask2(ctx, async () => {
1699
- var _a, _b, _c, _d, _e, _f;
1215
+ scheduleTask(ctx, async () => {
1700
1216
  try {
1701
1217
  if (++connectionCount > 1) {
1702
1218
  throw new Error(`multiple connections detected: ${connectionCount}`);
1703
1219
  }
1704
- log6("connected", {
1705
- guest: this._signingContext.deviceKey
1220
+ scheduleTask(ctx, () => ctx.raise(new TimeoutError(timeout)), timeout);
1221
+ log4("connected", {
1222
+ ...protocol.toJSON()
1706
1223
  }, {
1707
- file: "space-invitations-handler.ts",
1708
- line: 275,
1224
+ file: "invitations-handler.ts",
1225
+ line: 284,
1709
1226
  scope: this,
1710
1227
  callSite: (f, a) => f(...a)
1711
1228
  });
1712
- (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1713
- log6("introduce", {
1714
- guest: this._signingContext.deviceKey
1229
+ stream.next({
1230
+ ...invitation,
1231
+ state: Invitation2.State.CONNECTED
1232
+ });
1233
+ log4("introduce", {
1234
+ ...protocol.toJSON()
1715
1235
  }, {
1716
- file: "space-invitations-handler.ts",
1717
- line: 279,
1236
+ file: "invitations-handler.ts",
1237
+ line: 288,
1718
1238
  scope: this,
1719
1239
  callSite: (f, a) => f(...a)
1720
1240
  });
1721
- const introductionResponse = await extension.rpc.SpaceHostService.introduce({
1722
- profile: this._signingContext.profile
1723
- });
1724
- log6("introduce response", {
1725
- guest: this._signingContext.deviceKey,
1241
+ const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
1242
+ log4("introduce response", {
1243
+ ...protocol.toJSON(),
1726
1244
  response: introductionResponse
1727
1245
  }, {
1728
- file: "space-invitations-handler.ts",
1729
- line: 283,
1246
+ file: "invitations-handler.ts",
1247
+ line: 292,
1730
1248
  scope: this,
1731
1249
  callSite: (f, a) => f(...a)
1732
1250
  });
@@ -1735,39 +1253,45 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1735
1253
  invitation.spaceKey = introductionResponse.spaceKey;
1736
1254
  }
1737
1255
  if (isAuthenticationRequired(invitation)) {
1738
- (_d = (_c = observable.callback).onAuthenticating) == null ? void 0 : _d.call(_c, invitation);
1739
1256
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1740
- log6("guest waiting for authentication code...", {}, {
1741
- file: "space-invitations-handler.ts",
1742
- line: 297,
1257
+ log4("guest waiting for authentication code...", {}, {
1258
+ file: "invitations-handler.ts",
1259
+ line: 301,
1743
1260
  scope: this,
1744
1261
  callSite: (f, a) => f(...a)
1745
1262
  });
1746
- (_f = (_e = observable.callback).onAuthenticating) == null ? void 0 : _f.call(_e, invitation);
1747
- const authenticationCode = await authenticated.wait({
1263
+ stream.next({
1264
+ ...invitation,
1265
+ state: Invitation2.State.READY_FOR_AUTHENTICATION
1266
+ });
1267
+ const authCode = await authenticated.wait({
1748
1268
  timeout
1749
1269
  });
1750
- log6("sending authentication request", {}, {
1751
- file: "space-invitations-handler.ts",
1752
- line: 301,
1270
+ log4("sending authentication request", {}, {
1271
+ file: "invitations-handler.ts",
1272
+ line: 305,
1753
1273
  scope: this,
1754
1274
  callSite: (f, a) => f(...a)
1755
1275
  });
1756
- const response = await extension.rpc.SpaceHostService.authenticate({
1757
- authenticationCode
1276
+ stream.next({
1277
+ ...invitation,
1278
+ state: Invitation2.State.AUTHENTICATING
1758
1279
  });
1759
- if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
1280
+ const response = await extension.rpc.InvitationHostService.authenticate({
1281
+ authCode
1282
+ });
1283
+ if (response.status === void 0 || response.status === AuthenticationResponse.Status.OK) {
1760
1284
  break;
1761
1285
  }
1762
- if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
1286
+ if (response.status === AuthenticationResponse.Status.INVALID_OTP) {
1763
1287
  if (attempt === MAX_OTP_ATTEMPTS) {
1764
1288
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1765
1289
  } else {
1766
- log6("retrying invalid code", {
1290
+ log4("retrying invalid code", {
1767
1291
  attempt
1768
1292
  }, {
1769
- file: "space-invitations-handler.ts",
1770
- line: 311,
1293
+ file: "invitations-handler.ts",
1294
+ line: 316,
1771
1295
  scope: this,
1772
1296
  callSite: (f, a) => f(...a)
1773
1297
  });
@@ -1775,52 +1299,58 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1775
1299
  }
1776
1300
  }
1777
1301
  }
1302
+ } else {
1303
+ stream.next({
1304
+ ...invitation,
1305
+ state: Invitation2.State.READY_FOR_AUTHENTICATION
1306
+ });
1778
1307
  }
1779
- const controlFeedKey = await this._keyring.createKey();
1780
- const dataFeedKey = await this._keyring.createKey();
1781
- log6("request admission", {
1782
- guest: this._signingContext.deviceKey
1308
+ log4("request admission", {
1309
+ ...protocol.toJSON()
1783
1310
  }, {
1784
- file: "space-invitations-handler.ts",
1785
- line: 322,
1311
+ file: "invitations-handler.ts",
1312
+ line: 327,
1786
1313
  scope: this,
1787
1314
  callSite: (f, a) => f(...a)
1788
1315
  });
1789
- const { credential, controlTimeframe, dataTimeframe } = await extension.rpc.SpaceHostService.requestAdmission({
1790
- identityKey: this._signingContext.identityKey,
1791
- deviceKey: this._signingContext.deviceKey,
1792
- controlFeedKey,
1793
- dataFeedKey
1794
- });
1795
- const assertion = getCredentialAssertion(credential);
1796
- assert6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1797
- assert6(credential.subject.id.equals(this._signingContext.identityKey));
1798
- const space = await this._spaceManager.acceptSpace({
1799
- spaceKey: assertion.spaceKey,
1800
- genesisFeedKey: assertion.genesisFeedKey,
1801
- controlTimeframe,
1802
- dataTimeframe
1803
- });
1804
- await this._signingContext.recordCredential(credential);
1805
- log6("admitted by host", {
1806
- guest: this._signingContext.deviceKey,
1807
- spaceKey: space.key
1316
+ const admissionRequest = await protocol.createAdmissionRequest();
1317
+ const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
1318
+ const result = await protocol.accept(admissionResponse, admissionRequest);
1319
+ log4("admitted by host", {
1320
+ ...protocol.toJSON()
1808
1321
  }, {
1809
- file: "space-invitations-handler.ts",
1810
- line: 347,
1322
+ file: "invitations-handler.ts",
1323
+ line: 335,
1811
1324
  scope: this,
1812
1325
  callSite: (f, a) => f(...a)
1813
1326
  });
1814
- complete.wake();
1327
+ stream.next({
1328
+ ...invitation,
1329
+ ...result,
1330
+ state: Invitation2.State.SUCCESS
1331
+ });
1815
1332
  } catch (err) {
1816
- if (!observable.cancelled) {
1817
- log6.warn("auth failed", err, {
1818
- file: "space-invitations-handler.ts",
1819
- line: 351,
1333
+ if (err instanceof TimeoutError) {
1334
+ log4("timeout", {
1335
+ ...protocol.toJSON()
1336
+ }, {
1337
+ file: "invitations-handler.ts",
1338
+ line: 339,
1820
1339
  scope: this,
1821
1340
  callSite: (f, a) => f(...a)
1822
1341
  });
1823
- observable.callback.onError(err);
1342
+ stream.next({
1343
+ ...invitation,
1344
+ state: Invitation2.State.TIMEOUT
1345
+ });
1346
+ } else {
1347
+ log4.warn("auth failed", err, {
1348
+ file: "invitations-handler.ts",
1349
+ line: 342,
1350
+ scope: this,
1351
+ callSite: (f, a) => f(...a)
1352
+ });
1353
+ stream.error(err);
1824
1354
  }
1825
1355
  } finally {
1826
1356
  await ctx.dispose();
@@ -1830,33 +1360,46 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1830
1360
  });
1831
1361
  return extension;
1832
1362
  };
1833
- scheduleTask2(ctx, async () => {
1834
- var _a, _b;
1835
- assert6(invitation.swarmKey);
1363
+ scheduleTask(ctx, async () => {
1364
+ assert5(invitation.swarmKey);
1836
1365
  const topic = invitation.swarmKey;
1837
1366
  const swarmConnection = await this._networkManager.joinSwarm({
1838
1367
  topic,
1839
- peerId: PublicKey5.random(),
1840
- protocolProvider: createTeleportProtocolFactory2(async (teleport) => {
1368
+ peerId: PublicKey4.random(),
1369
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1841
1370
  teleport.addExtension("dxos.halo.invitations", createExtension());
1842
1371
  }),
1843
- topology: new StarTopology2(topic)
1372
+ topology: new StarTopology(topic)
1844
1373
  });
1845
1374
  ctx.onDispose(() => swarmConnection.close());
1846
- (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1847
- await complete.wait();
1848
- observable.callback.onSuccess(invitation);
1849
- await ctx.dispose();
1375
+ stream.next({
1376
+ ...invitation,
1377
+ state: Invitation2.State.CONNECTING
1378
+ });
1379
+ });
1380
+ const observable = new AuthenticatingInvitationObservable({
1381
+ initialInvitation: invitation,
1382
+ subscriber: stream.observable,
1383
+ onCancel: async () => {
1384
+ stream.next({
1385
+ ...invitation,
1386
+ state: Invitation2.State.CANCELLED
1387
+ });
1388
+ await ctx.dispose();
1389
+ },
1390
+ onAuthenticate: async (code) => {
1391
+ authenticated.wake(code);
1392
+ }
1850
1393
  });
1851
1394
  return observable;
1852
1395
  }
1853
1396
  };
1854
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== AuthMethod.NONE && invitation.type !== Invitation3.Type.INTERACTIVE_TESTING && invitation.type !== Invitation3.Type.MULTIUSE_TESTING;
1855
- var HostSpaceInvitationExtension = class extends RpcExtension2 {
1397
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
1398
+ var InvitationHostExtension = class extends RpcExtension {
1856
1399
  constructor(_callbacks) {
1857
1400
  super({
1858
1401
  exposed: {
1859
- SpaceHostService: schema3.getService("dxos.halo.invitations.SpaceHostService")
1402
+ InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
1860
1403
  }
1861
1404
  });
1862
1405
  this._callbacks = _callbacks;
@@ -1865,15 +1408,15 @@ var HostSpaceInvitationExtension = class extends RpcExtension2 {
1865
1408
  return {
1866
1409
  // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1867
1410
  // Perhaps in the future we will have more complex logic here.
1868
- SpaceHostService: {
1869
- introduce: async (params) => {
1870
- return this._callbacks.introduce(params);
1411
+ InvitationHostService: {
1412
+ introduce: async (request) => {
1413
+ return this._callbacks.introduce(request);
1871
1414
  },
1872
- authenticate: async (credentials) => {
1873
- return this._callbacks.authenticate(credentials);
1415
+ authenticate: async (request) => {
1416
+ return this._callbacks.authenticate(request);
1874
1417
  },
1875
- requestAdmission: async (credentials) => {
1876
- return this._callbacks.requestAdmission(credentials);
1418
+ admit: async (request) => {
1419
+ return this._callbacks.admit(request);
1877
1420
  }
1878
1421
  }
1879
1422
  };
@@ -1883,11 +1426,11 @@ var HostSpaceInvitationExtension = class extends RpcExtension2 {
1883
1426
  this._callbacks.onOpen();
1884
1427
  }
1885
1428
  };
1886
- var GuestSpaceInvitationExtension = class extends RpcExtension2 {
1429
+ var InvitationGuestExtension = class extends RpcExtension {
1887
1430
  constructor(_callbacks) {
1888
1431
  super({
1889
1432
  requested: {
1890
- SpaceHostService: schema3.getService("dxos.halo.invitations.SpaceHostService")
1433
+ InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
1891
1434
  }
1892
1435
  });
1893
1436
  this._callbacks = _callbacks;
@@ -1901,21 +1444,333 @@ var GuestSpaceInvitationExtension = class extends RpcExtension2 {
1901
1444
  }
1902
1445
  };
1903
1446
 
1904
- // packages/sdk/client-services/src/packlets/invitations/space-invitations-service.ts
1447
+ // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1448
+ import assert6 from "@dxos/node-std/assert";
1449
+ import { Stream as Stream7 } from "@dxos/codec-protobuf";
1450
+ import { log as log5 } from "@dxos/log";
1451
+ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1452
+ var InvitationsServiceImpl = class {
1453
+ constructor(_invitationsHandler, _getHandler) {
1454
+ this._invitationsHandler = _invitationsHandler;
1455
+ this._getHandler = _getHandler;
1456
+ this._createInvitations = /* @__PURE__ */ new Map();
1457
+ this._acceptInvitations = /* @__PURE__ */ new Map();
1458
+ }
1459
+ // TODO(burdon): Guest/host label.
1460
+ getLoggingContext() {
1461
+ return {};
1462
+ }
1463
+ createInvitation(invitation) {
1464
+ return new Stream7(({ next, close }) => {
1465
+ const handler = this._getHandler(invitation);
1466
+ log5("stream opened", this.getLoggingContext(), {
1467
+ file: "invitations-service.ts",
1468
+ line: 37,
1469
+ scope: this,
1470
+ callSite: (f, a) => f(...a)
1471
+ });
1472
+ let invitationId;
1473
+ const observable = this._invitationsHandler.createInvitation(handler, invitation);
1474
+ observable.subscribe((invitation2) => {
1475
+ switch (invitation2.state) {
1476
+ case Invitation3.State.CONNECTING: {
1477
+ assert6(invitation2.invitationId);
1478
+ invitationId = invitation2.invitationId;
1479
+ this._createInvitations.set(invitation2.invitationId, observable);
1480
+ invitation2.state = Invitation3.State.CONNECTING;
1481
+ next(invitation2);
1482
+ break;
1483
+ }
1484
+ case Invitation3.State.CONNECTED: {
1485
+ assert6(invitation2.invitationId);
1486
+ invitation2.state = Invitation3.State.CONNECTED;
1487
+ next(invitation2);
1488
+ break;
1489
+ }
1490
+ case Invitation3.State.READY_FOR_AUTHENTICATION: {
1491
+ assert6(invitation2.invitationId);
1492
+ invitation2.state = Invitation3.State.READY_FOR_AUTHENTICATION;
1493
+ next(invitation2);
1494
+ break;
1495
+ }
1496
+ case Invitation3.State.AUTHENTICATING: {
1497
+ assert6(invitation2.invitationId);
1498
+ invitation2.state = Invitation3.State.AUTHENTICATING;
1499
+ next(invitation2);
1500
+ break;
1501
+ }
1502
+ case Invitation3.State.SUCCESS: {
1503
+ assert6(invitation2.invitationId);
1504
+ invitation2.state = Invitation3.State.SUCCESS;
1505
+ next(invitation2);
1506
+ break;
1507
+ }
1508
+ case Invitation3.State.CANCELLED: {
1509
+ assert6(invitationId);
1510
+ invitation2.invitationId = invitationId;
1511
+ invitation2.state = Invitation3.State.CANCELLED;
1512
+ next(invitation2);
1513
+ break;
1514
+ }
1515
+ case Invitation3.State.TIMEOUT: {
1516
+ assert6(invitationId);
1517
+ invitation2.invitationId = invitationId;
1518
+ invitation2.state = Invitation3.State.TIMEOUT;
1519
+ next(invitation2);
1520
+ break;
1521
+ }
1522
+ }
1523
+ }, (err) => {
1524
+ close(err);
1525
+ }, () => {
1526
+ close();
1527
+ });
1528
+ return (err) => {
1529
+ const context = this.getLoggingContext();
1530
+ if (err) {
1531
+ log5.warn("stream closed", {
1532
+ ...context,
1533
+ err
1534
+ }, {
1535
+ file: "invitations-service.ts",
1536
+ line: 103,
1537
+ scope: this,
1538
+ callSite: (f, a) => f(...a)
1539
+ });
1540
+ } else {
1541
+ log5("stream closed", context, {
1542
+ file: "invitations-service.ts",
1543
+ line: 105,
1544
+ scope: this,
1545
+ callSite: (f, a) => f(...a)
1546
+ });
1547
+ }
1548
+ this._createInvitations.delete(invitation.invitationId);
1549
+ };
1550
+ });
1551
+ }
1552
+ acceptInvitation(invitation) {
1553
+ return new Stream7(({ next, close }) => {
1554
+ log5("stream opened", this.getLoggingContext(), {
1555
+ file: "invitations-service.ts",
1556
+ line: 115,
1557
+ scope: this,
1558
+ callSite: (f, a) => f(...a)
1559
+ });
1560
+ const handler = this._getHandler(invitation);
1561
+ let invitationId;
1562
+ const observable = this._invitationsHandler.acceptInvitation(handler, invitation);
1563
+ observable.subscribe((invitation2) => {
1564
+ switch (invitation2.state) {
1565
+ case Invitation3.State.CONNECTING: {
1566
+ assert6(invitation2.invitationId);
1567
+ invitationId = invitation2.invitationId;
1568
+ this._acceptInvitations.set(invitation2.invitationId, observable);
1569
+ invitation2.state = Invitation3.State.CONNECTING;
1570
+ next(invitation2);
1571
+ break;
1572
+ }
1573
+ case Invitation3.State.CONNECTED: {
1574
+ assert6(invitation2.invitationId);
1575
+ invitation2.state = Invitation3.State.CONNECTED;
1576
+ next(invitation2);
1577
+ break;
1578
+ }
1579
+ case Invitation3.State.READY_FOR_AUTHENTICATION: {
1580
+ assert6(invitation2.invitationId);
1581
+ invitation2.state = Invitation3.State.READY_FOR_AUTHENTICATION;
1582
+ next(invitation2);
1583
+ break;
1584
+ }
1585
+ case Invitation3.State.AUTHENTICATING: {
1586
+ assert6(invitation2.invitationId);
1587
+ invitation2.state = Invitation3.State.AUTHENTICATING;
1588
+ next(invitation2);
1589
+ break;
1590
+ }
1591
+ case Invitation3.State.SUCCESS: {
1592
+ invitation2.state = Invitation3.State.SUCCESS;
1593
+ next(invitation2);
1594
+ break;
1595
+ }
1596
+ case Invitation3.State.CANCELLED: {
1597
+ assert6(invitationId);
1598
+ invitation2.invitationId = invitationId;
1599
+ invitation2.state = Invitation3.State.CANCELLED;
1600
+ next(invitation2);
1601
+ break;
1602
+ }
1603
+ case Invitation3.State.TIMEOUT: {
1604
+ assert6(invitationId);
1605
+ invitation2.invitationId = invitationId;
1606
+ invitation2.state = Invitation3.State.TIMEOUT;
1607
+ next(invitation2);
1608
+ break;
1609
+ }
1610
+ }
1611
+ }, (err) => {
1612
+ close(err);
1613
+ }, () => {
1614
+ close();
1615
+ });
1616
+ return (err) => {
1617
+ const context = this.getLoggingContext();
1618
+ if (err) {
1619
+ log5.warn("stream closed", {
1620
+ ...context,
1621
+ err
1622
+ }, {
1623
+ file: "invitations-service.ts",
1624
+ line: 181,
1625
+ scope: this,
1626
+ callSite: (f, a) => f(...a)
1627
+ });
1628
+ } else {
1629
+ log5("stream closed", context, {
1630
+ file: "invitations-service.ts",
1631
+ line: 183,
1632
+ scope: this,
1633
+ callSite: (f, a) => f(...a)
1634
+ });
1635
+ }
1636
+ this._acceptInvitations.delete(invitation.invitationId);
1637
+ };
1638
+ });
1639
+ }
1640
+ async authenticate({ invitationId, authCode }) {
1641
+ log5("authenticating...", {}, {
1642
+ file: "invitations-service.ts",
1643
+ line: 192,
1644
+ scope: this,
1645
+ callSite: (f, a) => f(...a)
1646
+ });
1647
+ assert6(invitationId);
1648
+ const observable = this._acceptInvitations.get(invitationId);
1649
+ if (!observable) {
1650
+ log5.warn("invalid invitation", {
1651
+ invitationId
1652
+ }, {
1653
+ file: "invitations-service.ts",
1654
+ line: 196,
1655
+ scope: this,
1656
+ callSite: (f, a) => f(...a)
1657
+ });
1658
+ } else {
1659
+ await observable.authenticate(authCode);
1660
+ }
1661
+ }
1662
+ async cancelInvitation({ invitationId }) {
1663
+ var _a;
1664
+ log5("cancelling...", {}, {
1665
+ file: "invitations-service.ts",
1666
+ line: 203,
1667
+ scope: this,
1668
+ callSite: (f, a) => f(...a)
1669
+ });
1670
+ assert6(invitationId);
1671
+ const observable = (_a = this._createInvitations.get(invitationId)) != null ? _a : this._acceptInvitations.get(invitationId);
1672
+ if (!observable) {
1673
+ log5.warn("invalid invitation", {
1674
+ invitationId
1675
+ }, {
1676
+ file: "invitations-service.ts",
1677
+ line: 207,
1678
+ scope: this,
1679
+ callSite: (f, a) => f(...a)
1680
+ });
1681
+ } else {
1682
+ await (observable == null ? void 0 : observable.cancel());
1683
+ }
1684
+ }
1685
+ };
1686
+
1687
+ // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
1905
1688
  import assert7 from "@dxos/node-std/assert";
1906
- var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
1907
- // prettier-ignore
1908
- constructor(identityManager, invitationsHandler, _getSpaceManager) {
1909
- super(identityManager, invitationsHandler);
1910
- this.invitationsHandler = invitationsHandler;
1911
- this._getSpaceManager = _getSpaceManager;
1912
- }
1913
- getContext(invitation) {
1914
- assert7(invitation.spaceKey);
1915
- const spaceManager = this._getSpaceManager();
1916
- const space = spaceManager.spaces.get(invitation.spaceKey);
1689
+ import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
1690
+ import { writeMessages as writeMessages2 } from "@dxos/feed-store";
1691
+ import { log as log6 } from "@dxos/log";
1692
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
1693
+ var SpaceInvitationProtocol = class {
1694
+ constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
1695
+ this._spaceManager = _spaceManager;
1696
+ this._signingContext = _signingContext;
1697
+ this._keyring = _keyring;
1698
+ this._spaceKey = _spaceKey;
1699
+ }
1700
+ toJSON() {
1701
+ return {
1702
+ deviceKey: this._signingContext.deviceKey,
1703
+ spaceKey: this._spaceKey
1704
+ };
1705
+ }
1706
+ getInvitationContext() {
1707
+ return {
1708
+ kind: Invitation4.Kind.SPACE,
1709
+ spaceKey: this._spaceKey
1710
+ };
1711
+ }
1712
+ async admit(request, guestProfile) {
1713
+ var _a;
1714
+ assert7(this._spaceKey);
1715
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
1917
1716
  assert7(space);
1918
- return space;
1717
+ assert7(request.space);
1718
+ const { identityKey, deviceKey } = request.space;
1719
+ log6("writing guest credentials", {
1720
+ host: this._signingContext.deviceKey,
1721
+ guest: deviceKey
1722
+ }, {
1723
+ file: "space-invitation-protocol.ts",
1724
+ line: 51,
1725
+ scope: this,
1726
+ callSite: (f, a) => f(...a)
1727
+ });
1728
+ const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1729
+ assert7(credentials[0].credential);
1730
+ const spaceMemberCredential = credentials[0].credential.credential;
1731
+ assert7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1732
+ await writeMessages2(space.inner.controlPipeline.writer, credentials);
1733
+ return {
1734
+ space: {
1735
+ credential: spaceMemberCredential,
1736
+ controlTimeframe: space.inner.controlPipeline.state.timeframe,
1737
+ dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
1738
+ }
1739
+ };
1740
+ }
1741
+ createIntroduction() {
1742
+ return {
1743
+ profile: this._signingContext.profile
1744
+ };
1745
+ }
1746
+ async createAdmissionRequest() {
1747
+ const controlFeedKey = await this._keyring.createKey();
1748
+ const dataFeedKey = await this._keyring.createKey();
1749
+ return {
1750
+ space: {
1751
+ identityKey: this._signingContext.identityKey,
1752
+ deviceKey: this._signingContext.deviceKey,
1753
+ controlFeedKey,
1754
+ dataFeedKey
1755
+ }
1756
+ };
1757
+ }
1758
+ async accept(response) {
1759
+ assert7(response.space);
1760
+ const { credential, controlTimeframe, dataTimeframe } = response.space;
1761
+ const assertion = getCredentialAssertion(credential);
1762
+ assert7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1763
+ assert7(credential.subject.id.equals(this._signingContext.identityKey));
1764
+ await this._spaceManager.acceptSpace({
1765
+ spaceKey: assertion.spaceKey,
1766
+ genesisFeedKey: assertion.genesisFeedKey,
1767
+ controlTimeframe,
1768
+ dataTimeframe
1769
+ });
1770
+ await this._signingContext.recordCredential(credential);
1771
+ return {
1772
+ spaceKey: assertion.spaceKey
1773
+ };
1919
1774
  }
1920
1775
  };
1921
1776
 
@@ -1959,6 +1814,8 @@ var toStorageType = (type) => {
1959
1814
  return StorageType.IDB;
1960
1815
  case StorageDriver.NODE:
1961
1816
  return StorageType.NODE;
1817
+ case StorageDriver.WEBFS:
1818
+ return StorageType.WEBFS;
1962
1819
  default:
1963
1820
  throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
1964
1821
  }
@@ -2054,20 +1911,19 @@ var MemoryShellRuntime = class {
2054
1911
  };
2055
1912
 
2056
1913
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
2057
- import { Trigger as Trigger9 } from "@dxos/async";
1914
+ import { Trigger as Trigger8 } from "@dxos/async";
2058
1915
  import { log as log17, logInfo as logInfo3 } from "@dxos/log";
2059
1916
  import { MemorySignalManager as MemorySignalManager3, MemorySignalManagerContext as MemorySignalManagerContext3, WebsocketSignalManager as WebsocketSignalManager3 } from "@dxos/messaging";
2060
1917
  import { createWebRTCTransportFactory as createWebRTCTransportFactory2, NetworkManager as NetworkManager3 } from "@dxos/network-manager";
2061
1918
  import { getAsyncValue } from "@dxos/util";
2062
1919
 
2063
1920
  // packages/sdk/client-services/src/packlets/services/service-host.ts
2064
- import assert12 from "@dxos/node-std/assert";
1921
+ import assert13 from "@dxos/node-std/assert";
2065
1922
  import { Event as Event7 } from "@dxos/async";
2066
- import { clientServiceBundle, createDefaultModelFactory, PublicKey as PublicKey10 } from "@dxos/client";
2067
- import { raise as raise3 } from "@dxos/debug";
1923
+ import { clientServiceBundle, createDefaultModelFactory, PublicKey as PublicKey9 } from "@dxos/client";
2068
1924
  import { DataServiceImpl } from "@dxos/echo-pipeline";
2069
1925
  import { log as log15 } from "@dxos/log";
2070
- import { trace as trace3 } from "@dxos/protocols";
1926
+ import { trace as trace4 } from "@dxos/protocols";
2071
1927
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
2072
1928
 
2073
1929
  // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
@@ -2156,45 +2012,46 @@ var NetworkServiceImpl = class {
2156
2012
  import assert10 from "@dxos/node-std/assert";
2157
2013
  import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2158
2014
  import { SpaceState as SpaceState2 } from "@dxos/client";
2159
- import { cancelWithContext, Context as Context7 } from "@dxos/context";
2015
+ import { cancelWithContext, Context as Context6 } from "@dxos/context";
2160
2016
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2161
2017
  import { SnapshotManager, spaceGenesis } from "@dxos/echo-pipeline";
2162
- import { PublicKey as PublicKey8 } from "@dxos/keys";
2018
+ import { PublicKey as PublicKey7 } from "@dxos/keys";
2163
2019
  import { log as log9 } from "@dxos/log";
2020
+ import { trace as trace2 } from "@dxos/protocols";
2164
2021
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2165
2022
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
2166
2023
 
2167
2024
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2168
- import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2025
+ import { Event as Event5, scheduleTask as scheduleTask3, trackLeaks } from "@dxos/async";
2169
2026
  import { SpaceState } from "@dxos/client";
2170
- import { Context as Context6 } from "@dxos/context";
2027
+ import { Context as Context5 } from "@dxos/context";
2171
2028
  import { timed } from "@dxos/debug";
2172
2029
  import { createMappedFeedWriter, DataPipeline } from "@dxos/echo-pipeline";
2173
2030
  import { CancelledError, SystemError } from "@dxos/errors";
2174
- import { PublicKey as PublicKey7 } from "@dxos/keys";
2031
+ import { PublicKey as PublicKey6 } from "@dxos/keys";
2175
2032
  import { log as log8 } from "@dxos/log";
2176
2033
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2177
2034
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2178
2035
 
2179
2036
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2180
2037
  import assert9 from "@dxos/node-std/assert";
2181
- import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep as sleep3, TimeoutError, Trigger as Trigger4 } from "@dxos/async";
2182
- import { Context as Context5, rejectOnDispose } from "@dxos/context";
2183
- import { PublicKey as PublicKey6 } from "@dxos/keys";
2038
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask2, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger3 } from "@dxos/async";
2039
+ import { Context as Context4, rejectOnDispose } from "@dxos/context";
2040
+ import { PublicKey as PublicKey5 } from "@dxos/keys";
2184
2041
  import { log as log7 } from "@dxos/log";
2185
- import { schema as schema4 } from "@dxos/protocols";
2186
- import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
2042
+ import { schema as schema3 } from "@dxos/protocols";
2043
+ import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2187
2044
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2188
2045
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2189
2046
  var DEFAULT_SUCCESS_DELAY = 1e3;
2190
2047
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2191
2048
  var NotarizationPlugin = class {
2192
2049
  constructor() {
2193
- this._ctx = new Context5();
2050
+ this._ctx = new Context4();
2194
2051
  this._extensionOpened = new Event4();
2195
2052
  this._extensions = /* @__PURE__ */ new Set();
2196
- this._processedCredentials = new ComplexSet(PublicKey6.hash);
2197
- this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
2053
+ this._processedCredentials = new ComplexSet(PublicKey5.hash);
2054
+ this._processCredentialsTriggers = new ComplexMap2(PublicKey5.hash);
2198
2055
  }
2199
2056
  async open() {
2200
2057
  }
@@ -2214,7 +2071,7 @@ var NotarizationPlugin = class {
2214
2071
  callSite: (f, a) => f(...a)
2215
2072
  });
2216
2073
  assert9(credentials.every((credential) => credential.id), "Credentials must have an id");
2217
- const errors = new Trigger4();
2074
+ const errors = new Trigger3();
2218
2075
  const ctx = this._ctx.derive({
2219
2076
  onError: (err) => {
2220
2077
  log7.warn("Notarization error", {
@@ -2231,7 +2088,7 @@ var NotarizationPlugin = class {
2231
2088
  });
2232
2089
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2233
2090
  if (timeout !== 0) {
2234
- scheduleTask3(ctx, () => {
2091
+ scheduleTask2(ctx, () => {
2235
2092
  log7.warn("Notarization timeout", {
2236
2093
  timeout,
2237
2094
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
@@ -2242,7 +2099,7 @@ var NotarizationPlugin = class {
2242
2099
  callSite: (f, a) => f(...a)
2243
2100
  });
2244
2101
  void ctx.dispose();
2245
- errors.throw(new TimeoutError(timeout, "Notarization timed out"));
2102
+ errors.throw(new TimeoutError2(timeout, "Notarization timed out"));
2246
2103
  }, timeout);
2247
2104
  }
2248
2105
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
@@ -2265,7 +2122,7 @@ var NotarizationPlugin = class {
2265
2122
  callSite: (f, a) => f(...a)
2266
2123
  });
2267
2124
  peersTried.clear();
2268
- scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
2125
+ scheduleTask2(ctx, () => notarizeTask.schedule(), retryTimeout);
2269
2126
  return;
2270
2127
  }
2271
2128
  peersTried.add(peer);
@@ -2287,7 +2144,7 @@ var NotarizationPlugin = class {
2287
2144
  scope: this,
2288
2145
  callSite: (f, a) => f(...a)
2289
2146
  });
2290
- await sleep3(successDelay);
2147
+ await sleep2(successDelay);
2291
2148
  } catch (err) {
2292
2149
  log7.warn("error notarizing (recoverable)", err, {
2293
2150
  file: "notarization-plugin.ts",
@@ -2336,7 +2193,7 @@ var NotarizationPlugin = class {
2336
2193
  if (this._processedCredentials.has(id)) {
2337
2194
  return;
2338
2195
  }
2339
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger4()).value.wait();
2196
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger3()).value.wait();
2340
2197
  }
2341
2198
  /**
2342
2199
  * Requests from other peers to notarize credentials.
@@ -2384,14 +2241,14 @@ var NotarizationPlugin = class {
2384
2241
  return extension;
2385
2242
  }
2386
2243
  };
2387
- var NotarizationTeleportExtension = class extends RpcExtension3 {
2244
+ var NotarizationTeleportExtension = class extends RpcExtension2 {
2388
2245
  constructor(_params) {
2389
2246
  super({
2390
2247
  requested: {
2391
- NotarizationService: schema4.getService("dxos.mesh.teleport.notarization.NotarizationService")
2248
+ NotarizationService: schema3.getService("dxos.mesh.teleport.notarization.NotarizationService")
2392
2249
  },
2393
2250
  exposed: {
2394
- NotarizationService: schema4.getService("dxos.mesh.teleport.notarization.NotarizationService")
2251
+ NotarizationService: schema3.getService("dxos.mesh.teleport.notarization.NotarizationService")
2395
2252
  }
2396
2253
  });
2397
2254
  this._params = _params;
@@ -2429,7 +2286,7 @@ var __decorate = function(decorators, target, key, desc) {
2429
2286
  var AUTH_TIMEOUT2 = 3e4;
2430
2287
  var DataSpace = class DataSpace2 {
2431
2288
  constructor(params) {
2432
- this._ctx = new Context6();
2289
+ this._ctx = new Context5();
2433
2290
  this._state = SpaceState.CLOSED;
2434
2291
  this.stateUpdate = new Event5();
2435
2292
  var _a;
@@ -2452,7 +2309,7 @@ var DataSpace = class DataSpace2 {
2452
2309
  snapshotId: params.snapshotId
2453
2310
  });
2454
2311
  this.authVerifier = new TrustedKeySetAuthVerifier({
2455
- trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2312
+ trustedKeysProvider: () => new ComplexSet2(PublicKey6.hash, Array.from(this._inner.spaceState.members.keys())),
2456
2313
  update: this._inner.stateUpdate,
2457
2314
  authTimeout: AUTH_TIMEOUT2
2458
2315
  });
@@ -2506,7 +2363,7 @@ var DataSpace = class DataSpace2 {
2506
2363
  * Initialize the data pipeline in a separate task.
2507
2364
  */
2508
2365
  initializeDataPipelineAsync() {
2509
- scheduleTask4(this._ctx, async () => {
2366
+ scheduleTask3(this._ctx, async () => {
2510
2367
  try {
2511
2368
  await this.initializeDataPipeline();
2512
2369
  } catch (err) {
@@ -2653,10 +2510,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2653
2510
  this._modelFactory = _modelFactory;
2654
2511
  this._feedStore = _feedStore;
2655
2512
  this._snapshotStore = _snapshotStore;
2656
- this._ctx = new Context7();
2513
+ this._ctx = new Context6();
2657
2514
  this.updated = new Event6();
2658
- this._spaces = new ComplexMap3(PublicKey8.hash);
2515
+ this._spaces = new ComplexMap3(PublicKey7.hash);
2659
2516
  this._isOpen = false;
2517
+ this._instanceId = PublicKey7.random().toHex();
2660
2518
  }
2661
2519
  // TODO(burdon): Remove.
2662
2520
  get spaces() {
@@ -2665,7 +2523,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2665
2523
  async open() {
2666
2524
  log9("open", {}, {
2667
2525
  file: "data-space-manager.ts",
2668
- line: 80,
2526
+ line: 83,
2527
+ scope: this,
2528
+ callSite: (f, a) => f(...a)
2529
+ });
2530
+ log9.trace("dxos.echo.data-space-manager", trace2.begin({
2531
+ id: this._instanceId,
2532
+ parentId: this._traceParent
2533
+ }), {
2534
+ file: "data-space-manager.ts",
2535
+ line: 84,
2669
2536
  scope: this,
2670
2537
  callSite: (f, a) => f(...a)
2671
2538
  });
@@ -2674,7 +2541,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2674
2541
  spaces: this._metadataStore.spaces.length
2675
2542
  }, {
2676
2543
  file: "data-space-manager.ts",
2677
- line: 82,
2544
+ line: 86,
2678
2545
  scope: this,
2679
2546
  callSite: (f, a) => f(...a)
2680
2547
  });
@@ -2683,7 +2550,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2683
2550
  spaceMetadata
2684
2551
  }, {
2685
2552
  file: "data-space-manager.ts",
2686
- line: 85,
2553
+ line: 89,
2687
2554
  scope: this,
2688
2555
  callSite: (f, a) => f(...a)
2689
2556
  });
@@ -2696,7 +2563,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2696
2563
  async close() {
2697
2564
  log9("close", {}, {
2698
2565
  file: "data-space-manager.ts",
2699
- line: 96,
2566
+ line: 100,
2700
2567
  scope: this,
2701
2568
  callSite: (f, a) => f(...a)
2702
2569
  });
@@ -2705,6 +2572,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2705
2572
  for (const space of this._spaces.values()) {
2706
2573
  await space.close();
2707
2574
  }
2575
+ log9.trace("dxos.echo.data-space-manager", trace2.end({
2576
+ id: this._instanceId
2577
+ }), {
2578
+ file: "data-space-manager.ts",
2579
+ line: 106,
2580
+ scope: this,
2581
+ callSite: (f, a) => f(...a)
2582
+ });
2708
2583
  }
2709
2584
  /**
2710
2585
  * Creates a new space writing the genesis credentials to the control feed.
@@ -2724,7 +2599,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2724
2599
  spaceKey
2725
2600
  }, {
2726
2601
  file: "data-space-manager.ts",
2727
- line: 120,
2602
+ line: 125,
2728
2603
  scope: this,
2729
2604
  callSite: (f, a) => f(...a)
2730
2605
  });
@@ -2744,7 +2619,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2744
2619
  opts
2745
2620
  }, {
2746
2621
  file: "data-space-manager.ts",
2747
- line: 139,
2622
+ line: 144,
2748
2623
  scope: this,
2749
2624
  callSite: (f, a) => f(...a)
2750
2625
  });
@@ -2778,7 +2653,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2778
2653
  metadata
2779
2654
  }, {
2780
2655
  file: "data-space-manager.ts",
2781
- line: 175,
2656
+ line: 180,
2782
2657
  scope: this,
2783
2658
  callSite: (f, a) => f(...a)
2784
2659
  });
@@ -2833,7 +2708,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2833
2708
  space: space.key
2834
2709
  }, {
2835
2710
  file: "data-space-manager.ts",
2836
- line: 224,
2711
+ line: 229,
2837
2712
  scope: this,
2838
2713
  callSite: (f, a) => f(...a)
2839
2714
  });
@@ -2845,7 +2720,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2845
2720
  open: this._isOpen
2846
2721
  }, {
2847
2722
  file: "data-space-manager.ts",
2848
- line: 231,
2723
+ line: 236,
2849
2724
  scope: this,
2850
2725
  callSite: (f, a) => f(...a)
2851
2726
  });
@@ -2883,7 +2758,7 @@ DataSpaceManager = __decorate2([
2883
2758
  ], DataSpaceManager);
2884
2759
 
2885
2760
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2886
- import { EventSubscriptions as EventSubscriptions3, scheduleTask as scheduleTask5 } from "@dxos/async";
2761
+ import { EventSubscriptions as EventSubscriptions3, scheduleTask as scheduleTask4 } from "@dxos/async";
2887
2762
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
2888
2763
  import { raise, todo as todo2 } from "@dxos/debug";
2889
2764
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
@@ -2926,7 +2801,7 @@ var SpacesServiceImpl = class {
2926
2801
  spaces
2927
2802
  });
2928
2803
  };
2929
- scheduleTask5(ctx, async () => {
2804
+ scheduleTask4(ctx, async () => {
2930
2805
  const dataSpaceManager = await this._getDataSpaceManager();
2931
2806
  const subscriptions = new EventSubscriptions3();
2932
2807
  ctx.onDispose(() => subscriptions.clear());
@@ -2963,7 +2838,7 @@ var SpacesServiceImpl = class {
2963
2838
  }
2964
2839
  subscribeMessages({ spaceKey, channel }) {
2965
2840
  return new Stream10(({ ctx, next }) => {
2966
- scheduleTask5(ctx, async () => {
2841
+ scheduleTask4(ctx, async () => {
2967
2842
  var _a;
2968
2843
  const dataSpaceManager = await this._getDataSpaceManager();
2969
2844
  const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
@@ -2984,7 +2859,7 @@ var SpacesServiceImpl = class {
2984
2859
  }
2985
2860
  });
2986
2861
  ctx.onDispose(() => processor.close());
2987
- scheduleTask5(ctx, () => processor.open());
2862
+ scheduleTask4(ctx, () => processor.open());
2988
2863
  });
2989
2864
  }
2990
2865
  async writeCredentials({ spaceKey, credentials }) {
@@ -2999,18 +2874,22 @@ var SpacesServiceImpl = class {
2999
2874
  }
3000
2875
  }
3001
2876
  _transformSpace(space) {
3002
- var _a, _b;
2877
+ var _a, _b, _c, _d, _e;
3003
2878
  return {
3004
2879
  spaceKey: space.key,
3005
2880
  state: space.state,
3006
2881
  pipeline: {
3007
- targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2882
+ controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
3008
2883
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3009
- currentDataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe,
3010
- targetDataTimeframe: (_b = space.dataPipeline.pipelineState) == null ? void 0 : _b.targetTimeframe
2884
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2885
+ totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2886
+ dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2887
+ currentDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.timeframe,
2888
+ targetDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.targetTimeframe,
2889
+ totalDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.endTimeframe
3011
2890
  },
3012
2891
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3013
- var _a2, _b2, _c;
2892
+ var _a2, _b2, _c2;
3014
2893
  return {
3015
2894
  identity: {
3016
2895
  identityKey: member.key,
@@ -3018,7 +2897,7 @@ var SpacesServiceImpl = class {
3018
2897
  displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : humanize(member.key)
3019
2898
  }
3020
2899
  },
3021
- presence: ((_c = this._identityManager.identity) == null ? void 0 : _c.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2900
+ presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
3022
2901
  };
3023
2902
  })
3024
2903
  };
@@ -3114,7 +2993,7 @@ var IFrameProxyRuntime = class {
3114
2993
  };
3115
2994
 
3116
2995
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3117
- import { asyncTimeout, Trigger as Trigger5 } from "@dxos/async";
2996
+ import { asyncTimeout, Trigger as Trigger4 } from "@dxos/async";
3118
2997
  import { log as log11, logInfo } from "@dxos/log";
3119
2998
  var __decorate3 = function(decorators, target, key, desc) {
3120
2999
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3133,7 +3012,7 @@ var Message;
3133
3012
  var VaultResourceLock = class {
3134
3013
  constructor({ lockKey, onAcquire, onRelease }) {
3135
3014
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3136
- this._releaseTrigger = new Trigger5();
3015
+ this._releaseTrigger = new Trigger4();
3137
3016
  this._lockKey = lockKey;
3138
3017
  this._onAcquire = onAcquire;
3139
3018
  this._onRelease = onRelease;
@@ -3193,14 +3072,14 @@ var VaultResourceLock = class {
3193
3072
  scope: this,
3194
3073
  callSite: (f, a) => f(...a)
3195
3074
  });
3196
- const acquired = new Trigger5();
3075
+ const acquired = new Trigger4();
3197
3076
  void navigator.locks.request(this._lockKey, {
3198
3077
  steal
3199
3078
  }, async () => {
3200
3079
  var _a, _b;
3201
3080
  await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3202
3081
  acquired.wake();
3203
- this._releaseTrigger = new Trigger5();
3082
+ this._releaseTrigger = new Trigger4();
3204
3083
  await this._releaseTrigger.wait();
3205
3084
  log11("releasing lock...", {}, {
3206
3085
  file: "vault-resource-lock.ts",
@@ -3235,14 +3114,14 @@ __decorate3([
3235
3114
  ], VaultResourceLock.prototype, "lockKey", null);
3236
3115
 
3237
3116
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3238
- import { Trigger as Trigger7 } from "@dxos/async";
3117
+ import { Trigger as Trigger6 } from "@dxos/async";
3239
3118
  import { log as log13 } from "@dxos/log";
3240
3119
  import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
3241
3120
  import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manager";
3242
3121
 
3243
3122
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3244
3123
  import assert11 from "@dxos/node-std/assert";
3245
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
3124
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger5 } from "@dxos/async";
3246
3125
  import { iframeServiceBundle as iframeServiceBundle2, workerServiceBundle as workerServiceBundle2 } from "@dxos/client";
3247
3126
  import { log as log12, logInfo as logInfo2 } from "@dxos/log";
3248
3127
  import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
@@ -3316,7 +3195,7 @@ var WorkerSession = class {
3316
3195
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
3317
3196
  heartbeatInterval: 1e3
3318
3197
  } }) {
3319
- this._startTrigger = new Trigger6();
3198
+ this._startTrigger = new Trigger5();
3320
3199
  this.onClose = new Callback();
3321
3200
  assert11(options);
3322
3201
  assert11(serviceHost);
@@ -3471,14 +3350,17 @@ var WorkerRuntime = class {
3471
3350
  constructor(_configProvider) {
3472
3351
  this._configProvider = _configProvider;
3473
3352
  this._transportFactory = new WebRTCTransportProxyFactory();
3474
- this._ready = new Trigger7();
3353
+ this._ready = new Trigger6();
3475
3354
  this.sessions = /* @__PURE__ */ new Set();
3476
3355
  this._clientServices = new ClientServicesHost();
3477
3356
  }
3357
+ get host() {
3358
+ return this._clientServices;
3359
+ }
3478
3360
  async start() {
3479
3361
  log13("starting...", {}, {
3480
3362
  file: "worker-runtime.ts",
3481
- line: 44,
3363
+ line: 48,
3482
3364
  scope: this,
3483
3365
  callSite: (f, a) => f(...a)
3484
3366
  });
@@ -3499,7 +3381,7 @@ var WorkerRuntime = class {
3499
3381
  this._ready.wake(void 0);
3500
3382
  log13("started", {}, {
3501
3383
  file: "worker-runtime.ts",
3502
- line: 61,
3384
+ line: 65,
3503
3385
  scope: this,
3504
3386
  callSite: (f, a) => f(...a)
3505
3387
  });
@@ -3507,7 +3389,7 @@ var WorkerRuntime = class {
3507
3389
  this._ready.wake(err);
3508
3390
  log13.catch(err, {}, {
3509
3391
  file: "worker-runtime.ts",
3510
- line: 64,
3392
+ line: 68,
3511
3393
  scope: this,
3512
3394
  callSite: (f, a) => f(...a)
3513
3395
  });
@@ -3557,24 +3439,28 @@ var WorkerRuntime = class {
3557
3439
  };
3558
3440
 
3559
3441
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3560
- import { Trigger as Trigger8 } from "@dxos/async";
3442
+ import assert12 from "@dxos/node-std/assert";
3443
+ import { Trigger as Trigger7 } from "@dxos/async";
3444
+ import { Invitation as Invitation5 } from "@dxos/client";
3561
3445
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3562
3446
  import { failUndefined as failUndefined2 } from "@dxos/debug";
3563
3447
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3564
3448
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3565
3449
  import { Keyring } from "@dxos/keyring";
3566
- import { PublicKey as PublicKey9 } from "@dxos/keys";
3450
+ import { PublicKey as PublicKey8 } from "@dxos/keys";
3567
3451
  import { log as log14 } from "@dxos/log";
3568
- import { trace as trace2 } from "@dxos/protocols";
3452
+ import { trace as trace3 } from "@dxos/protocols";
3569
3453
  var ServiceContext = class {
3570
3454
  // prettier-ignore
3571
3455
  constructor(storage, networkManager, modelFactory) {
3572
3456
  this.storage = storage;
3573
3457
  this.networkManager = networkManager;
3574
3458
  this.modelFactory = modelFactory;
3575
- this.initialized = new Trigger8();
3459
+ this.initialized = new Trigger7();
3576
3460
  this.dataServiceSubscriptions = new DataServiceSubscriptions();
3577
- this._instanceId = PublicKey9.random().toHex();
3461
+ this._handlerFactories = /* @__PURE__ */ new Map();
3462
+ this._instanceId = PublicKey8.random().toHex();
3463
+ networkManager._traceParent = this._instanceId;
3578
3464
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
3579
3465
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
3580
3466
  this.keyring = new Keyring(storage.createDirectory("keyring"));
@@ -3591,29 +3477,27 @@ var ServiceContext = class {
3591
3477
  feedStore: this.feedStore,
3592
3478
  networkManager: this.networkManager
3593
3479
  });
3480
+ this.spaceManager._traceParent = this._instanceId;
3594
3481
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3595
- this.deviceInvitations = new DeviceInvitationsHandler({
3596
- networkManager: this.networkManager,
3597
- getIdentity: () => {
3598
- var _a;
3599
- return (_a = this.identityManager.identity) != null ? _a : failUndefined2();
3600
- },
3601
- acceptIdentity: this._acceptIdentity.bind(this),
3602
- keyring: this.keyring
3603
- });
3482
+ this.identityManager._traceParent = this._instanceId;
3483
+ this.invitations = new InvitationsHandler(this.networkManager);
3484
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3485
+ var _a;
3486
+ return (_a = this.identityManager.identity) != null ? _a : failUndefined2();
3487
+ }, this._acceptIdentity.bind(this)));
3604
3488
  }
3605
3489
  async open() {
3606
- log14.trace("dxos.sdk.client-services", trace2.begin({
3490
+ log14.trace("dxos.sdk.service-context", trace3.begin({
3607
3491
  id: this._instanceId
3608
3492
  }), {
3609
3493
  file: "service-context.ts",
3610
- line: 98,
3494
+ line: 114,
3611
3495
  scope: this,
3612
3496
  callSite: (f, a) => f(...a)
3613
3497
  });
3614
3498
  log14("opening...", {}, {
3615
3499
  file: "service-context.ts",
3616
- line: 100,
3500
+ line: 116,
3617
3501
  scope: this,
3618
3502
  callSite: (f, a) => f(...a)
3619
3503
  });
@@ -3625,7 +3509,7 @@ var ServiceContext = class {
3625
3509
  }
3626
3510
  log14("opened", {}, {
3627
3511
  file: "service-context.ts",
3628
- line: 107,
3512
+ line: 123,
3629
3513
  scope: this,
3630
3514
  callSite: (f, a) => f(...a)
3631
3515
  });
@@ -3634,7 +3518,7 @@ var ServiceContext = class {
3634
3518
  var _a, _b;
3635
3519
  log14("closing...", {}, {
3636
3520
  file: "service-context.ts",
3637
- line: 111,
3521
+ line: 127,
3638
3522
  scope: this,
3639
3523
  callSite: (f, a) => f(...a)
3640
3524
  });
@@ -3647,15 +3531,15 @@ var ServiceContext = class {
3647
3531
  this.dataServiceSubscriptions.clear();
3648
3532
  log14("closed", {}, {
3649
3533
  file: "service-context.ts",
3650
- line: 119,
3534
+ line: 135,
3651
3535
  scope: this,
3652
3536
  callSite: (f, a) => f(...a)
3653
3537
  });
3654
- log14.trace("dxos.sdk.client-services", trace2.end({
3538
+ log14.trace("dxos.sdk.service-context", trace3.end({
3655
3539
  id: this._instanceId
3656
3540
  }), {
3657
3541
  file: "service-context.ts",
3658
- line: 121,
3542
+ line: 137,
3659
3543
  scope: this,
3660
3544
  callSite: (f, a) => f(...a)
3661
3545
  });
@@ -3663,7 +3547,7 @@ var ServiceContext = class {
3663
3547
  async reset() {
3664
3548
  log14("resetting...", {}, {
3665
3549
  file: "service-context.ts",
3666
- line: 125,
3550
+ line: 141,
3667
3551
  scope: this,
3668
3552
  callSite: (f, a) => f(...a)
3669
3553
  });
@@ -3671,7 +3555,7 @@ var ServiceContext = class {
3671
3555
  await this.storage.reset();
3672
3556
  log14("reset", {}, {
3673
3557
  file: "service-context.ts",
3674
- line: 128,
3558
+ line: 144,
3675
3559
  scope: this,
3676
3560
  callSite: (f, a) => f(...a)
3677
3561
  });
@@ -3681,6 +3565,11 @@ var ServiceContext = class {
3681
3565
  await this._initialize();
3682
3566
  return identity;
3683
3567
  }
3568
+ getInvitationHandler(invitation) {
3569
+ const factory = this._handlerFactories.get(invitation.kind);
3570
+ assert12(factory, `Unknown invitation kind: ${invitation.kind}`);
3571
+ return factory(invitation);
3572
+ }
3684
3573
  async _acceptIdentity(params) {
3685
3574
  const identity = await this.identityManager.acceptIdentity(params);
3686
3575
  await this._initialize();
@@ -3691,7 +3580,7 @@ var ServiceContext = class {
3691
3580
  var _a;
3692
3581
  log14("initializing spaces...", {}, {
3693
3582
  file: "service-context.ts",
3694
- line: 147,
3583
+ line: 169,
3695
3584
  scope: this,
3696
3585
  callSite: (f, a) => f(...a)
3697
3586
  });
@@ -3710,8 +3599,12 @@ var ServiceContext = class {
3710
3599
  }
3711
3600
  };
3712
3601
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
3602
+ this.dataSpaceManager._traceParent = this._instanceId;
3713
3603
  await this.dataSpaceManager.open();
3714
- this.spaceInvitations = new SpaceInvitationsHandler(this.networkManager, this.dataSpaceManager, signingContext, this.keyring);
3604
+ this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3605
+ assert12(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3606
+ return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3607
+ });
3715
3608
  this.initialized.wake();
3716
3609
  this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3717
3610
  process: async (credential) => {
@@ -3727,7 +3620,7 @@ var ServiceContext = class {
3727
3620
  details: assertion
3728
3621
  }, {
3729
3622
  file: "service-context.ts",
3730
- line: 190,
3623
+ line: 211,
3731
3624
  scope: this,
3732
3625
  callSite: (f, a) => f(...a)
3733
3626
  });
@@ -3738,7 +3631,7 @@ var ServiceContext = class {
3738
3631
  details: assertion
3739
3632
  }, {
3740
3633
  file: "service-context.ts",
3741
- line: 194,
3634
+ line: 215,
3742
3635
  scope: this,
3743
3636
  callSite: (f, a) => f(...a)
3744
3637
  });
@@ -3749,7 +3642,7 @@ var ServiceContext = class {
3749
3642
  details: assertion
3750
3643
  }, {
3751
3644
  file: "service-context.ts",
3752
- line: 199,
3645
+ line: 220,
3753
3646
  scope: this,
3754
3647
  callSite: (f, a) => f(...a)
3755
3648
  });
@@ -3760,7 +3653,7 @@ var ServiceContext = class {
3760
3653
  } catch (err) {
3761
3654
  log14.catch(err, {}, {
3762
3655
  file: "service-context.ts",
3763
- line: 205,
3656
+ line: 226,
3764
3657
  scope: this,
3765
3658
  callSite: (f, a) => f(...a)
3766
3659
  });
@@ -3809,7 +3702,7 @@ var ClientServicesHost = class {
3809
3702
  this._statusUpdate = new Event7();
3810
3703
  this._opening = false;
3811
3704
  this._open = false;
3812
- this._instanceId = PublicKey10.random().toHex();
3705
+ this._instanceId = PublicKey9.random().toHex();
3813
3706
  this._storage = storage;
3814
3707
  this._modelFactory = modelFactory;
3815
3708
  if (config) {
@@ -3838,7 +3731,7 @@ var ClientServicesHost = class {
3838
3731
  }
3839
3732
  },
3840
3733
  onReset: async () => {
3841
- assert12(this._serviceContext, "service host is closed");
3734
+ assert13(this._serviceContext, "service host is closed");
3842
3735
  await this._serviceContext.reset();
3843
3736
  }
3844
3737
  });
@@ -3864,16 +3757,16 @@ var ClientServicesHost = class {
3864
3757
  * Can only be called once.
3865
3758
  */
3866
3759
  initialize({ config, networkManager }) {
3867
- assert12(!this._open, "service host is open");
3760
+ assert13(!this._open, "service host is open");
3868
3761
  if (config) {
3869
- assert12(!this._config, "config already set");
3762
+ assert13(!this._config, "config already set");
3870
3763
  this._config = config;
3871
3764
  if (!this._storage) {
3872
3765
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
3873
3766
  }
3874
3767
  }
3875
3768
  if (networkManager) {
3876
- assert12(!this._networkManager, "network manager already set");
3769
+ assert13(!this._networkManager, "network manager already set");
3877
3770
  this._networkManager = networkManager;
3878
3771
  }
3879
3772
  }
@@ -3882,23 +3775,23 @@ var ClientServicesHost = class {
3882
3775
  if (this._open) {
3883
3776
  return;
3884
3777
  }
3885
- log15.trace("dxos.sdk.client-services-host", trace3.begin({
3778
+ log15.trace("dxos.sdk.client-services-host", trace4.begin({
3886
3779
  id: this._instanceId
3887
3780
  }), {
3888
3781
  file: "service-host.ts",
3889
- line: 168,
3782
+ line: 167,
3890
3783
  scope: this,
3891
3784
  callSite: (f, a) => f(...a)
3892
3785
  });
3893
- assert12(this._config, "config not set");
3894
- assert12(this._storage, "storage not set");
3895
- assert12(this._networkManager, "network manager not set");
3786
+ assert13(this._config, "config not set");
3787
+ assert13(this._storage, "storage not set");
3788
+ assert13(this._networkManager, "network manager not set");
3896
3789
  this._opening = true;
3897
3790
  log15("opening...", {
3898
3791
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
3899
3792
  }, {
3900
3793
  file: "service-host.ts",
3901
- line: 175,
3794
+ line: 174,
3902
3795
  scope: this,
3903
3796
  callSite: (f, a) => f(...a)
3904
3797
  });
@@ -3907,15 +3800,8 @@ var ClientServicesHost = class {
3907
3800
  this._serviceRegistry.setServices({
3908
3801
  SystemService: this._systemService,
3909
3802
  IdentityService: new IdentityServiceImpl(this._serviceContext),
3803
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
3910
3804
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
3911
- DeviceInvitationsService: new DeviceInvitationsServiceImpl(this._serviceContext.identityManager, this._serviceContext.deviceInvitations),
3912
- SpaceInvitationsService: new SpaceInvitationsServiceImpl(this._serviceContext.identityManager, () => {
3913
- var _a2;
3914
- return (_a2 = this._serviceContext.spaceInvitations) != null ? _a2 : raise3(new Error("SpaceInvitations not initialized"));
3915
- }, () => {
3916
- var _a2;
3917
- return (_a2 = this._serviceContext.dataSpaceManager) != null ? _a2 : raise3(new Error("SpaceManager not initialized"));
3918
- }),
3919
3805
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
3920
3806
  await this._serviceContext.initialized.wait();
3921
3807
  return this._serviceContext.dataSpaceManager;
@@ -3939,7 +3825,7 @@ var ClientServicesHost = class {
3939
3825
  deviceKey
3940
3826
  }, {
3941
3827
  file: "service-host.ts",
3942
- line: 229,
3828
+ line: 221,
3943
3829
  scope: this,
3944
3830
  callSite: (f, a) => f(...a)
3945
3831
  });
@@ -3954,7 +3840,7 @@ var ClientServicesHost = class {
3954
3840
  deviceKey
3955
3841
  }, {
3956
3842
  file: "service-host.ts",
3957
- line: 238,
3843
+ line: 230,
3958
3844
  scope: this,
3959
3845
  callSite: (f, a) => f(...a)
3960
3846
  });
@@ -3968,15 +3854,15 @@ var ClientServicesHost = class {
3968
3854
  deviceKey
3969
3855
  }, {
3970
3856
  file: "service-host.ts",
3971
- line: 243,
3857
+ line: 235,
3972
3858
  scope: this,
3973
3859
  callSite: (f, a) => f(...a)
3974
3860
  });
3975
- log15.trace("dxos.sdk.client-services-host", trace3.end({
3861
+ log15.trace("dxos.sdk.client-services-host", trace4.end({
3976
3862
  id: this._instanceId
3977
3863
  }), {
3978
3864
  file: "service-host.ts",
3979
- line: 245,
3865
+ line: 237,
3980
3866
  scope: this,
3981
3867
  callSite: (f, a) => f(...a)
3982
3868
  });
@@ -4057,7 +3943,7 @@ var LOCK_KEY = "DXOS_RESOURCE_LOCK";
4057
3943
  var IFrameHostRuntime = class {
4058
3944
  constructor({ configProvider, appPort, shellPort }) {
4059
3945
  this._transportFactory = createWebRTCTransportFactory2();
4060
- this._ready = new Trigger9();
3946
+ this._ready = new Trigger8();
4061
3947
  this._configProvider = configProvider;
4062
3948
  this._appPort = appPort;
4063
3949
  this._shellPort = shellPort;
@@ -4179,11 +4065,10 @@ export {
4179
4065
  Identity,
4180
4066
  IdentityManager,
4181
4067
  IdentityServiceImpl,
4182
- DeviceInvitationsHandler,
4183
- AbstractInvitationsService,
4184
- DeviceInvitationsServiceImpl,
4185
- SpaceInvitationsHandler,
4186
- SpaceInvitationsServiceImpl,
4068
+ DeviceInvitationProtocol,
4069
+ InvitationsHandler,
4070
+ InvitationsServiceImpl,
4071
+ SpaceInvitationProtocol,
4187
4072
  createStorageObjects,
4188
4073
  ShellRuntimeImpl,
4189
4074
  MemoryShellRuntime,
@@ -4198,4 +4083,4 @@ export {
4198
4083
  LocalClientServices,
4199
4084
  fromHost
4200
4085
  };
4201
- //# sourceMappingURL=chunk-H5IXSSI7.mjs.map
4086
+ //# sourceMappingURL=chunk-2AYYVPWN.mjs.map