@dxos/client-services 0.5.9-main.2dbe289 → 0.5.9-main.3179d45
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.
- package/dist/lib/browser/{chunk-QWL2M4EU.mjs → chunk-M35K3NOZ.mjs} +1483 -962
- package/dist/lib/browser/chunk-M35K3NOZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -4
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +20 -13
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-NPYJIVOX.cjs → chunk-XT7E4KWB.cjs} +1723 -1211
- package/dist/lib/node/chunk-XT7E4KWB.cjs.map +7 -0
- package/dist/lib/node/index.cjs +45 -44
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +26 -19
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/identity/contacts-service.d.ts +14 -0
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +19 -0
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/identity-service.d.ts +14 -7
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +4 -1
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +15 -4
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +5 -2
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +8 -6
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +36 -36
- package/src/packlets/identity/contacts-service.ts +85 -0
- package/src/packlets/identity/default-space-state-machine.ts +44 -0
- package/src/packlets/identity/identity-service.test.ts +35 -5
- package/src/packlets/identity/identity-service.ts +76 -8
- package/src/packlets/identity/identity.ts +25 -2
- package/src/packlets/invitations/invitations-handler.ts +13 -5
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -32
- package/src/packlets/services/service-context.ts +1 -4
- package/src/packlets/services/service-host.ts +23 -42
- package/src/packlets/spaces/automerge-space-state.ts +11 -2
- package/src/packlets/spaces/data-space-manager.test.ts +46 -1
- package/src/packlets/spaces/data-space-manager.ts +136 -33
- package/src/packlets/spaces/data-space.ts +85 -153
- package/src/packlets/spaces/epoch-migrations.ts +135 -0
- package/src/packlets/spaces/spaces-service.ts +54 -4
- package/src/packlets/testing/test-builder.ts +12 -10
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-QWL2M4EU.mjs.map +0 -7
- package/dist/lib/node/chunk-NPYJIVOX.cjs.map +0 -7
|
@@ -85,6 +85,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
|
|
|
85
85
|
import { Stream as Stream2 } from "@dxos/codec-protobuf";
|
|
86
86
|
import { Context } from "@dxos/context";
|
|
87
87
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
88
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/network.ts";
|
|
88
89
|
var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close }) => {
|
|
89
90
|
const update = () => {
|
|
90
91
|
try {
|
|
@@ -100,7 +101,10 @@ var subscribeToNetworkStatus = ({ signalManager }) => new Stream2(({ next, close
|
|
|
100
101
|
update();
|
|
101
102
|
});
|
|
102
103
|
var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
|
|
103
|
-
const ctx = new Context(
|
|
104
|
+
const ctx = new Context(void 0, {
|
|
105
|
+
F: __dxlog_file,
|
|
106
|
+
L: 36
|
|
107
|
+
});
|
|
104
108
|
signalManager.onMessage.on(ctx, (message) => {
|
|
105
109
|
next({
|
|
106
110
|
message: {
|
|
@@ -355,7 +359,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
|
|
|
355
359
|
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
356
360
|
|
|
357
361
|
// packages/sdk/client-services/src/version.ts
|
|
358
|
-
var DXOS_VERSION = "0.5.9-main.
|
|
362
|
+
var DXOS_VERSION = "0.5.9-main.3179d45";
|
|
359
363
|
|
|
360
364
|
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
361
365
|
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -388,7 +392,7 @@ var getPlatform = () => {
|
|
|
388
392
|
};
|
|
389
393
|
|
|
390
394
|
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
391
|
-
var
|
|
395
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
|
|
392
396
|
var DEFAULT_TIMEOUT = 1e3;
|
|
393
397
|
var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
394
398
|
const diagnostics = {
|
|
@@ -405,7 +409,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
|
405
409
|
await Promise.all([
|
|
406
410
|
(async () => {
|
|
407
411
|
invariant(clientServices.LoggingService, "SystemService is not available.", {
|
|
408
|
-
F:
|
|
412
|
+
F: __dxlog_file2,
|
|
409
413
|
L: 110,
|
|
410
414
|
S: void 0,
|
|
411
415
|
A: [
|
|
@@ -510,7 +514,7 @@ var getStorageDiagnostics = async () => {
|
|
|
510
514
|
// packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
|
|
511
515
|
import { Trigger } from "@dxos/async";
|
|
512
516
|
import { log } from "@dxos/log";
|
|
513
|
-
var
|
|
517
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
|
|
514
518
|
var CHANNEL_NAME = "dxos.diagnostics.broadcast";
|
|
515
519
|
var MessageType;
|
|
516
520
|
(function(MessageType2) {
|
|
@@ -579,7 +583,7 @@ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
|
|
|
579
583
|
}
|
|
580
584
|
} catch (error) {
|
|
581
585
|
log.catch(error, void 0, {
|
|
582
|
-
F:
|
|
586
|
+
F: __dxlog_file3,
|
|
583
587
|
L: 77,
|
|
584
588
|
S: void 0,
|
|
585
589
|
C: (f, a) => f(...a)
|
|
@@ -687,7 +691,7 @@ import { Context as Context2 } from "@dxos/context";
|
|
|
687
691
|
import { verifyCredential } from "@dxos/credentials";
|
|
688
692
|
import { log as log2 } from "@dxos/log";
|
|
689
693
|
import { schema } from "@dxos/protocols";
|
|
690
|
-
var
|
|
694
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
|
|
691
695
|
var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
|
|
692
696
|
var createAuthProvider = (signer) => async (nonce) => {
|
|
693
697
|
const credential = await signer.createCredential({
|
|
@@ -702,7 +706,10 @@ var createAuthProvider = (signer) => async (nonce) => {
|
|
|
702
706
|
var TrustedKeySetAuthVerifier = class {
|
|
703
707
|
constructor(_params) {
|
|
704
708
|
this._params = _params;
|
|
705
|
-
this._ctx = new Context2(
|
|
709
|
+
this._ctx = new Context2(void 0, {
|
|
710
|
+
F: __dxlog_file4,
|
|
711
|
+
L: 45
|
|
712
|
+
});
|
|
706
713
|
}
|
|
707
714
|
async close() {
|
|
708
715
|
await this._ctx.dispose();
|
|
@@ -713,7 +720,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
713
720
|
log2("authenticating...", {
|
|
714
721
|
credential
|
|
715
722
|
}, {
|
|
716
|
-
F:
|
|
723
|
+
F: __dxlog_file4,
|
|
717
724
|
L: 56,
|
|
718
725
|
S: this,
|
|
719
726
|
C: (f, a) => f(...a)
|
|
@@ -723,7 +730,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
723
730
|
log2("Invalid credential", {
|
|
724
731
|
result
|
|
725
732
|
}, {
|
|
726
|
-
F:
|
|
733
|
+
F: __dxlog_file4,
|
|
727
734
|
L: 60,
|
|
728
735
|
S: this,
|
|
729
736
|
C: (f, a) => f(...a)
|
|
@@ -735,7 +742,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
735
742
|
nonce,
|
|
736
743
|
credential
|
|
737
744
|
}, {
|
|
738
|
-
F:
|
|
745
|
+
F: __dxlog_file4,
|
|
739
746
|
L: 65,
|
|
740
747
|
S: this,
|
|
741
748
|
C: (f, a) => f(...a)
|
|
@@ -746,7 +753,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
746
753
|
log2("key is not currently in trusted set, waiting...", {
|
|
747
754
|
key: credential.issuer
|
|
748
755
|
}, {
|
|
749
|
-
F:
|
|
756
|
+
F: __dxlog_file4,
|
|
750
757
|
L: 70,
|
|
751
758
|
S: this,
|
|
752
759
|
C: (f, a) => f(...a)
|
|
@@ -762,7 +769,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
762
769
|
log2("auth success", {
|
|
763
770
|
key: credential.issuer
|
|
764
771
|
}, {
|
|
765
|
-
F:
|
|
772
|
+
F: __dxlog_file4,
|
|
766
773
|
L: 81,
|
|
767
774
|
S: this,
|
|
768
775
|
C: (f, a) => f(...a)
|
|
@@ -772,7 +779,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
772
779
|
log2("key is not currently in trusted set, waiting...", {
|
|
773
780
|
key: credential.issuer
|
|
774
781
|
}, {
|
|
775
|
-
F:
|
|
782
|
+
F: __dxlog_file4,
|
|
776
783
|
L: 84,
|
|
777
784
|
S: this,
|
|
778
785
|
C: (f, a) => f(...a)
|
|
@@ -803,10 +810,59 @@ import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSign
|
|
|
803
810
|
import { writeMessages } from "@dxos/feed-store";
|
|
804
811
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
805
812
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
806
|
-
import { log as
|
|
813
|
+
import { log as log4 } from "@dxos/log";
|
|
807
814
|
import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
815
|
+
import { Timeframe } from "@dxos/timeframe";
|
|
808
816
|
import { trace as trace2 } from "@dxos/tracing";
|
|
809
817
|
import { ComplexSet } from "@dxos/util";
|
|
818
|
+
|
|
819
|
+
// packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts
|
|
820
|
+
import { getCredentialAssertion } from "@dxos/credentials";
|
|
821
|
+
import { SpaceId } from "@dxos/keys";
|
|
822
|
+
import { log as log3 } from "@dxos/log";
|
|
823
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
|
|
824
|
+
var DefaultSpaceStateMachine = class {
|
|
825
|
+
constructor(_params) {
|
|
826
|
+
this._params = _params;
|
|
827
|
+
}
|
|
828
|
+
get spaceId() {
|
|
829
|
+
return this._spaceId;
|
|
830
|
+
}
|
|
831
|
+
async processCredential(credential) {
|
|
832
|
+
const assertion = getCredentialAssertion(credential);
|
|
833
|
+
switch (assertion["@type"]) {
|
|
834
|
+
case "dxos.halo.credentials.DefaultSpace": {
|
|
835
|
+
if (!credential.subject.id.equals(this._params.identityKey)) {
|
|
836
|
+
log3.warn("Invalid default space credential", {
|
|
837
|
+
expectedIdentity: this._params.identityKey,
|
|
838
|
+
credential
|
|
839
|
+
}, {
|
|
840
|
+
F: __dxlog_file5,
|
|
841
|
+
L: 32,
|
|
842
|
+
S: this,
|
|
843
|
+
C: (f, a) => f(...a)
|
|
844
|
+
});
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
if (!SpaceId.isValid(assertion.spaceId)) {
|
|
848
|
+
log3.warn("Invalid default space id", {
|
|
849
|
+
id: assertion.spaceId
|
|
850
|
+
}, {
|
|
851
|
+
F: __dxlog_file5,
|
|
852
|
+
L: 36,
|
|
853
|
+
S: this,
|
|
854
|
+
C: (f, a) => f(...a)
|
|
855
|
+
});
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
this._spaceId = assertion.spaceId;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
// packages/sdk/client-services/src/packlets/identity/identity.ts
|
|
810
866
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
811
867
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
812
868
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -817,7 +873,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
817
873
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
818
874
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
819
875
|
}
|
|
820
|
-
var
|
|
876
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
|
|
821
877
|
var Identity = class {
|
|
822
878
|
constructor({ space, signer, identityKey, deviceKey, presence }) {
|
|
823
879
|
this.stateUpdate = new Event();
|
|
@@ -826,11 +882,11 @@ var Identity = class {
|
|
|
826
882
|
this._presence = presence;
|
|
827
883
|
this.identityKey = identityKey;
|
|
828
884
|
this.deviceKey = deviceKey;
|
|
829
|
-
|
|
885
|
+
log4.trace("dxos.halo.device", {
|
|
830
886
|
deviceKey
|
|
831
887
|
}, {
|
|
832
|
-
F:
|
|
833
|
-
L:
|
|
888
|
+
F: __dxlog_file6,
|
|
889
|
+
L: 70,
|
|
834
890
|
S: this,
|
|
835
891
|
C: (f, a) => f(...a)
|
|
836
892
|
});
|
|
@@ -843,6 +899,10 @@ var Identity = class {
|
|
|
843
899
|
identityKey: this.identityKey,
|
|
844
900
|
onUpdate: () => this.stateUpdate.emit()
|
|
845
901
|
});
|
|
902
|
+
this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
|
|
903
|
+
identityKey: this.identityKey,
|
|
904
|
+
onUpdate: () => this.stateUpdate.emit()
|
|
905
|
+
});
|
|
846
906
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
847
907
|
trustedKeysProvider: () => new ComplexSet(PublicKey3.hash, this.authorizedDeviceKeys.keys()),
|
|
848
908
|
update: this.stateUpdate,
|
|
@@ -853,14 +913,20 @@ var Identity = class {
|
|
|
853
913
|
get authorizedDeviceKeys() {
|
|
854
914
|
return this._deviceStateMachine.authorizedDeviceKeys;
|
|
855
915
|
}
|
|
916
|
+
get defaultSpaceId() {
|
|
917
|
+
return this._defaultSpaceStateMachine.spaceId;
|
|
918
|
+
}
|
|
856
919
|
async open(ctx) {
|
|
920
|
+
await this._presence?.open();
|
|
857
921
|
await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
|
|
858
922
|
await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
|
|
923
|
+
await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
|
|
859
924
|
await this.space.open(ctx);
|
|
860
925
|
}
|
|
861
926
|
async close(ctx) {
|
|
862
|
-
await this._presence?.
|
|
927
|
+
await this._presence?.close();
|
|
863
928
|
await this.authVerifier.close();
|
|
929
|
+
await this.space.spaceState.removeCredentialProcessor(this._defaultSpaceStateMachine);
|
|
864
930
|
await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
|
|
865
931
|
await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
|
|
866
932
|
await this.space.close();
|
|
@@ -898,8 +964,8 @@ var Identity = class {
|
|
|
898
964
|
*/
|
|
899
965
|
getIdentityCredentialSigner() {
|
|
900
966
|
invariant2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
|
|
901
|
-
F:
|
|
902
|
-
L:
|
|
967
|
+
F: __dxlog_file6,
|
|
968
|
+
L: 159,
|
|
903
969
|
S: this,
|
|
904
970
|
A: [
|
|
905
971
|
"this._deviceStateMachine.deviceCredentialChain",
|
|
@@ -914,16 +980,36 @@ var Identity = class {
|
|
|
914
980
|
getDeviceCredentialSigner() {
|
|
915
981
|
return createCredentialSignerWithKey(this._signer, this.deviceKey);
|
|
916
982
|
}
|
|
983
|
+
async updateDefaultSpace(spaceId) {
|
|
984
|
+
const credential = await this.getDeviceCredentialSigner().createCredential({
|
|
985
|
+
subject: this.identityKey,
|
|
986
|
+
assertion: {
|
|
987
|
+
"@type": "dxos.halo.credentials.DefaultSpace",
|
|
988
|
+
spaceId
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
const receipt = await this.controlPipeline.writer.write({
|
|
992
|
+
credential: {
|
|
993
|
+
credential
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
await this.controlPipeline.state.waitUntilTimeframe(new Timeframe([
|
|
997
|
+
[
|
|
998
|
+
receipt.feedKey,
|
|
999
|
+
receipt.seq
|
|
1000
|
+
]
|
|
1001
|
+
]));
|
|
1002
|
+
}
|
|
917
1003
|
async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
|
|
918
|
-
|
|
1004
|
+
log4("Admitting device:", {
|
|
919
1005
|
identityKey: this.identityKey,
|
|
920
1006
|
hostDevice: this.deviceKey,
|
|
921
1007
|
deviceKey,
|
|
922
1008
|
controlFeedKey,
|
|
923
1009
|
dataFeedKey
|
|
924
1010
|
}, {
|
|
925
|
-
F:
|
|
926
|
-
L:
|
|
1011
|
+
F: __dxlog_file6,
|
|
1012
|
+
L: 184,
|
|
927
1013
|
S: this,
|
|
928
1014
|
C: (f, a) => f(...a)
|
|
929
1015
|
});
|
|
@@ -981,12 +1067,12 @@ import { Context as Context3 } from "@dxos/context";
|
|
|
981
1067
|
import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
|
|
982
1068
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
983
1069
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
984
|
-
import { log as
|
|
1070
|
+
import { log as log5 } from "@dxos/log";
|
|
985
1071
|
import { trace as trace3 } from "@dxos/protocols";
|
|
986
1072
|
import { Device, DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
|
|
987
1073
|
import { AdmittedFeed as AdmittedFeed2, DeviceType } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
988
1074
|
import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
|
|
989
|
-
import { Timeframe } from "@dxos/timeframe";
|
|
1075
|
+
import { Timeframe as Timeframe2 } from "@dxos/timeframe";
|
|
990
1076
|
import { trace as Trace } from "@dxos/tracing";
|
|
991
1077
|
import { isNode, deferFunction } from "@dxos/util";
|
|
992
1078
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
@@ -999,7 +1085,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
999
1085
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1000
1086
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1001
1087
|
}
|
|
1002
|
-
var
|
|
1088
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
|
|
1003
1089
|
var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
1004
1090
|
var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
1005
1091
|
var IdentityManager = class {
|
|
@@ -1020,19 +1106,19 @@ var IdentityManager = class {
|
|
|
1020
1106
|
}
|
|
1021
1107
|
async open(ctx) {
|
|
1022
1108
|
const traceId = PublicKey4.random().toHex();
|
|
1023
|
-
|
|
1109
|
+
log5.trace("dxos.halo.identity-manager.open", trace3.begin({
|
|
1024
1110
|
id: traceId
|
|
1025
1111
|
}), {
|
|
1026
|
-
F:
|
|
1112
|
+
F: __dxlog_file7,
|
|
1027
1113
|
L: 104,
|
|
1028
1114
|
S: this,
|
|
1029
1115
|
C: (f, a) => f(...a)
|
|
1030
1116
|
});
|
|
1031
1117
|
const identityRecord = this._metadataStore.getIdentityRecord();
|
|
1032
|
-
|
|
1118
|
+
log5("identity record", {
|
|
1033
1119
|
identityRecord
|
|
1034
1120
|
}, {
|
|
1035
|
-
F:
|
|
1121
|
+
F: __dxlog_file7,
|
|
1036
1122
|
L: 107,
|
|
1037
1123
|
S: this,
|
|
1038
1124
|
C: (f, a) => f(...a)
|
|
@@ -1041,32 +1127,35 @@ var IdentityManager = class {
|
|
|
1041
1127
|
this._identity = await this._constructIdentity(identityRecord);
|
|
1042
1128
|
await this._identity.open(ctx);
|
|
1043
1129
|
await this._identity.ready();
|
|
1044
|
-
|
|
1130
|
+
log5.trace("dxos.halo.identity", {
|
|
1045
1131
|
identityKey: identityRecord.identityKey,
|
|
1046
1132
|
displayName: this._identity.profileDocument?.displayName
|
|
1047
1133
|
}, {
|
|
1048
|
-
F:
|
|
1134
|
+
F: __dxlog_file7,
|
|
1049
1135
|
L: 112,
|
|
1050
1136
|
S: this,
|
|
1051
1137
|
C: (f, a) => f(...a)
|
|
1052
1138
|
});
|
|
1053
1139
|
this.stateUpdate.emit();
|
|
1054
1140
|
}
|
|
1055
|
-
|
|
1141
|
+
log5.trace("dxos.halo.identity-manager.open", trace3.end({
|
|
1056
1142
|
id: traceId
|
|
1057
1143
|
}), {
|
|
1058
|
-
F:
|
|
1144
|
+
F: __dxlog_file7,
|
|
1059
1145
|
L: 119,
|
|
1060
1146
|
S: this,
|
|
1061
1147
|
C: (f, a) => f(...a)
|
|
1062
1148
|
});
|
|
1063
1149
|
}
|
|
1064
1150
|
async close() {
|
|
1065
|
-
await this._identity?.close(new Context3(
|
|
1151
|
+
await this._identity?.close(new Context3(void 0, {
|
|
1152
|
+
F: __dxlog_file7,
|
|
1153
|
+
L: 123
|
|
1154
|
+
}));
|
|
1066
1155
|
}
|
|
1067
1156
|
async createIdentity({ displayName, deviceProfile } = {}) {
|
|
1068
1157
|
invariant3(!this._identity, "Identity already exists.", {
|
|
1069
|
-
F:
|
|
1158
|
+
F: __dxlog_file7,
|
|
1070
1159
|
L: 128,
|
|
1071
1160
|
S: this,
|
|
1072
1161
|
A: [
|
|
@@ -1074,8 +1163,8 @@ var IdentityManager = class {
|
|
|
1074
1163
|
"'Identity already exists.'"
|
|
1075
1164
|
]
|
|
1076
1165
|
});
|
|
1077
|
-
|
|
1078
|
-
F:
|
|
1166
|
+
log5("creating identity...", void 0, {
|
|
1167
|
+
F: __dxlog_file7,
|
|
1079
1168
|
L: 129,
|
|
1080
1169
|
S: this,
|
|
1081
1170
|
C: (f, a) => f(...a)
|
|
@@ -1092,11 +1181,14 @@ var IdentityManager = class {
|
|
|
1092
1181
|
}
|
|
1093
1182
|
};
|
|
1094
1183
|
const identity = await this._constructIdentity(identityRecord);
|
|
1095
|
-
await identity.open(new Context3(
|
|
1184
|
+
await identity.open(new Context3(void 0, {
|
|
1185
|
+
F: __dxlog_file7,
|
|
1186
|
+
L: 144
|
|
1187
|
+
}));
|
|
1096
1188
|
{
|
|
1097
1189
|
const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
|
|
1098
1190
|
invariant3(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
|
|
1099
|
-
F:
|
|
1191
|
+
F: __dxlog_file7,
|
|
1100
1192
|
L: 148,
|
|
1101
1193
|
S: this,
|
|
1102
1194
|
A: [
|
|
@@ -1105,7 +1197,7 @@ var IdentityManager = class {
|
|
|
1105
1197
|
]
|
|
1106
1198
|
});
|
|
1107
1199
|
invariant3(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
|
|
1108
|
-
F:
|
|
1200
|
+
F: __dxlog_file7,
|
|
1109
1201
|
L: 149,
|
|
1110
1202
|
S: this,
|
|
1111
1203
|
A: [
|
|
@@ -1140,22 +1232,22 @@ var IdentityManager = class {
|
|
|
1140
1232
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
1141
1233
|
this._identity = identity;
|
|
1142
1234
|
await this._identity.ready();
|
|
1143
|
-
|
|
1235
|
+
log5.trace("dxos.halo.identity", {
|
|
1144
1236
|
identityKey: identityRecord.identityKey,
|
|
1145
1237
|
displayName: this._identity.profileDocument?.displayName
|
|
1146
1238
|
}, {
|
|
1147
|
-
F:
|
|
1239
|
+
F: __dxlog_file7,
|
|
1148
1240
|
L: 191,
|
|
1149
1241
|
S: this,
|
|
1150
1242
|
C: (f, a) => f(...a)
|
|
1151
1243
|
});
|
|
1152
1244
|
this.stateUpdate.emit();
|
|
1153
|
-
|
|
1245
|
+
log5("created identity", {
|
|
1154
1246
|
identityKey: identity.identityKey,
|
|
1155
1247
|
deviceKey: identity.deviceKey,
|
|
1156
1248
|
profile: identity.profileDocument
|
|
1157
1249
|
}, {
|
|
1158
|
-
F:
|
|
1250
|
+
F: __dxlog_file7,
|
|
1159
1251
|
L: 197,
|
|
1160
1252
|
S: this,
|
|
1161
1253
|
C: (f, a) => f(...a)
|
|
@@ -1189,16 +1281,16 @@ var IdentityManager = class {
|
|
|
1189
1281
|
* Accept an existing identity. Expects its device key to be authorized (now or later).
|
|
1190
1282
|
*/
|
|
1191
1283
|
async acceptIdentity(params) {
|
|
1192
|
-
|
|
1284
|
+
log5("accepting identity", {
|
|
1193
1285
|
params
|
|
1194
1286
|
}, {
|
|
1195
|
-
F:
|
|
1287
|
+
F: __dxlog_file7,
|
|
1196
1288
|
L: 235,
|
|
1197
1289
|
S: this,
|
|
1198
1290
|
C: (f, a) => f(...a)
|
|
1199
1291
|
});
|
|
1200
1292
|
invariant3(!this._identity, "Identity already exists.", {
|
|
1201
|
-
F:
|
|
1293
|
+
F: __dxlog_file7,
|
|
1202
1294
|
L: 236,
|
|
1203
1295
|
S: this,
|
|
1204
1296
|
A: [
|
|
@@ -1218,15 +1310,18 @@ var IdentityManager = class {
|
|
|
1218
1310
|
}
|
|
1219
1311
|
};
|
|
1220
1312
|
const identity = await this._constructIdentity(identityRecord);
|
|
1221
|
-
await identity.open(new Context3(
|
|
1313
|
+
await identity.open(new Context3(void 0, {
|
|
1314
|
+
F: __dxlog_file7,
|
|
1315
|
+
L: 251
|
|
1316
|
+
}));
|
|
1222
1317
|
this._identity = identity;
|
|
1223
1318
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
1224
1319
|
await this._identity.ready();
|
|
1225
|
-
|
|
1320
|
+
log5.trace("dxos.halo.identity", {
|
|
1226
1321
|
identityKey: identityRecord.identityKey,
|
|
1227
1322
|
displayName: this._identity.profileDocument?.displayName
|
|
1228
1323
|
}, {
|
|
1229
|
-
F:
|
|
1324
|
+
F: __dxlog_file7,
|
|
1230
1325
|
L: 255,
|
|
1231
1326
|
S: this,
|
|
1232
1327
|
C: (f, a) => f(...a)
|
|
@@ -1236,11 +1331,11 @@ var IdentityManager = class {
|
|
|
1236
1331
|
...params.deviceProfile
|
|
1237
1332
|
});
|
|
1238
1333
|
this.stateUpdate.emit();
|
|
1239
|
-
|
|
1334
|
+
log5("accepted identity", {
|
|
1240
1335
|
identityKey: identity.identityKey,
|
|
1241
1336
|
deviceKey: identity.deviceKey
|
|
1242
1337
|
}, {
|
|
1243
|
-
F:
|
|
1338
|
+
F: __dxlog_file7,
|
|
1244
1339
|
L: 265,
|
|
1245
1340
|
S: this,
|
|
1246
1341
|
C: (f, a) => f(...a)
|
|
@@ -1252,7 +1347,7 @@ var IdentityManager = class {
|
|
|
1252
1347
|
*/
|
|
1253
1348
|
async updateProfile(profile) {
|
|
1254
1349
|
invariant3(this._identity, "Identity not initialized.", {
|
|
1255
|
-
F:
|
|
1350
|
+
F: __dxlog_file7,
|
|
1256
1351
|
L: 273,
|
|
1257
1352
|
S: this,
|
|
1258
1353
|
A: [
|
|
@@ -1272,7 +1367,7 @@ var IdentityManager = class {
|
|
|
1272
1367
|
credential
|
|
1273
1368
|
}
|
|
1274
1369
|
});
|
|
1275
|
-
await this._identity.controlPipeline.state.waitUntilTimeframe(new
|
|
1370
|
+
await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
|
|
1276
1371
|
[
|
|
1277
1372
|
receipt.feedKey,
|
|
1278
1373
|
receipt.seq
|
|
@@ -1283,7 +1378,7 @@ var IdentityManager = class {
|
|
|
1283
1378
|
}
|
|
1284
1379
|
async updateDeviceProfile(profile) {
|
|
1285
1380
|
invariant3(this._identity, "Identity not initialized.", {
|
|
1286
|
-
F:
|
|
1381
|
+
F: __dxlog_file7,
|
|
1287
1382
|
L: 290,
|
|
1288
1383
|
S: this,
|
|
1289
1384
|
A: [
|
|
@@ -1303,7 +1398,7 @@ var IdentityManager = class {
|
|
|
1303
1398
|
credential
|
|
1304
1399
|
}
|
|
1305
1400
|
});
|
|
1306
|
-
await this._identity.controlPipeline.state.waitUntilTimeframe(new
|
|
1401
|
+
await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
|
|
1307
1402
|
[
|
|
1308
1403
|
receipt.feedKey,
|
|
1309
1404
|
receipt.seq
|
|
@@ -1319,7 +1414,7 @@ var IdentityManager = class {
|
|
|
1319
1414
|
}
|
|
1320
1415
|
async _constructIdentity(identityRecord) {
|
|
1321
1416
|
invariant3(!this._identity, void 0, {
|
|
1322
|
-
F:
|
|
1417
|
+
F: __dxlog_file7,
|
|
1323
1418
|
L: 316,
|
|
1324
1419
|
S: this,
|
|
1325
1420
|
A: [
|
|
@@ -1327,10 +1422,10 @@ var IdentityManager = class {
|
|
|
1327
1422
|
""
|
|
1328
1423
|
]
|
|
1329
1424
|
});
|
|
1330
|
-
|
|
1425
|
+
log5("constructing identity", {
|
|
1331
1426
|
identityRecord
|
|
1332
1427
|
}, {
|
|
1333
|
-
F:
|
|
1428
|
+
F: __dxlog_file7,
|
|
1334
1429
|
L: 317,
|
|
1335
1430
|
S: this,
|
|
1336
1431
|
C: (f, a) => f(...a)
|
|
@@ -1345,7 +1440,7 @@ var IdentityManager = class {
|
|
|
1345
1440
|
gossip
|
|
1346
1441
|
});
|
|
1347
1442
|
invariant3(identityRecord.haloSpace.controlFeedKey, void 0, {
|
|
1348
|
-
F:
|
|
1443
|
+
F: __dxlog_file7,
|
|
1349
1444
|
L: 330,
|
|
1350
1445
|
S: this,
|
|
1351
1446
|
A: [
|
|
@@ -1357,7 +1452,7 @@ var IdentityManager = class {
|
|
|
1357
1452
|
writable: true
|
|
1358
1453
|
});
|
|
1359
1454
|
invariant3(identityRecord.haloSpace.dataFeedKey, void 0, {
|
|
1360
|
-
F:
|
|
1455
|
+
F: __dxlog_file7,
|
|
1361
1456
|
L: 334,
|
|
1362
1457
|
S: this,
|
|
1363
1458
|
A: [
|
|
@@ -1388,10 +1483,10 @@ var IdentityManager = class {
|
|
|
1388
1483
|
identityKey: identityRecord.identityKey,
|
|
1389
1484
|
deviceKey: identityRecord.deviceKey
|
|
1390
1485
|
});
|
|
1391
|
-
|
|
1486
|
+
log5("done", {
|
|
1392
1487
|
identityKey: identityRecord.identityKey
|
|
1393
1488
|
}, {
|
|
1394
|
-
F:
|
|
1489
|
+
F: __dxlog_file7,
|
|
1395
1490
|
L: 360,
|
|
1396
1491
|
S: this,
|
|
1397
1492
|
C: (f, a) => f(...a)
|
|
@@ -1415,8 +1510,8 @@ var IdentityManager = class {
|
|
|
1415
1510
|
}));
|
|
1416
1511
|
},
|
|
1417
1512
|
onAuthFailure: () => {
|
|
1418
|
-
|
|
1419
|
-
F:
|
|
1513
|
+
log5.warn("auth failure", void 0, {
|
|
1514
|
+
F: __dxlog_file7,
|
|
1420
1515
|
L: 385,
|
|
1421
1516
|
S: this,
|
|
1422
1517
|
C: (f, a) => f(...a)
|
|
@@ -1440,25 +1535,55 @@ IdentityManager = _ts_decorate3([
|
|
|
1440
1535
|
], IdentityManager);
|
|
1441
1536
|
|
|
1442
1537
|
// packages/sdk/client-services/src/packlets/identity/identity-service.ts
|
|
1538
|
+
import { Trigger as Trigger3, sleep } from "@dxos/async";
|
|
1443
1539
|
import { Stream as Stream8 } from "@dxos/codec-protobuf";
|
|
1540
|
+
import { Resource } from "@dxos/context";
|
|
1444
1541
|
import { signPresentation } from "@dxos/credentials";
|
|
1445
1542
|
import { todo } from "@dxos/debug";
|
|
1446
1543
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1544
|
+
import { log as log6 } from "@dxos/log";
|
|
1545
|
+
import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
|
|
1546
|
+
import { safeAwaitAll } from "@dxos/util";
|
|
1547
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
|
|
1548
|
+
var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
|
|
1549
|
+
var IdentityServiceImpl = class extends Resource {
|
|
1550
|
+
constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
|
|
1551
|
+
super();
|
|
1451
1552
|
this._identityManager = _identityManager;
|
|
1452
1553
|
this._keyring = _keyring;
|
|
1554
|
+
this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
|
|
1555
|
+
this._createIdentity = _createIdentity;
|
|
1453
1556
|
this._onProfileUpdate = _onProfileUpdate;
|
|
1454
1557
|
}
|
|
1558
|
+
async _open() {
|
|
1559
|
+
const identity = this._identityManager.identity;
|
|
1560
|
+
if (identity && !identity.defaultSpaceId) {
|
|
1561
|
+
await this._fixIdentityWithoutDefaultSpace(identity);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1455
1564
|
async createIdentity(request) {
|
|
1456
1565
|
await this._createIdentity({
|
|
1457
1566
|
displayName: request.profile?.displayName,
|
|
1458
1567
|
deviceProfile: request.deviceProfile
|
|
1459
1568
|
});
|
|
1569
|
+
const dataSpaceManager = this._dataSpaceManagerProvider();
|
|
1570
|
+
await this._createDefaultSpace(dataSpaceManager);
|
|
1460
1571
|
return this._getIdentity();
|
|
1461
1572
|
}
|
|
1573
|
+
async _createDefaultSpace(dataSpaceManager) {
|
|
1574
|
+
const space = await dataSpaceManager.createDefaultSpace();
|
|
1575
|
+
const identity = this._identityManager.identity;
|
|
1576
|
+
invariant4(identity, void 0, {
|
|
1577
|
+
F: __dxlog_file8,
|
|
1578
|
+
L: 59,
|
|
1579
|
+
S: this,
|
|
1580
|
+
A: [
|
|
1581
|
+
"identity",
|
|
1582
|
+
""
|
|
1583
|
+
]
|
|
1584
|
+
});
|
|
1585
|
+
await identity.updateDefaultSpace(space.id);
|
|
1586
|
+
}
|
|
1462
1587
|
async recoverIdentity(request) {
|
|
1463
1588
|
return todo();
|
|
1464
1589
|
}
|
|
@@ -1483,8 +1608,8 @@ var IdentityServiceImpl = class {
|
|
|
1483
1608
|
}
|
|
1484
1609
|
async updateProfile(profile) {
|
|
1485
1610
|
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1486
|
-
F:
|
|
1487
|
-
L:
|
|
1611
|
+
F: __dxlog_file8,
|
|
1612
|
+
L: 89,
|
|
1488
1613
|
S: this,
|
|
1489
1614
|
A: [
|
|
1490
1615
|
"this._identityManager.identity",
|
|
@@ -1497,8 +1622,8 @@ var IdentityServiceImpl = class {
|
|
|
1497
1622
|
}
|
|
1498
1623
|
async signPresentation({ presentation, nonce }) {
|
|
1499
1624
|
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1500
|
-
F:
|
|
1501
|
-
L:
|
|
1625
|
+
F: __dxlog_file8,
|
|
1626
|
+
L: 96,
|
|
1502
1627
|
S: this,
|
|
1503
1628
|
A: [
|
|
1504
1629
|
"this._identityManager.identity",
|
|
@@ -1513,13 +1638,54 @@ var IdentityServiceImpl = class {
|
|
|
1513
1638
|
nonce
|
|
1514
1639
|
});
|
|
1515
1640
|
}
|
|
1641
|
+
async _fixIdentityWithoutDefaultSpace(identity) {
|
|
1642
|
+
let recodedDefaultSpace = false;
|
|
1643
|
+
let foundDefaultSpace = false;
|
|
1644
|
+
const dataSpaceManager = this._dataSpaceManagerProvider();
|
|
1645
|
+
const recordedDefaultSpaceTrigger = new Trigger3();
|
|
1646
|
+
const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
|
|
1647
|
+
if (space.state === SpaceState.CLOSED) {
|
|
1648
|
+
await space.open();
|
|
1649
|
+
const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
|
|
1650
|
+
await Promise.race([
|
|
1651
|
+
space.initializeDataPipeline(),
|
|
1652
|
+
requiresMigration
|
|
1653
|
+
]);
|
|
1654
|
+
}
|
|
1655
|
+
if (await dataSpaceManager.isDefaultSpace(space)) {
|
|
1656
|
+
if (foundDefaultSpace) {
|
|
1657
|
+
log6.warn("Multiple default spaces found. Using the first one.", {
|
|
1658
|
+
duplicate: space.id
|
|
1659
|
+
}, {
|
|
1660
|
+
F: __dxlog_file8,
|
|
1661
|
+
L: 127,
|
|
1662
|
+
S: this,
|
|
1663
|
+
C: (f, a) => f(...a)
|
|
1664
|
+
});
|
|
1665
|
+
return;
|
|
1666
|
+
}
|
|
1667
|
+
foundDefaultSpace = true;
|
|
1668
|
+
await identity.updateDefaultSpace(space.id);
|
|
1669
|
+
recodedDefaultSpace = true;
|
|
1670
|
+
recordedDefaultSpaceTrigger.wake();
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
await Promise.race([
|
|
1674
|
+
allProcessed,
|
|
1675
|
+
recordedDefaultSpaceTrigger.wait(),
|
|
1676
|
+
sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)
|
|
1677
|
+
]);
|
|
1678
|
+
if (!recodedDefaultSpace) {
|
|
1679
|
+
await this._createDefaultSpace(dataSpaceManager);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1516
1682
|
};
|
|
1517
1683
|
|
|
1518
1684
|
// packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
|
|
1519
1685
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1520
1686
|
import { AlreadyJoinedError } from "@dxos/protocols";
|
|
1521
1687
|
import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
|
|
1522
|
-
var
|
|
1688
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
|
|
1523
1689
|
var DeviceInvitationProtocol = class {
|
|
1524
1690
|
constructor(_keyring, _getIdentity, _acceptIdentity) {
|
|
1525
1691
|
this._keyring = _keyring;
|
|
@@ -1545,7 +1711,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1545
1711
|
}
|
|
1546
1712
|
async admit(_, request) {
|
|
1547
1713
|
invariant5(request.device, void 0, {
|
|
1548
|
-
F:
|
|
1714
|
+
F: __dxlog_file9,
|
|
1549
1715
|
L: 50,
|
|
1550
1716
|
S: this,
|
|
1551
1717
|
A: [
|
|
@@ -1591,7 +1757,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1591
1757
|
}
|
|
1592
1758
|
async accept(response, request) {
|
|
1593
1759
|
invariant5(response.device, void 0, {
|
|
1594
|
-
F:
|
|
1760
|
+
F: __dxlog_file9,
|
|
1595
1761
|
L: 95,
|
|
1596
1762
|
S: this,
|
|
1597
1763
|
A: [
|
|
@@ -1601,7 +1767,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1601
1767
|
});
|
|
1602
1768
|
const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
|
|
1603
1769
|
invariant5(request.device, void 0, {
|
|
1604
|
-
F:
|
|
1770
|
+
F: __dxlog_file9,
|
|
1605
1771
|
L: 98,
|
|
1606
1772
|
S: this,
|
|
1607
1773
|
A: [
|
|
@@ -1633,7 +1799,7 @@ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
|
1633
1799
|
import { createKeyPair, sign } from "@dxos/crypto";
|
|
1634
1800
|
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1635
1801
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1636
|
-
import { log as
|
|
1802
|
+
import { log as log10 } from "@dxos/log";
|
|
1637
1803
|
import { createTeleportProtocolFactory } from "@dxos/network-manager";
|
|
1638
1804
|
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
|
|
1639
1805
|
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -1642,10 +1808,10 @@ import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations
|
|
|
1642
1808
|
import { ComplexSet as ComplexSet3 } from "@dxos/util";
|
|
1643
1809
|
|
|
1644
1810
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1645
|
-
import { Trigger as
|
|
1811
|
+
import { Trigger as Trigger4 } from "@dxos/async";
|
|
1646
1812
|
import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
|
|
1647
1813
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1648
|
-
import { log as
|
|
1814
|
+
import { log as log7 } from "@dxos/log";
|
|
1649
1815
|
import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
|
|
1650
1816
|
import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1651
1817
|
import { RpcExtension } from "@dxos/teleport";
|
|
@@ -1670,7 +1836,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
|
|
|
1670
1836
|
};
|
|
1671
1837
|
|
|
1672
1838
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1673
|
-
var
|
|
1839
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
|
|
1674
1840
|
var OPTIONS_TIMEOUT = 1e4;
|
|
1675
1841
|
var InvitationGuestExtension = class extends RpcExtension {
|
|
1676
1842
|
constructor(_invitationFlowMutex, _callbacks) {
|
|
@@ -1684,8 +1850,11 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1684
1850
|
});
|
|
1685
1851
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1686
1852
|
this._callbacks = _callbacks;
|
|
1687
|
-
this._ctx = new Context4(
|
|
1688
|
-
|
|
1853
|
+
this._ctx = new Context4(void 0, {
|
|
1854
|
+
F: __dxlog_file10,
|
|
1855
|
+
L: 33
|
|
1856
|
+
});
|
|
1857
|
+
this._remoteOptionsTrigger = new Trigger4();
|
|
1689
1858
|
this._invitationFlowLock = null;
|
|
1690
1859
|
}
|
|
1691
1860
|
hasFlowLock() {
|
|
@@ -1696,7 +1865,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1696
1865
|
InvitationHostService: {
|
|
1697
1866
|
options: async (options) => {
|
|
1698
1867
|
invariant6(!this._remoteOptions, "Remote options already set.", {
|
|
1699
|
-
F:
|
|
1868
|
+
F: __dxlog_file10,
|
|
1700
1869
|
L: 63,
|
|
1701
1870
|
S: this,
|
|
1702
1871
|
A: [
|
|
@@ -1722,15 +1891,15 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1722
1891
|
async onOpen(context) {
|
|
1723
1892
|
await super.onOpen(context);
|
|
1724
1893
|
try {
|
|
1725
|
-
|
|
1726
|
-
F:
|
|
1894
|
+
log7("guest acquire lock", void 0, {
|
|
1895
|
+
F: __dxlog_file10,
|
|
1727
1896
|
L: 84,
|
|
1728
1897
|
S: this,
|
|
1729
1898
|
C: (f, a) => f(...a)
|
|
1730
1899
|
});
|
|
1731
1900
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1732
|
-
|
|
1733
|
-
F:
|
|
1901
|
+
log7("guest lock acquired", void 0, {
|
|
1902
|
+
F: __dxlog_file10,
|
|
1734
1903
|
L: 86,
|
|
1735
1904
|
S: this,
|
|
1736
1905
|
C: (f, a) => f(...a)
|
|
@@ -1738,8 +1907,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1738
1907
|
await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
|
|
1739
1908
|
role: Options.Role.GUEST
|
|
1740
1909
|
}));
|
|
1741
|
-
|
|
1742
|
-
F:
|
|
1910
|
+
log7("options sent", void 0, {
|
|
1911
|
+
F: __dxlog_file10,
|
|
1743
1912
|
L: 88,
|
|
1744
1913
|
S: this,
|
|
1745
1914
|
C: (f, a) => f(...a)
|
|
@@ -1747,8 +1916,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1747
1916
|
await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1748
1917
|
timeout: OPTIONS_TIMEOUT
|
|
1749
1918
|
}));
|
|
1750
|
-
|
|
1751
|
-
F:
|
|
1919
|
+
log7("options received", void 0, {
|
|
1920
|
+
F: __dxlog_file10,
|
|
1752
1921
|
L: 90,
|
|
1753
1922
|
S: this,
|
|
1754
1923
|
C: (f, a) => f(...a)
|
|
@@ -1781,8 +1950,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1781
1950
|
if (this._invitationFlowLock != null) {
|
|
1782
1951
|
this._invitationFlowLock.release();
|
|
1783
1952
|
this._invitationFlowLock = null;
|
|
1784
|
-
|
|
1785
|
-
F:
|
|
1953
|
+
log7("invitation flow lock released", void 0, {
|
|
1954
|
+
F: __dxlog_file10,
|
|
1786
1955
|
L: 123,
|
|
1787
1956
|
S: this,
|
|
1788
1957
|
C: (f, a) => f(...a)
|
|
@@ -1792,17 +1961,17 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1792
1961
|
};
|
|
1793
1962
|
|
|
1794
1963
|
// packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
|
|
1795
|
-
import { Trigger as
|
|
1964
|
+
import { Trigger as Trigger5, scheduleTask as scheduleTask2 } from "@dxos/async";
|
|
1796
1965
|
import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
|
|
1797
1966
|
import { randomBytes, verify } from "@dxos/crypto";
|
|
1798
1967
|
import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
|
|
1799
1968
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1800
|
-
import { log as
|
|
1969
|
+
import { log as log8 } from "@dxos/log";
|
|
1801
1970
|
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
|
|
1802
1971
|
import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1803
1972
|
import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1804
1973
|
import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
|
|
1805
|
-
var
|
|
1974
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
|
|
1806
1975
|
var OPTIONS_TIMEOUT2 = 1e4;
|
|
1807
1976
|
var MAX_OTP_ATTEMPTS = 3;
|
|
1808
1977
|
var InvitationHostExtension = class extends RpcExtension2 {
|
|
@@ -1817,13 +1986,16 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1817
1986
|
});
|
|
1818
1987
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1819
1988
|
this._callbacks = _callbacks;
|
|
1820
|
-
this._ctx = new Context5(
|
|
1821
|
-
|
|
1989
|
+
this._ctx = new Context5(void 0, {
|
|
1990
|
+
F: __dxlog_file11,
|
|
1991
|
+
L: 52
|
|
1992
|
+
});
|
|
1993
|
+
this._remoteOptionsTrigger = new Trigger5();
|
|
1822
1994
|
this._challenge = void 0;
|
|
1823
1995
|
this.guestProfile = void 0;
|
|
1824
1996
|
this.authenticationPassed = false;
|
|
1825
1997
|
this.authenticationRetry = 0;
|
|
1826
|
-
this.completedTrigger = new
|
|
1998
|
+
this.completedTrigger = new Trigger5();
|
|
1827
1999
|
this._invitationFlowLock = null;
|
|
1828
2000
|
}
|
|
1829
2001
|
hasFlowLock() {
|
|
@@ -1836,7 +2008,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1836
2008
|
InvitationHostService: {
|
|
1837
2009
|
options: async (options) => {
|
|
1838
2010
|
invariant7(!this._remoteOptions, "Remote options already set.", {
|
|
1839
|
-
F:
|
|
2011
|
+
F: __dxlog_file11,
|
|
1840
2012
|
L: 101,
|
|
1841
2013
|
S: this,
|
|
1842
2014
|
A: [
|
|
@@ -1850,10 +2022,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1850
2022
|
introduce: async (request) => {
|
|
1851
2023
|
const { profile, invitationId } = request;
|
|
1852
2024
|
const traceId = PublicKey5.random().toHex();
|
|
1853
|
-
|
|
2025
|
+
log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
|
|
1854
2026
|
id: traceId
|
|
1855
2027
|
}), {
|
|
1856
|
-
F:
|
|
2028
|
+
F: __dxlog_file11,
|
|
1857
2029
|
L: 110,
|
|
1858
2030
|
S: this,
|
|
1859
2031
|
C: (f, a) => f(...a)
|
|
@@ -1861,11 +2033,11 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1861
2033
|
const invitation = this._requireActiveInvitation();
|
|
1862
2034
|
this._assertInvitationState(Invitation3.State.CONNECTED);
|
|
1863
2035
|
if (invitationId !== invitation?.invitationId) {
|
|
1864
|
-
|
|
2036
|
+
log8.warn("incorrect invitationId", {
|
|
1865
2037
|
expected: invitation.invitationId,
|
|
1866
2038
|
actual: invitationId
|
|
1867
2039
|
}, {
|
|
1868
|
-
F:
|
|
2040
|
+
F: __dxlog_file11,
|
|
1869
2041
|
L: 116,
|
|
1870
2042
|
S: this,
|
|
1871
2043
|
C: (f, a) => f(...a)
|
|
@@ -1876,10 +2048,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1876
2048
|
authMethod: Invitation3.AuthMethod.NONE
|
|
1877
2049
|
};
|
|
1878
2050
|
}
|
|
1879
|
-
|
|
2051
|
+
log8("guest introduced themselves", {
|
|
1880
2052
|
guestProfile: profile
|
|
1881
2053
|
}, {
|
|
1882
|
-
F:
|
|
2054
|
+
F: __dxlog_file11,
|
|
1883
2055
|
L: 125,
|
|
1884
2056
|
S: this,
|
|
1885
2057
|
C: (f, a) => f(...a)
|
|
@@ -1887,10 +2059,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1887
2059
|
this.guestProfile = profile;
|
|
1888
2060
|
this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
|
|
1889
2061
|
this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
1890
|
-
|
|
2062
|
+
log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
|
|
1891
2063
|
id: traceId
|
|
1892
2064
|
}), {
|
|
1893
|
-
F:
|
|
2065
|
+
F: __dxlog_file11,
|
|
1894
2066
|
L: 132,
|
|
1895
2067
|
S: this,
|
|
1896
2068
|
C: (f, a) => f(...a)
|
|
@@ -1902,19 +2074,19 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1902
2074
|
},
|
|
1903
2075
|
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
1904
2076
|
const traceId = PublicKey5.random().toHex();
|
|
1905
|
-
|
|
2077
|
+
log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
|
|
1906
2078
|
id: traceId
|
|
1907
2079
|
}), {
|
|
1908
|
-
F:
|
|
2080
|
+
F: __dxlog_file11,
|
|
1909
2081
|
L: 141,
|
|
1910
2082
|
S: this,
|
|
1911
2083
|
C: (f, a) => f(...a)
|
|
1912
2084
|
});
|
|
1913
2085
|
const invitation = this._requireActiveInvitation();
|
|
1914
|
-
|
|
2086
|
+
log8("received authentication request", {
|
|
1915
2087
|
authCode: code
|
|
1916
2088
|
}, {
|
|
1917
|
-
F:
|
|
2089
|
+
F: __dxlog_file11,
|
|
1918
2090
|
L: 144,
|
|
1919
2091
|
S: this,
|
|
1920
2092
|
C: (f, a) => f(...a)
|
|
@@ -1927,8 +2099,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1927
2099
|
this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
|
|
1928
2100
|
switch (invitation.authMethod) {
|
|
1929
2101
|
case Invitation3.AuthMethod.NONE: {
|
|
1930
|
-
|
|
1931
|
-
F:
|
|
2102
|
+
log8("authentication not required", void 0, {
|
|
2103
|
+
F: __dxlog_file11,
|
|
1932
2104
|
L: 152,
|
|
1933
2105
|
S: this,
|
|
1934
2106
|
C: (f, a) => f(...a)
|
|
@@ -1963,10 +2135,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1963
2135
|
break;
|
|
1964
2136
|
}
|
|
1965
2137
|
default: {
|
|
1966
|
-
|
|
2138
|
+
log8.error("invalid authentication method", {
|
|
1967
2139
|
authMethod: invitation.authMethod
|
|
1968
2140
|
}, {
|
|
1969
|
-
F:
|
|
2141
|
+
F: __dxlog_file11,
|
|
1970
2142
|
L: 190,
|
|
1971
2143
|
S: this,
|
|
1972
2144
|
C: (f, a) => f(...a)
|
|
@@ -1985,13 +2157,13 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1985
2157
|
status
|
|
1986
2158
|
};
|
|
1987
2159
|
}
|
|
1988
|
-
|
|
2160
|
+
log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
|
|
1989
2161
|
id: traceId,
|
|
1990
2162
|
data: {
|
|
1991
2163
|
status
|
|
1992
2164
|
}
|
|
1993
2165
|
}), {
|
|
1994
|
-
F:
|
|
2166
|
+
F: __dxlog_file11,
|
|
1995
2167
|
L: 202,
|
|
1996
2168
|
S: this,
|
|
1997
2169
|
C: (f, a) => f(...a)
|
|
@@ -2002,10 +2174,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2002
2174
|
},
|
|
2003
2175
|
admit: async (request) => {
|
|
2004
2176
|
const traceId = PublicKey5.random().toHex();
|
|
2005
|
-
|
|
2177
|
+
log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
|
|
2006
2178
|
id: traceId
|
|
2007
2179
|
}), {
|
|
2008
|
-
F:
|
|
2180
|
+
F: __dxlog_file11,
|
|
2009
2181
|
L: 208,
|
|
2010
2182
|
S: this,
|
|
2011
2183
|
C: (f, a) => f(...a)
|
|
@@ -2019,10 +2191,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2019
2191
|
}
|
|
2020
2192
|
}
|
|
2021
2193
|
const response = await this._callbacks.admit(request);
|
|
2022
|
-
|
|
2194
|
+
log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
|
|
2023
2195
|
id: traceId
|
|
2024
2196
|
}), {
|
|
2025
|
-
F:
|
|
2197
|
+
F: __dxlog_file11,
|
|
2026
2198
|
L: 222,
|
|
2027
2199
|
S: this,
|
|
2028
2200
|
C: (f, a) => f(...a)
|
|
@@ -2039,15 +2211,15 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2039
2211
|
async onOpen(context) {
|
|
2040
2212
|
await super.onOpen(context);
|
|
2041
2213
|
try {
|
|
2042
|
-
|
|
2043
|
-
F:
|
|
2214
|
+
log8("host acquire lock", void 0, {
|
|
2215
|
+
F: __dxlog_file11,
|
|
2044
2216
|
L: 237,
|
|
2045
2217
|
S: this,
|
|
2046
2218
|
C: (f, a) => f(...a)
|
|
2047
2219
|
});
|
|
2048
2220
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
2049
|
-
|
|
2050
|
-
F:
|
|
2221
|
+
log8("host lock acquired", void 0, {
|
|
2222
|
+
F: __dxlog_file11,
|
|
2051
2223
|
L: 239,
|
|
2052
2224
|
S: this,
|
|
2053
2225
|
C: (f, a) => f(...a)
|
|
@@ -2057,8 +2229,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2057
2229
|
await this.rpc.InvitationHostService.options({
|
|
2058
2230
|
role: Options2.Role.HOST
|
|
2059
2231
|
});
|
|
2060
|
-
|
|
2061
|
-
F:
|
|
2232
|
+
log8("options sent", void 0, {
|
|
2233
|
+
F: __dxlog_file11,
|
|
2062
2234
|
L: 243,
|
|
2063
2235
|
S: this,
|
|
2064
2236
|
C: (f, a) => f(...a)
|
|
@@ -2066,8 +2238,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2066
2238
|
await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
|
|
2067
2239
|
timeout: OPTIONS_TIMEOUT2
|
|
2068
2240
|
}));
|
|
2069
|
-
|
|
2070
|
-
F:
|
|
2241
|
+
log8("options received", void 0, {
|
|
2242
|
+
F: __dxlog_file11,
|
|
2071
2243
|
L: 245,
|
|
2072
2244
|
S: this,
|
|
2073
2245
|
C: (f, a) => f(...a)
|
|
@@ -2120,8 +2292,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
2120
2292
|
if (this._invitationFlowLock != null) {
|
|
2121
2293
|
this._invitationFlowLock?.release();
|
|
2122
2294
|
this._invitationFlowLock = null;
|
|
2123
|
-
|
|
2124
|
-
F:
|
|
2295
|
+
log8("invitation flow lock released", void 0, {
|
|
2296
|
+
F: __dxlog_file11,
|
|
2125
2297
|
L: 300,
|
|
2126
2298
|
S: this,
|
|
2127
2299
|
C: (f, a) => f(...a)
|
|
@@ -2134,10 +2306,10 @@ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitat
|
|
|
2134
2306
|
// packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
|
|
2135
2307
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2136
2308
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2137
|
-
import { log as
|
|
2309
|
+
import { log as log9 } from "@dxos/log";
|
|
2138
2310
|
import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
2139
2311
|
import { ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
2140
|
-
var
|
|
2312
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
|
|
2141
2313
|
var InvitationTopology = class {
|
|
2142
2314
|
constructor(_role) {
|
|
2143
2315
|
this._role = _role;
|
|
@@ -2145,7 +2317,7 @@ var InvitationTopology = class {
|
|
|
2145
2317
|
}
|
|
2146
2318
|
init(controller) {
|
|
2147
2319
|
invariant8(!this._controller, "Already initialized.", {
|
|
2148
|
-
F:
|
|
2320
|
+
F: __dxlog_file12,
|
|
2149
2321
|
L: 42,
|
|
2150
2322
|
S: this,
|
|
2151
2323
|
A: [
|
|
@@ -2157,7 +2329,7 @@ var InvitationTopology = class {
|
|
|
2157
2329
|
}
|
|
2158
2330
|
update() {
|
|
2159
2331
|
invariant8(this._controller, "Not initialized.", {
|
|
2160
|
-
F:
|
|
2332
|
+
F: __dxlog_file12,
|
|
2161
2333
|
L: 47,
|
|
2162
2334
|
S: this,
|
|
2163
2335
|
A: [
|
|
@@ -2176,11 +2348,11 @@ var InvitationTopology = class {
|
|
|
2176
2348
|
const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
|
|
2177
2349
|
this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
|
|
2178
2350
|
if (firstUnknownPeer != null) {
|
|
2179
|
-
|
|
2351
|
+
log9("invitation connect", {
|
|
2180
2352
|
ownPeerId,
|
|
2181
2353
|
remotePeerId: firstUnknownPeer
|
|
2182
2354
|
}, {
|
|
2183
|
-
F:
|
|
2355
|
+
F: __dxlog_file12,
|
|
2184
2356
|
L: 69,
|
|
2185
2357
|
S: this,
|
|
2186
2358
|
C: (f, a) => f(...a)
|
|
@@ -2191,7 +2363,7 @@ var InvitationTopology = class {
|
|
|
2191
2363
|
}
|
|
2192
2364
|
async onOffer(peer) {
|
|
2193
2365
|
invariant8(this._controller, "Not initialized.", {
|
|
2194
|
-
F:
|
|
2366
|
+
F: __dxlog_file12,
|
|
2195
2367
|
L: 76,
|
|
2196
2368
|
S: this,
|
|
2197
2369
|
A: [
|
|
@@ -2210,7 +2382,7 @@ var InvitationTopology = class {
|
|
|
2210
2382
|
};
|
|
2211
2383
|
|
|
2212
2384
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
2213
|
-
var
|
|
2385
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
|
|
2214
2386
|
var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
|
|
2215
2387
|
var InvitationsHandler = class {
|
|
2216
2388
|
/**
|
|
@@ -2235,7 +2407,7 @@ var InvitationsHandler = class {
|
|
|
2235
2407
|
try {
|
|
2236
2408
|
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
2237
2409
|
invariant9(deviceKey, void 0, {
|
|
2238
|
-
F:
|
|
2410
|
+
F: __dxlog_file13,
|
|
2239
2411
|
L: 90,
|
|
2240
2412
|
S: this,
|
|
2241
2413
|
A: [
|
|
@@ -2261,18 +2433,18 @@ var InvitationsHandler = class {
|
|
|
2261
2433
|
scheduleTask3(connectionCtx, async () => {
|
|
2262
2434
|
const traceId = PublicKey7.random().toHex();
|
|
2263
2435
|
try {
|
|
2264
|
-
|
|
2436
|
+
log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
|
|
2265
2437
|
id: traceId
|
|
2266
2438
|
}), {
|
|
2267
|
-
F:
|
|
2439
|
+
F: __dxlog_file13,
|
|
2268
2440
|
L: 115,
|
|
2269
2441
|
S: this,
|
|
2270
2442
|
C: (f, a) => f(...a)
|
|
2271
2443
|
});
|
|
2272
|
-
|
|
2444
|
+
log10("connected", {
|
|
2273
2445
|
...protocol.toJSON()
|
|
2274
2446
|
}, {
|
|
2275
|
-
F:
|
|
2447
|
+
F: __dxlog_file13,
|
|
2276
2448
|
L: 116,
|
|
2277
2449
|
S: this,
|
|
2278
2450
|
C: (f, a) => f(...a)
|
|
@@ -2280,20 +2452,20 @@ var InvitationsHandler = class {
|
|
|
2280
2452
|
const deviceKey = await extension.completedTrigger.wait({
|
|
2281
2453
|
timeout: invitation.timeout
|
|
2282
2454
|
});
|
|
2283
|
-
|
|
2455
|
+
log10("admitted guest", {
|
|
2284
2456
|
guest: deviceKey,
|
|
2285
2457
|
...protocol.toJSON()
|
|
2286
2458
|
}, {
|
|
2287
|
-
F:
|
|
2459
|
+
F: __dxlog_file13,
|
|
2288
2460
|
L: 118,
|
|
2289
2461
|
S: this,
|
|
2290
2462
|
C: (f, a) => f(...a)
|
|
2291
2463
|
});
|
|
2292
2464
|
guardedState.set(extension, Invitation4.State.SUCCESS);
|
|
2293
|
-
|
|
2465
|
+
log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
|
|
2294
2466
|
id: traceId
|
|
2295
2467
|
}), {
|
|
2296
|
-
F:
|
|
2468
|
+
F: __dxlog_file13,
|
|
2297
2469
|
L: 120,
|
|
2298
2470
|
S: this,
|
|
2299
2471
|
C: (f, a) => f(...a)
|
|
@@ -2305,10 +2477,10 @@ var InvitationsHandler = class {
|
|
|
2305
2477
|
} catch (err) {
|
|
2306
2478
|
if (err instanceof TimeoutError) {
|
|
2307
2479
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2308
|
-
|
|
2480
|
+
log10("timeout", {
|
|
2309
2481
|
...protocol.toJSON()
|
|
2310
2482
|
}, {
|
|
2311
|
-
F:
|
|
2483
|
+
F: __dxlog_file13,
|
|
2312
2484
|
L: 129,
|
|
2313
2485
|
S: this,
|
|
2314
2486
|
C: (f, a) => f(...a)
|
|
@@ -2316,19 +2488,19 @@ var InvitationsHandler = class {
|
|
|
2316
2488
|
}
|
|
2317
2489
|
} else {
|
|
2318
2490
|
if (guardedState.error(extension, err)) {
|
|
2319
|
-
|
|
2320
|
-
F:
|
|
2491
|
+
log10.error("failed", err, {
|
|
2492
|
+
F: __dxlog_file13,
|
|
2321
2493
|
L: 133,
|
|
2322
2494
|
S: this,
|
|
2323
2495
|
C: (f, a) => f(...a)
|
|
2324
2496
|
});
|
|
2325
2497
|
}
|
|
2326
2498
|
}
|
|
2327
|
-
|
|
2499
|
+
log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
|
|
2328
2500
|
id: traceId,
|
|
2329
2501
|
error: err
|
|
2330
2502
|
}), {
|
|
2331
|
-
F:
|
|
2503
|
+
F: __dxlog_file13,
|
|
2332
2504
|
L: 136,
|
|
2333
2505
|
S: this,
|
|
2334
2506
|
C: (f, a) => f(...a)
|
|
@@ -2339,10 +2511,10 @@ var InvitationsHandler = class {
|
|
|
2339
2511
|
},
|
|
2340
2512
|
onError: (err) => {
|
|
2341
2513
|
if (err instanceof InvalidInvitationExtensionRoleError3) {
|
|
2342
|
-
|
|
2514
|
+
log10("invalid role", {
|
|
2343
2515
|
...err.context
|
|
2344
2516
|
}, {
|
|
2345
|
-
F:
|
|
2517
|
+
F: __dxlog_file13,
|
|
2346
2518
|
L: 144,
|
|
2347
2519
|
S: this,
|
|
2348
2520
|
C: (f, a) => f(...a)
|
|
@@ -2351,10 +2523,10 @@ var InvitationsHandler = class {
|
|
|
2351
2523
|
}
|
|
2352
2524
|
if (err instanceof TimeoutError) {
|
|
2353
2525
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2354
|
-
|
|
2526
|
+
log10("timeout", {
|
|
2355
2527
|
err
|
|
2356
2528
|
}, {
|
|
2357
|
-
F:
|
|
2529
|
+
F: __dxlog_file13,
|
|
2358
2530
|
L: 149,
|
|
2359
2531
|
S: this,
|
|
2360
2532
|
C: (f, a) => f(...a)
|
|
@@ -2362,8 +2534,8 @@ var InvitationsHandler = class {
|
|
|
2362
2534
|
}
|
|
2363
2535
|
} else {
|
|
2364
2536
|
if (guardedState.error(extension, err)) {
|
|
2365
|
-
|
|
2366
|
-
F:
|
|
2537
|
+
log10.error("failed", err, {
|
|
2538
|
+
F: __dxlog_file13,
|
|
2367
2539
|
L: 153,
|
|
2368
2540
|
S: this,
|
|
2369
2541
|
C: (f, a) => f(...a)
|
|
@@ -2376,8 +2548,8 @@ var InvitationsHandler = class {
|
|
|
2376
2548
|
};
|
|
2377
2549
|
if (invitation.lifetime && invitation.created) {
|
|
2378
2550
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
2379
|
-
|
|
2380
|
-
F:
|
|
2551
|
+
log10.warn("invitation has already expired", void 0, {
|
|
2552
|
+
F: __dxlog_file13,
|
|
2381
2553
|
L: 164,
|
|
2382
2554
|
S: this,
|
|
2383
2555
|
C: (f, a) => f(...a)
|
|
@@ -2400,7 +2572,7 @@ var InvitationsHandler = class {
|
|
|
2400
2572
|
const { timeout = INVITATION_TIMEOUT } = invitation;
|
|
2401
2573
|
if (deviceProfile) {
|
|
2402
2574
|
invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2403
|
-
F:
|
|
2575
|
+
F: __dxlog_file13,
|
|
2404
2576
|
L: 197,
|
|
2405
2577
|
S: this,
|
|
2406
2578
|
A: [
|
|
@@ -2413,12 +2585,12 @@ var InvitationsHandler = class {
|
|
|
2413
2585
|
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
2414
2586
|
const shouldCancelInvitationFlow = (extension) => {
|
|
2415
2587
|
const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
|
|
2416
|
-
|
|
2588
|
+
log10("should cancel invitation flow", {
|
|
2417
2589
|
isLockedByAnotherConnection,
|
|
2418
2590
|
invitationType: Invitation4.Type.DELEGATED,
|
|
2419
2591
|
triedPeers: triedPeersIds.size
|
|
2420
2592
|
}, {
|
|
2421
|
-
F:
|
|
2593
|
+
F: __dxlog_file13,
|
|
2422
2594
|
L: 205,
|
|
2423
2595
|
S: this,
|
|
2424
2596
|
C: (f, a) => f(...a)
|
|
@@ -2441,11 +2613,11 @@ var InvitationsHandler = class {
|
|
|
2441
2613
|
return;
|
|
2442
2614
|
}
|
|
2443
2615
|
connectionCtx.onDispose(async () => {
|
|
2444
|
-
|
|
2616
|
+
log10("extension disposed", {
|
|
2445
2617
|
admitted,
|
|
2446
2618
|
currentState: guardedState.current.state
|
|
2447
2619
|
}, {
|
|
2448
|
-
F:
|
|
2620
|
+
F: __dxlog_file13,
|
|
2449
2621
|
L: 233,
|
|
2450
2622
|
S: this,
|
|
2451
2623
|
C: (f, a) => f(...a)
|
|
@@ -2460,10 +2632,10 @@ var InvitationsHandler = class {
|
|
|
2460
2632
|
scheduleTask3(connectionCtx, async () => {
|
|
2461
2633
|
const traceId = PublicKey7.random().toHex();
|
|
2462
2634
|
try {
|
|
2463
|
-
|
|
2635
|
+
log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
|
|
2464
2636
|
id: traceId
|
|
2465
2637
|
}), {
|
|
2466
|
-
F:
|
|
2638
|
+
F: __dxlog_file13,
|
|
2467
2639
|
L: 245,
|
|
2468
2640
|
S: this,
|
|
2469
2641
|
C: (f, a) => f(...a)
|
|
@@ -2472,19 +2644,19 @@ var InvitationsHandler = class {
|
|
|
2472
2644
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2473
2645
|
extensionCtx.close();
|
|
2474
2646
|
}, timeout);
|
|
2475
|
-
|
|
2647
|
+
log10("connected", {
|
|
2476
2648
|
...protocol.toJSON()
|
|
2477
2649
|
}, {
|
|
2478
|
-
F:
|
|
2650
|
+
F: __dxlog_file13,
|
|
2479
2651
|
L: 256,
|
|
2480
2652
|
S: this,
|
|
2481
2653
|
C: (f, a) => f(...a)
|
|
2482
2654
|
});
|
|
2483
2655
|
guardedState.set(extension, Invitation4.State.CONNECTED);
|
|
2484
|
-
|
|
2656
|
+
log10("introduce", {
|
|
2485
2657
|
...protocol.toJSON()
|
|
2486
2658
|
}, {
|
|
2487
|
-
F:
|
|
2659
|
+
F: __dxlog_file13,
|
|
2488
2660
|
L: 260,
|
|
2489
2661
|
S: this,
|
|
2490
2662
|
C: (f, a) => f(...a)
|
|
@@ -2493,11 +2665,11 @@ var InvitationsHandler = class {
|
|
|
2493
2665
|
invitationId: invitation.invitationId,
|
|
2494
2666
|
...protocol.createIntroduction()
|
|
2495
2667
|
});
|
|
2496
|
-
|
|
2668
|
+
log10("introduce response", {
|
|
2497
2669
|
...protocol.toJSON(),
|
|
2498
2670
|
response: introductionResponse
|
|
2499
2671
|
}, {
|
|
2500
|
-
F:
|
|
2672
|
+
F: __dxlog_file13,
|
|
2501
2673
|
L: 265,
|
|
2502
2674
|
S: this,
|
|
2503
2675
|
C: (f, a) => f(...a)
|
|
@@ -2515,10 +2687,10 @@ var InvitationsHandler = class {
|
|
|
2515
2687
|
break;
|
|
2516
2688
|
}
|
|
2517
2689
|
}
|
|
2518
|
-
|
|
2690
|
+
log10("request admission", {
|
|
2519
2691
|
...protocol.toJSON()
|
|
2520
2692
|
}, {
|
|
2521
|
-
F:
|
|
2693
|
+
F: __dxlog_file13,
|
|
2522
2694
|
L: 291,
|
|
2523
2695
|
S: this,
|
|
2524
2696
|
C: (f, a) => f(...a)
|
|
@@ -2527,10 +2699,10 @@ var InvitationsHandler = class {
|
|
|
2527
2699
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
2528
2700
|
admitted = true;
|
|
2529
2701
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
2530
|
-
|
|
2702
|
+
log10("admitted by host", {
|
|
2531
2703
|
...protocol.toJSON()
|
|
2532
2704
|
}, {
|
|
2533
|
-
F:
|
|
2705
|
+
F: __dxlog_file13,
|
|
2534
2706
|
L: 302,
|
|
2535
2707
|
S: this,
|
|
2536
2708
|
C: (f, a) => f(...a)
|
|
@@ -2540,28 +2712,28 @@ var InvitationsHandler = class {
|
|
|
2540
2712
|
...result,
|
|
2541
2713
|
state: Invitation4.State.SUCCESS
|
|
2542
2714
|
});
|
|
2543
|
-
|
|
2715
|
+
log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
|
|
2544
2716
|
id: traceId
|
|
2545
2717
|
}), {
|
|
2546
|
-
F:
|
|
2718
|
+
F: __dxlog_file13,
|
|
2547
2719
|
L: 308,
|
|
2548
2720
|
S: this,
|
|
2549
2721
|
C: (f, a) => f(...a)
|
|
2550
2722
|
});
|
|
2551
2723
|
} catch (err) {
|
|
2552
2724
|
if (err instanceof TimeoutError) {
|
|
2553
|
-
|
|
2725
|
+
log10("timeout", {
|
|
2554
2726
|
...protocol.toJSON()
|
|
2555
2727
|
}, {
|
|
2556
|
-
F:
|
|
2728
|
+
F: __dxlog_file13,
|
|
2557
2729
|
L: 311,
|
|
2558
2730
|
S: this,
|
|
2559
2731
|
C: (f, a) => f(...a)
|
|
2560
2732
|
});
|
|
2561
2733
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2562
2734
|
} else {
|
|
2563
|
-
|
|
2564
|
-
F:
|
|
2735
|
+
log10("auth failed", err, {
|
|
2736
|
+
F: __dxlog_file13,
|
|
2565
2737
|
L: 314,
|
|
2566
2738
|
S: this,
|
|
2567
2739
|
C: (f, a) => f(...a)
|
|
@@ -2569,11 +2741,11 @@ var InvitationsHandler = class {
|
|
|
2569
2741
|
guardedState.error(extension, err);
|
|
2570
2742
|
}
|
|
2571
2743
|
extensionCtx.close(err);
|
|
2572
|
-
|
|
2744
|
+
log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
|
|
2573
2745
|
id: traceId,
|
|
2574
2746
|
error: err
|
|
2575
2747
|
}), {
|
|
2576
|
-
F:
|
|
2748
|
+
F: __dxlog_file13,
|
|
2577
2749
|
L: 318,
|
|
2578
2750
|
S: this,
|
|
2579
2751
|
C: (f, a) => f(...a)
|
|
@@ -2586,18 +2758,18 @@ var InvitationsHandler = class {
|
|
|
2586
2758
|
return;
|
|
2587
2759
|
}
|
|
2588
2760
|
if (err instanceof TimeoutError) {
|
|
2589
|
-
|
|
2761
|
+
log10("timeout", {
|
|
2590
2762
|
...protocol.toJSON()
|
|
2591
2763
|
}, {
|
|
2592
|
-
F:
|
|
2764
|
+
F: __dxlog_file13,
|
|
2593
2765
|
L: 327,
|
|
2594
2766
|
S: this,
|
|
2595
2767
|
C: (f, a) => f(...a)
|
|
2596
2768
|
});
|
|
2597
2769
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2598
2770
|
} else {
|
|
2599
|
-
|
|
2600
|
-
F:
|
|
2771
|
+
log10("auth failed", err, {
|
|
2772
|
+
F: __dxlog_file13,
|
|
2601
2773
|
L: 330,
|
|
2602
2774
|
S: this,
|
|
2603
2775
|
C: (f, a) => f(...a)
|
|
@@ -2615,7 +2787,7 @@ var InvitationsHandler = class {
|
|
|
2615
2787
|
await ctx.dispose();
|
|
2616
2788
|
} else {
|
|
2617
2789
|
invariant9(invitation.swarmKey, void 0, {
|
|
2618
|
-
F:
|
|
2790
|
+
F: __dxlog_file13,
|
|
2619
2791
|
L: 345,
|
|
2620
2792
|
S: this,
|
|
2621
2793
|
A: [
|
|
@@ -2709,16 +2881,29 @@ var InvitationsHandler = class {
|
|
|
2709
2881
|
};
|
|
2710
2882
|
}
|
|
2711
2883
|
_logStateUpdate(invitation, actor, newState) {
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2884
|
+
if (this._isNotTerminal(newState)) {
|
|
2885
|
+
log10("invitation state update", {
|
|
2886
|
+
actor: actor?.constructor.name,
|
|
2887
|
+
newState: stateToString(newState),
|
|
2888
|
+
oldState: stateToString(invitation.state)
|
|
2889
|
+
}, {
|
|
2890
|
+
F: __dxlog_file13,
|
|
2891
|
+
L: 439,
|
|
2892
|
+
S: this,
|
|
2893
|
+
C: (f, a) => f(...a)
|
|
2894
|
+
});
|
|
2895
|
+
} else {
|
|
2896
|
+
log10.info("invitation state update", {
|
|
2897
|
+
actor: actor?.constructor.name,
|
|
2898
|
+
newState: stateToString(newState),
|
|
2899
|
+
oldState: stateToString(invitation.state)
|
|
2900
|
+
}, {
|
|
2901
|
+
F: __dxlog_file13,
|
|
2902
|
+
L: 445,
|
|
2903
|
+
S: this,
|
|
2904
|
+
C: (f, a) => f(...a)
|
|
2905
|
+
});
|
|
2906
|
+
}
|
|
2722
2907
|
}
|
|
2723
2908
|
_isNotTerminal(currentState) {
|
|
2724
2909
|
return ![
|
|
@@ -2731,17 +2916,17 @@ var InvitationsHandler = class {
|
|
|
2731
2916
|
}
|
|
2732
2917
|
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2733
2918
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2734
|
-
|
|
2735
|
-
F:
|
|
2736
|
-
L:
|
|
2919
|
+
log10("guest waiting for authentication code...", void 0, {
|
|
2920
|
+
F: __dxlog_file13,
|
|
2921
|
+
L: 470,
|
|
2737
2922
|
S: this,
|
|
2738
2923
|
C: (f, a) => f(...a)
|
|
2739
2924
|
});
|
|
2740
2925
|
setState(Invitation4.State.READY_FOR_AUTHENTICATION);
|
|
2741
2926
|
const authCode = await authenticated.wait(options);
|
|
2742
|
-
|
|
2743
|
-
F:
|
|
2744
|
-
L:
|
|
2927
|
+
log10("sending authentication request", void 0, {
|
|
2928
|
+
F: __dxlog_file13,
|
|
2929
|
+
L: 474,
|
|
2745
2930
|
S: this,
|
|
2746
2931
|
C: (f, a) => f(...a)
|
|
2747
2932
|
});
|
|
@@ -2756,11 +2941,11 @@ var InvitationsHandler = class {
|
|
|
2756
2941
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2757
2942
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2758
2943
|
} else {
|
|
2759
|
-
|
|
2944
|
+
log10("retrying invalid code", {
|
|
2760
2945
|
attempt
|
|
2761
2946
|
}, {
|
|
2762
|
-
F:
|
|
2763
|
-
L:
|
|
2947
|
+
F: __dxlog_file13,
|
|
2948
|
+
L: 485,
|
|
2764
2949
|
S: this,
|
|
2765
2950
|
C: (f, a) => f(...a)
|
|
2766
2951
|
});
|
|
@@ -2776,9 +2961,9 @@ var InvitationsHandler = class {
|
|
|
2776
2961
|
if (introductionResponse.challenge == null) {
|
|
2777
2962
|
throw new Error("challenge missing in the introduction");
|
|
2778
2963
|
}
|
|
2779
|
-
|
|
2780
|
-
F:
|
|
2781
|
-
L:
|
|
2964
|
+
log10("sending authentication request", void 0, {
|
|
2965
|
+
F: __dxlog_file13,
|
|
2966
|
+
L: 504,
|
|
2782
2967
|
S: this,
|
|
2783
2968
|
C: (f, a) => f(...a)
|
|
2784
2969
|
});
|
|
@@ -2898,14 +3083,14 @@ var InvitationsServiceImpl = class {
|
|
|
2898
3083
|
};
|
|
2899
3084
|
|
|
2900
3085
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2901
|
-
import {
|
|
3086
|
+
import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
2902
3087
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
2903
3088
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2904
|
-
import { log as
|
|
3089
|
+
import { log as log11 } from "@dxos/log";
|
|
2905
3090
|
import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
|
|
2906
3091
|
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2907
3092
|
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2908
|
-
var
|
|
3093
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2909
3094
|
var SpaceInvitationProtocol = class {
|
|
2910
3095
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2911
3096
|
this._spaceManager = _spaceManager;
|
|
@@ -2939,99 +3124,63 @@ var SpaceInvitationProtocol = class {
|
|
|
2939
3124
|
};
|
|
2940
3125
|
}
|
|
2941
3126
|
async admit(invitation, request, guestProfile) {
|
|
2942
|
-
invariant10(this._spaceKey, void 0, {
|
|
2943
|
-
F:
|
|
2944
|
-
L:
|
|
3127
|
+
invariant10(this._spaceKey && request.space, void 0, {
|
|
3128
|
+
F: __dxlog_file14,
|
|
3129
|
+
L: 74,
|
|
2945
3130
|
S: this,
|
|
2946
3131
|
A: [
|
|
2947
|
-
"this._spaceKey",
|
|
3132
|
+
"this._spaceKey && request.space",
|
|
2948
3133
|
""
|
|
2949
3134
|
]
|
|
2950
3135
|
});
|
|
3136
|
+
log11("writing guest credentials", {
|
|
3137
|
+
host: this._signingContext.deviceKey,
|
|
3138
|
+
guest: request.space.deviceKey
|
|
3139
|
+
}, {
|
|
3140
|
+
F: __dxlog_file14,
|
|
3141
|
+
L: 75,
|
|
3142
|
+
S: this,
|
|
3143
|
+
C: (f, a) => f(...a)
|
|
3144
|
+
});
|
|
3145
|
+
const spaceMemberCredential = await this._spaceManager.admitMember({
|
|
3146
|
+
spaceKey: this._spaceKey,
|
|
3147
|
+
identityKey: request.space.identityKey,
|
|
3148
|
+
role: invitation.role ?? SpaceMember2.Role.ADMIN,
|
|
3149
|
+
profile: guestProfile,
|
|
3150
|
+
delegationCredentialId: invitation.delegationCredentialId
|
|
3151
|
+
});
|
|
2951
3152
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
3153
|
+
return {
|
|
3154
|
+
space: {
|
|
3155
|
+
credential: spaceMemberCredential,
|
|
3156
|
+
controlTimeframe: space?.inner.controlPipeline.state.timeframe
|
|
3157
|
+
}
|
|
3158
|
+
};
|
|
3159
|
+
}
|
|
3160
|
+
async delegate(invitation) {
|
|
3161
|
+
invariant10(this._spaceKey, void 0, {
|
|
3162
|
+
F: __dxlog_file14,
|
|
3163
|
+
L: 95,
|
|
2955
3164
|
S: this,
|
|
2956
3165
|
A: [
|
|
2957
|
-
"
|
|
3166
|
+
"this._spaceKey",
|
|
2958
3167
|
""
|
|
2959
3168
|
]
|
|
2960
3169
|
});
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
3170
|
+
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
3171
|
+
invariant10(space, void 0, {
|
|
3172
|
+
F: __dxlog_file14,
|
|
3173
|
+
L: 97,
|
|
2964
3174
|
S: this,
|
|
2965
3175
|
A: [
|
|
2966
|
-
"
|
|
2967
|
-
""
|
|
2968
|
-
]
|
|
2969
|
-
});
|
|
2970
|
-
const { identityKey, deviceKey } = request.space;
|
|
2971
|
-
if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
|
|
2972
|
-
throw new AlreadyJoinedError2();
|
|
2973
|
-
}
|
|
2974
|
-
log9("writing guest credentials", {
|
|
2975
|
-
host: this._signingContext.deviceKey,
|
|
2976
|
-
guest: deviceKey
|
|
2977
|
-
}, {
|
|
2978
|
-
F: __dxlog_file12,
|
|
2979
|
-
L: 87,
|
|
2980
|
-
S: this,
|
|
2981
|
-
C: (f, a) => f(...a)
|
|
2982
|
-
});
|
|
2983
|
-
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember2.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
|
|
2984
|
-
invariant10(credentials[0].credential, void 0, {
|
|
2985
|
-
F: __dxlog_file12,
|
|
2986
|
-
L: 101,
|
|
2987
|
-
S: this,
|
|
2988
|
-
A: [
|
|
2989
|
-
"credentials[0].credential",
|
|
2990
|
-
""
|
|
2991
|
-
]
|
|
2992
|
-
});
|
|
2993
|
-
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2994
|
-
invariant10(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2995
|
-
F: __dxlog_file12,
|
|
2996
|
-
L: 103,
|
|
2997
|
-
S: this,
|
|
2998
|
-
A: [
|
|
2999
|
-
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
3000
|
-
""
|
|
3001
|
-
]
|
|
3002
|
-
});
|
|
3003
|
-
await writeMessages2(space.inner.controlPipeline.writer, credentials);
|
|
3004
|
-
return {
|
|
3005
|
-
space: {
|
|
3006
|
-
credential: spaceMemberCredential,
|
|
3007
|
-
controlTimeframe: space.inner.controlPipeline.state.timeframe
|
|
3008
|
-
}
|
|
3009
|
-
};
|
|
3010
|
-
}
|
|
3011
|
-
async delegate(invitation) {
|
|
3012
|
-
invariant10(this._spaceKey, void 0, {
|
|
3013
|
-
F: __dxlog_file12,
|
|
3014
|
-
L: 116,
|
|
3015
|
-
S: this,
|
|
3016
|
-
A: [
|
|
3017
|
-
"this._spaceKey",
|
|
3018
|
-
""
|
|
3019
|
-
]
|
|
3020
|
-
});
|
|
3021
|
-
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
3022
|
-
invariant10(space, void 0, {
|
|
3023
|
-
F: __dxlog_file12,
|
|
3024
|
-
L: 118,
|
|
3025
|
-
S: this,
|
|
3026
|
-
A: [
|
|
3027
|
-
"space",
|
|
3176
|
+
"space",
|
|
3028
3177
|
""
|
|
3029
3178
|
]
|
|
3030
3179
|
});
|
|
3031
3180
|
if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
|
|
3032
3181
|
invariant10(invitation.guestKeypair?.publicKey, void 0, {
|
|
3033
|
-
F:
|
|
3034
|
-
L:
|
|
3182
|
+
F: __dxlog_file14,
|
|
3183
|
+
L: 99,
|
|
3035
3184
|
S: this,
|
|
3036
3185
|
A: [
|
|
3037
3186
|
"invitation.guestKeypair?.publicKey",
|
|
@@ -3039,12 +3188,12 @@ var SpaceInvitationProtocol = class {
|
|
|
3039
3188
|
]
|
|
3040
3189
|
});
|
|
3041
3190
|
}
|
|
3042
|
-
|
|
3191
|
+
log11("writing delegate space invitation", {
|
|
3043
3192
|
host: this._signingContext.deviceKey,
|
|
3044
3193
|
id: invitation.invitationId
|
|
3045
3194
|
}, {
|
|
3046
|
-
F:
|
|
3047
|
-
L:
|
|
3195
|
+
F: __dxlog_file14,
|
|
3196
|
+
L: 102,
|
|
3048
3197
|
S: this,
|
|
3049
3198
|
C: (f, a) => f(...a)
|
|
3050
3199
|
});
|
|
@@ -3058,8 +3207,8 @@ var SpaceInvitationProtocol = class {
|
|
|
3058
3207
|
guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
|
|
3059
3208
|
});
|
|
3060
3209
|
invariant10(credential.credential, void 0, {
|
|
3061
|
-
F:
|
|
3062
|
-
L:
|
|
3210
|
+
F: __dxlog_file14,
|
|
3211
|
+
L: 122,
|
|
3063
3212
|
S: this,
|
|
3064
3213
|
A: [
|
|
3065
3214
|
"credential.credential",
|
|
@@ -3073,8 +3222,8 @@ var SpaceInvitationProtocol = class {
|
|
|
3073
3222
|
}
|
|
3074
3223
|
async cancelDelegation(invitation) {
|
|
3075
3224
|
invariant10(this._spaceKey, void 0, {
|
|
3076
|
-
F:
|
|
3077
|
-
L:
|
|
3225
|
+
F: __dxlog_file14,
|
|
3226
|
+
L: 128,
|
|
3078
3227
|
S: this,
|
|
3079
3228
|
A: [
|
|
3080
3229
|
"this._spaceKey",
|
|
@@ -3082,8 +3231,8 @@ var SpaceInvitationProtocol = class {
|
|
|
3082
3231
|
]
|
|
3083
3232
|
});
|
|
3084
3233
|
invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
|
|
3085
|
-
F:
|
|
3086
|
-
L:
|
|
3234
|
+
F: __dxlog_file14,
|
|
3235
|
+
L: 129,
|
|
3087
3236
|
S: this,
|
|
3088
3237
|
A: [
|
|
3089
3238
|
"invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
|
|
@@ -3092,27 +3241,27 @@ var SpaceInvitationProtocol = class {
|
|
|
3092
3241
|
});
|
|
3093
3242
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
3094
3243
|
invariant10(space, void 0, {
|
|
3095
|
-
F:
|
|
3096
|
-
L:
|
|
3244
|
+
F: __dxlog_file14,
|
|
3245
|
+
L: 131,
|
|
3097
3246
|
S: this,
|
|
3098
3247
|
A: [
|
|
3099
3248
|
"space",
|
|
3100
3249
|
""
|
|
3101
3250
|
]
|
|
3102
3251
|
});
|
|
3103
|
-
|
|
3252
|
+
log11("cancelling delegated space invitation", {
|
|
3104
3253
|
host: this._signingContext.deviceKey,
|
|
3105
3254
|
id: invitation.invitationId
|
|
3106
3255
|
}, {
|
|
3107
|
-
F:
|
|
3108
|
-
L:
|
|
3256
|
+
F: __dxlog_file14,
|
|
3257
|
+
L: 133,
|
|
3109
3258
|
S: this,
|
|
3110
3259
|
C: (f, a) => f(...a)
|
|
3111
3260
|
});
|
|
3112
3261
|
const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
|
|
3113
3262
|
invariant10(credential.credential, void 0, {
|
|
3114
|
-
F:
|
|
3115
|
-
L:
|
|
3263
|
+
F: __dxlog_file14,
|
|
3264
|
+
L: 140,
|
|
3116
3265
|
S: this,
|
|
3117
3266
|
A: [
|
|
3118
3267
|
"credential.credential",
|
|
@@ -3150,8 +3299,8 @@ var SpaceInvitationProtocol = class {
|
|
|
3150
3299
|
}
|
|
3151
3300
|
async accept(response) {
|
|
3152
3301
|
invariant10(response.space, void 0, {
|
|
3153
|
-
F:
|
|
3154
|
-
L:
|
|
3302
|
+
F: __dxlog_file14,
|
|
3303
|
+
L: 175,
|
|
3155
3304
|
S: this,
|
|
3156
3305
|
A: [
|
|
3157
3306
|
"response.space",
|
|
@@ -3159,10 +3308,10 @@ var SpaceInvitationProtocol = class {
|
|
|
3159
3308
|
]
|
|
3160
3309
|
});
|
|
3161
3310
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
3162
|
-
const assertion =
|
|
3311
|
+
const assertion = getCredentialAssertion2(credential);
|
|
3163
3312
|
invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
3164
|
-
F:
|
|
3165
|
-
L:
|
|
3313
|
+
F: __dxlog_file14,
|
|
3314
|
+
L: 178,
|
|
3166
3315
|
S: this,
|
|
3167
3316
|
A: [
|
|
3168
3317
|
"assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -3170,8 +3319,8 @@ var SpaceInvitationProtocol = class {
|
|
|
3170
3319
|
]
|
|
3171
3320
|
});
|
|
3172
3321
|
invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
3173
|
-
F:
|
|
3174
|
-
L:
|
|
3322
|
+
F: __dxlog_file14,
|
|
3323
|
+
L: 179,
|
|
3175
3324
|
S: this,
|
|
3176
3325
|
A: [
|
|
3177
3326
|
"credential.subject.id.equals(this._signingContext.identityKey)",
|
|
@@ -3195,17 +3344,17 @@ var SpaceInvitationProtocol = class {
|
|
|
3195
3344
|
};
|
|
3196
3345
|
|
|
3197
3346
|
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
3198
|
-
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as
|
|
3347
|
+
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger6 } from "@dxos/async";
|
|
3199
3348
|
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3200
3349
|
import { Context as Context6 } from "@dxos/context";
|
|
3201
3350
|
import { generatePasscode } from "@dxos/credentials";
|
|
3202
3351
|
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
3203
3352
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3204
3353
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
3205
|
-
import { log as
|
|
3354
|
+
import { log as log12 } from "@dxos/log";
|
|
3206
3355
|
import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3207
3356
|
import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3208
|
-
var
|
|
3357
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
3209
3358
|
var InvitationsManager = class {
|
|
3210
3359
|
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
3211
3360
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -3247,8 +3396,8 @@ var InvitationsManager = class {
|
|
|
3247
3396
|
try {
|
|
3248
3397
|
await this._persistIfRequired(handler, stream, invitation);
|
|
3249
3398
|
} catch (err) {
|
|
3250
|
-
|
|
3251
|
-
F:
|
|
3399
|
+
log12.catch(err, void 0, {
|
|
3400
|
+
F: __dxlog_file15,
|
|
3252
3401
|
L: 82,
|
|
3253
3402
|
S: this,
|
|
3254
3403
|
C: (f, a) => f(...a)
|
|
@@ -3271,7 +3420,7 @@ var InvitationsManager = class {
|
|
|
3271
3420
|
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
3272
3421
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
3273
3422
|
invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
3274
|
-
F:
|
|
3423
|
+
F: __dxlog_file15,
|
|
3275
3424
|
L: 103,
|
|
3276
3425
|
S: this,
|
|
3277
3426
|
A: [
|
|
@@ -3289,8 +3438,8 @@ var InvitationsManager = class {
|
|
|
3289
3438
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
3290
3439
|
};
|
|
3291
3440
|
} catch (err) {
|
|
3292
|
-
|
|
3293
|
-
F:
|
|
3441
|
+
log12.catch(err, void 0, {
|
|
3442
|
+
F: __dxlog_file15,
|
|
3294
3443
|
L: 110,
|
|
3295
3444
|
S: this,
|
|
3296
3445
|
C: (f, a) => f(...a)
|
|
@@ -3321,14 +3470,14 @@ var InvitationsManager = class {
|
|
|
3321
3470
|
return invitation;
|
|
3322
3471
|
}
|
|
3323
3472
|
async authenticate({ invitationId, authCode }) {
|
|
3324
|
-
|
|
3325
|
-
F:
|
|
3473
|
+
log12("authenticating...", void 0, {
|
|
3474
|
+
F: __dxlog_file15,
|
|
3326
3475
|
L: 140,
|
|
3327
3476
|
S: this,
|
|
3328
3477
|
C: (f, a) => f(...a)
|
|
3329
3478
|
});
|
|
3330
3479
|
invariant11(invitationId, void 0, {
|
|
3331
|
-
F:
|
|
3480
|
+
F: __dxlog_file15,
|
|
3332
3481
|
L: 141,
|
|
3333
3482
|
S: this,
|
|
3334
3483
|
A: [
|
|
@@ -3338,10 +3487,10 @@ var InvitationsManager = class {
|
|
|
3338
3487
|
});
|
|
3339
3488
|
const observable = this._acceptInvitations.get(invitationId);
|
|
3340
3489
|
if (!observable) {
|
|
3341
|
-
|
|
3490
|
+
log12.warn("invalid invitation", {
|
|
3342
3491
|
invitationId
|
|
3343
3492
|
}, {
|
|
3344
|
-
F:
|
|
3493
|
+
F: __dxlog_file15,
|
|
3345
3494
|
L: 144,
|
|
3346
3495
|
S: this,
|
|
3347
3496
|
C: (f, a) => f(...a)
|
|
@@ -3351,16 +3500,16 @@ var InvitationsManager = class {
|
|
|
3351
3500
|
}
|
|
3352
3501
|
}
|
|
3353
3502
|
async cancelInvitation({ invitationId }) {
|
|
3354
|
-
|
|
3503
|
+
log12("cancelInvitation...", {
|
|
3355
3504
|
invitationId
|
|
3356
3505
|
}, {
|
|
3357
|
-
F:
|
|
3506
|
+
F: __dxlog_file15,
|
|
3358
3507
|
L: 151,
|
|
3359
3508
|
S: this,
|
|
3360
3509
|
C: (f, a) => f(...a)
|
|
3361
3510
|
});
|
|
3362
3511
|
invariant11(invitationId, void 0, {
|
|
3363
|
-
F:
|
|
3512
|
+
F: __dxlog_file15,
|
|
3364
3513
|
L: 152,
|
|
3365
3514
|
S: this,
|
|
3366
3515
|
A: [
|
|
@@ -3434,12 +3583,15 @@ var InvitationsManager = class {
|
|
|
3434
3583
|
stream.error(err);
|
|
3435
3584
|
void ctx.dispose();
|
|
3436
3585
|
}
|
|
3586
|
+
}, {
|
|
3587
|
+
F: __dxlog_file15,
|
|
3588
|
+
L: 234
|
|
3437
3589
|
});
|
|
3438
3590
|
ctx.onDispose(() => {
|
|
3439
|
-
|
|
3591
|
+
log12("complete", {
|
|
3440
3592
|
...handler.toJSON()
|
|
3441
3593
|
}, {
|
|
3442
|
-
F:
|
|
3594
|
+
F: __dxlog_file15,
|
|
3443
3595
|
L: 241,
|
|
3444
3596
|
S: this,
|
|
3445
3597
|
C: (f, a) => f(...a)
|
|
@@ -3464,15 +3616,15 @@ var InvitationsManager = class {
|
|
|
3464
3616
|
};
|
|
3465
3617
|
}
|
|
3466
3618
|
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3467
|
-
const otpEnteredTrigger = new
|
|
3619
|
+
const otpEnteredTrigger = new Trigger6();
|
|
3468
3620
|
const stream = new PushStream();
|
|
3469
3621
|
const ctx = new Context6({
|
|
3470
3622
|
onError: (err) => {
|
|
3471
3623
|
if (err instanceof TimeoutError2) {
|
|
3472
|
-
|
|
3624
|
+
log12("timeout", {
|
|
3473
3625
|
...handler.toJSON()
|
|
3474
3626
|
}, {
|
|
3475
|
-
F:
|
|
3627
|
+
F: __dxlog_file15,
|
|
3476
3628
|
L: 261,
|
|
3477
3629
|
S: this,
|
|
3478
3630
|
C: (f, a) => f(...a)
|
|
@@ -3482,8 +3634,8 @@ var InvitationsManager = class {
|
|
|
3482
3634
|
state: Invitation6.State.TIMEOUT
|
|
3483
3635
|
});
|
|
3484
3636
|
} else {
|
|
3485
|
-
|
|
3486
|
-
F:
|
|
3637
|
+
log12.warn("auth failed", err, {
|
|
3638
|
+
F: __dxlog_file15,
|
|
3487
3639
|
L: 264,
|
|
3488
3640
|
S: this,
|
|
3489
3641
|
C: (f, a) => f(...a)
|
|
@@ -3495,12 +3647,15 @@ var InvitationsManager = class {
|
|
|
3495
3647
|
}
|
|
3496
3648
|
void ctx.dispose();
|
|
3497
3649
|
}
|
|
3650
|
+
}, {
|
|
3651
|
+
F: __dxlog_file15,
|
|
3652
|
+
L: 258
|
|
3498
3653
|
});
|
|
3499
3654
|
ctx.onDispose(() => {
|
|
3500
|
-
|
|
3655
|
+
log12("complete", {
|
|
3501
3656
|
...handler.toJSON()
|
|
3502
3657
|
}, {
|
|
3503
|
-
F:
|
|
3658
|
+
F: __dxlog_file15,
|
|
3504
3659
|
L: 271,
|
|
3505
3660
|
S: this,
|
|
3506
3661
|
C: (f, a) => f(...a)
|
|
@@ -3544,8 +3699,8 @@ var InvitationsManager = class {
|
|
|
3544
3699
|
try {
|
|
3545
3700
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
3546
3701
|
} catch (err) {
|
|
3547
|
-
|
|
3548
|
-
F:
|
|
3702
|
+
log12.catch(err, void 0, {
|
|
3703
|
+
F: __dxlog_file15,
|
|
3549
3704
|
L: 307,
|
|
3550
3705
|
S: this,
|
|
3551
3706
|
C: (f, a) => f(...a)
|
|
@@ -3560,33 +3715,40 @@ var InvitationsManager = class {
|
|
|
3560
3715
|
};
|
|
3561
3716
|
|
|
3562
3717
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
3563
|
-
import { Event as Event6,
|
|
3718
|
+
import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
|
|
3564
3719
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3565
|
-
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as
|
|
3720
|
+
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
|
|
3566
3721
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
3567
|
-
import {
|
|
3568
|
-
import {
|
|
3569
|
-
import { failedInvariant
|
|
3722
|
+
import { createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3723
|
+
import { SpaceDocVersion } from "@dxos/echo-protocol";
|
|
3724
|
+
import { failedInvariant } from "@dxos/invariant";
|
|
3570
3725
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3571
|
-
import { log as
|
|
3726
|
+
import { log as log15 } from "@dxos/log";
|
|
3572
3727
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
3573
|
-
import {
|
|
3728
|
+
import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3574
3729
|
import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3575
|
-
import { Timeframe as
|
|
3730
|
+
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
3576
3731
|
import { trace as trace6 } from "@dxos/tracing";
|
|
3577
|
-
import { ComplexSet as ComplexSet5
|
|
3732
|
+
import { ComplexSet as ComplexSet5 } from "@dxos/util";
|
|
3578
3733
|
|
|
3579
3734
|
// packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
|
|
3580
3735
|
import { Event as Event4 } from "@dxos/async";
|
|
3736
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
3581
3737
|
import { checkCredentialType } from "@dxos/credentials";
|
|
3582
|
-
var AutomergeSpaceState = class {
|
|
3738
|
+
var AutomergeSpaceState = class extends Resource2 {
|
|
3583
3739
|
constructor(_onNewRoot) {
|
|
3740
|
+
super();
|
|
3584
3741
|
this._onNewRoot = _onNewRoot;
|
|
3585
3742
|
this.rootUrl = void 0;
|
|
3586
3743
|
this.lastEpoch = void 0;
|
|
3587
3744
|
this.onNewEpoch = new Event4();
|
|
3588
3745
|
this._isProcessingRootDocs = false;
|
|
3589
3746
|
}
|
|
3747
|
+
async _open(ctx) {
|
|
3748
|
+
}
|
|
3749
|
+
async _close(ctx) {
|
|
3750
|
+
this._isProcessingRootDocs = false;
|
|
3751
|
+
}
|
|
3590
3752
|
async processCredential(credential) {
|
|
3591
3753
|
if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
|
|
3592
3754
|
return;
|
|
@@ -3614,23 +3776,172 @@ var AutomergeSpaceState = class {
|
|
|
3614
3776
|
}
|
|
3615
3777
|
};
|
|
3616
3778
|
|
|
3779
|
+
// packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
|
|
3780
|
+
import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
|
|
3781
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
3782
|
+
import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
|
|
3783
|
+
import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
|
|
3784
|
+
import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
|
|
3785
|
+
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
3786
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3787
|
+
import { log as log13 } from "@dxos/log";
|
|
3788
|
+
import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
3789
|
+
import { assignDeep } from "@dxos/util";
|
|
3790
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
|
|
3791
|
+
var runEpochMigration = async (ctx, context) => {
|
|
3792
|
+
switch (context.migration) {
|
|
3793
|
+
case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
|
|
3794
|
+
const document = context.repo.create();
|
|
3795
|
+
await context.repo.flush();
|
|
3796
|
+
return {
|
|
3797
|
+
newRoot: document.url
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3800
|
+
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
|
|
3801
|
+
if (!context.currentRoot) {
|
|
3802
|
+
throw new Error("Space does not have an automerge root");
|
|
3803
|
+
}
|
|
3804
|
+
const rootHandle = context.repo.find(context.currentRoot);
|
|
3805
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3806
|
+
const newRoot = context.repo.create(rootHandle.docSync());
|
|
3807
|
+
await context.repo.flush();
|
|
3808
|
+
return {
|
|
3809
|
+
newRoot: newRoot.url
|
|
3810
|
+
};
|
|
3811
|
+
}
|
|
3812
|
+
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
|
|
3813
|
+
log13.info("Fragmenting", void 0, {
|
|
3814
|
+
F: __dxlog_file16,
|
|
3815
|
+
L: 63,
|
|
3816
|
+
S: void 0,
|
|
3817
|
+
C: (f, a) => f(...a)
|
|
3818
|
+
});
|
|
3819
|
+
const currentRootUrl = context.currentRoot;
|
|
3820
|
+
const rootHandle = context.repo.find(currentRootUrl);
|
|
3821
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3822
|
+
const objects = Object.entries(rootHandle.docSync().objects);
|
|
3823
|
+
const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
|
|
3824
|
+
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
3825
|
+
invariant12(properties, "Properties not found", {
|
|
3826
|
+
F: __dxlog_file16,
|
|
3827
|
+
L: 73,
|
|
3828
|
+
S: void 0,
|
|
3829
|
+
A: [
|
|
3830
|
+
"properties",
|
|
3831
|
+
"'Properties not found'"
|
|
3832
|
+
]
|
|
3833
|
+
});
|
|
3834
|
+
const newSpaceDoc = {
|
|
3835
|
+
...rootHandle.docSync(),
|
|
3836
|
+
objects: Object.fromEntries([
|
|
3837
|
+
properties
|
|
3838
|
+
])
|
|
3839
|
+
};
|
|
3840
|
+
const newRoot = context.repo.create(newSpaceDoc);
|
|
3841
|
+
invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
3842
|
+
F: __dxlog_file16,
|
|
3843
|
+
L: 78,
|
|
3844
|
+
S: void 0,
|
|
3845
|
+
A: [
|
|
3846
|
+
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
3847
|
+
""
|
|
3848
|
+
]
|
|
3849
|
+
});
|
|
3850
|
+
const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
|
|
3851
|
+
await docLoader.loadSpaceRootDocHandle(ctx, {
|
|
3852
|
+
rootUrl: newRoot.url
|
|
3853
|
+
});
|
|
3854
|
+
otherObjects.forEach(([key, value]) => {
|
|
3855
|
+
const handle = docLoader.createDocumentForObject(key);
|
|
3856
|
+
handle.change((doc) => {
|
|
3857
|
+
assignDeep(doc, [
|
|
3858
|
+
"objects",
|
|
3859
|
+
key
|
|
3860
|
+
], value);
|
|
3861
|
+
});
|
|
3862
|
+
});
|
|
3863
|
+
await context.repo.flush();
|
|
3864
|
+
return {
|
|
3865
|
+
newRoot: newRoot.url
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
|
|
3869
|
+
const currentRootUrl = context.currentRoot;
|
|
3870
|
+
const rootHandle = context.repo.find(currentRootUrl);
|
|
3871
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3872
|
+
invariant12(rootHandle.docSync(), "Root doc not found", {
|
|
3873
|
+
F: __dxlog_file16,
|
|
3874
|
+
L: 100,
|
|
3875
|
+
S: void 0,
|
|
3876
|
+
A: [
|
|
3877
|
+
"rootHandle.docSync()",
|
|
3878
|
+
"'Root doc not found'"
|
|
3879
|
+
]
|
|
3880
|
+
});
|
|
3881
|
+
const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
|
|
3882
|
+
for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
|
|
3883
|
+
const handle = context.repo.find(url);
|
|
3884
|
+
await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
|
|
3885
|
+
invariant12(handle.docSync(), "Doc not found", {
|
|
3886
|
+
F: __dxlog_file16,
|
|
3887
|
+
L: 107,
|
|
3888
|
+
S: void 0,
|
|
3889
|
+
A: [
|
|
3890
|
+
"handle.docSync()",
|
|
3891
|
+
"'Doc not found'"
|
|
3892
|
+
]
|
|
3893
|
+
});
|
|
3894
|
+
const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
|
|
3895
|
+
const migratedDoc = migrateDocument(handle.docSync(), newDoc);
|
|
3896
|
+
const newHandle = context.repo.import(am.save(migratedDoc));
|
|
3897
|
+
newRootContent.links[id] = newHandle.url;
|
|
3898
|
+
}
|
|
3899
|
+
const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
|
|
3900
|
+
const newRoot = context.repo.import(am.save(migratedRoot));
|
|
3901
|
+
await context.repo.flush();
|
|
3902
|
+
return {
|
|
3903
|
+
newRoot: newRoot.url
|
|
3904
|
+
};
|
|
3905
|
+
}
|
|
3906
|
+
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
|
|
3907
|
+
invariant12(context.newAutomergeRoot, void 0, {
|
|
3908
|
+
F: __dxlog_file16,
|
|
3909
|
+
L: 124,
|
|
3910
|
+
S: void 0,
|
|
3911
|
+
A: [
|
|
3912
|
+
"context.newAutomergeRoot",
|
|
3913
|
+
""
|
|
3914
|
+
]
|
|
3915
|
+
});
|
|
3916
|
+
await context.repo.flush();
|
|
3917
|
+
return {
|
|
3918
|
+
newRoot: context.newAutomergeRoot
|
|
3919
|
+
};
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
return {};
|
|
3923
|
+
};
|
|
3924
|
+
|
|
3617
3925
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
3618
|
-
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as
|
|
3926
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
|
|
3619
3927
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
3620
|
-
import { invariant as
|
|
3928
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
3621
3929
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3622
|
-
import { log as
|
|
3930
|
+
import { log as log14 } from "@dxos/log";
|
|
3623
3931
|
import { schema as schema4 } from "@dxos/protocols";
|
|
3624
3932
|
import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
|
|
3625
3933
|
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
|
|
3626
|
-
var
|
|
3934
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
3627
3935
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
3628
3936
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
3629
3937
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
3630
3938
|
var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
|
|
3631
3939
|
var NotarizationPlugin = class {
|
|
3632
3940
|
constructor() {
|
|
3633
|
-
this._ctx = new Context7(
|
|
3941
|
+
this._ctx = new Context7(void 0, {
|
|
3942
|
+
F: __dxlog_file17,
|
|
3943
|
+
L: 62
|
|
3944
|
+
});
|
|
3634
3945
|
this._extensionOpened = new Event5();
|
|
3635
3946
|
this._extensions = /* @__PURE__ */ new Set();
|
|
3636
3947
|
this._processedCredentials = new ComplexSet4(PublicKey9.hash);
|
|
@@ -3648,16 +3959,16 @@ var NotarizationPlugin = class {
|
|
|
3648
3959
|
* Request credentials to be notarized.
|
|
3649
3960
|
*/
|
|
3650
3961
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3651
|
-
|
|
3962
|
+
log14("notarize", {
|
|
3652
3963
|
credentials
|
|
3653
3964
|
}, {
|
|
3654
|
-
F:
|
|
3965
|
+
F: __dxlog_file17,
|
|
3655
3966
|
L: 90,
|
|
3656
3967
|
S: this,
|
|
3657
3968
|
C: (f, a) => f(...a)
|
|
3658
3969
|
});
|
|
3659
|
-
|
|
3660
|
-
F:
|
|
3970
|
+
invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
3971
|
+
F: __dxlog_file17,
|
|
3661
3972
|
L: 91,
|
|
3662
3973
|
S: this,
|
|
3663
3974
|
A: [
|
|
@@ -3665,13 +3976,13 @@ var NotarizationPlugin = class {
|
|
|
3665
3976
|
"'Credentials must have an id'"
|
|
3666
3977
|
]
|
|
3667
3978
|
});
|
|
3668
|
-
const errors = new
|
|
3979
|
+
const errors = new Trigger7();
|
|
3669
3980
|
const ctx = this._ctx.derive({
|
|
3670
3981
|
onError: (err) => {
|
|
3671
|
-
|
|
3982
|
+
log14.warn("Notarization error", {
|
|
3672
3983
|
err
|
|
3673
3984
|
}, {
|
|
3674
|
-
F:
|
|
3985
|
+
F: __dxlog_file17,
|
|
3675
3986
|
L: 99,
|
|
3676
3987
|
S: this,
|
|
3677
3988
|
C: (f, a) => f(...a)
|
|
@@ -3683,11 +3994,11 @@ var NotarizationPlugin = class {
|
|
|
3683
3994
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3684
3995
|
if (timeout !== 0) {
|
|
3685
3996
|
scheduleTask4(ctx, () => {
|
|
3686
|
-
|
|
3997
|
+
log14.warn("Notarization timeout", {
|
|
3687
3998
|
timeout,
|
|
3688
3999
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3689
4000
|
}, {
|
|
3690
|
-
F:
|
|
4001
|
+
F: __dxlog_file17,
|
|
3691
4002
|
L: 111,
|
|
3692
4003
|
S: this,
|
|
3693
4004
|
C: (f, a) => f(...a)
|
|
@@ -3707,10 +4018,10 @@ var NotarizationPlugin = class {
|
|
|
3707
4018
|
...this._extensions
|
|
3708
4019
|
].find((peer2) => !peersTried.has(peer2));
|
|
3709
4020
|
if (!peer) {
|
|
3710
|
-
|
|
4021
|
+
log14.info("Exhausted all peers to notarize with", {
|
|
3711
4022
|
retryIn: retryTimeout
|
|
3712
4023
|
}, {
|
|
3713
|
-
F:
|
|
4024
|
+
F: __dxlog_file17,
|
|
3714
4025
|
L: 136,
|
|
3715
4026
|
S: this,
|
|
3716
4027
|
C: (f, a) => f(...a)
|
|
@@ -3720,11 +4031,11 @@ var NotarizationPlugin = class {
|
|
|
3720
4031
|
return;
|
|
3721
4032
|
}
|
|
3722
4033
|
peersTried.add(peer);
|
|
3723
|
-
|
|
4034
|
+
log14("try notarizing", {
|
|
3724
4035
|
peer: peer.localPeerId,
|
|
3725
4036
|
credentialId: credentials.map((credential) => credential.id)
|
|
3726
4037
|
}, {
|
|
3727
|
-
F:
|
|
4038
|
+
F: __dxlog_file17,
|
|
3728
4039
|
L: 143,
|
|
3729
4040
|
S: this,
|
|
3730
4041
|
C: (f, a) => f(...a)
|
|
@@ -3732,17 +4043,17 @@ var NotarizationPlugin = class {
|
|
|
3732
4043
|
await peer.rpc.NotarizationService.notarize({
|
|
3733
4044
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3734
4045
|
});
|
|
3735
|
-
|
|
3736
|
-
F:
|
|
4046
|
+
log14("success", void 0, {
|
|
4047
|
+
F: __dxlog_file17,
|
|
3737
4048
|
L: 147,
|
|
3738
4049
|
S: this,
|
|
3739
4050
|
C: (f, a) => f(...a)
|
|
3740
4051
|
});
|
|
3741
|
-
await
|
|
4052
|
+
await sleep2(successDelay);
|
|
3742
4053
|
} catch (err) {
|
|
3743
4054
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3744
|
-
|
|
3745
|
-
F:
|
|
4055
|
+
log14.info("error notarizing (recoverable)", err, {
|
|
4056
|
+
F: __dxlog_file17,
|
|
3746
4057
|
L: 151,
|
|
3747
4058
|
S: this,
|
|
3748
4059
|
C: (f, a) => f(...a)
|
|
@@ -3759,8 +4070,8 @@ var NotarizationPlugin = class {
|
|
|
3759
4070
|
allNotarized,
|
|
3760
4071
|
errors.wait()
|
|
3761
4072
|
]);
|
|
3762
|
-
|
|
3763
|
-
F:
|
|
4073
|
+
log14("done", void 0, {
|
|
4074
|
+
F: __dxlog_file17,
|
|
3764
4075
|
L: 162,
|
|
3765
4076
|
S: this,
|
|
3766
4077
|
C: (f, a) => f(...a)
|
|
@@ -3781,8 +4092,8 @@ var NotarizationPlugin = class {
|
|
|
3781
4092
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3782
4093
|
}
|
|
3783
4094
|
setWriter(writer) {
|
|
3784
|
-
|
|
3785
|
-
F:
|
|
4095
|
+
invariant13(!this._writer, "Writer already set.", {
|
|
4096
|
+
F: __dxlog_file17,
|
|
3786
4097
|
L: 181,
|
|
3787
4098
|
S: this,
|
|
3788
4099
|
A: [
|
|
@@ -3796,7 +4107,7 @@ var NotarizationPlugin = class {
|
|
|
3796
4107
|
if (this._processedCredentials.has(id)) {
|
|
3797
4108
|
return;
|
|
3798
4109
|
}
|
|
3799
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
4110
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger7()).value.wait();
|
|
3800
4111
|
}
|
|
3801
4112
|
/**
|
|
3802
4113
|
* Requests from other peers to notarize credentials.
|
|
@@ -3806,8 +4117,8 @@ var NotarizationPlugin = class {
|
|
|
3806
4117
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3807
4118
|
}
|
|
3808
4119
|
for (const credential of request.credentials ?? []) {
|
|
3809
|
-
|
|
3810
|
-
F:
|
|
4120
|
+
invariant13(credential.id, "Credential must have an id", {
|
|
4121
|
+
F: __dxlog_file17,
|
|
3811
4122
|
L: 200,
|
|
3812
4123
|
S: this,
|
|
3813
4124
|
A: [
|
|
@@ -3824,10 +4135,10 @@ var NotarizationPlugin = class {
|
|
|
3824
4135
|
createExtension() {
|
|
3825
4136
|
const extension = new NotarizationTeleportExtension({
|
|
3826
4137
|
onOpen: async () => {
|
|
3827
|
-
|
|
4138
|
+
log14("extension opened", {
|
|
3828
4139
|
peer: extension.localPeerId
|
|
3829
4140
|
}, {
|
|
3830
|
-
F:
|
|
4141
|
+
F: __dxlog_file17,
|
|
3831
4142
|
L: 211,
|
|
3832
4143
|
S: this,
|
|
3833
4144
|
C: (f, a) => f(...a)
|
|
@@ -3836,10 +4147,10 @@ var NotarizationPlugin = class {
|
|
|
3836
4147
|
this._extensionOpened.emit();
|
|
3837
4148
|
},
|
|
3838
4149
|
onClose: async () => {
|
|
3839
|
-
|
|
4150
|
+
log14("extension closed", {
|
|
3840
4151
|
peer: extension.localPeerId
|
|
3841
4152
|
}, {
|
|
3842
|
-
F:
|
|
4153
|
+
F: __dxlog_file17,
|
|
3843
4154
|
L: 216,
|
|
3844
4155
|
S: this,
|
|
3845
4156
|
C: (f, a) => f(...a)
|
|
@@ -3893,15 +4204,83 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3893
4204
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3894
4205
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3895
4206
|
}
|
|
3896
|
-
|
|
4207
|
+
function _using_ctx() {
|
|
4208
|
+
var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
|
|
4209
|
+
var err = new Error();
|
|
4210
|
+
err.name = "SuppressedError";
|
|
4211
|
+
err.suppressed = suppressed;
|
|
4212
|
+
err.error = error;
|
|
4213
|
+
return err;
|
|
4214
|
+
}, empty = {}, stack = [];
|
|
4215
|
+
function using(isAwait, value) {
|
|
4216
|
+
if (value != null) {
|
|
4217
|
+
if (Object(value) !== value) {
|
|
4218
|
+
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
4219
|
+
}
|
|
4220
|
+
if (isAwait) {
|
|
4221
|
+
var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
|
|
4222
|
+
}
|
|
4223
|
+
if (dispose == null) {
|
|
4224
|
+
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
|
|
4225
|
+
}
|
|
4226
|
+
if (typeof dispose !== "function") {
|
|
4227
|
+
throw new TypeError(`Property [Symbol.dispose] is not a function.`);
|
|
4228
|
+
}
|
|
4229
|
+
stack.push({
|
|
4230
|
+
v: value,
|
|
4231
|
+
d: dispose,
|
|
4232
|
+
a: isAwait
|
|
4233
|
+
});
|
|
4234
|
+
} else if (isAwait) {
|
|
4235
|
+
stack.push({
|
|
4236
|
+
d: value,
|
|
4237
|
+
a: isAwait
|
|
4238
|
+
});
|
|
4239
|
+
}
|
|
4240
|
+
return value;
|
|
4241
|
+
}
|
|
4242
|
+
return {
|
|
4243
|
+
e: empty,
|
|
4244
|
+
u: using.bind(null, false),
|
|
4245
|
+
a: using.bind(null, true),
|
|
4246
|
+
d: function() {
|
|
4247
|
+
var error = this.e;
|
|
4248
|
+
function next() {
|
|
4249
|
+
while (resource = stack.pop()) {
|
|
4250
|
+
try {
|
|
4251
|
+
var resource, disposalResult = resource.d && resource.d.call(resource.v);
|
|
4252
|
+
if (resource.a) {
|
|
4253
|
+
return Promise.resolve(disposalResult).then(next, err);
|
|
4254
|
+
}
|
|
4255
|
+
} catch (e) {
|
|
4256
|
+
return err(e);
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
if (error !== empty)
|
|
4260
|
+
throw error;
|
|
4261
|
+
}
|
|
4262
|
+
function err(e) {
|
|
4263
|
+
error = error !== empty ? new _disposeSuppressedError(error, e) : e;
|
|
4264
|
+
return next();
|
|
4265
|
+
}
|
|
4266
|
+
return next();
|
|
4267
|
+
}
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3897
4271
|
var DataSpace = class {
|
|
3898
4272
|
constructor(params) {
|
|
3899
|
-
this._ctx = new Context8(
|
|
4273
|
+
this._ctx = new Context8(void 0, {
|
|
4274
|
+
F: __dxlog_file18,
|
|
4275
|
+
L: 84
|
|
4276
|
+
});
|
|
3900
4277
|
this._notarizationPlugin = new NotarizationPlugin();
|
|
3901
4278
|
this._cache = void 0;
|
|
3902
4279
|
// TODO(dmaretskyi): Move into Space?
|
|
3903
4280
|
this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
|
|
3904
|
-
this.
|
|
4281
|
+
this._epochProcessingMutex = new Mutex2();
|
|
4282
|
+
this._state = SpaceState2.CLOSED;
|
|
4283
|
+
this._databaseRoot = null;
|
|
3905
4284
|
/**
|
|
3906
4285
|
* Error for _state === SpaceState.ERROR.
|
|
3907
4286
|
*/
|
|
@@ -3925,11 +4304,11 @@ var DataSpace = class {
|
|
|
3925
4304
|
});
|
|
3926
4305
|
this._cache = params.cache;
|
|
3927
4306
|
this._state = params.initialState;
|
|
3928
|
-
|
|
3929
|
-
state:
|
|
4307
|
+
log15("new state", {
|
|
4308
|
+
state: SpaceState2[this._state]
|
|
3930
4309
|
}, {
|
|
3931
|
-
F:
|
|
3932
|
-
L:
|
|
4310
|
+
F: __dxlog_file18,
|
|
4311
|
+
L: 146,
|
|
3933
4312
|
S: this,
|
|
3934
4313
|
C: (f, a) => f(...a)
|
|
3935
4314
|
});
|
|
@@ -3962,6 +4341,9 @@ var DataSpace = class {
|
|
|
3962
4341
|
get automergeSpaceState() {
|
|
3963
4342
|
return this._automergeSpaceState;
|
|
3964
4343
|
}
|
|
4344
|
+
get databaseRoot() {
|
|
4345
|
+
return this._databaseRoot;
|
|
4346
|
+
}
|
|
3965
4347
|
get _automergeInfo() {
|
|
3966
4348
|
return {
|
|
3967
4349
|
rootUrl: this._automergeSpaceState.rootUrl,
|
|
@@ -3969,20 +4351,27 @@ var DataSpace = class {
|
|
|
3969
4351
|
};
|
|
3970
4352
|
}
|
|
3971
4353
|
async open() {
|
|
3972
|
-
|
|
4354
|
+
if (this._state === SpaceState2.CLOSED) {
|
|
4355
|
+
await this._open();
|
|
4356
|
+
}
|
|
3973
4357
|
}
|
|
3974
4358
|
async _open() {
|
|
4359
|
+
await this._presence.open();
|
|
3975
4360
|
await this._gossip.open();
|
|
3976
4361
|
await this._notarizationPlugin.open();
|
|
3977
4362
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
4363
|
+
await this._automergeSpaceState.open();
|
|
3978
4364
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3979
|
-
await this._inner.open(new Context8(
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4365
|
+
await this._inner.open(new Context8(void 0, {
|
|
4366
|
+
F: __dxlog_file18,
|
|
4367
|
+
L: 215
|
|
4368
|
+
}));
|
|
4369
|
+
this._state = SpaceState2.CONTROL_ONLY;
|
|
4370
|
+
log15("new state", {
|
|
4371
|
+
state: SpaceState2[this._state]
|
|
3983
4372
|
}, {
|
|
3984
|
-
F:
|
|
3985
|
-
L:
|
|
4373
|
+
F: __dxlog_file18,
|
|
4374
|
+
L: 217,
|
|
3986
4375
|
S: this,
|
|
3987
4376
|
C: (f, a) => f(...a)
|
|
3988
4377
|
});
|
|
@@ -3995,23 +4384,27 @@ var DataSpace = class {
|
|
|
3995
4384
|
}
|
|
3996
4385
|
async _close() {
|
|
3997
4386
|
await this._callbacks.beforeClose?.();
|
|
3998
|
-
this._state =
|
|
3999
|
-
|
|
4000
|
-
state:
|
|
4387
|
+
this._state = SpaceState2.CLOSED;
|
|
4388
|
+
log15("new state", {
|
|
4389
|
+
state: SpaceState2[this._state]
|
|
4001
4390
|
}, {
|
|
4002
|
-
F:
|
|
4003
|
-
L:
|
|
4391
|
+
F: __dxlog_file18,
|
|
4392
|
+
L: 231,
|
|
4004
4393
|
S: this,
|
|
4005
4394
|
C: (f, a) => f(...a)
|
|
4006
4395
|
});
|
|
4007
4396
|
await this._ctx.dispose();
|
|
4008
|
-
this._ctx = new Context8(
|
|
4397
|
+
this._ctx = new Context8(void 0, {
|
|
4398
|
+
F: __dxlog_file18,
|
|
4399
|
+
L: 233
|
|
4400
|
+
});
|
|
4009
4401
|
await this.authVerifier.close();
|
|
4010
4402
|
await this._inner.close();
|
|
4011
4403
|
await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
|
|
4404
|
+
await this._automergeSpaceState.close();
|
|
4012
4405
|
await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
|
|
4013
4406
|
await this._notarizationPlugin.close();
|
|
4014
|
-
await this._presence.
|
|
4407
|
+
await this._presence.close();
|
|
4015
4408
|
await this._gossip.close();
|
|
4016
4409
|
}
|
|
4017
4410
|
async postMessage(channel, message) {
|
|
@@ -4030,26 +4423,26 @@ var DataSpace = class {
|
|
|
4030
4423
|
await this.initializeDataPipeline();
|
|
4031
4424
|
} catch (err) {
|
|
4032
4425
|
if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
|
|
4033
|
-
|
|
4034
|
-
F:
|
|
4035
|
-
L:
|
|
4426
|
+
log15("data pipeline initialization cancelled", err, {
|
|
4427
|
+
F: __dxlog_file18,
|
|
4428
|
+
L: 265,
|
|
4036
4429
|
S: this,
|
|
4037
4430
|
C: (f, a) => f(...a)
|
|
4038
4431
|
});
|
|
4039
4432
|
return;
|
|
4040
4433
|
}
|
|
4041
|
-
|
|
4042
|
-
F:
|
|
4043
|
-
L:
|
|
4434
|
+
log15.error("Error initializing data pipeline", err, {
|
|
4435
|
+
F: __dxlog_file18,
|
|
4436
|
+
L: 269,
|
|
4044
4437
|
S: this,
|
|
4045
4438
|
C: (f, a) => f(...a)
|
|
4046
4439
|
});
|
|
4047
|
-
this._state =
|
|
4048
|
-
|
|
4049
|
-
state:
|
|
4440
|
+
this._state = SpaceState2.ERROR;
|
|
4441
|
+
log15("new state", {
|
|
4442
|
+
state: SpaceState2[this._state]
|
|
4050
4443
|
}, {
|
|
4051
|
-
F:
|
|
4052
|
-
L:
|
|
4444
|
+
F: __dxlog_file18,
|
|
4445
|
+
L: 271,
|
|
4053
4446
|
S: this,
|
|
4054
4447
|
C: (f, a) => f(...a)
|
|
4055
4448
|
});
|
|
@@ -4061,35 +4454,32 @@ var DataSpace = class {
|
|
|
4061
4454
|
});
|
|
4062
4455
|
}
|
|
4063
4456
|
async initializeDataPipeline() {
|
|
4064
|
-
if (this._state !==
|
|
4457
|
+
if (this._state !== SpaceState2.CONTROL_ONLY) {
|
|
4065
4458
|
throw new SystemError("Invalid operation");
|
|
4066
4459
|
}
|
|
4067
|
-
this._state =
|
|
4068
|
-
|
|
4069
|
-
state:
|
|
4460
|
+
this._state = SpaceState2.INITIALIZING;
|
|
4461
|
+
log15("new state", {
|
|
4462
|
+
state: SpaceState2[this._state]
|
|
4070
4463
|
}, {
|
|
4071
|
-
F:
|
|
4072
|
-
L:
|
|
4464
|
+
F: __dxlog_file18,
|
|
4465
|
+
L: 287,
|
|
4073
4466
|
S: this,
|
|
4074
4467
|
C: (f, a) => f(...a)
|
|
4075
4468
|
});
|
|
4076
4469
|
await this._initializeAndReadControlPipeline();
|
|
4077
|
-
await
|
|
4470
|
+
await sleep3(1);
|
|
4471
|
+
const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
|
|
4078
4472
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
4079
|
-
await
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
L: 287,
|
|
4083
|
-
S: this,
|
|
4084
|
-
C: (f, a) => f(...a)
|
|
4085
|
-
});
|
|
4473
|
+
await ready;
|
|
4474
|
+
}
|
|
4475
|
+
async _enterReadyState() {
|
|
4086
4476
|
await this._callbacks.beforeReady?.();
|
|
4087
|
-
this._state =
|
|
4088
|
-
|
|
4089
|
-
state:
|
|
4477
|
+
this._state = SpaceState2.READY;
|
|
4478
|
+
log15("new state", {
|
|
4479
|
+
state: SpaceState2[this._state]
|
|
4090
4480
|
}, {
|
|
4091
|
-
F:
|
|
4092
|
-
L:
|
|
4481
|
+
F: __dxlog_file18,
|
|
4482
|
+
L: 306,
|
|
4093
4483
|
S: this,
|
|
4094
4484
|
C: (f, a) => f(...a)
|
|
4095
4485
|
});
|
|
@@ -4103,9 +4493,9 @@ var DataSpace = class {
|
|
|
4103
4493
|
});
|
|
4104
4494
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
4105
4495
|
await this._createWritableFeeds();
|
|
4106
|
-
|
|
4107
|
-
F:
|
|
4108
|
-
L:
|
|
4496
|
+
log15("writable feeds created", void 0, {
|
|
4497
|
+
F: __dxlog_file18,
|
|
4498
|
+
L: 322,
|
|
4109
4499
|
S: this,
|
|
4110
4500
|
C: (f, a) => f(...a)
|
|
4111
4501
|
});
|
|
@@ -4163,57 +4553,66 @@ var DataSpace = class {
|
|
|
4163
4553
|
}
|
|
4164
4554
|
}
|
|
4165
4555
|
_onNewAutomergeRoot(rootUrl) {
|
|
4166
|
-
|
|
4556
|
+
log15("loading automerge root doc for space", {
|
|
4167
4557
|
space: this.key,
|
|
4168
4558
|
rootUrl
|
|
4169
4559
|
}, {
|
|
4170
|
-
F:
|
|
4171
|
-
L:
|
|
4560
|
+
F: __dxlog_file18,
|
|
4561
|
+
L: 388,
|
|
4172
4562
|
S: this,
|
|
4173
4563
|
C: (f, a) => f(...a)
|
|
4174
4564
|
});
|
|
4175
|
-
this._echoHost.replicateDocument(rootUrl);
|
|
4176
4565
|
const handle = this._echoHost.automergeRepo.find(rootUrl);
|
|
4177
4566
|
queueMicrotask(async () => {
|
|
4178
4567
|
try {
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
return;
|
|
4184
|
-
}
|
|
4185
|
-
const doc = handle.docSync() ?? failedInvariant();
|
|
4186
|
-
if (!doc.access?.spaceKey) {
|
|
4187
|
-
handle.change((doc2) => {
|
|
4188
|
-
doc2.access = {
|
|
4189
|
-
spaceKey: this.key.toHex()
|
|
4190
|
-
};
|
|
4191
|
-
});
|
|
4192
|
-
}
|
|
4193
|
-
if (!this._echoHost.roots.has(handle.documentId)) {
|
|
4194
|
-
await this._echoHost.openSpaceRoot(handle.url);
|
|
4195
|
-
} else {
|
|
4196
|
-
log12.warn("echo database root already exists", {
|
|
4197
|
-
space: this.key,
|
|
4198
|
-
rootUrl
|
|
4199
|
-
}, {
|
|
4200
|
-
F: __dxlog_file15,
|
|
4201
|
-
L: 400,
|
|
4202
|
-
S: this,
|
|
4203
|
-
C: (f, a) => f(...a)
|
|
4568
|
+
try {
|
|
4569
|
+
var _usingCtx = _using_ctx();
|
|
4570
|
+
await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
|
|
4571
|
+
await cancelWithContext5(this._ctx, handle.whenReady());
|
|
4204
4572
|
});
|
|
4573
|
+
if (this._ctx.disposed) {
|
|
4574
|
+
return;
|
|
4575
|
+
}
|
|
4576
|
+
const _guard = (
|
|
4577
|
+
// Ensure only one root is processed at a time.
|
|
4578
|
+
_usingCtx.u(await this._epochProcessingMutex.acquire())
|
|
4579
|
+
);
|
|
4580
|
+
const doc = handle.docSync() ?? failedInvariant();
|
|
4581
|
+
if (!doc.access?.spaceKey) {
|
|
4582
|
+
handle.change((doc2) => {
|
|
4583
|
+
doc2.access = {
|
|
4584
|
+
spaceKey: this.key.toHex()
|
|
4585
|
+
};
|
|
4586
|
+
});
|
|
4587
|
+
}
|
|
4588
|
+
const root = await this._echoHost.openSpaceRoot(handle.url);
|
|
4589
|
+
this._databaseRoot = root;
|
|
4590
|
+
if (root.getVersion() !== SpaceDocVersion.CURRENT) {
|
|
4591
|
+
if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
|
|
4592
|
+
this._state = SpaceState2.REQUIRES_MIGRATION;
|
|
4593
|
+
this.stateUpdate.emit();
|
|
4594
|
+
}
|
|
4595
|
+
} else {
|
|
4596
|
+
if (this._state !== SpaceState2.READY) {
|
|
4597
|
+
await this._enterReadyState();
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
} catch (_) {
|
|
4601
|
+
_usingCtx.e = _;
|
|
4602
|
+
} finally {
|
|
4603
|
+
_usingCtx.d();
|
|
4205
4604
|
}
|
|
4206
4605
|
} catch (err) {
|
|
4207
4606
|
if (err instanceof ContextDisposedError3) {
|
|
4208
4607
|
return;
|
|
4209
4608
|
}
|
|
4210
|
-
|
|
4609
|
+
log15.warn("error loading automerge root doc", {
|
|
4211
4610
|
space: this.key,
|
|
4212
4611
|
rootUrl,
|
|
4213
4612
|
err
|
|
4214
4613
|
}, {
|
|
4215
|
-
F:
|
|
4216
|
-
L:
|
|
4614
|
+
F: __dxlog_file18,
|
|
4615
|
+
L: 431,
|
|
4217
4616
|
S: this,
|
|
4218
4617
|
C: (f, a) => f(...a)
|
|
4219
4618
|
});
|
|
@@ -4236,178 +4635,70 @@ var DataSpace = class {
|
|
|
4236
4635
|
});
|
|
4237
4636
|
}
|
|
4238
4637
|
async createEpoch(options) {
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
case CreateEpochRequest.Migration.NONE:
|
|
4243
|
-
{
|
|
4244
|
-
epoch = {
|
|
4245
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4246
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4247
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4248
|
-
automergeRoot: this._automergeSpaceState.lastEpoch?.subject.assertion?.automergeRoot
|
|
4249
|
-
};
|
|
4250
|
-
}
|
|
4251
|
-
break;
|
|
4252
|
-
case CreateEpochRequest.Migration.INIT_AUTOMERGE:
|
|
4253
|
-
{
|
|
4254
|
-
const document = this._echoHost.automergeRepo.create();
|
|
4255
|
-
epoch = {
|
|
4256
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4257
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4258
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4259
|
-
automergeRoot: document.url
|
|
4260
|
-
};
|
|
4261
|
-
}
|
|
4262
|
-
break;
|
|
4263
|
-
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
|
|
4264
|
-
{
|
|
4265
|
-
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4266
|
-
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4267
|
-
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4268
|
-
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
4269
|
-
await this._echoHost.automergeRepo.flush([
|
|
4270
|
-
newRoot.documentId
|
|
4271
|
-
]);
|
|
4272
|
-
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4273
|
-
F: __dxlog_file15,
|
|
4274
|
-
L: 457,
|
|
4275
|
-
S: this,
|
|
4276
|
-
A: [
|
|
4277
|
-
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4278
|
-
""
|
|
4279
|
-
]
|
|
4280
|
-
});
|
|
4281
|
-
epoch = {
|
|
4282
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4283
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4284
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4285
|
-
automergeRoot: newRoot.url
|
|
4286
|
-
};
|
|
4287
|
-
}
|
|
4288
|
-
break;
|
|
4289
|
-
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
4290
|
-
{
|
|
4291
|
-
log12.info("Fragmenting", void 0, {
|
|
4292
|
-
F: __dxlog_file15,
|
|
4293
|
-
L: 469,
|
|
4294
|
-
S: this,
|
|
4295
|
-
C: (f, a) => f(...a)
|
|
4296
|
-
});
|
|
4297
|
-
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4298
|
-
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4299
|
-
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4300
|
-
const objects = Object.entries(rootHandle.docSync().objects);
|
|
4301
|
-
const properties = findPropertiesObject(rootHandle.docSync());
|
|
4302
|
-
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
4303
|
-
invariant13(properties, "Properties not found", {
|
|
4304
|
-
F: __dxlog_file15,
|
|
4305
|
-
L: 479,
|
|
4306
|
-
S: this,
|
|
4307
|
-
A: [
|
|
4308
|
-
"properties",
|
|
4309
|
-
"'Properties not found'"
|
|
4310
|
-
]
|
|
4311
|
-
});
|
|
4312
|
-
const newSpaceDoc = {
|
|
4313
|
-
...rootHandle.docSync(),
|
|
4314
|
-
objects: Object.fromEntries([
|
|
4315
|
-
properties
|
|
4316
|
-
])
|
|
4317
|
-
};
|
|
4318
|
-
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
4319
|
-
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4320
|
-
F: __dxlog_file15,
|
|
4321
|
-
L: 484,
|
|
4322
|
-
S: this,
|
|
4323
|
-
A: [
|
|
4324
|
-
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4325
|
-
""
|
|
4326
|
-
]
|
|
4327
|
-
});
|
|
4328
|
-
const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
|
|
4329
|
-
await docLoader.loadSpaceRootDocHandle(this._ctx, {
|
|
4330
|
-
rootUrl: newRoot.url
|
|
4331
|
-
});
|
|
4332
|
-
otherObjects.forEach(([key, value]) => {
|
|
4333
|
-
const handle = docLoader.createDocumentForObject(key);
|
|
4334
|
-
handle.change((doc) => {
|
|
4335
|
-
assignDeep(doc, [
|
|
4336
|
-
"objects",
|
|
4337
|
-
key
|
|
4338
|
-
], value);
|
|
4339
|
-
});
|
|
4340
|
-
});
|
|
4341
|
-
epoch = {
|
|
4342
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4343
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4344
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4345
|
-
automergeRoot: newRoot.url
|
|
4346
|
-
};
|
|
4347
|
-
}
|
|
4348
|
-
break;
|
|
4349
|
-
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
|
|
4350
|
-
{
|
|
4351
|
-
invariant13(options.newAutomergeRoot, void 0, {
|
|
4352
|
-
F: __dxlog_file15,
|
|
4353
|
-
L: 514,
|
|
4354
|
-
S: this,
|
|
4355
|
-
A: [
|
|
4356
|
-
"options.newAutomergeRoot",
|
|
4357
|
-
""
|
|
4358
|
-
]
|
|
4359
|
-
});
|
|
4360
|
-
epoch = {
|
|
4361
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4362
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4363
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4364
|
-
automergeRoot: options.newAutomergeRoot
|
|
4365
|
-
};
|
|
4366
|
-
}
|
|
4367
|
-
break;
|
|
4368
|
-
}
|
|
4369
|
-
if (!epoch) {
|
|
4370
|
-
return;
|
|
4638
|
+
const ctx = this._ctx.derive();
|
|
4639
|
+
if (!options?.migration) {
|
|
4640
|
+
return null;
|
|
4371
4641
|
}
|
|
4642
|
+
const { newRoot } = await runEpochMigration(ctx, {
|
|
4643
|
+
repo: this._echoHost.automergeRepo,
|
|
4644
|
+
spaceId: this.id,
|
|
4645
|
+
spaceKey: this.key,
|
|
4646
|
+
migration: options.migration,
|
|
4647
|
+
currentRoot: this._automergeSpaceState.rootUrl ?? null,
|
|
4648
|
+
newAutomergeRoot: options.newAutomergeRoot
|
|
4649
|
+
});
|
|
4650
|
+
const epoch = {
|
|
4651
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4652
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4653
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4654
|
+
automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
|
|
4655
|
+
};
|
|
4656
|
+
const credential = await this._signingContext.credentialSigner.createCredential({
|
|
4657
|
+
subject: this.key,
|
|
4658
|
+
assertion: {
|
|
4659
|
+
"@type": "dxos.halo.credentials.Epoch",
|
|
4660
|
+
...epoch
|
|
4661
|
+
}
|
|
4662
|
+
});
|
|
4372
4663
|
const receipt = await this.inner.controlPipeline.writer.write({
|
|
4373
4664
|
credential: {
|
|
4374
|
-
credential
|
|
4375
|
-
subject: this.key,
|
|
4376
|
-
assertion: {
|
|
4377
|
-
"@type": "dxos.halo.credentials.Epoch",
|
|
4378
|
-
...epoch
|
|
4379
|
-
}
|
|
4380
|
-
})
|
|
4665
|
+
credential
|
|
4381
4666
|
}
|
|
4382
4667
|
});
|
|
4383
|
-
await this.inner.controlPipeline.state.waitUntilTimeframe(new
|
|
4668
|
+
await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
|
|
4384
4669
|
[
|
|
4385
4670
|
receipt.feedKey,
|
|
4386
4671
|
receipt.seq
|
|
4387
4672
|
]
|
|
4388
4673
|
]));
|
|
4389
4674
|
await this._echoHost.updateIndexes();
|
|
4675
|
+
return credential;
|
|
4390
4676
|
}
|
|
4391
4677
|
async activate() {
|
|
4392
|
-
if (
|
|
4678
|
+
if (![
|
|
4679
|
+
SpaceState2.CLOSED,
|
|
4680
|
+
SpaceState2.INACTIVE
|
|
4681
|
+
].includes(this._state)) {
|
|
4393
4682
|
return;
|
|
4394
4683
|
}
|
|
4395
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
4684
|
+
await this._metadataStore.setSpaceState(this.key, SpaceState2.ACTIVE);
|
|
4396
4685
|
await this._open();
|
|
4397
4686
|
this.initializeDataPipelineAsync();
|
|
4398
4687
|
}
|
|
4399
4688
|
async deactivate() {
|
|
4400
|
-
if (this._state ===
|
|
4689
|
+
if (this._state === SpaceState2.INACTIVE) {
|
|
4401
4690
|
return;
|
|
4402
4691
|
}
|
|
4403
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4692
|
+
await this._metadataStore.setSpaceState(this.key, SpaceState2.INACTIVE);
|
|
4693
|
+
if (this._state !== SpaceState2.CLOSED) {
|
|
4694
|
+
await this._close();
|
|
4695
|
+
}
|
|
4696
|
+
this._state = SpaceState2.INACTIVE;
|
|
4697
|
+
log15("new state", {
|
|
4698
|
+
state: SpaceState2[this._state]
|
|
4408
4699
|
}, {
|
|
4409
|
-
F:
|
|
4410
|
-
L:
|
|
4700
|
+
F: __dxlog_file18,
|
|
4701
|
+
L: 512,
|
|
4411
4702
|
S: this,
|
|
4412
4703
|
C: (f, a) => f(...a)
|
|
4413
4704
|
});
|
|
@@ -4425,7 +4716,7 @@ _ts_decorate4([
|
|
|
4425
4716
|
], DataSpace.prototype, "key", null);
|
|
4426
4717
|
_ts_decorate4([
|
|
4427
4718
|
trace6.info({
|
|
4428
|
-
enum:
|
|
4719
|
+
enum: SpaceState2
|
|
4429
4720
|
})
|
|
4430
4721
|
], DataSpace.prototype, "state", null);
|
|
4431
4722
|
_ts_decorate4([
|
|
@@ -4462,39 +4753,33 @@ DataSpace = _ts_decorate4([
|
|
|
4462
4753
|
trackLeaks("open", "close"),
|
|
4463
4754
|
trace6.resource()
|
|
4464
4755
|
], DataSpace);
|
|
4465
|
-
var findPropertiesObject = (spaceDoc) => {
|
|
4466
|
-
for (const id in spaceDoc.objects ?? {}) {
|
|
4467
|
-
const obj = spaceDoc.objects[id];
|
|
4468
|
-
if (obj.system.type?.itemId === TYPE_PROPERTIES) {
|
|
4469
|
-
return [
|
|
4470
|
-
id,
|
|
4471
|
-
obj
|
|
4472
|
-
];
|
|
4473
|
-
}
|
|
4474
|
-
}
|
|
4475
|
-
return void 0;
|
|
4476
|
-
};
|
|
4477
4756
|
|
|
4478
4757
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
4479
4758
|
import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
4480
|
-
import {
|
|
4481
|
-
import {
|
|
4759
|
+
import { PropertiesType } from "@dxos/client-protocol";
|
|
4760
|
+
import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
|
|
4761
|
+
import { getCredentialAssertion as getCredentialAssertion3, createAdmissionCredentials } from "@dxos/credentials";
|
|
4762
|
+
import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
|
|
4482
4763
|
import { AuthStatus } from "@dxos/echo-pipeline";
|
|
4764
|
+
import { CredentialServerExtension } from "@dxos/echo-pipeline";
|
|
4765
|
+
import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
|
|
4766
|
+
import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
|
|
4767
|
+
import { writeMessages as writeMessages3 } from "@dxos/feed-store";
|
|
4483
4768
|
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4484
4769
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4485
|
-
import { log as
|
|
4486
|
-
import { trace as Trace2 } from "@dxos/protocols";
|
|
4487
|
-
import { Invitation as Invitation7, SpaceState as
|
|
4770
|
+
import { log as log16 } from "@dxos/log";
|
|
4771
|
+
import { trace as Trace2, AlreadyJoinedError as AlreadyJoinedError3 } from "@dxos/protocols";
|
|
4772
|
+
import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4488
4773
|
import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4489
4774
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
4490
4775
|
import { trace as trace7 } from "@dxos/tracing";
|
|
4491
|
-
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
4776
|
+
import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
4492
4777
|
|
|
4493
4778
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
4494
4779
|
import { createCredential } from "@dxos/credentials";
|
|
4495
4780
|
import { failUndefined } from "@dxos/debug";
|
|
4496
4781
|
import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4497
|
-
import { Timeframe as
|
|
4782
|
+
import { Timeframe as Timeframe4 } from "@dxos/timeframe";
|
|
4498
4783
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
4499
4784
|
const credentials = [
|
|
4500
4785
|
await createCredential({
|
|
@@ -4544,7 +4829,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
|
4544
4829
|
"@type": "dxos.halo.credentials.Epoch",
|
|
4545
4830
|
number: 0,
|
|
4546
4831
|
previousId: void 0,
|
|
4547
|
-
timeframe: new
|
|
4832
|
+
timeframe: new Timeframe4(),
|
|
4548
4833
|
snapshotCid: void 0,
|
|
4549
4834
|
automergeRoot
|
|
4550
4835
|
}
|
|
@@ -4571,11 +4856,12 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
4571
4856
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4572
4857
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4573
4858
|
}
|
|
4574
|
-
var
|
|
4859
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
4575
4860
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
4576
4861
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
4862
|
+
var DEFAULT_SPACE_KEY = "__DEFAULT__";
|
|
4577
4863
|
var DataSpaceManager = class {
|
|
4578
|
-
constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager,
|
|
4864
|
+
constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, _params) {
|
|
4579
4865
|
this._spaceManager = _spaceManager;
|
|
4580
4866
|
this._metadataStore = _metadataStore;
|
|
4581
4867
|
this._keyring = _keyring;
|
|
@@ -4583,14 +4869,15 @@ var DataSpaceManager = class {
|
|
|
4583
4869
|
this._feedStore = _feedStore;
|
|
4584
4870
|
this._echoHost = _echoHost;
|
|
4585
4871
|
this._invitationsManager = _invitationsManager;
|
|
4586
|
-
this.
|
|
4872
|
+
this._params = _params;
|
|
4873
|
+
this._ctx = new Context9(void 0, {
|
|
4874
|
+
F: __dxlog_file19,
|
|
4875
|
+
L: 104
|
|
4876
|
+
});
|
|
4587
4877
|
this.updated = new Event7();
|
|
4588
4878
|
this._spaces = new ComplexMap3(PublicKey11.hash);
|
|
4589
4879
|
this._isOpen = false;
|
|
4590
4880
|
this._instanceId = PublicKey11.random().toHex();
|
|
4591
|
-
const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
|
|
4592
|
-
this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
|
|
4593
|
-
this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
|
|
4594
4881
|
trace7.diagnostic({
|
|
4595
4882
|
id: "spaces",
|
|
4596
4883
|
name: "Spaces",
|
|
@@ -4599,10 +4886,10 @@ var DataSpaceManager = class {
|
|
|
4599
4886
|
const rootUrl = space.automergeSpaceState.rootUrl;
|
|
4600
4887
|
const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
|
|
4601
4888
|
const rootDoc = rootHandle?.docSync();
|
|
4602
|
-
const properties = rootDoc &&
|
|
4889
|
+
const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
|
|
4603
4890
|
return {
|
|
4604
4891
|
key: space.key.toHex(),
|
|
4605
|
-
state:
|
|
4892
|
+
state: SpaceState3[space.state],
|
|
4606
4893
|
name: properties?.[1].data.name ?? null,
|
|
4607
4894
|
inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
|
|
4608
4895
|
linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
|
|
@@ -4619,46 +4906,46 @@ var DataSpaceManager = class {
|
|
|
4619
4906
|
return this._spaces;
|
|
4620
4907
|
}
|
|
4621
4908
|
async open() {
|
|
4622
|
-
|
|
4623
|
-
F:
|
|
4624
|
-
L:
|
|
4909
|
+
log16("open", void 0, {
|
|
4910
|
+
F: __dxlog_file19,
|
|
4911
|
+
L: 156,
|
|
4625
4912
|
S: this,
|
|
4626
4913
|
C: (f, a) => f(...a)
|
|
4627
4914
|
});
|
|
4628
|
-
|
|
4915
|
+
log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
|
|
4629
4916
|
id: this._instanceId
|
|
4630
4917
|
}), {
|
|
4631
|
-
F:
|
|
4632
|
-
L:
|
|
4918
|
+
F: __dxlog_file19,
|
|
4919
|
+
L: 157,
|
|
4633
4920
|
S: this,
|
|
4634
4921
|
C: (f, a) => f(...a)
|
|
4635
4922
|
});
|
|
4636
|
-
|
|
4923
|
+
log16("metadata loaded", {
|
|
4637
4924
|
spaces: this._metadataStore.spaces.length
|
|
4638
4925
|
}, {
|
|
4639
|
-
F:
|
|
4640
|
-
L:
|
|
4926
|
+
F: __dxlog_file19,
|
|
4927
|
+
L: 158,
|
|
4641
4928
|
S: this,
|
|
4642
4929
|
C: (f, a) => f(...a)
|
|
4643
4930
|
});
|
|
4644
4931
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
4645
4932
|
try {
|
|
4646
|
-
|
|
4933
|
+
log16("load space", {
|
|
4647
4934
|
spaceMetadata
|
|
4648
4935
|
}, {
|
|
4649
|
-
F:
|
|
4650
|
-
L:
|
|
4936
|
+
F: __dxlog_file19,
|
|
4937
|
+
L: 162,
|
|
4651
4938
|
S: this,
|
|
4652
4939
|
C: (f, a) => f(...a)
|
|
4653
4940
|
});
|
|
4654
4941
|
await this._constructSpace(spaceMetadata);
|
|
4655
4942
|
} catch (err) {
|
|
4656
|
-
|
|
4943
|
+
log16.error("Error loading space", {
|
|
4657
4944
|
spaceMetadata,
|
|
4658
4945
|
err
|
|
4659
4946
|
}, {
|
|
4660
|
-
F:
|
|
4661
|
-
L:
|
|
4947
|
+
F: __dxlog_file19,
|
|
4948
|
+
L: 165,
|
|
4662
4949
|
S: this,
|
|
4663
4950
|
C: (f, a) => f(...a)
|
|
4664
4951
|
});
|
|
@@ -4666,24 +4953,19 @@ var DataSpaceManager = class {
|
|
|
4666
4953
|
});
|
|
4667
4954
|
this._isOpen = true;
|
|
4668
4955
|
this.updated.emit();
|
|
4669
|
-
|
|
4670
|
-
if (space.state !== SpaceState2.INACTIVE) {
|
|
4671
|
-
space.initializeDataPipelineAsync();
|
|
4672
|
-
}
|
|
4673
|
-
}
|
|
4674
|
-
log13.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4956
|
+
log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4675
4957
|
id: this._instanceId
|
|
4676
4958
|
}), {
|
|
4677
|
-
F:
|
|
4678
|
-
L:
|
|
4959
|
+
F: __dxlog_file19,
|
|
4960
|
+
L: 172,
|
|
4679
4961
|
S: this,
|
|
4680
4962
|
C: (f, a) => f(...a)
|
|
4681
4963
|
});
|
|
4682
4964
|
}
|
|
4683
4965
|
async close() {
|
|
4684
|
-
|
|
4685
|
-
F:
|
|
4686
|
-
L:
|
|
4966
|
+
log16("close", void 0, {
|
|
4967
|
+
F: __dxlog_file19,
|
|
4968
|
+
L: 177,
|
|
4687
4969
|
S: this,
|
|
4688
4970
|
C: (f, a) => f(...a)
|
|
4689
4971
|
});
|
|
@@ -4692,14 +4974,15 @@ var DataSpaceManager = class {
|
|
|
4692
4974
|
for (const space of this._spaces.values()) {
|
|
4693
4975
|
await space.close();
|
|
4694
4976
|
}
|
|
4977
|
+
this._spaces.clear();
|
|
4695
4978
|
}
|
|
4696
4979
|
/**
|
|
4697
4980
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
4698
4981
|
*/
|
|
4699
4982
|
async createSpace() {
|
|
4700
4983
|
invariant14(this._isOpen, "Not open.", {
|
|
4701
|
-
F:
|
|
4702
|
-
L:
|
|
4984
|
+
F: __dxlog_file19,
|
|
4985
|
+
L: 191,
|
|
4703
4986
|
S: this,
|
|
4704
4987
|
A: [
|
|
4705
4988
|
"this._isOpen",
|
|
@@ -4714,48 +4997,115 @@ var DataSpaceManager = class {
|
|
|
4714
4997
|
genesisFeedKey: controlFeedKey,
|
|
4715
4998
|
controlFeedKey,
|
|
4716
4999
|
dataFeedKey,
|
|
4717
|
-
state:
|
|
5000
|
+
state: SpaceState3.ACTIVE
|
|
5001
|
+
};
|
|
5002
|
+
log16("creating space...", {
|
|
5003
|
+
spaceKey
|
|
5004
|
+
}, {
|
|
5005
|
+
F: __dxlog_file19,
|
|
5006
|
+
L: 203,
|
|
5007
|
+
S: this,
|
|
5008
|
+
C: (f, a) => f(...a)
|
|
5009
|
+
});
|
|
5010
|
+
const root = await this._echoHost.createSpaceRoot(spaceKey);
|
|
5011
|
+
const space = await this._constructSpace(metadata);
|
|
5012
|
+
await space.open();
|
|
5013
|
+
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
|
|
5014
|
+
await this._metadataStore.addSpace(metadata);
|
|
5015
|
+
const memberCredential = credentials[1];
|
|
5016
|
+
invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5017
|
+
F: __dxlog_file19,
|
|
5018
|
+
L: 213,
|
|
5019
|
+
S: this,
|
|
5020
|
+
A: [
|
|
5021
|
+
"getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
5022
|
+
""
|
|
5023
|
+
]
|
|
5024
|
+
});
|
|
5025
|
+
await this._signingContext.recordCredential(memberCredential);
|
|
5026
|
+
await space.initializeDataPipeline();
|
|
5027
|
+
this.updated.emit();
|
|
5028
|
+
return space;
|
|
5029
|
+
}
|
|
5030
|
+
async isDefaultSpace(space) {
|
|
5031
|
+
if (!space.databaseRoot) {
|
|
5032
|
+
return false;
|
|
5033
|
+
}
|
|
5034
|
+
switch (space.databaseRoot.getVersion()) {
|
|
5035
|
+
case SpaceDocVersion2.CURRENT: {
|
|
5036
|
+
const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
|
|
5037
|
+
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
5038
|
+
}
|
|
5039
|
+
case SpaceDocVersion2.LEGACY: {
|
|
5040
|
+
const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
|
|
5041
|
+
const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
|
|
5042
|
+
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
5043
|
+
}
|
|
5044
|
+
default:
|
|
5045
|
+
log16.warn("unknown space version", {
|
|
5046
|
+
version: space.databaseRoot.getVersion(),
|
|
5047
|
+
spaceId: space.id
|
|
5048
|
+
}, {
|
|
5049
|
+
F: __dxlog_file19,
|
|
5050
|
+
L: 238,
|
|
5051
|
+
S: this,
|
|
5052
|
+
C: (f, a) => f(...a)
|
|
5053
|
+
});
|
|
5054
|
+
return false;
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
async createDefaultSpace() {
|
|
5058
|
+
const space = await this.createSpace();
|
|
5059
|
+
const document = await this._getSpaceRootDocument(space);
|
|
5060
|
+
const properties = {
|
|
5061
|
+
system: {
|
|
5062
|
+
type: encodeReference(getTypeReference(PropertiesType))
|
|
5063
|
+
},
|
|
5064
|
+
data: {
|
|
5065
|
+
[DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
|
|
5066
|
+
},
|
|
5067
|
+
meta: {
|
|
5068
|
+
keys: []
|
|
5069
|
+
}
|
|
4718
5070
|
};
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
C: (f, a) => f(...a)
|
|
5071
|
+
const propertiesId = generateEchoId();
|
|
5072
|
+
document.change((doc) => {
|
|
5073
|
+
assignDeep2(doc, [
|
|
5074
|
+
"objects",
|
|
5075
|
+
propertiesId
|
|
5076
|
+
], properties);
|
|
4726
5077
|
});
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
const
|
|
4732
|
-
invariant14(
|
|
4733
|
-
F:
|
|
4734
|
-
L:
|
|
5078
|
+
await this._echoHost.flush();
|
|
5079
|
+
return space;
|
|
5080
|
+
}
|
|
5081
|
+
async _getSpaceRootDocument(space) {
|
|
5082
|
+
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5083
|
+
invariant14(automergeIndex, void 0, {
|
|
5084
|
+
F: __dxlog_file19,
|
|
5085
|
+
L: 271,
|
|
4735
5086
|
S: this,
|
|
4736
5087
|
A: [
|
|
4737
|
-
"
|
|
5088
|
+
"automergeIndex",
|
|
4738
5089
|
""
|
|
4739
5090
|
]
|
|
4740
5091
|
});
|
|
4741
|
-
|
|
4742
|
-
await
|
|
4743
|
-
|
|
4744
|
-
return space;
|
|
5092
|
+
const document = this._echoHost.automergeRepo.find(automergeIndex);
|
|
5093
|
+
await document.whenReady();
|
|
5094
|
+
return document;
|
|
4745
5095
|
}
|
|
4746
5096
|
// TODO(burdon): Rename join space.
|
|
4747
5097
|
async acceptSpace(opts) {
|
|
4748
|
-
|
|
5098
|
+
log16("accept space", {
|
|
4749
5099
|
opts
|
|
4750
5100
|
}, {
|
|
4751
|
-
F:
|
|
4752
|
-
L:
|
|
5101
|
+
F: __dxlog_file19,
|
|
5102
|
+
L: 280,
|
|
4753
5103
|
S: this,
|
|
4754
5104
|
C: (f, a) => f(...a)
|
|
4755
5105
|
});
|
|
4756
5106
|
invariant14(this._isOpen, "Not open.", {
|
|
4757
|
-
F:
|
|
4758
|
-
L:
|
|
5107
|
+
F: __dxlog_file19,
|
|
5108
|
+
L: 281,
|
|
4759
5109
|
S: this,
|
|
4760
5110
|
A: [
|
|
4761
5111
|
"this._isOpen",
|
|
@@ -4763,8 +5113,8 @@ var DataSpaceManager = class {
|
|
|
4763
5113
|
]
|
|
4764
5114
|
});
|
|
4765
5115
|
invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4766
|
-
F:
|
|
4767
|
-
L:
|
|
5116
|
+
F: __dxlog_file19,
|
|
5117
|
+
L: 282,
|
|
4768
5118
|
S: this,
|
|
4769
5119
|
A: [
|
|
4770
5120
|
"!this._spaces.has(opts.spaceKey)",
|
|
@@ -4778,28 +5128,78 @@ var DataSpaceManager = class {
|
|
|
4778
5128
|
dataTimeframe: opts.dataTimeframe
|
|
4779
5129
|
};
|
|
4780
5130
|
const space = await this._constructSpace(metadata);
|
|
5131
|
+
await space.open();
|
|
4781
5132
|
await this._metadataStore.addSpace(metadata);
|
|
4782
5133
|
space.initializeDataPipelineAsync();
|
|
4783
5134
|
this.updated.emit();
|
|
4784
5135
|
return space;
|
|
4785
5136
|
}
|
|
5137
|
+
async admitMember(options) {
|
|
5138
|
+
const space = this._spaceManager.spaces.get(options.spaceKey);
|
|
5139
|
+
invariant14(space, void 0, {
|
|
5140
|
+
F: __dxlog_file19,
|
|
5141
|
+
L: 302,
|
|
5142
|
+
S: this,
|
|
5143
|
+
A: [
|
|
5144
|
+
"space",
|
|
5145
|
+
""
|
|
5146
|
+
]
|
|
5147
|
+
});
|
|
5148
|
+
if (space.spaceState.getMemberRole(options.identityKey) !== SpaceMember6.Role.REMOVED) {
|
|
5149
|
+
throw new AlreadyJoinedError3();
|
|
5150
|
+
}
|
|
5151
|
+
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
|
|
5152
|
+
invariant14(credentials[0].credential, void 0, {
|
|
5153
|
+
F: __dxlog_file19,
|
|
5154
|
+
L: 321,
|
|
5155
|
+
S: this,
|
|
5156
|
+
A: [
|
|
5157
|
+
"credentials[0].credential",
|
|
5158
|
+
""
|
|
5159
|
+
]
|
|
5160
|
+
});
|
|
5161
|
+
const spaceMemberCredential = credentials[0].credential.credential;
|
|
5162
|
+
invariant14(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5163
|
+
F: __dxlog_file19,
|
|
5164
|
+
L: 323,
|
|
5165
|
+
S: this,
|
|
5166
|
+
A: [
|
|
5167
|
+
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
5168
|
+
""
|
|
5169
|
+
]
|
|
5170
|
+
});
|
|
5171
|
+
await writeMessages3(space.controlPipeline.writer, credentials);
|
|
5172
|
+
return spaceMemberCredential;
|
|
5173
|
+
}
|
|
4786
5174
|
/**
|
|
4787
5175
|
* Wait until the space data pipeline is fully initialized.
|
|
4788
5176
|
* Used by invitation handler.
|
|
4789
5177
|
* TODO(dmaretskyi): Consider removing.
|
|
4790
5178
|
*/
|
|
4791
5179
|
async waitUntilSpaceReady(spaceKey) {
|
|
4792
|
-
await
|
|
5180
|
+
await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
|
|
4793
5181
|
const space = this._spaces.get(spaceKey);
|
|
4794
|
-
return !!space && space.state ===
|
|
5182
|
+
return !!space && space.state === SpaceState3.READY;
|
|
4795
5183
|
}));
|
|
4796
5184
|
}
|
|
5185
|
+
async requestSpaceAdmissionCredential(spaceKey) {
|
|
5186
|
+
return this._spaceManager.requestSpaceAdmissionCredential({
|
|
5187
|
+
spaceKey,
|
|
5188
|
+
identityKey: this._signingContext.identityKey,
|
|
5189
|
+
timeout: 15e3,
|
|
5190
|
+
swarmIdentity: {
|
|
5191
|
+
peerKey: this._signingContext.deviceKey,
|
|
5192
|
+
credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
|
|
5193
|
+
credentialAuthenticator: async () => true
|
|
5194
|
+
}
|
|
5195
|
+
});
|
|
5196
|
+
}
|
|
4797
5197
|
async _constructSpace(metadata) {
|
|
4798
|
-
|
|
5198
|
+
log16("construct space", {
|
|
4799
5199
|
metadata
|
|
4800
5200
|
}, {
|
|
4801
|
-
F:
|
|
4802
|
-
L:
|
|
5201
|
+
F: __dxlog_file19,
|
|
5202
|
+
L: 358,
|
|
4803
5203
|
S: this,
|
|
4804
5204
|
C: (f, a) => f(...a)
|
|
4805
5205
|
});
|
|
@@ -4807,8 +5207,8 @@ var DataSpaceManager = class {
|
|
|
4807
5207
|
localPeerId: this._signingContext.deviceKey
|
|
4808
5208
|
});
|
|
4809
5209
|
const presence = new Presence2({
|
|
4810
|
-
announceInterval: this.
|
|
4811
|
-
offlineTimeout: this.
|
|
5210
|
+
announceInterval: this._params?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
|
|
5211
|
+
offlineTimeout: this._params?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
|
|
4812
5212
|
identityKey: this._signingContext.identityKey,
|
|
4813
5213
|
gossip
|
|
4814
5214
|
});
|
|
@@ -4827,6 +5227,7 @@ var DataSpaceManager = class {
|
|
|
4827
5227
|
credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
|
|
4828
5228
|
},
|
|
4829
5229
|
onAuthorizedConnection: (session) => {
|
|
5230
|
+
session.addExtension("dxos.mesh.teleport.admission-discovery", new CredentialServerExtension(space));
|
|
4830
5231
|
session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
|
|
4831
5232
|
remotePeerId: session.remotePeerId
|
|
4832
5233
|
}));
|
|
@@ -4835,15 +5236,15 @@ var DataSpaceManager = class {
|
|
|
4835
5236
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
4836
5237
|
},
|
|
4837
5238
|
onAuthFailure: () => {
|
|
4838
|
-
|
|
4839
|
-
F:
|
|
4840
|
-
L:
|
|
5239
|
+
log16.warn("auth failure", void 0, {
|
|
5240
|
+
F: __dxlog_file19,
|
|
5241
|
+
L: 396,
|
|
4841
5242
|
S: this,
|
|
4842
5243
|
C: (f, a) => f(...a)
|
|
4843
5244
|
});
|
|
4844
5245
|
},
|
|
4845
5246
|
onMemberRolesChanged: async (members) => {
|
|
4846
|
-
if (dataSpace?.state ===
|
|
5247
|
+
if (dataSpace?.state === SpaceState3.READY) {
|
|
4847
5248
|
this._handleMemberRoleChanges(presence, space.protocol, members);
|
|
4848
5249
|
}
|
|
4849
5250
|
},
|
|
@@ -4856,7 +5257,7 @@ var DataSpaceManager = class {
|
|
|
4856
5257
|
dataFeed && await space.setDataFeed(dataFeed);
|
|
4857
5258
|
const dataSpace = new DataSpace({
|
|
4858
5259
|
inner: space,
|
|
4859
|
-
initialState: metadata.state ===
|
|
5260
|
+
initialState: metadata.state === SpaceState3.INACTIVE ? SpaceState3.INACTIVE : SpaceState3.CLOSED,
|
|
4860
5261
|
metadataStore: this._metadataStore,
|
|
4861
5262
|
gossip,
|
|
4862
5263
|
presence,
|
|
@@ -4866,22 +5267,22 @@ var DataSpaceManager = class {
|
|
|
4866
5267
|
signingContext: this._signingContext,
|
|
4867
5268
|
callbacks: {
|
|
4868
5269
|
beforeReady: async () => {
|
|
4869
|
-
|
|
5270
|
+
log16("before space ready", {
|
|
4870
5271
|
space: space.key
|
|
4871
5272
|
}, {
|
|
4872
|
-
F:
|
|
4873
|
-
L:
|
|
5273
|
+
F: __dxlog_file19,
|
|
5274
|
+
L: 423,
|
|
4874
5275
|
S: this,
|
|
4875
5276
|
C: (f, a) => f(...a)
|
|
4876
5277
|
});
|
|
4877
5278
|
},
|
|
4878
5279
|
afterReady: async () => {
|
|
4879
|
-
|
|
5280
|
+
log16("after space ready", {
|
|
4880
5281
|
space: space.key,
|
|
4881
5282
|
open: this._isOpen
|
|
4882
5283
|
}, {
|
|
4883
|
-
F:
|
|
4884
|
-
L:
|
|
5284
|
+
F: __dxlog_file19,
|
|
5285
|
+
L: 426,
|
|
4885
5286
|
S: this,
|
|
4886
5287
|
C: (f, a) => f(...a)
|
|
4887
5288
|
});
|
|
@@ -4896,11 +5297,11 @@ var DataSpaceManager = class {
|
|
|
4896
5297
|
}
|
|
4897
5298
|
},
|
|
4898
5299
|
beforeClose: async () => {
|
|
4899
|
-
|
|
5300
|
+
log16("before space close", {
|
|
4900
5301
|
space: space.key
|
|
4901
5302
|
}, {
|
|
4902
|
-
F:
|
|
4903
|
-
L:
|
|
5303
|
+
F: __dxlog_file19,
|
|
5304
|
+
L: 434,
|
|
4904
5305
|
S: this,
|
|
4905
5306
|
C: (f, a) => f(...a)
|
|
4906
5307
|
});
|
|
@@ -4909,13 +5310,10 @@ var DataSpaceManager = class {
|
|
|
4909
5310
|
cache: metadata.cache
|
|
4910
5311
|
});
|
|
4911
5312
|
presence.newPeer.on((peerState) => {
|
|
4912
|
-
if (dataSpace.state ===
|
|
5313
|
+
if (dataSpace.state === SpaceState3.READY) {
|
|
4913
5314
|
this._handleNewPeerConnected(space, peerState);
|
|
4914
5315
|
}
|
|
4915
5316
|
});
|
|
4916
|
-
if (metadata.state !== SpaceState2.INACTIVE) {
|
|
4917
|
-
await dataSpace.open();
|
|
4918
|
-
}
|
|
4919
5317
|
if (metadata.controlTimeframe) {
|
|
4920
5318
|
dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
|
|
4921
5319
|
}
|
|
@@ -4934,17 +5332,17 @@ var DataSpaceManager = class {
|
|
|
4934
5332
|
return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
|
|
4935
5333
|
});
|
|
4936
5334
|
sessionsToClose.forEach((session) => {
|
|
4937
|
-
void session.close().catch(
|
|
5335
|
+
void session.close().catch(log16.error);
|
|
4938
5336
|
});
|
|
4939
5337
|
closedSessions += sessionsToClose.length;
|
|
4940
5338
|
}
|
|
4941
|
-
|
|
5339
|
+
log16("processed member role changes", {
|
|
4942
5340
|
roleChangeCount: memberInfo.length,
|
|
4943
5341
|
peersOnline: presence.getPeersOnline().length,
|
|
4944
5342
|
closedSessions
|
|
4945
5343
|
}, {
|
|
4946
|
-
F:
|
|
4947
|
-
L:
|
|
5344
|
+
F: __dxlog_file19,
|
|
5345
|
+
L: 470,
|
|
4948
5346
|
S: this,
|
|
4949
5347
|
C: (f, a) => f(...a)
|
|
4950
5348
|
});
|
|
@@ -4955,20 +5353,20 @@ var DataSpaceManager = class {
|
|
|
4955
5353
|
if (role === SpaceMember6.Role.REMOVED) {
|
|
4956
5354
|
const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
|
|
4957
5355
|
if (session != null) {
|
|
4958
|
-
|
|
5356
|
+
log16("closing a session with a removed peer", {
|
|
4959
5357
|
peerId: peerState.peerId
|
|
4960
5358
|
}, {
|
|
4961
|
-
F:
|
|
4962
|
-
L:
|
|
5359
|
+
F: __dxlog_file19,
|
|
5360
|
+
L: 484,
|
|
4963
5361
|
S: this,
|
|
4964
5362
|
C: (f, a) => f(...a)
|
|
4965
5363
|
});
|
|
4966
|
-
void session.close().catch(
|
|
5364
|
+
void session.close().catch(log16.error);
|
|
4967
5365
|
}
|
|
4968
5366
|
}
|
|
4969
5367
|
}
|
|
4970
5368
|
async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
|
|
4971
|
-
if (dataSpace?.state !==
|
|
5369
|
+
if (dataSpace?.state !== SpaceState3.READY) {
|
|
4972
5370
|
return;
|
|
4973
5371
|
}
|
|
4974
5372
|
if (isActive) {
|
|
@@ -5022,15 +5420,15 @@ DataSpaceManager = _ts_decorate5([
|
|
|
5022
5420
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
5023
5421
|
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
|
|
5024
5422
|
import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
5025
|
-
import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as
|
|
5423
|
+
import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
|
|
5026
5424
|
import { raise as raise2 } from "@dxos/debug";
|
|
5027
|
-
import { writeMessages as
|
|
5425
|
+
import { writeMessages as writeMessages4 } from "@dxos/feed-store";
|
|
5028
5426
|
import { invariant as invariant15 } from "@dxos/invariant";
|
|
5029
|
-
import { log as
|
|
5427
|
+
import { log as log17 } from "@dxos/log";
|
|
5030
5428
|
import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
|
|
5031
|
-
import { SpaceMember as SpaceMember7, SpaceState as
|
|
5429
|
+
import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5032
5430
|
import { trace as trace8 } from "@dxos/tracing";
|
|
5033
|
-
var
|
|
5431
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
5034
5432
|
var SpacesServiceImpl = class {
|
|
5035
5433
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
5036
5434
|
this._identityManager = _identityManager;
|
|
@@ -5049,10 +5447,10 @@ var SpacesServiceImpl = class {
|
|
|
5049
5447
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
|
|
5050
5448
|
if (state) {
|
|
5051
5449
|
switch (state) {
|
|
5052
|
-
case
|
|
5450
|
+
case SpaceState4.ACTIVE:
|
|
5053
5451
|
await space.activate();
|
|
5054
5452
|
break;
|
|
5055
|
-
case
|
|
5453
|
+
case SpaceState4.INACTIVE:
|
|
5056
5454
|
await space.deactivate();
|
|
5057
5455
|
break;
|
|
5058
5456
|
default:
|
|
@@ -5074,8 +5472,8 @@ var SpacesServiceImpl = class {
|
|
|
5074
5472
|
}
|
|
5075
5473
|
const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
|
|
5076
5474
|
invariant15(credentials[0].credential, void 0, {
|
|
5077
|
-
F:
|
|
5078
|
-
L:
|
|
5475
|
+
F: __dxlog_file20,
|
|
5476
|
+
L: 102,
|
|
5079
5477
|
S: this,
|
|
5080
5478
|
A: [
|
|
5081
5479
|
"credentials[0].credential",
|
|
@@ -5083,27 +5481,27 @@ var SpacesServiceImpl = class {
|
|
|
5083
5481
|
]
|
|
5084
5482
|
});
|
|
5085
5483
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
5086
|
-
invariant15(
|
|
5087
|
-
F:
|
|
5088
|
-
L:
|
|
5484
|
+
invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5485
|
+
F: __dxlog_file20,
|
|
5486
|
+
L: 104,
|
|
5089
5487
|
S: this,
|
|
5090
5488
|
A: [
|
|
5091
5489
|
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
5092
5490
|
""
|
|
5093
5491
|
]
|
|
5094
5492
|
});
|
|
5095
|
-
await
|
|
5493
|
+
await writeMessages4(space.controlPipeline.writer, credentials);
|
|
5096
5494
|
}
|
|
5097
5495
|
querySpaces() {
|
|
5098
5496
|
return new Stream10(({ next, ctx }) => {
|
|
5099
5497
|
const scheduler = new UpdateScheduler(ctx, async () => {
|
|
5100
5498
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5101
5499
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
5102
|
-
|
|
5500
|
+
log17("update", {
|
|
5103
5501
|
spaces
|
|
5104
5502
|
}, {
|
|
5105
|
-
F:
|
|
5106
|
-
L:
|
|
5503
|
+
F: __dxlog_file20,
|
|
5504
|
+
L: 115,
|
|
5107
5505
|
S: this,
|
|
5108
5506
|
C: (f, a) => f(...a)
|
|
5109
5507
|
});
|
|
@@ -5121,7 +5519,15 @@ var SpacesServiceImpl = class {
|
|
|
5121
5519
|
const subscribeSpaces = () => {
|
|
5122
5520
|
subscriptions.clear();
|
|
5123
5521
|
for (const space of dataSpaceManager.spaces.values()) {
|
|
5124
|
-
|
|
5522
|
+
let lastState;
|
|
5523
|
+
subscriptions.add(space.stateUpdate.on(ctx, () => {
|
|
5524
|
+
if (space.state !== lastState) {
|
|
5525
|
+
scheduler.forceTrigger();
|
|
5526
|
+
} else {
|
|
5527
|
+
scheduler.trigger();
|
|
5528
|
+
}
|
|
5529
|
+
lastState = space.state;
|
|
5530
|
+
}));
|
|
5125
5531
|
subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
|
|
5126
5532
|
subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
|
|
5127
5533
|
subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
|
|
@@ -5186,8 +5592,8 @@ var SpacesServiceImpl = class {
|
|
|
5186
5592
|
});
|
|
5187
5593
|
} else {
|
|
5188
5594
|
invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
5189
|
-
F:
|
|
5190
|
-
L:
|
|
5595
|
+
F: __dxlog_file20,
|
|
5596
|
+
L: 213,
|
|
5191
5597
|
S: this,
|
|
5192
5598
|
A: [
|
|
5193
5599
|
"!credential.id",
|
|
@@ -5195,8 +5601,8 @@ var SpacesServiceImpl = class {
|
|
|
5195
5601
|
]
|
|
5196
5602
|
});
|
|
5197
5603
|
invariant15(this._identityManager.identity, "Identity is not available", {
|
|
5198
|
-
F:
|
|
5199
|
-
L:
|
|
5604
|
+
F: __dxlog_file20,
|
|
5605
|
+
L: 214,
|
|
5200
5606
|
S: this,
|
|
5201
5607
|
A: [
|
|
5202
5608
|
"this._identityManager.identity",
|
|
@@ -5205,8 +5611,8 @@ var SpacesServiceImpl = class {
|
|
|
5205
5611
|
});
|
|
5206
5612
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
5207
5613
|
invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
5208
|
-
F:
|
|
5209
|
-
L:
|
|
5614
|
+
F: __dxlog_file20,
|
|
5615
|
+
L: 216,
|
|
5210
5616
|
S: this,
|
|
5211
5617
|
A: [
|
|
5212
5618
|
"credential.issuer.equals(signer.getIssuer())",
|
|
@@ -5228,10 +5634,66 @@ var SpacesServiceImpl = class {
|
|
|
5228
5634
|
async createEpoch({ spaceKey, migration, automergeRootUrl }) {
|
|
5229
5635
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5230
5636
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
|
|
5231
|
-
await space.createEpoch({
|
|
5637
|
+
const credential = await space.createEpoch({
|
|
5232
5638
|
migration,
|
|
5233
5639
|
newAutomergeRoot: automergeRootUrl
|
|
5234
5640
|
});
|
|
5641
|
+
return {
|
|
5642
|
+
epochCredential: credential ?? void 0
|
|
5643
|
+
};
|
|
5644
|
+
}
|
|
5645
|
+
async admitContact(request) {
|
|
5646
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5647
|
+
await dataSpaceManager.admitMember({
|
|
5648
|
+
spaceKey: request.spaceKey,
|
|
5649
|
+
identityKey: request.contact.identityKey,
|
|
5650
|
+
role: request.role
|
|
5651
|
+
});
|
|
5652
|
+
}
|
|
5653
|
+
async joinBySpaceKey({ spaceKey }) {
|
|
5654
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5655
|
+
const credential = await dataSpaceManager.requestSpaceAdmissionCredential(spaceKey);
|
|
5656
|
+
return this._joinByAdmission({
|
|
5657
|
+
credential
|
|
5658
|
+
});
|
|
5659
|
+
}
|
|
5660
|
+
async _joinByAdmission({ credential }) {
|
|
5661
|
+
const assertion = getCredentialAssertion4(credential);
|
|
5662
|
+
invariant15(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
5663
|
+
F: __dxlog_file20,
|
|
5664
|
+
L: 250,
|
|
5665
|
+
S: this,
|
|
5666
|
+
A: [
|
|
5667
|
+
"assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
5668
|
+
"'Invalid credential'"
|
|
5669
|
+
]
|
|
5670
|
+
});
|
|
5671
|
+
const myIdentity = this._identityManager.identity;
|
|
5672
|
+
invariant15(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
|
|
5673
|
+
F: __dxlog_file20,
|
|
5674
|
+
L: 252,
|
|
5675
|
+
S: this,
|
|
5676
|
+
A: [
|
|
5677
|
+
"myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
|
|
5678
|
+
""
|
|
5679
|
+
]
|
|
5680
|
+
});
|
|
5681
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5682
|
+
let dataSpace = dataSpaceManager.spaces.get(assertion.spaceKey);
|
|
5683
|
+
if (!dataSpace) {
|
|
5684
|
+
dataSpace = await dataSpaceManager.acceptSpace({
|
|
5685
|
+
spaceKey: assertion.spaceKey,
|
|
5686
|
+
genesisFeedKey: assertion.genesisFeedKey
|
|
5687
|
+
});
|
|
5688
|
+
await myIdentity.controlPipeline.writer.write({
|
|
5689
|
+
credential: {
|
|
5690
|
+
credential
|
|
5691
|
+
}
|
|
5692
|
+
});
|
|
5693
|
+
}
|
|
5694
|
+
return {
|
|
5695
|
+
space: this._serializeSpace(dataSpace)
|
|
5696
|
+
};
|
|
5235
5697
|
}
|
|
5236
5698
|
_serializeSpace(space) {
|
|
5237
5699
|
return {
|
|
@@ -5294,9 +5756,9 @@ var SpacesServiceImpl = class {
|
|
|
5294
5756
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
5295
5757
|
|
|
5296
5758
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
5297
|
-
import { Trigger as
|
|
5298
|
-
import { Context as Context10, Resource } from "@dxos/context";
|
|
5299
|
-
import { getCredentialAssertion as
|
|
5759
|
+
import { Trigger as Trigger8 } from "@dxos/async";
|
|
5760
|
+
import { Context as Context10, Resource as Resource3 } from "@dxos/context";
|
|
5761
|
+
import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
|
|
5300
5762
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
5301
5763
|
import { EchoHost } from "@dxos/echo-db";
|
|
5302
5764
|
import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
@@ -5304,7 +5766,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
|
5304
5766
|
import { invariant as invariant16 } from "@dxos/invariant";
|
|
5305
5767
|
import { Keyring } from "@dxos/keyring";
|
|
5306
5768
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5307
|
-
import { log as
|
|
5769
|
+
import { log as log18 } from "@dxos/log";
|
|
5308
5770
|
import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
|
|
5309
5771
|
import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5310
5772
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
@@ -5320,8 +5782,8 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
5320
5782
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5321
5783
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5322
5784
|
}
|
|
5323
|
-
var
|
|
5324
|
-
var ServiceContext = class extends
|
|
5785
|
+
var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
5786
|
+
var ServiceContext = class extends Resource3 {
|
|
5325
5787
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
5326
5788
|
super();
|
|
5327
5789
|
this.storage = storage;
|
|
@@ -5329,7 +5791,7 @@ var ServiceContext = class extends Resource {
|
|
|
5329
5791
|
this.networkManager = networkManager;
|
|
5330
5792
|
this.signalManager = signalManager;
|
|
5331
5793
|
this._runtimeParams = _runtimeParams;
|
|
5332
|
-
this.initialized = new
|
|
5794
|
+
this.initialized = new Trigger8();
|
|
5333
5795
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
5334
5796
|
this._instanceId = PublicKey12.random().toHex();
|
|
5335
5797
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
@@ -5355,8 +5817,7 @@ var ServiceContext = class extends Resource {
|
|
|
5355
5817
|
});
|
|
5356
5818
|
this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
|
|
5357
5819
|
this.echoHost = new EchoHost({
|
|
5358
|
-
kv: this.level
|
|
5359
|
-
storage: this.storage
|
|
5820
|
+
kv: this.level
|
|
5360
5821
|
});
|
|
5361
5822
|
this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
|
|
5362
5823
|
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
@@ -5364,17 +5825,17 @@ var ServiceContext = class extends Resource {
|
|
|
5364
5825
|
}
|
|
5365
5826
|
async _open(ctx) {
|
|
5366
5827
|
await this._checkStorageVersion();
|
|
5367
|
-
|
|
5368
|
-
F:
|
|
5369
|
-
L:
|
|
5828
|
+
log18("opening...", void 0, {
|
|
5829
|
+
F: __dxlog_file21,
|
|
5830
|
+
L: 149,
|
|
5370
5831
|
S: this,
|
|
5371
5832
|
C: (f, a) => f(...a)
|
|
5372
5833
|
});
|
|
5373
|
-
|
|
5834
|
+
log18.trace("dxos.sdk.service-context.open", trace9.begin({
|
|
5374
5835
|
id: this._instanceId
|
|
5375
5836
|
}), {
|
|
5376
|
-
F:
|
|
5377
|
-
L:
|
|
5837
|
+
F: __dxlog_file21,
|
|
5838
|
+
L: 150,
|
|
5378
5839
|
S: this,
|
|
5379
5840
|
C: (f, a) => f(...a)
|
|
5380
5841
|
});
|
|
@@ -5388,33 +5849,33 @@ var ServiceContext = class extends Resource {
|
|
|
5388
5849
|
await this._initialize(ctx);
|
|
5389
5850
|
}
|
|
5390
5851
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
5391
|
-
|
|
5852
|
+
log18("loaded persistent invitations", {
|
|
5392
5853
|
count: loadedInvitations.invitations?.length
|
|
5393
5854
|
}, {
|
|
5394
|
-
F:
|
|
5395
|
-
L:
|
|
5855
|
+
F: __dxlog_file21,
|
|
5856
|
+
L: 163,
|
|
5396
5857
|
S: this,
|
|
5397
5858
|
C: (f, a) => f(...a)
|
|
5398
5859
|
});
|
|
5399
|
-
|
|
5860
|
+
log18.trace("dxos.sdk.service-context.open", trace9.end({
|
|
5400
5861
|
id: this._instanceId
|
|
5401
5862
|
}), {
|
|
5402
|
-
F:
|
|
5403
|
-
L:
|
|
5863
|
+
F: __dxlog_file21,
|
|
5864
|
+
L: 165,
|
|
5404
5865
|
S: this,
|
|
5405
5866
|
C: (f, a) => f(...a)
|
|
5406
5867
|
});
|
|
5407
|
-
|
|
5408
|
-
F:
|
|
5409
|
-
L:
|
|
5868
|
+
log18("opened", void 0, {
|
|
5869
|
+
F: __dxlog_file21,
|
|
5870
|
+
L: 166,
|
|
5410
5871
|
S: this,
|
|
5411
5872
|
C: (f, a) => f(...a)
|
|
5412
5873
|
});
|
|
5413
5874
|
}
|
|
5414
5875
|
async _close(ctx) {
|
|
5415
|
-
|
|
5416
|
-
F:
|
|
5417
|
-
L:
|
|
5876
|
+
log18("closing...", void 0, {
|
|
5877
|
+
F: __dxlog_file21,
|
|
5878
|
+
L: 170,
|
|
5418
5879
|
S: this,
|
|
5419
5880
|
C: (f, a) => f(...a)
|
|
5420
5881
|
});
|
|
@@ -5429,23 +5890,26 @@ var ServiceContext = class extends Resource {
|
|
|
5429
5890
|
await this.echoHost.close(ctx);
|
|
5430
5891
|
await this.networkManager.close();
|
|
5431
5892
|
await this.signalManager.close();
|
|
5432
|
-
|
|
5433
|
-
F:
|
|
5434
|
-
L:
|
|
5893
|
+
log18("closed", void 0, {
|
|
5894
|
+
F: __dxlog_file21,
|
|
5895
|
+
L: 182,
|
|
5435
5896
|
S: this,
|
|
5436
5897
|
C: (f, a) => f(...a)
|
|
5437
5898
|
});
|
|
5438
5899
|
}
|
|
5439
5900
|
async createIdentity(params = {}) {
|
|
5440
5901
|
const identity = await this.identityManager.createIdentity(params);
|
|
5441
|
-
await this._initialize(new Context10(
|
|
5902
|
+
await this._initialize(new Context10(void 0, {
|
|
5903
|
+
F: __dxlog_file21,
|
|
5904
|
+
L: 187
|
|
5905
|
+
}));
|
|
5442
5906
|
return identity;
|
|
5443
5907
|
}
|
|
5444
5908
|
getInvitationHandler(invitation) {
|
|
5445
5909
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
5446
5910
|
invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
5447
|
-
F:
|
|
5448
|
-
L:
|
|
5911
|
+
F: __dxlog_file21,
|
|
5912
|
+
L: 193,
|
|
5449
5913
|
S: this,
|
|
5450
5914
|
A: [
|
|
5451
5915
|
"factory",
|
|
@@ -5464,7 +5928,10 @@ var ServiceContext = class extends Resource {
|
|
|
5464
5928
|
}
|
|
5465
5929
|
async _acceptIdentity(params) {
|
|
5466
5930
|
const identity = await this.identityManager.acceptIdentity(params);
|
|
5467
|
-
await this._initialize(new Context10(
|
|
5931
|
+
await this._initialize(new Context10(void 0, {
|
|
5932
|
+
F: __dxlog_file21,
|
|
5933
|
+
L: 209
|
|
5934
|
+
}));
|
|
5468
5935
|
return identity;
|
|
5469
5936
|
}
|
|
5470
5937
|
async _checkStorageVersion() {
|
|
@@ -5475,9 +5942,9 @@ var ServiceContext = class extends Resource {
|
|
|
5475
5942
|
}
|
|
5476
5943
|
// Called when identity is created.
|
|
5477
5944
|
async _initialize(ctx) {
|
|
5478
|
-
|
|
5479
|
-
F:
|
|
5480
|
-
L:
|
|
5945
|
+
log18("initializing spaces...", void 0, {
|
|
5946
|
+
F: __dxlog_file21,
|
|
5947
|
+
L: 224,
|
|
5481
5948
|
S: this,
|
|
5482
5949
|
C: (f, a) => f(...a)
|
|
5483
5950
|
});
|
|
@@ -5499,8 +5966,8 @@ var ServiceContext = class extends Resource {
|
|
|
5499
5966
|
await this.dataSpaceManager.open();
|
|
5500
5967
|
this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
|
|
5501
5968
|
invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5502
|
-
F:
|
|
5503
|
-
L:
|
|
5969
|
+
F: __dxlog_file21,
|
|
5970
|
+
L: 249,
|
|
5504
5971
|
S: this,
|
|
5505
5972
|
A: [
|
|
5506
5973
|
"this.dataSpaceManager",
|
|
@@ -5512,7 +5979,7 @@ var ServiceContext = class extends Resource {
|
|
|
5512
5979
|
this.initialized.wake();
|
|
5513
5980
|
this._deviceSpaceSync = {
|
|
5514
5981
|
processCredential: async (credential) => {
|
|
5515
|
-
const assertion =
|
|
5982
|
+
const assertion = getCredentialAssertion5(credential);
|
|
5516
5983
|
if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
|
|
5517
5984
|
return;
|
|
5518
5985
|
}
|
|
@@ -5520,33 +5987,33 @@ var ServiceContext = class extends Resource {
|
|
|
5520
5987
|
return;
|
|
5521
5988
|
}
|
|
5522
5989
|
if (!this.dataSpaceManager) {
|
|
5523
|
-
|
|
5990
|
+
log18("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
5524
5991
|
details: assertion
|
|
5525
5992
|
}, {
|
|
5526
|
-
F:
|
|
5527
|
-
L:
|
|
5993
|
+
F: __dxlog_file21,
|
|
5994
|
+
L: 265,
|
|
5528
5995
|
S: this,
|
|
5529
5996
|
C: (f, a) => f(...a)
|
|
5530
5997
|
});
|
|
5531
5998
|
return;
|
|
5532
5999
|
}
|
|
5533
6000
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
5534
|
-
|
|
6001
|
+
log18("space already exists, ignoring space admission", {
|
|
5535
6002
|
details: assertion
|
|
5536
6003
|
}, {
|
|
5537
|
-
F:
|
|
5538
|
-
L:
|
|
6004
|
+
F: __dxlog_file21,
|
|
6005
|
+
L: 269,
|
|
5539
6006
|
S: this,
|
|
5540
6007
|
C: (f, a) => f(...a)
|
|
5541
6008
|
});
|
|
5542
6009
|
return;
|
|
5543
6010
|
}
|
|
5544
6011
|
try {
|
|
5545
|
-
|
|
6012
|
+
log18("accepting space recorded in halo", {
|
|
5546
6013
|
details: assertion
|
|
5547
6014
|
}, {
|
|
5548
|
-
F:
|
|
5549
|
-
L:
|
|
6015
|
+
F: __dxlog_file21,
|
|
6016
|
+
L: 274,
|
|
5550
6017
|
S: this,
|
|
5551
6018
|
C: (f, a) => f(...a)
|
|
5552
6019
|
});
|
|
@@ -5555,9 +6022,9 @@ var ServiceContext = class extends Resource {
|
|
|
5555
6022
|
genesisFeedKey: assertion.genesisFeedKey
|
|
5556
6023
|
});
|
|
5557
6024
|
} catch (err) {
|
|
5558
|
-
|
|
5559
|
-
F:
|
|
5560
|
-
L:
|
|
6025
|
+
log18.catch(err, void 0, {
|
|
6026
|
+
F: __dxlog_file21,
|
|
6027
|
+
L: 280,
|
|
5561
6028
|
S: this,
|
|
5562
6029
|
C: (f, a) => f(...a)
|
|
5563
6030
|
});
|
|
@@ -5603,9 +6070,9 @@ var ServiceRegistry = class {
|
|
|
5603
6070
|
};
|
|
5604
6071
|
|
|
5605
6072
|
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5606
|
-
import { asyncTimeout as asyncTimeout3, Trigger as
|
|
6073
|
+
import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
|
|
5607
6074
|
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5608
|
-
import { log as
|
|
6075
|
+
import { log as log19, logInfo } from "@dxos/log";
|
|
5609
6076
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
5610
6077
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5611
6078
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -5616,7 +6083,7 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
5616
6083
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5617
6084
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5618
6085
|
}
|
|
5619
|
-
var
|
|
6086
|
+
var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5620
6087
|
var Message;
|
|
5621
6088
|
(function(Message2) {
|
|
5622
6089
|
Message2["ACQUIRING"] = "acquiring";
|
|
@@ -5624,7 +6091,7 @@ var Message;
|
|
|
5624
6091
|
var Lock = class {
|
|
5625
6092
|
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5626
6093
|
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5627
|
-
this._releaseTrigger = new
|
|
6094
|
+
this._releaseTrigger = new Trigger9();
|
|
5628
6095
|
this._lockKey = lockKey;
|
|
5629
6096
|
this._onAcquire = onAcquire;
|
|
5630
6097
|
this._onRelease = onRelease;
|
|
@@ -5638,29 +6105,29 @@ var Lock = class {
|
|
|
5638
6105
|
message: "acquiring"
|
|
5639
6106
|
});
|
|
5640
6107
|
try {
|
|
5641
|
-
|
|
5642
|
-
F:
|
|
6108
|
+
log19("aquiring lock...", void 0, {
|
|
6109
|
+
F: __dxlog_file22,
|
|
5643
6110
|
L: 42,
|
|
5644
6111
|
S: this,
|
|
5645
6112
|
C: (f, a) => f(...a)
|
|
5646
6113
|
});
|
|
5647
6114
|
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5648
|
-
|
|
5649
|
-
F:
|
|
6115
|
+
log19("acquired lock", void 0, {
|
|
6116
|
+
F: __dxlog_file22,
|
|
5650
6117
|
L: 44,
|
|
5651
6118
|
S: this,
|
|
5652
6119
|
C: (f, a) => f(...a)
|
|
5653
6120
|
});
|
|
5654
6121
|
} catch {
|
|
5655
|
-
|
|
5656
|
-
F:
|
|
6122
|
+
log19("stealing lock...", void 0, {
|
|
6123
|
+
F: __dxlog_file22,
|
|
5657
6124
|
L: 46,
|
|
5658
6125
|
S: this,
|
|
5659
6126
|
C: (f, a) => f(...a)
|
|
5660
6127
|
});
|
|
5661
6128
|
await this._requestLock(true);
|
|
5662
|
-
|
|
5663
|
-
F:
|
|
6129
|
+
log19("stolen lock", void 0, {
|
|
6130
|
+
F: __dxlog_file22,
|
|
5664
6131
|
L: 48,
|
|
5665
6132
|
S: this,
|
|
5666
6133
|
C: (f, a) => f(...a)
|
|
@@ -5676,31 +6143,31 @@ var Lock = class {
|
|
|
5676
6143
|
}
|
|
5677
6144
|
}
|
|
5678
6145
|
async _requestLock(steal = false) {
|
|
5679
|
-
|
|
6146
|
+
log19("requesting lock...", {
|
|
5680
6147
|
steal
|
|
5681
6148
|
}, {
|
|
5682
|
-
F:
|
|
6149
|
+
F: __dxlog_file22,
|
|
5683
6150
|
L: 63,
|
|
5684
6151
|
S: this,
|
|
5685
6152
|
C: (f, a) => f(...a)
|
|
5686
6153
|
});
|
|
5687
|
-
const acquired = new
|
|
6154
|
+
const acquired = new Trigger9();
|
|
5688
6155
|
void navigator.locks.request(this._lockKey, {
|
|
5689
6156
|
steal
|
|
5690
6157
|
}, async () => {
|
|
5691
6158
|
await this._onAcquire?.();
|
|
5692
6159
|
acquired.wake();
|
|
5693
|
-
this._releaseTrigger = new
|
|
6160
|
+
this._releaseTrigger = new Trigger9();
|
|
5694
6161
|
await this._releaseTrigger.wait();
|
|
5695
|
-
|
|
5696
|
-
F:
|
|
6162
|
+
log19("releasing lock...", void 0, {
|
|
6163
|
+
F: __dxlog_file22,
|
|
5697
6164
|
L: 72,
|
|
5698
6165
|
S: this,
|
|
5699
6166
|
C: (f, a) => f(...a)
|
|
5700
6167
|
});
|
|
5701
6168
|
await this._onRelease?.();
|
|
5702
|
-
|
|
5703
|
-
F:
|
|
6169
|
+
log19("released lock", void 0, {
|
|
6170
|
+
F: __dxlog_file22,
|
|
5704
6171
|
L: 74,
|
|
5705
6172
|
S: this,
|
|
5706
6173
|
C: (f, a) => f(...a)
|
|
@@ -5709,10 +6176,10 @@ var Lock = class {
|
|
|
5709
6176
|
await this._onRelease?.();
|
|
5710
6177
|
});
|
|
5711
6178
|
await acquired.wait();
|
|
5712
|
-
|
|
6179
|
+
log19("recieved lock", {
|
|
5713
6180
|
steal
|
|
5714
6181
|
}, {
|
|
5715
|
-
F:
|
|
6182
|
+
F: __dxlog_file22,
|
|
5716
6183
|
L: 81,
|
|
5717
6184
|
S: this,
|
|
5718
6185
|
C: (f, a) => f(...a)
|
|
@@ -5802,19 +6269,16 @@ var createLevel = async (config) => {
|
|
|
5802
6269
|
|
|
5803
6270
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
5804
6271
|
import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
|
|
5805
|
-
import { clientServiceBundle
|
|
6272
|
+
import { clientServiceBundle } from "@dxos/client-protocol";
|
|
5806
6273
|
import { Context as Context11 } from "@dxos/context";
|
|
5807
|
-
import { encodeReference } from "@dxos/echo-protocol";
|
|
5808
|
-
import { getTypeReference } from "@dxos/echo-schema";
|
|
5809
6274
|
import { invariant as invariant18 } from "@dxos/invariant";
|
|
5810
|
-
import { PublicKey as
|
|
5811
|
-
import { log as
|
|
6275
|
+
import { PublicKey as PublicKey17 } from "@dxos/keys";
|
|
6276
|
+
import { log as log21 } from "@dxos/log";
|
|
5812
6277
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
5813
6278
|
import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
5814
6279
|
import { trace as trace10 } from "@dxos/protocols";
|
|
5815
6280
|
import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
5816
6281
|
import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
|
|
5817
|
-
import { assignDeep as assignDeep2 } from "@dxos/util";
|
|
5818
6282
|
import { WebsocketRpcClient } from "@dxos/websocket-rpc";
|
|
5819
6283
|
|
|
5820
6284
|
// packages/sdk/client-services/src/packlets/devices/devices-service.ts
|
|
@@ -5822,7 +6286,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
|
|
|
5822
6286
|
import { Stream as Stream11 } from "@dxos/codec-protobuf";
|
|
5823
6287
|
import { invariant as invariant17 } from "@dxos/invariant";
|
|
5824
6288
|
import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5825
|
-
var
|
|
6289
|
+
var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
5826
6290
|
var DevicesServiceImpl = class {
|
|
5827
6291
|
constructor(_identityManager) {
|
|
5828
6292
|
this._identityManager = _identityManager;
|
|
@@ -5840,7 +6304,7 @@ var DevicesServiceImpl = class {
|
|
|
5840
6304
|
});
|
|
5841
6305
|
} else {
|
|
5842
6306
|
invariant17(this._identityManager.identity?.presence, "presence not present", {
|
|
5843
|
-
F:
|
|
6307
|
+
F: __dxlog_file23,
|
|
5844
6308
|
L: 32,
|
|
5845
6309
|
S: this,
|
|
5846
6310
|
A: [
|
|
@@ -5946,28 +6410,111 @@ var findConfigs = () => {
|
|
|
5946
6410
|
return configs.map((r) => r.instance.deref()).filter(nonNullable);
|
|
5947
6411
|
};
|
|
5948
6412
|
|
|
5949
|
-
// packages/sdk/client-services/src/packlets/
|
|
5950
|
-
import {
|
|
6413
|
+
// packages/sdk/client-services/src/packlets/identity/contacts-service.ts
|
|
6414
|
+
import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
|
|
5951
6415
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5952
6416
|
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5953
|
-
import {
|
|
6417
|
+
import { ComplexMap as ComplexMap4, ComplexSet as ComplexSet6 } from "@dxos/util";
|
|
6418
|
+
var ContactsServiceImpl = class {
|
|
6419
|
+
constructor(_identityManager, _spaceManager, _dataSpaceManagerProvider) {
|
|
6420
|
+
this._identityManager = _identityManager;
|
|
6421
|
+
this._spaceManager = _spaceManager;
|
|
6422
|
+
this._dataSpaceManagerProvider = _dataSpaceManagerProvider;
|
|
6423
|
+
}
|
|
6424
|
+
async getContacts() {
|
|
6425
|
+
const identity = this._identityManager.identity;
|
|
6426
|
+
if (identity == null) {
|
|
6427
|
+
return {
|
|
6428
|
+
contacts: []
|
|
6429
|
+
};
|
|
6430
|
+
}
|
|
6431
|
+
const contacts = [
|
|
6432
|
+
...this._spaceManager.spaces.values()
|
|
6433
|
+
].flatMap((s) => [
|
|
6434
|
+
...s.spaceState.members.values()
|
|
6435
|
+
].map((m) => [
|
|
6436
|
+
s.key,
|
|
6437
|
+
m
|
|
6438
|
+
])).reduce((acc, v) => {
|
|
6439
|
+
const [spaceKey, memberInfo] = v;
|
|
6440
|
+
if (memberInfo.key.equals(identity.identityKey)) {
|
|
6441
|
+
return acc;
|
|
6442
|
+
}
|
|
6443
|
+
const existing = acc.get(memberInfo.key);
|
|
6444
|
+
if (existing != null) {
|
|
6445
|
+
existing.profile ??= memberInfo.profile;
|
|
6446
|
+
existing.commonSpaces?.push(spaceKey);
|
|
6447
|
+
} else {
|
|
6448
|
+
acc.set(memberInfo.key, {
|
|
6449
|
+
identityKey: memberInfo.key,
|
|
6450
|
+
profile: memberInfo.profile,
|
|
6451
|
+
commonSpaces: [
|
|
6452
|
+
spaceKey
|
|
6453
|
+
]
|
|
6454
|
+
});
|
|
6455
|
+
}
|
|
6456
|
+
return acc;
|
|
6457
|
+
}, new ComplexMap4(PublicKey15.hash));
|
|
6458
|
+
return {
|
|
6459
|
+
contacts: [
|
|
6460
|
+
...contacts.values()
|
|
6461
|
+
]
|
|
6462
|
+
};
|
|
6463
|
+
}
|
|
6464
|
+
queryContacts() {
|
|
6465
|
+
const subscribedSpaceKeySet = new ComplexSet6(PublicKey15.hash);
|
|
6466
|
+
return new Stream12(({ next, ctx }) => {
|
|
6467
|
+
const pushUpdateTask = new UpdateScheduler2(ctx, async () => {
|
|
6468
|
+
const contacts = await this.getContacts();
|
|
6469
|
+
next(contacts);
|
|
6470
|
+
}, {
|
|
6471
|
+
maxFrequency: 2
|
|
6472
|
+
});
|
|
6473
|
+
scheduleTask7(ctx, async () => {
|
|
6474
|
+
const subscriptions = new EventSubscriptions4();
|
|
6475
|
+
ctx.onDispose(() => subscriptions.clear());
|
|
6476
|
+
const subscribeToSpaceAndUpdate = () => {
|
|
6477
|
+
const oldSetSize = subscribedSpaceKeySet.size;
|
|
6478
|
+
for (const space of this._spaceManager.spaces.values()) {
|
|
6479
|
+
if (!subscribedSpaceKeySet.has(space.key)) {
|
|
6480
|
+
subscriptions.add(space.stateUpdate.on(ctx, () => pushUpdateTask.trigger()));
|
|
6481
|
+
subscribedSpaceKeySet.add(space.key);
|
|
6482
|
+
}
|
|
6483
|
+
}
|
|
6484
|
+
if (oldSetSize !== subscribedSpaceKeySet.size) {
|
|
6485
|
+
pushUpdateTask.trigger();
|
|
6486
|
+
}
|
|
6487
|
+
};
|
|
6488
|
+
const unsubscribe = (await this._dataSpaceManagerProvider()).updated.on(ctx, subscribeToSpaceAndUpdate);
|
|
6489
|
+
ctx.onDispose(unsubscribe);
|
|
6490
|
+
subscribeToSpaceAndUpdate();
|
|
6491
|
+
});
|
|
6492
|
+
});
|
|
6493
|
+
}
|
|
6494
|
+
};
|
|
6495
|
+
|
|
6496
|
+
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
6497
|
+
import { Event as Event8 } from "@dxos/async";
|
|
6498
|
+
import { Stream as Stream13 } from "@dxos/codec-protobuf";
|
|
6499
|
+
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
6500
|
+
import { getContextFromEntry, log as log20 } from "@dxos/log";
|
|
5954
6501
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5955
6502
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
5956
6503
|
var LoggingServiceImpl = class {
|
|
5957
6504
|
constructor() {
|
|
5958
6505
|
this._logs = new Event8();
|
|
5959
6506
|
this._started = Date.now();
|
|
5960
|
-
this._sessionId =
|
|
6507
|
+
this._sessionId = PublicKey16.random().toHex();
|
|
5961
6508
|
this._logProcessor = (_config, entry2) => {
|
|
5962
6509
|
this._logs.emit(entry2);
|
|
5963
6510
|
};
|
|
5964
6511
|
}
|
|
5965
6512
|
async open() {
|
|
5966
|
-
|
|
6513
|
+
log20.runtimeConfig.processors.push(this._logProcessor);
|
|
5967
6514
|
}
|
|
5968
6515
|
async close() {
|
|
5969
|
-
const index =
|
|
5970
|
-
|
|
6516
|
+
const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
6517
|
+
log20.runtimeConfig.processors.splice(index, 1);
|
|
5971
6518
|
}
|
|
5972
6519
|
async controlMetrics({ reset, record }) {
|
|
5973
6520
|
if (reset) {
|
|
@@ -5993,7 +6540,7 @@ var LoggingServiceImpl = class {
|
|
|
5993
6540
|
stats: numericalValues(events, "duration")
|
|
5994
6541
|
};
|
|
5995
6542
|
};
|
|
5996
|
-
return new
|
|
6543
|
+
return new Stream13(({ next }) => {
|
|
5997
6544
|
const update = () => {
|
|
5998
6545
|
const metrics = {
|
|
5999
6546
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -6015,7 +6562,7 @@ var LoggingServiceImpl = class {
|
|
|
6015
6562
|
});
|
|
6016
6563
|
}
|
|
6017
6564
|
queryLogs(request) {
|
|
6018
|
-
return new
|
|
6565
|
+
return new Stream13(({ ctx, next }) => {
|
|
6019
6566
|
const handler = (entry2) => {
|
|
6020
6567
|
if (LOG_PROCESSING > 0) {
|
|
6021
6568
|
return;
|
|
@@ -6071,14 +6618,14 @@ var shouldLog = (entry2, request) => {
|
|
|
6071
6618
|
var LOG_PROCESSING = 0;
|
|
6072
6619
|
|
|
6073
6620
|
// packages/sdk/client-services/src/packlets/network/network-service.ts
|
|
6074
|
-
import { Stream as
|
|
6621
|
+
import { Stream as Stream14 } from "@dxos/codec-protobuf";
|
|
6075
6622
|
var NetworkServiceImpl = class {
|
|
6076
6623
|
constructor(networkManager, signalManager) {
|
|
6077
6624
|
this.networkManager = networkManager;
|
|
6078
6625
|
this.signalManager = signalManager;
|
|
6079
6626
|
}
|
|
6080
6627
|
queryStatus() {
|
|
6081
|
-
return new
|
|
6628
|
+
return new Stream14(({ next }) => {
|
|
6082
6629
|
const update = () => {
|
|
6083
6630
|
next({
|
|
6084
6631
|
swarm: this.networkManager.connectionState,
|
|
@@ -6104,7 +6651,7 @@ var NetworkServiceImpl = class {
|
|
|
6104
6651
|
};
|
|
6105
6652
|
|
|
6106
6653
|
// packages/sdk/client-services/src/packlets/system/system-service.ts
|
|
6107
|
-
import { Stream as
|
|
6654
|
+
import { Stream as Stream15 } from "@dxos/codec-protobuf";
|
|
6108
6655
|
import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
6109
6656
|
import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
|
|
6110
6657
|
var SystemServiceImpl = class {
|
|
@@ -6140,7 +6687,7 @@ var SystemServiceImpl = class {
|
|
|
6140
6687
|
}
|
|
6141
6688
|
// TODO(burdon): Standardize interval option in stream request?
|
|
6142
6689
|
queryStatus({ interval = 3e3 } = {}) {
|
|
6143
|
-
return new
|
|
6690
|
+
return new Stream15(({ next }) => {
|
|
6144
6691
|
const update = () => {
|
|
6145
6692
|
next({
|
|
6146
6693
|
status: this._getCurrentStatus()
|
|
@@ -6171,7 +6718,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
6171
6718
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6172
6719
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6173
6720
|
}
|
|
6174
|
-
var
|
|
6721
|
+
var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
|
|
6175
6722
|
var ClientServicesHost = class {
|
|
6176
6723
|
constructor({
|
|
6177
6724
|
config,
|
|
@@ -6191,7 +6738,7 @@ var ClientServicesHost = class {
|
|
|
6191
6738
|
this._storage = storage;
|
|
6192
6739
|
this._level = level;
|
|
6193
6740
|
this._callbacks = callbacks;
|
|
6194
|
-
this._runtimeParams = runtimeParams;
|
|
6741
|
+
this._runtimeParams = runtimeParams ?? {};
|
|
6195
6742
|
if (config) {
|
|
6196
6743
|
this.initialize({
|
|
6197
6744
|
config,
|
|
@@ -6204,7 +6751,10 @@ var ClientServicesHost = class {
|
|
|
6204
6751
|
lockKey,
|
|
6205
6752
|
onAcquire: () => {
|
|
6206
6753
|
if (!this._opening) {
|
|
6207
|
-
void this.open(new Context11(
|
|
6754
|
+
void this.open(new Context11(void 0, {
|
|
6755
|
+
F: __dxlog_file24,
|
|
6756
|
+
L: 121
|
|
6757
|
+
}));
|
|
6208
6758
|
}
|
|
6209
6759
|
},
|
|
6210
6760
|
onRelease: () => this.close()
|
|
@@ -6260,24 +6810,24 @@ var ClientServicesHost = class {
|
|
|
6260
6810
|
*/
|
|
6261
6811
|
initialize({ config, ...options }) {
|
|
6262
6812
|
invariant18(!this._open, "service host is open", {
|
|
6263
|
-
F:
|
|
6264
|
-
L:
|
|
6813
|
+
F: __dxlog_file24,
|
|
6814
|
+
L: 187,
|
|
6265
6815
|
S: this,
|
|
6266
6816
|
A: [
|
|
6267
6817
|
"!this._open",
|
|
6268
6818
|
"'service host is open'"
|
|
6269
6819
|
]
|
|
6270
6820
|
});
|
|
6271
|
-
|
|
6272
|
-
F:
|
|
6273
|
-
L:
|
|
6821
|
+
log21("initializing...", void 0, {
|
|
6822
|
+
F: __dxlog_file24,
|
|
6823
|
+
L: 188,
|
|
6274
6824
|
S: this,
|
|
6275
6825
|
C: (f, a) => f(...a)
|
|
6276
6826
|
});
|
|
6277
6827
|
if (config) {
|
|
6278
6828
|
invariant18(!this._config, "config already set", {
|
|
6279
|
-
F:
|
|
6280
|
-
L:
|
|
6829
|
+
F: __dxlog_file24,
|
|
6830
|
+
L: 191,
|
|
6281
6831
|
S: this,
|
|
6282
6832
|
A: [
|
|
6283
6833
|
"!this._config",
|
|
@@ -6290,9 +6840,9 @@ var ClientServicesHost = class {
|
|
|
6290
6840
|
}
|
|
6291
6841
|
}
|
|
6292
6842
|
if (!options.signalManager) {
|
|
6293
|
-
|
|
6294
|
-
F:
|
|
6295
|
-
L:
|
|
6843
|
+
log21.warn("running signaling without telemetry metadata.", void 0, {
|
|
6844
|
+
F: __dxlog_file24,
|
|
6845
|
+
L: 199,
|
|
6296
6846
|
S: this,
|
|
6297
6847
|
C: (f, a) => f(...a)
|
|
6298
6848
|
});
|
|
@@ -6302,8 +6852,8 @@ var ClientServicesHost = class {
|
|
|
6302
6852
|
}), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
|
|
6303
6853
|
this._signalManager = signalManager;
|
|
6304
6854
|
invariant18(!this._networkManager, "network manager already set", {
|
|
6305
|
-
F:
|
|
6306
|
-
L:
|
|
6855
|
+
F: __dxlog_file24,
|
|
6856
|
+
L: 210,
|
|
6307
6857
|
S: this,
|
|
6308
6858
|
A: [
|
|
6309
6859
|
"!this._networkManager",
|
|
@@ -6315,9 +6865,9 @@ var ClientServicesHost = class {
|
|
|
6315
6865
|
transportFactory,
|
|
6316
6866
|
signalManager
|
|
6317
6867
|
});
|
|
6318
|
-
|
|
6319
|
-
F:
|
|
6320
|
-
L:
|
|
6868
|
+
log21("initialized", void 0, {
|
|
6869
|
+
F: __dxlog_file24,
|
|
6870
|
+
L: 217,
|
|
6321
6871
|
S: this,
|
|
6322
6872
|
C: (f, a) => f(...a)
|
|
6323
6873
|
});
|
|
@@ -6326,18 +6876,18 @@ var ClientServicesHost = class {
|
|
|
6326
6876
|
if (this._open) {
|
|
6327
6877
|
return;
|
|
6328
6878
|
}
|
|
6329
|
-
const traceId =
|
|
6330
|
-
|
|
6879
|
+
const traceId = PublicKey17.random().toHex();
|
|
6880
|
+
log21.trace("dxos.client-services.host.open", trace10.begin({
|
|
6331
6881
|
id: traceId
|
|
6332
6882
|
}), {
|
|
6333
|
-
F:
|
|
6334
|
-
L:
|
|
6883
|
+
F: __dxlog_file24,
|
|
6884
|
+
L: 228,
|
|
6335
6885
|
S: this,
|
|
6336
6886
|
C: (f, a) => f(...a)
|
|
6337
6887
|
});
|
|
6338
6888
|
invariant18(this._config, "config not set", {
|
|
6339
|
-
F:
|
|
6340
|
-
L:
|
|
6889
|
+
F: __dxlog_file24,
|
|
6890
|
+
L: 230,
|
|
6341
6891
|
S: this,
|
|
6342
6892
|
A: [
|
|
6343
6893
|
"this._config",
|
|
@@ -6345,8 +6895,8 @@ var ClientServicesHost = class {
|
|
|
6345
6895
|
]
|
|
6346
6896
|
});
|
|
6347
6897
|
invariant18(this._storage, "storage not set", {
|
|
6348
|
-
F:
|
|
6349
|
-
L:
|
|
6898
|
+
F: __dxlog_file24,
|
|
6899
|
+
L: 231,
|
|
6350
6900
|
S: this,
|
|
6351
6901
|
A: [
|
|
6352
6902
|
"this._storage",
|
|
@@ -6354,8 +6904,8 @@ var ClientServicesHost = class {
|
|
|
6354
6904
|
]
|
|
6355
6905
|
});
|
|
6356
6906
|
invariant18(this._signalManager, "signal manager not set", {
|
|
6357
|
-
F:
|
|
6358
|
-
L:
|
|
6907
|
+
F: __dxlog_file24,
|
|
6908
|
+
L: 232,
|
|
6359
6909
|
S: this,
|
|
6360
6910
|
A: [
|
|
6361
6911
|
"this._signalManager",
|
|
@@ -6363,8 +6913,8 @@ var ClientServicesHost = class {
|
|
|
6363
6913
|
]
|
|
6364
6914
|
});
|
|
6365
6915
|
invariant18(this._networkManager, "network manager not set", {
|
|
6366
|
-
F:
|
|
6367
|
-
L:
|
|
6916
|
+
F: __dxlog_file24,
|
|
6917
|
+
L: 233,
|
|
6368
6918
|
S: this,
|
|
6369
6919
|
A: [
|
|
6370
6920
|
"this._networkManager",
|
|
@@ -6372,11 +6922,11 @@ var ClientServicesHost = class {
|
|
|
6372
6922
|
]
|
|
6373
6923
|
});
|
|
6374
6924
|
this._opening = true;
|
|
6375
|
-
|
|
6925
|
+
log21("opening...", {
|
|
6376
6926
|
lockKey: this._resourceLock?.lockKey
|
|
6377
6927
|
}, {
|
|
6378
|
-
F:
|
|
6379
|
-
L:
|
|
6928
|
+
F: __dxlog_file24,
|
|
6929
|
+
L: 236,
|
|
6380
6930
|
S: this,
|
|
6381
6931
|
C: (f, a) => f(...a)
|
|
6382
6932
|
});
|
|
@@ -6387,15 +6937,18 @@ var ClientServicesHost = class {
|
|
|
6387
6937
|
await this._level.open();
|
|
6388
6938
|
await this._loggingService.open();
|
|
6389
6939
|
this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
|
|
6940
|
+
const dataSpaceManagerProvider = async () => {
|
|
6941
|
+
await this._serviceContext.initialized.wait();
|
|
6942
|
+
return this._serviceContext.dataSpaceManager;
|
|
6943
|
+
};
|
|
6944
|
+
const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
|
|
6390
6945
|
this._serviceRegistry.setServices({
|
|
6391
6946
|
SystemService: this._systemService,
|
|
6392
|
-
IdentityService:
|
|
6947
|
+
IdentityService: identityService,
|
|
6948
|
+
ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
|
|
6393
6949
|
InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
|
|
6394
6950
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
6395
|
-
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager,
|
|
6396
|
-
await this._serviceContext.initialized.wait();
|
|
6397
|
-
return this._serviceContext.dataSpaceManager;
|
|
6398
|
-
}),
|
|
6951
|
+
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
|
|
6399
6952
|
DataService: this._serviceContext.echoHost.dataService,
|
|
6400
6953
|
QueryService: this._serviceContext.echoHost.queryService,
|
|
6401
6954
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
@@ -6409,6 +6962,7 @@ var ClientServicesHost = class {
|
|
|
6409
6962
|
})
|
|
6410
6963
|
});
|
|
6411
6964
|
await this._serviceContext.open(ctx);
|
|
6965
|
+
await identityService.open();
|
|
6412
6966
|
const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
|
|
6413
6967
|
if (devtoolsProxy) {
|
|
6414
6968
|
this._devtoolsProxy = new WebsocketRpcClient({
|
|
@@ -6424,19 +6978,19 @@ var ClientServicesHost = class {
|
|
|
6424
6978
|
this._open = true;
|
|
6425
6979
|
this._statusUpdate.emit();
|
|
6426
6980
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
6427
|
-
|
|
6981
|
+
log21("opened", {
|
|
6428
6982
|
deviceKey
|
|
6429
6983
|
}, {
|
|
6430
|
-
F:
|
|
6431
|
-
L:
|
|
6984
|
+
F: __dxlog_file24,
|
|
6985
|
+
L: 322,
|
|
6432
6986
|
S: this,
|
|
6433
6987
|
C: (f, a) => f(...a)
|
|
6434
6988
|
});
|
|
6435
|
-
|
|
6989
|
+
log21.trace("dxos.client-services.host.open", trace10.end({
|
|
6436
6990
|
id: traceId
|
|
6437
6991
|
}), {
|
|
6438
|
-
F:
|
|
6439
|
-
L:
|
|
6992
|
+
F: __dxlog_file24,
|
|
6993
|
+
L: 323,
|
|
6440
6994
|
S: this,
|
|
6441
6995
|
C: (f, a) => f(...a)
|
|
6442
6996
|
});
|
|
@@ -6446,11 +7000,11 @@ var ClientServicesHost = class {
|
|
|
6446
7000
|
return;
|
|
6447
7001
|
}
|
|
6448
7002
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
6449
|
-
|
|
7003
|
+
log21("closing...", {
|
|
6450
7004
|
deviceKey
|
|
6451
7005
|
}, {
|
|
6452
|
-
F:
|
|
6453
|
-
L:
|
|
7006
|
+
F: __dxlog_file24,
|
|
7007
|
+
L: 334,
|
|
6454
7008
|
S: this,
|
|
6455
7009
|
C: (f, a) => f(...a)
|
|
6456
7010
|
});
|
|
@@ -6464,44 +7018,44 @@ var ClientServicesHost = class {
|
|
|
6464
7018
|
await this._level?.close();
|
|
6465
7019
|
this._open = false;
|
|
6466
7020
|
this._statusUpdate.emit();
|
|
6467
|
-
|
|
7021
|
+
log21("closed", {
|
|
6468
7022
|
deviceKey
|
|
6469
7023
|
}, {
|
|
6470
|
-
F:
|
|
6471
|
-
L:
|
|
7024
|
+
F: __dxlog_file24,
|
|
7025
|
+
L: 343,
|
|
6472
7026
|
S: this,
|
|
6473
7027
|
C: (f, a) => f(...a)
|
|
6474
7028
|
});
|
|
6475
7029
|
}
|
|
6476
7030
|
async reset() {
|
|
6477
|
-
const traceId =
|
|
6478
|
-
|
|
7031
|
+
const traceId = PublicKey17.random().toHex();
|
|
7032
|
+
log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
|
|
6479
7033
|
id: traceId
|
|
6480
7034
|
}), {
|
|
6481
|
-
F:
|
|
6482
|
-
L:
|
|
7035
|
+
F: __dxlog_file24,
|
|
7036
|
+
L: 348,
|
|
6483
7037
|
S: this,
|
|
6484
7038
|
C: (f, a) => f(...a)
|
|
6485
7039
|
});
|
|
6486
|
-
|
|
6487
|
-
F:
|
|
6488
|
-
L:
|
|
7040
|
+
log21.info("resetting...", void 0, {
|
|
7041
|
+
F: __dxlog_file24,
|
|
7042
|
+
L: 350,
|
|
6489
7043
|
S: this,
|
|
6490
7044
|
C: (f, a) => f(...a)
|
|
6491
7045
|
});
|
|
6492
7046
|
await this._serviceContext?.close();
|
|
6493
7047
|
await this._storage.reset();
|
|
6494
|
-
|
|
6495
|
-
F:
|
|
6496
|
-
L:
|
|
7048
|
+
log21.info("reset", void 0, {
|
|
7049
|
+
F: __dxlog_file24,
|
|
7050
|
+
L: 353,
|
|
6497
7051
|
S: this,
|
|
6498
7052
|
C: (f, a) => f(...a)
|
|
6499
7053
|
});
|
|
6500
|
-
|
|
7054
|
+
log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
|
|
6501
7055
|
id: traceId
|
|
6502
7056
|
}), {
|
|
6503
|
-
F:
|
|
6504
|
-
L:
|
|
7057
|
+
F: __dxlog_file24,
|
|
7058
|
+
L: 354,
|
|
6505
7059
|
S: this,
|
|
6506
7060
|
C: (f, a) => f(...a)
|
|
6507
7061
|
});
|
|
@@ -6510,38 +7064,6 @@ var ClientServicesHost = class {
|
|
|
6510
7064
|
async _createIdentity(params) {
|
|
6511
7065
|
const identity = await this._serviceContext.createIdentity(params);
|
|
6512
7066
|
await this._serviceContext.initialized.wait();
|
|
6513
|
-
const space = await this._serviceContext.dataSpaceManager.createSpace();
|
|
6514
|
-
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
6515
|
-
invariant18(automergeIndex, void 0, {
|
|
6516
|
-
F: __dxlog_file21,
|
|
6517
|
-
L: 358,
|
|
6518
|
-
S: this,
|
|
6519
|
-
A: [
|
|
6520
|
-
"automergeIndex",
|
|
6521
|
-
""
|
|
6522
|
-
]
|
|
6523
|
-
});
|
|
6524
|
-
const document = this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
|
|
6525
|
-
await document.whenReady();
|
|
6526
|
-
const properties = {
|
|
6527
|
-
system: {
|
|
6528
|
-
type: encodeReference(getTypeReference(PropertiesType))
|
|
6529
|
-
},
|
|
6530
|
-
data: {
|
|
6531
|
-
[defaultKey]: identity.identityKey.toHex()
|
|
6532
|
-
},
|
|
6533
|
-
meta: {
|
|
6534
|
-
keys: []
|
|
6535
|
-
}
|
|
6536
|
-
};
|
|
6537
|
-
const propertiesId = PublicKey16.random().toHex();
|
|
6538
|
-
document.change((doc) => {
|
|
6539
|
-
assignDeep2(doc, [
|
|
6540
|
-
"objects",
|
|
6541
|
-
propertiesId
|
|
6542
|
-
], properties);
|
|
6543
|
-
});
|
|
6544
|
-
await this._serviceContext.echoHost.flush();
|
|
6545
7067
|
return identity;
|
|
6546
7068
|
}
|
|
6547
7069
|
};
|
|
@@ -6591,7 +7113,6 @@ export {
|
|
|
6591
7113
|
SpaceInvitationProtocol,
|
|
6592
7114
|
InvitationsManager,
|
|
6593
7115
|
DataSpace,
|
|
6594
|
-
findPropertiesObject,
|
|
6595
7116
|
DataSpaceManager,
|
|
6596
7117
|
SpacesServiceImpl,
|
|
6597
7118
|
ServiceContext,
|
|
@@ -6604,4 +7125,4 @@ export {
|
|
|
6604
7125
|
ClientServicesProviderResource,
|
|
6605
7126
|
DiagnosticsCollector
|
|
6606
7127
|
};
|
|
6607
|
-
//# sourceMappingURL=chunk-
|
|
7128
|
+
//# sourceMappingURL=chunk-M35K3NOZ.mjs.map
|