@dxos/client-services 0.5.9-main.ea1d25b → 0.5.9-main.eacfffa
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-LKSDZ2AB.mjs → chunk-J4DDMC6A.mjs} +1214 -844
- package/dist/lib/browser/chunk-J4DDMC6A.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-FBXXJHAL.cjs → chunk-6HFQ2SQ5.cjs} +1493 -1130
- package/dist/lib/node/chunk-6HFQ2SQ5.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/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/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 +5 -3
- 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 +2 -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/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/services/service-context.ts +1 -4
- package/src/packlets/services/service-host.ts +13 -40
- 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 +81 -31
- package/src/packlets/spaces/data-space.ts +85 -152
- package/src/packlets/spaces/epoch-migrations.ts +135 -0
- package/src/packlets/spaces/spaces-service.ts +16 -4
- package/src/packlets/testing/test-builder.ts +12 -10
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-LKSDZ2AB.mjs.map +0 -7
- package/dist/lib/node/chunk-FBXXJHAL.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.eacfffa";
|
|
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 { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
|
|
3086
|
+
import { createAdmissionCredentials, 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;
|
|
@@ -2940,7 +3125,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2940
3125
|
}
|
|
2941
3126
|
async admit(invitation, request, guestProfile) {
|
|
2942
3127
|
invariant10(this._spaceKey, void 0, {
|
|
2943
|
-
F:
|
|
3128
|
+
F: __dxlog_file14,
|
|
2944
3129
|
L: 76,
|
|
2945
3130
|
S: this,
|
|
2946
3131
|
A: [
|
|
@@ -2950,7 +3135,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2950
3135
|
});
|
|
2951
3136
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2952
3137
|
invariant10(space, void 0, {
|
|
2953
|
-
F:
|
|
3138
|
+
F: __dxlog_file14,
|
|
2954
3139
|
L: 78,
|
|
2955
3140
|
S: this,
|
|
2956
3141
|
A: [
|
|
@@ -2959,7 +3144,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2959
3144
|
]
|
|
2960
3145
|
});
|
|
2961
3146
|
invariant10(request.space, void 0, {
|
|
2962
|
-
F:
|
|
3147
|
+
F: __dxlog_file14,
|
|
2963
3148
|
L: 80,
|
|
2964
3149
|
S: this,
|
|
2965
3150
|
A: [
|
|
@@ -2971,18 +3156,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2971
3156
|
if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
|
|
2972
3157
|
throw new AlreadyJoinedError2();
|
|
2973
3158
|
}
|
|
2974
|
-
|
|
3159
|
+
log11("writing guest credentials", {
|
|
2975
3160
|
host: this._signingContext.deviceKey,
|
|
2976
3161
|
guest: deviceKey
|
|
2977
3162
|
}, {
|
|
2978
|
-
F:
|
|
3163
|
+
F: __dxlog_file14,
|
|
2979
3164
|
L: 87,
|
|
2980
3165
|
S: this,
|
|
2981
3166
|
C: (f, a) => f(...a)
|
|
2982
3167
|
});
|
|
2983
3168
|
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
3169
|
invariant10(credentials[0].credential, void 0, {
|
|
2985
|
-
F:
|
|
3170
|
+
F: __dxlog_file14,
|
|
2986
3171
|
L: 101,
|
|
2987
3172
|
S: this,
|
|
2988
3173
|
A: [
|
|
@@ -2991,8 +3176,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2991
3176
|
]
|
|
2992
3177
|
});
|
|
2993
3178
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2994
|
-
invariant10(
|
|
2995
|
-
F:
|
|
3179
|
+
invariant10(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
3180
|
+
F: __dxlog_file14,
|
|
2996
3181
|
L: 103,
|
|
2997
3182
|
S: this,
|
|
2998
3183
|
A: [
|
|
@@ -3010,7 +3195,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3010
3195
|
}
|
|
3011
3196
|
async delegate(invitation) {
|
|
3012
3197
|
invariant10(this._spaceKey, void 0, {
|
|
3013
|
-
F:
|
|
3198
|
+
F: __dxlog_file14,
|
|
3014
3199
|
L: 116,
|
|
3015
3200
|
S: this,
|
|
3016
3201
|
A: [
|
|
@@ -3020,7 +3205,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3020
3205
|
});
|
|
3021
3206
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
3022
3207
|
invariant10(space, void 0, {
|
|
3023
|
-
F:
|
|
3208
|
+
F: __dxlog_file14,
|
|
3024
3209
|
L: 118,
|
|
3025
3210
|
S: this,
|
|
3026
3211
|
A: [
|
|
@@ -3030,7 +3215,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3030
3215
|
});
|
|
3031
3216
|
if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
|
|
3032
3217
|
invariant10(invitation.guestKeypair?.publicKey, void 0, {
|
|
3033
|
-
F:
|
|
3218
|
+
F: __dxlog_file14,
|
|
3034
3219
|
L: 120,
|
|
3035
3220
|
S: this,
|
|
3036
3221
|
A: [
|
|
@@ -3039,11 +3224,11 @@ var SpaceInvitationProtocol = class {
|
|
|
3039
3224
|
]
|
|
3040
3225
|
});
|
|
3041
3226
|
}
|
|
3042
|
-
|
|
3227
|
+
log11("writing delegate space invitation", {
|
|
3043
3228
|
host: this._signingContext.deviceKey,
|
|
3044
3229
|
id: invitation.invitationId
|
|
3045
3230
|
}, {
|
|
3046
|
-
F:
|
|
3231
|
+
F: __dxlog_file14,
|
|
3047
3232
|
L: 123,
|
|
3048
3233
|
S: this,
|
|
3049
3234
|
C: (f, a) => f(...a)
|
|
@@ -3058,7 +3243,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3058
3243
|
guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
|
|
3059
3244
|
});
|
|
3060
3245
|
invariant10(credential.credential, void 0, {
|
|
3061
|
-
F:
|
|
3246
|
+
F: __dxlog_file14,
|
|
3062
3247
|
L: 143,
|
|
3063
3248
|
S: this,
|
|
3064
3249
|
A: [
|
|
@@ -3073,7 +3258,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3073
3258
|
}
|
|
3074
3259
|
async cancelDelegation(invitation) {
|
|
3075
3260
|
invariant10(this._spaceKey, void 0, {
|
|
3076
|
-
F:
|
|
3261
|
+
F: __dxlog_file14,
|
|
3077
3262
|
L: 149,
|
|
3078
3263
|
S: this,
|
|
3079
3264
|
A: [
|
|
@@ -3082,7 +3267,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3082
3267
|
]
|
|
3083
3268
|
});
|
|
3084
3269
|
invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
|
|
3085
|
-
F:
|
|
3270
|
+
F: __dxlog_file14,
|
|
3086
3271
|
L: 150,
|
|
3087
3272
|
S: this,
|
|
3088
3273
|
A: [
|
|
@@ -3092,7 +3277,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3092
3277
|
});
|
|
3093
3278
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
3094
3279
|
invariant10(space, void 0, {
|
|
3095
|
-
F:
|
|
3280
|
+
F: __dxlog_file14,
|
|
3096
3281
|
L: 152,
|
|
3097
3282
|
S: this,
|
|
3098
3283
|
A: [
|
|
@@ -3100,18 +3285,18 @@ var SpaceInvitationProtocol = class {
|
|
|
3100
3285
|
""
|
|
3101
3286
|
]
|
|
3102
3287
|
});
|
|
3103
|
-
|
|
3288
|
+
log11("cancelling delegated space invitation", {
|
|
3104
3289
|
host: this._signingContext.deviceKey,
|
|
3105
3290
|
id: invitation.invitationId
|
|
3106
3291
|
}, {
|
|
3107
|
-
F:
|
|
3292
|
+
F: __dxlog_file14,
|
|
3108
3293
|
L: 154,
|
|
3109
3294
|
S: this,
|
|
3110
3295
|
C: (f, a) => f(...a)
|
|
3111
3296
|
});
|
|
3112
3297
|
const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
|
|
3113
3298
|
invariant10(credential.credential, void 0, {
|
|
3114
|
-
F:
|
|
3299
|
+
F: __dxlog_file14,
|
|
3115
3300
|
L: 161,
|
|
3116
3301
|
S: this,
|
|
3117
3302
|
A: [
|
|
@@ -3150,7 +3335,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3150
3335
|
}
|
|
3151
3336
|
async accept(response) {
|
|
3152
3337
|
invariant10(response.space, void 0, {
|
|
3153
|
-
F:
|
|
3338
|
+
F: __dxlog_file14,
|
|
3154
3339
|
L: 196,
|
|
3155
3340
|
S: this,
|
|
3156
3341
|
A: [
|
|
@@ -3159,9 +3344,9 @@ var SpaceInvitationProtocol = class {
|
|
|
3159
3344
|
]
|
|
3160
3345
|
});
|
|
3161
3346
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
3162
|
-
const assertion =
|
|
3347
|
+
const assertion = getCredentialAssertion2(credential);
|
|
3163
3348
|
invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
3164
|
-
F:
|
|
3349
|
+
F: __dxlog_file14,
|
|
3165
3350
|
L: 199,
|
|
3166
3351
|
S: this,
|
|
3167
3352
|
A: [
|
|
@@ -3170,7 +3355,7 @@ var SpaceInvitationProtocol = class {
|
|
|
3170
3355
|
]
|
|
3171
3356
|
});
|
|
3172
3357
|
invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
3173
|
-
F:
|
|
3358
|
+
F: __dxlog_file14,
|
|
3174
3359
|
L: 200,
|
|
3175
3360
|
S: this,
|
|
3176
3361
|
A: [
|
|
@@ -3195,17 +3380,17 @@ var SpaceInvitationProtocol = class {
|
|
|
3195
3380
|
};
|
|
3196
3381
|
|
|
3197
3382
|
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
3198
|
-
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as
|
|
3383
|
+
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger6 } from "@dxos/async";
|
|
3199
3384
|
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3200
3385
|
import { Context as Context6 } from "@dxos/context";
|
|
3201
3386
|
import { generatePasscode } from "@dxos/credentials";
|
|
3202
3387
|
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
3203
3388
|
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3204
3389
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
3205
|
-
import { log as
|
|
3390
|
+
import { log as log12 } from "@dxos/log";
|
|
3206
3391
|
import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3207
3392
|
import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3208
|
-
var
|
|
3393
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
3209
3394
|
var InvitationsManager = class {
|
|
3210
3395
|
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
3211
3396
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -3247,8 +3432,8 @@ var InvitationsManager = class {
|
|
|
3247
3432
|
try {
|
|
3248
3433
|
await this._persistIfRequired(handler, stream, invitation);
|
|
3249
3434
|
} catch (err) {
|
|
3250
|
-
|
|
3251
|
-
F:
|
|
3435
|
+
log12.catch(err, void 0, {
|
|
3436
|
+
F: __dxlog_file15,
|
|
3252
3437
|
L: 82,
|
|
3253
3438
|
S: this,
|
|
3254
3439
|
C: (f, a) => f(...a)
|
|
@@ -3271,7 +3456,7 @@ var InvitationsManager = class {
|
|
|
3271
3456
|
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
3272
3457
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
3273
3458
|
invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
3274
|
-
F:
|
|
3459
|
+
F: __dxlog_file15,
|
|
3275
3460
|
L: 103,
|
|
3276
3461
|
S: this,
|
|
3277
3462
|
A: [
|
|
@@ -3289,8 +3474,8 @@ var InvitationsManager = class {
|
|
|
3289
3474
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
3290
3475
|
};
|
|
3291
3476
|
} catch (err) {
|
|
3292
|
-
|
|
3293
|
-
F:
|
|
3477
|
+
log12.catch(err, void 0, {
|
|
3478
|
+
F: __dxlog_file15,
|
|
3294
3479
|
L: 110,
|
|
3295
3480
|
S: this,
|
|
3296
3481
|
C: (f, a) => f(...a)
|
|
@@ -3321,14 +3506,14 @@ var InvitationsManager = class {
|
|
|
3321
3506
|
return invitation;
|
|
3322
3507
|
}
|
|
3323
3508
|
async authenticate({ invitationId, authCode }) {
|
|
3324
|
-
|
|
3325
|
-
F:
|
|
3509
|
+
log12("authenticating...", void 0, {
|
|
3510
|
+
F: __dxlog_file15,
|
|
3326
3511
|
L: 140,
|
|
3327
3512
|
S: this,
|
|
3328
3513
|
C: (f, a) => f(...a)
|
|
3329
3514
|
});
|
|
3330
3515
|
invariant11(invitationId, void 0, {
|
|
3331
|
-
F:
|
|
3516
|
+
F: __dxlog_file15,
|
|
3332
3517
|
L: 141,
|
|
3333
3518
|
S: this,
|
|
3334
3519
|
A: [
|
|
@@ -3338,10 +3523,10 @@ var InvitationsManager = class {
|
|
|
3338
3523
|
});
|
|
3339
3524
|
const observable = this._acceptInvitations.get(invitationId);
|
|
3340
3525
|
if (!observable) {
|
|
3341
|
-
|
|
3526
|
+
log12.warn("invalid invitation", {
|
|
3342
3527
|
invitationId
|
|
3343
3528
|
}, {
|
|
3344
|
-
F:
|
|
3529
|
+
F: __dxlog_file15,
|
|
3345
3530
|
L: 144,
|
|
3346
3531
|
S: this,
|
|
3347
3532
|
C: (f, a) => f(...a)
|
|
@@ -3351,16 +3536,16 @@ var InvitationsManager = class {
|
|
|
3351
3536
|
}
|
|
3352
3537
|
}
|
|
3353
3538
|
async cancelInvitation({ invitationId }) {
|
|
3354
|
-
|
|
3539
|
+
log12("cancelInvitation...", {
|
|
3355
3540
|
invitationId
|
|
3356
3541
|
}, {
|
|
3357
|
-
F:
|
|
3542
|
+
F: __dxlog_file15,
|
|
3358
3543
|
L: 151,
|
|
3359
3544
|
S: this,
|
|
3360
3545
|
C: (f, a) => f(...a)
|
|
3361
3546
|
});
|
|
3362
3547
|
invariant11(invitationId, void 0, {
|
|
3363
|
-
F:
|
|
3548
|
+
F: __dxlog_file15,
|
|
3364
3549
|
L: 152,
|
|
3365
3550
|
S: this,
|
|
3366
3551
|
A: [
|
|
@@ -3434,12 +3619,15 @@ var InvitationsManager = class {
|
|
|
3434
3619
|
stream.error(err);
|
|
3435
3620
|
void ctx.dispose();
|
|
3436
3621
|
}
|
|
3622
|
+
}, {
|
|
3623
|
+
F: __dxlog_file15,
|
|
3624
|
+
L: 234
|
|
3437
3625
|
});
|
|
3438
3626
|
ctx.onDispose(() => {
|
|
3439
|
-
|
|
3627
|
+
log12("complete", {
|
|
3440
3628
|
...handler.toJSON()
|
|
3441
3629
|
}, {
|
|
3442
|
-
F:
|
|
3630
|
+
F: __dxlog_file15,
|
|
3443
3631
|
L: 241,
|
|
3444
3632
|
S: this,
|
|
3445
3633
|
C: (f, a) => f(...a)
|
|
@@ -3464,15 +3652,15 @@ var InvitationsManager = class {
|
|
|
3464
3652
|
};
|
|
3465
3653
|
}
|
|
3466
3654
|
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3467
|
-
const otpEnteredTrigger = new
|
|
3655
|
+
const otpEnteredTrigger = new Trigger6();
|
|
3468
3656
|
const stream = new PushStream();
|
|
3469
3657
|
const ctx = new Context6({
|
|
3470
3658
|
onError: (err) => {
|
|
3471
3659
|
if (err instanceof TimeoutError2) {
|
|
3472
|
-
|
|
3660
|
+
log12("timeout", {
|
|
3473
3661
|
...handler.toJSON()
|
|
3474
3662
|
}, {
|
|
3475
|
-
F:
|
|
3663
|
+
F: __dxlog_file15,
|
|
3476
3664
|
L: 261,
|
|
3477
3665
|
S: this,
|
|
3478
3666
|
C: (f, a) => f(...a)
|
|
@@ -3482,8 +3670,8 @@ var InvitationsManager = class {
|
|
|
3482
3670
|
state: Invitation6.State.TIMEOUT
|
|
3483
3671
|
});
|
|
3484
3672
|
} else {
|
|
3485
|
-
|
|
3486
|
-
F:
|
|
3673
|
+
log12.warn("auth failed", err, {
|
|
3674
|
+
F: __dxlog_file15,
|
|
3487
3675
|
L: 264,
|
|
3488
3676
|
S: this,
|
|
3489
3677
|
C: (f, a) => f(...a)
|
|
@@ -3495,12 +3683,15 @@ var InvitationsManager = class {
|
|
|
3495
3683
|
}
|
|
3496
3684
|
void ctx.dispose();
|
|
3497
3685
|
}
|
|
3686
|
+
}, {
|
|
3687
|
+
F: __dxlog_file15,
|
|
3688
|
+
L: 258
|
|
3498
3689
|
});
|
|
3499
3690
|
ctx.onDispose(() => {
|
|
3500
|
-
|
|
3691
|
+
log12("complete", {
|
|
3501
3692
|
...handler.toJSON()
|
|
3502
3693
|
}, {
|
|
3503
|
-
F:
|
|
3694
|
+
F: __dxlog_file15,
|
|
3504
3695
|
L: 271,
|
|
3505
3696
|
S: this,
|
|
3506
3697
|
C: (f, a) => f(...a)
|
|
@@ -3544,8 +3735,8 @@ var InvitationsManager = class {
|
|
|
3544
3735
|
try {
|
|
3545
3736
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
3546
3737
|
} catch (err) {
|
|
3547
|
-
|
|
3548
|
-
F:
|
|
3738
|
+
log12.catch(err, void 0, {
|
|
3739
|
+
F: __dxlog_file15,
|
|
3549
3740
|
L: 307,
|
|
3550
3741
|
S: this,
|
|
3551
3742
|
C: (f, a) => f(...a)
|
|
@@ -3560,33 +3751,40 @@ var InvitationsManager = class {
|
|
|
3560
3751
|
};
|
|
3561
3752
|
|
|
3562
3753
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
3563
|
-
import { Event as Event6,
|
|
3754
|
+
import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
|
|
3564
3755
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3565
|
-
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as
|
|
3756
|
+
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
|
|
3566
3757
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
3567
|
-
import {
|
|
3568
|
-
import {
|
|
3569
|
-
import { failedInvariant
|
|
3758
|
+
import { createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3759
|
+
import { SpaceDocVersion } from "@dxos/echo-protocol";
|
|
3760
|
+
import { failedInvariant } from "@dxos/invariant";
|
|
3570
3761
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3571
|
-
import { log as
|
|
3762
|
+
import { log as log15 } from "@dxos/log";
|
|
3572
3763
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
3573
|
-
import {
|
|
3764
|
+
import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3574
3765
|
import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3575
|
-
import { Timeframe as
|
|
3766
|
+
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
3576
3767
|
import { trace as trace6 } from "@dxos/tracing";
|
|
3577
|
-
import { ComplexSet as ComplexSet5
|
|
3768
|
+
import { ComplexSet as ComplexSet5 } from "@dxos/util";
|
|
3578
3769
|
|
|
3579
3770
|
// packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
|
|
3580
3771
|
import { Event as Event4 } from "@dxos/async";
|
|
3772
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
3581
3773
|
import { checkCredentialType } from "@dxos/credentials";
|
|
3582
|
-
var AutomergeSpaceState = class {
|
|
3774
|
+
var AutomergeSpaceState = class extends Resource2 {
|
|
3583
3775
|
constructor(_onNewRoot) {
|
|
3776
|
+
super();
|
|
3584
3777
|
this._onNewRoot = _onNewRoot;
|
|
3585
3778
|
this.rootUrl = void 0;
|
|
3586
3779
|
this.lastEpoch = void 0;
|
|
3587
3780
|
this.onNewEpoch = new Event4();
|
|
3588
3781
|
this._isProcessingRootDocs = false;
|
|
3589
3782
|
}
|
|
3783
|
+
async _open(ctx) {
|
|
3784
|
+
}
|
|
3785
|
+
async _close(ctx) {
|
|
3786
|
+
this._isProcessingRootDocs = false;
|
|
3787
|
+
}
|
|
3590
3788
|
async processCredential(credential) {
|
|
3591
3789
|
if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
|
|
3592
3790
|
return;
|
|
@@ -3614,23 +3812,172 @@ var AutomergeSpaceState = class {
|
|
|
3614
3812
|
}
|
|
3615
3813
|
};
|
|
3616
3814
|
|
|
3815
|
+
// packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
|
|
3816
|
+
import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
|
|
3817
|
+
import { next as am } from "@dxos/automerge/automerge";
|
|
3818
|
+
import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
|
|
3819
|
+
import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
|
|
3820
|
+
import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
|
|
3821
|
+
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
3822
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3823
|
+
import { log as log13 } from "@dxos/log";
|
|
3824
|
+
import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
3825
|
+
import { assignDeep } from "@dxos/util";
|
|
3826
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
|
|
3827
|
+
var runEpochMigration = async (ctx, context) => {
|
|
3828
|
+
switch (context.migration) {
|
|
3829
|
+
case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
|
|
3830
|
+
const document = context.repo.create();
|
|
3831
|
+
await context.repo.flush();
|
|
3832
|
+
return {
|
|
3833
|
+
newRoot: document.url
|
|
3834
|
+
};
|
|
3835
|
+
}
|
|
3836
|
+
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
|
|
3837
|
+
if (!context.currentRoot) {
|
|
3838
|
+
throw new Error("Space does not have an automerge root");
|
|
3839
|
+
}
|
|
3840
|
+
const rootHandle = context.repo.find(context.currentRoot);
|
|
3841
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3842
|
+
const newRoot = context.repo.create(rootHandle.docSync());
|
|
3843
|
+
await context.repo.flush();
|
|
3844
|
+
return {
|
|
3845
|
+
newRoot: newRoot.url
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
|
|
3849
|
+
log13.info("Fragmenting", void 0, {
|
|
3850
|
+
F: __dxlog_file16,
|
|
3851
|
+
L: 63,
|
|
3852
|
+
S: void 0,
|
|
3853
|
+
C: (f, a) => f(...a)
|
|
3854
|
+
});
|
|
3855
|
+
const currentRootUrl = context.currentRoot;
|
|
3856
|
+
const rootHandle = context.repo.find(currentRootUrl);
|
|
3857
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3858
|
+
const objects = Object.entries(rootHandle.docSync().objects);
|
|
3859
|
+
const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
|
|
3860
|
+
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
3861
|
+
invariant12(properties, "Properties not found", {
|
|
3862
|
+
F: __dxlog_file16,
|
|
3863
|
+
L: 73,
|
|
3864
|
+
S: void 0,
|
|
3865
|
+
A: [
|
|
3866
|
+
"properties",
|
|
3867
|
+
"'Properties not found'"
|
|
3868
|
+
]
|
|
3869
|
+
});
|
|
3870
|
+
const newSpaceDoc = {
|
|
3871
|
+
...rootHandle.docSync(),
|
|
3872
|
+
objects: Object.fromEntries([
|
|
3873
|
+
properties
|
|
3874
|
+
])
|
|
3875
|
+
};
|
|
3876
|
+
const newRoot = context.repo.create(newSpaceDoc);
|
|
3877
|
+
invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
3878
|
+
F: __dxlog_file16,
|
|
3879
|
+
L: 78,
|
|
3880
|
+
S: void 0,
|
|
3881
|
+
A: [
|
|
3882
|
+
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
3883
|
+
""
|
|
3884
|
+
]
|
|
3885
|
+
});
|
|
3886
|
+
const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
|
|
3887
|
+
await docLoader.loadSpaceRootDocHandle(ctx, {
|
|
3888
|
+
rootUrl: newRoot.url
|
|
3889
|
+
});
|
|
3890
|
+
otherObjects.forEach(([key, value]) => {
|
|
3891
|
+
const handle = docLoader.createDocumentForObject(key);
|
|
3892
|
+
handle.change((doc) => {
|
|
3893
|
+
assignDeep(doc, [
|
|
3894
|
+
"objects",
|
|
3895
|
+
key
|
|
3896
|
+
], value);
|
|
3897
|
+
});
|
|
3898
|
+
});
|
|
3899
|
+
await context.repo.flush();
|
|
3900
|
+
return {
|
|
3901
|
+
newRoot: newRoot.url
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
|
|
3905
|
+
const currentRootUrl = context.currentRoot;
|
|
3906
|
+
const rootHandle = context.repo.find(currentRootUrl);
|
|
3907
|
+
await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
3908
|
+
invariant12(rootHandle.docSync(), "Root doc not found", {
|
|
3909
|
+
F: __dxlog_file16,
|
|
3910
|
+
L: 100,
|
|
3911
|
+
S: void 0,
|
|
3912
|
+
A: [
|
|
3913
|
+
"rootHandle.docSync()",
|
|
3914
|
+
"'Root doc not found'"
|
|
3915
|
+
]
|
|
3916
|
+
});
|
|
3917
|
+
const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
|
|
3918
|
+
for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
|
|
3919
|
+
const handle = context.repo.find(url);
|
|
3920
|
+
await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
|
|
3921
|
+
invariant12(handle.docSync(), "Doc not found", {
|
|
3922
|
+
F: __dxlog_file16,
|
|
3923
|
+
L: 107,
|
|
3924
|
+
S: void 0,
|
|
3925
|
+
A: [
|
|
3926
|
+
"handle.docSync()",
|
|
3927
|
+
"'Doc not found'"
|
|
3928
|
+
]
|
|
3929
|
+
});
|
|
3930
|
+
const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
|
|
3931
|
+
const migratedDoc = migrateDocument(handle.docSync(), newDoc);
|
|
3932
|
+
const newHandle = context.repo.import(am.save(migratedDoc));
|
|
3933
|
+
newRootContent.links[id] = newHandle.url;
|
|
3934
|
+
}
|
|
3935
|
+
const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
|
|
3936
|
+
const newRoot = context.repo.import(am.save(migratedRoot));
|
|
3937
|
+
await context.repo.flush();
|
|
3938
|
+
return {
|
|
3939
|
+
newRoot: newRoot.url
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
|
|
3943
|
+
invariant12(context.newAutomergeRoot, void 0, {
|
|
3944
|
+
F: __dxlog_file16,
|
|
3945
|
+
L: 124,
|
|
3946
|
+
S: void 0,
|
|
3947
|
+
A: [
|
|
3948
|
+
"context.newAutomergeRoot",
|
|
3949
|
+
""
|
|
3950
|
+
]
|
|
3951
|
+
});
|
|
3952
|
+
await context.repo.flush();
|
|
3953
|
+
return {
|
|
3954
|
+
newRoot: context.newAutomergeRoot
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
return {};
|
|
3959
|
+
};
|
|
3960
|
+
|
|
3617
3961
|
// 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
|
|
3962
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
|
|
3619
3963
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
3620
|
-
import { invariant as
|
|
3964
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
3621
3965
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3622
|
-
import { log as
|
|
3966
|
+
import { log as log14 } from "@dxos/log";
|
|
3623
3967
|
import { schema as schema4 } from "@dxos/protocols";
|
|
3624
3968
|
import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
|
|
3625
3969
|
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
|
|
3626
|
-
var
|
|
3970
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
3627
3971
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
3628
3972
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
3629
3973
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
3630
3974
|
var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
|
|
3631
3975
|
var NotarizationPlugin = class {
|
|
3632
3976
|
constructor() {
|
|
3633
|
-
this._ctx = new Context7(
|
|
3977
|
+
this._ctx = new Context7(void 0, {
|
|
3978
|
+
F: __dxlog_file17,
|
|
3979
|
+
L: 62
|
|
3980
|
+
});
|
|
3634
3981
|
this._extensionOpened = new Event5();
|
|
3635
3982
|
this._extensions = /* @__PURE__ */ new Set();
|
|
3636
3983
|
this._processedCredentials = new ComplexSet4(PublicKey9.hash);
|
|
@@ -3648,16 +3995,16 @@ var NotarizationPlugin = class {
|
|
|
3648
3995
|
* Request credentials to be notarized.
|
|
3649
3996
|
*/
|
|
3650
3997
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3651
|
-
|
|
3998
|
+
log14("notarize", {
|
|
3652
3999
|
credentials
|
|
3653
4000
|
}, {
|
|
3654
|
-
F:
|
|
4001
|
+
F: __dxlog_file17,
|
|
3655
4002
|
L: 90,
|
|
3656
4003
|
S: this,
|
|
3657
4004
|
C: (f, a) => f(...a)
|
|
3658
4005
|
});
|
|
3659
|
-
|
|
3660
|
-
F:
|
|
4006
|
+
invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
4007
|
+
F: __dxlog_file17,
|
|
3661
4008
|
L: 91,
|
|
3662
4009
|
S: this,
|
|
3663
4010
|
A: [
|
|
@@ -3665,13 +4012,13 @@ var NotarizationPlugin = class {
|
|
|
3665
4012
|
"'Credentials must have an id'"
|
|
3666
4013
|
]
|
|
3667
4014
|
});
|
|
3668
|
-
const errors = new
|
|
4015
|
+
const errors = new Trigger7();
|
|
3669
4016
|
const ctx = this._ctx.derive({
|
|
3670
4017
|
onError: (err) => {
|
|
3671
|
-
|
|
4018
|
+
log14.warn("Notarization error", {
|
|
3672
4019
|
err
|
|
3673
4020
|
}, {
|
|
3674
|
-
F:
|
|
4021
|
+
F: __dxlog_file17,
|
|
3675
4022
|
L: 99,
|
|
3676
4023
|
S: this,
|
|
3677
4024
|
C: (f, a) => f(...a)
|
|
@@ -3683,11 +4030,11 @@ var NotarizationPlugin = class {
|
|
|
3683
4030
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3684
4031
|
if (timeout !== 0) {
|
|
3685
4032
|
scheduleTask4(ctx, () => {
|
|
3686
|
-
|
|
4033
|
+
log14.warn("Notarization timeout", {
|
|
3687
4034
|
timeout,
|
|
3688
4035
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3689
4036
|
}, {
|
|
3690
|
-
F:
|
|
4037
|
+
F: __dxlog_file17,
|
|
3691
4038
|
L: 111,
|
|
3692
4039
|
S: this,
|
|
3693
4040
|
C: (f, a) => f(...a)
|
|
@@ -3707,10 +4054,10 @@ var NotarizationPlugin = class {
|
|
|
3707
4054
|
...this._extensions
|
|
3708
4055
|
].find((peer2) => !peersTried.has(peer2));
|
|
3709
4056
|
if (!peer) {
|
|
3710
|
-
|
|
4057
|
+
log14.info("Exhausted all peers to notarize with", {
|
|
3711
4058
|
retryIn: retryTimeout
|
|
3712
4059
|
}, {
|
|
3713
|
-
F:
|
|
4060
|
+
F: __dxlog_file17,
|
|
3714
4061
|
L: 136,
|
|
3715
4062
|
S: this,
|
|
3716
4063
|
C: (f, a) => f(...a)
|
|
@@ -3720,11 +4067,11 @@ var NotarizationPlugin = class {
|
|
|
3720
4067
|
return;
|
|
3721
4068
|
}
|
|
3722
4069
|
peersTried.add(peer);
|
|
3723
|
-
|
|
4070
|
+
log14("try notarizing", {
|
|
3724
4071
|
peer: peer.localPeerId,
|
|
3725
4072
|
credentialId: credentials.map((credential) => credential.id)
|
|
3726
4073
|
}, {
|
|
3727
|
-
F:
|
|
4074
|
+
F: __dxlog_file17,
|
|
3728
4075
|
L: 143,
|
|
3729
4076
|
S: this,
|
|
3730
4077
|
C: (f, a) => f(...a)
|
|
@@ -3732,17 +4079,17 @@ var NotarizationPlugin = class {
|
|
|
3732
4079
|
await peer.rpc.NotarizationService.notarize({
|
|
3733
4080
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3734
4081
|
});
|
|
3735
|
-
|
|
3736
|
-
F:
|
|
4082
|
+
log14("success", void 0, {
|
|
4083
|
+
F: __dxlog_file17,
|
|
3737
4084
|
L: 147,
|
|
3738
4085
|
S: this,
|
|
3739
4086
|
C: (f, a) => f(...a)
|
|
3740
4087
|
});
|
|
3741
|
-
await
|
|
4088
|
+
await sleep2(successDelay);
|
|
3742
4089
|
} catch (err) {
|
|
3743
4090
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3744
|
-
|
|
3745
|
-
F:
|
|
4091
|
+
log14.info("error notarizing (recoverable)", err, {
|
|
4092
|
+
F: __dxlog_file17,
|
|
3746
4093
|
L: 151,
|
|
3747
4094
|
S: this,
|
|
3748
4095
|
C: (f, a) => f(...a)
|
|
@@ -3759,8 +4106,8 @@ var NotarizationPlugin = class {
|
|
|
3759
4106
|
allNotarized,
|
|
3760
4107
|
errors.wait()
|
|
3761
4108
|
]);
|
|
3762
|
-
|
|
3763
|
-
F:
|
|
4109
|
+
log14("done", void 0, {
|
|
4110
|
+
F: __dxlog_file17,
|
|
3764
4111
|
L: 162,
|
|
3765
4112
|
S: this,
|
|
3766
4113
|
C: (f, a) => f(...a)
|
|
@@ -3781,8 +4128,8 @@ var NotarizationPlugin = class {
|
|
|
3781
4128
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3782
4129
|
}
|
|
3783
4130
|
setWriter(writer) {
|
|
3784
|
-
|
|
3785
|
-
F:
|
|
4131
|
+
invariant13(!this._writer, "Writer already set.", {
|
|
4132
|
+
F: __dxlog_file17,
|
|
3786
4133
|
L: 181,
|
|
3787
4134
|
S: this,
|
|
3788
4135
|
A: [
|
|
@@ -3796,7 +4143,7 @@ var NotarizationPlugin = class {
|
|
|
3796
4143
|
if (this._processedCredentials.has(id)) {
|
|
3797
4144
|
return;
|
|
3798
4145
|
}
|
|
3799
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
4146
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger7()).value.wait();
|
|
3800
4147
|
}
|
|
3801
4148
|
/**
|
|
3802
4149
|
* Requests from other peers to notarize credentials.
|
|
@@ -3806,8 +4153,8 @@ var NotarizationPlugin = class {
|
|
|
3806
4153
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3807
4154
|
}
|
|
3808
4155
|
for (const credential of request.credentials ?? []) {
|
|
3809
|
-
|
|
3810
|
-
F:
|
|
4156
|
+
invariant13(credential.id, "Credential must have an id", {
|
|
4157
|
+
F: __dxlog_file17,
|
|
3811
4158
|
L: 200,
|
|
3812
4159
|
S: this,
|
|
3813
4160
|
A: [
|
|
@@ -3824,10 +4171,10 @@ var NotarizationPlugin = class {
|
|
|
3824
4171
|
createExtension() {
|
|
3825
4172
|
const extension = new NotarizationTeleportExtension({
|
|
3826
4173
|
onOpen: async () => {
|
|
3827
|
-
|
|
4174
|
+
log14("extension opened", {
|
|
3828
4175
|
peer: extension.localPeerId
|
|
3829
4176
|
}, {
|
|
3830
|
-
F:
|
|
4177
|
+
F: __dxlog_file17,
|
|
3831
4178
|
L: 211,
|
|
3832
4179
|
S: this,
|
|
3833
4180
|
C: (f, a) => f(...a)
|
|
@@ -3836,10 +4183,10 @@ var NotarizationPlugin = class {
|
|
|
3836
4183
|
this._extensionOpened.emit();
|
|
3837
4184
|
},
|
|
3838
4185
|
onClose: async () => {
|
|
3839
|
-
|
|
4186
|
+
log14("extension closed", {
|
|
3840
4187
|
peer: extension.localPeerId
|
|
3841
4188
|
}, {
|
|
3842
|
-
F:
|
|
4189
|
+
F: __dxlog_file17,
|
|
3843
4190
|
L: 216,
|
|
3844
4191
|
S: this,
|
|
3845
4192
|
C: (f, a) => f(...a)
|
|
@@ -3893,15 +4240,83 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3893
4240
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3894
4241
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3895
4242
|
}
|
|
3896
|
-
|
|
4243
|
+
function _using_ctx() {
|
|
4244
|
+
var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
|
|
4245
|
+
var err = new Error();
|
|
4246
|
+
err.name = "SuppressedError";
|
|
4247
|
+
err.suppressed = suppressed;
|
|
4248
|
+
err.error = error;
|
|
4249
|
+
return err;
|
|
4250
|
+
}, empty = {}, stack = [];
|
|
4251
|
+
function using(isAwait, value) {
|
|
4252
|
+
if (value != null) {
|
|
4253
|
+
if (Object(value) !== value) {
|
|
4254
|
+
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
4255
|
+
}
|
|
4256
|
+
if (isAwait) {
|
|
4257
|
+
var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
|
|
4258
|
+
}
|
|
4259
|
+
if (dispose == null) {
|
|
4260
|
+
dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
|
|
4261
|
+
}
|
|
4262
|
+
if (typeof dispose !== "function") {
|
|
4263
|
+
throw new TypeError(`Property [Symbol.dispose] is not a function.`);
|
|
4264
|
+
}
|
|
4265
|
+
stack.push({
|
|
4266
|
+
v: value,
|
|
4267
|
+
d: dispose,
|
|
4268
|
+
a: isAwait
|
|
4269
|
+
});
|
|
4270
|
+
} else if (isAwait) {
|
|
4271
|
+
stack.push({
|
|
4272
|
+
d: value,
|
|
4273
|
+
a: isAwait
|
|
4274
|
+
});
|
|
4275
|
+
}
|
|
4276
|
+
return value;
|
|
4277
|
+
}
|
|
4278
|
+
return {
|
|
4279
|
+
e: empty,
|
|
4280
|
+
u: using.bind(null, false),
|
|
4281
|
+
a: using.bind(null, true),
|
|
4282
|
+
d: function() {
|
|
4283
|
+
var error = this.e;
|
|
4284
|
+
function next() {
|
|
4285
|
+
while (resource = stack.pop()) {
|
|
4286
|
+
try {
|
|
4287
|
+
var resource, disposalResult = resource.d && resource.d.call(resource.v);
|
|
4288
|
+
if (resource.a) {
|
|
4289
|
+
return Promise.resolve(disposalResult).then(next, err);
|
|
4290
|
+
}
|
|
4291
|
+
} catch (e) {
|
|
4292
|
+
return err(e);
|
|
4293
|
+
}
|
|
4294
|
+
}
|
|
4295
|
+
if (error !== empty)
|
|
4296
|
+
throw error;
|
|
4297
|
+
}
|
|
4298
|
+
function err(e) {
|
|
4299
|
+
error = error !== empty ? new _disposeSuppressedError(error, e) : e;
|
|
4300
|
+
return next();
|
|
4301
|
+
}
|
|
4302
|
+
return next();
|
|
4303
|
+
}
|
|
4304
|
+
};
|
|
4305
|
+
}
|
|
4306
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3897
4307
|
var DataSpace = class {
|
|
3898
4308
|
constructor(params) {
|
|
3899
|
-
this._ctx = new Context8(
|
|
4309
|
+
this._ctx = new Context8(void 0, {
|
|
4310
|
+
F: __dxlog_file18,
|
|
4311
|
+
L: 84
|
|
4312
|
+
});
|
|
3900
4313
|
this._notarizationPlugin = new NotarizationPlugin();
|
|
3901
4314
|
this._cache = void 0;
|
|
3902
4315
|
// TODO(dmaretskyi): Move into Space?
|
|
3903
4316
|
this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
|
|
3904
|
-
this.
|
|
4317
|
+
this._epochProcessingMutex = new Mutex2();
|
|
4318
|
+
this._state = SpaceState2.CLOSED;
|
|
4319
|
+
this._databaseRoot = null;
|
|
3905
4320
|
/**
|
|
3906
4321
|
* Error for _state === SpaceState.ERROR.
|
|
3907
4322
|
*/
|
|
@@ -3925,11 +4340,11 @@ var DataSpace = class {
|
|
|
3925
4340
|
});
|
|
3926
4341
|
this._cache = params.cache;
|
|
3927
4342
|
this._state = params.initialState;
|
|
3928
|
-
|
|
3929
|
-
state:
|
|
4343
|
+
log15("new state", {
|
|
4344
|
+
state: SpaceState2[this._state]
|
|
3930
4345
|
}, {
|
|
3931
|
-
F:
|
|
3932
|
-
L:
|
|
4346
|
+
F: __dxlog_file18,
|
|
4347
|
+
L: 146,
|
|
3933
4348
|
S: this,
|
|
3934
4349
|
C: (f, a) => f(...a)
|
|
3935
4350
|
});
|
|
@@ -3962,6 +4377,9 @@ var DataSpace = class {
|
|
|
3962
4377
|
get automergeSpaceState() {
|
|
3963
4378
|
return this._automergeSpaceState;
|
|
3964
4379
|
}
|
|
4380
|
+
get databaseRoot() {
|
|
4381
|
+
return this._databaseRoot;
|
|
4382
|
+
}
|
|
3965
4383
|
get _automergeInfo() {
|
|
3966
4384
|
return {
|
|
3967
4385
|
rootUrl: this._automergeSpaceState.rootUrl,
|
|
@@ -3969,20 +4387,27 @@ var DataSpace = class {
|
|
|
3969
4387
|
};
|
|
3970
4388
|
}
|
|
3971
4389
|
async open() {
|
|
3972
|
-
|
|
4390
|
+
if (this._state === SpaceState2.CLOSED) {
|
|
4391
|
+
await this._open();
|
|
4392
|
+
}
|
|
3973
4393
|
}
|
|
3974
4394
|
async _open() {
|
|
4395
|
+
await this._presence.open();
|
|
3975
4396
|
await this._gossip.open();
|
|
3976
4397
|
await this._notarizationPlugin.open();
|
|
3977
4398
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
4399
|
+
await this._automergeSpaceState.open();
|
|
3978
4400
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3979
|
-
await this._inner.open(new Context8(
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4401
|
+
await this._inner.open(new Context8(void 0, {
|
|
4402
|
+
F: __dxlog_file18,
|
|
4403
|
+
L: 215
|
|
4404
|
+
}));
|
|
4405
|
+
this._state = SpaceState2.CONTROL_ONLY;
|
|
4406
|
+
log15("new state", {
|
|
4407
|
+
state: SpaceState2[this._state]
|
|
3983
4408
|
}, {
|
|
3984
|
-
F:
|
|
3985
|
-
L:
|
|
4409
|
+
F: __dxlog_file18,
|
|
4410
|
+
L: 217,
|
|
3986
4411
|
S: this,
|
|
3987
4412
|
C: (f, a) => f(...a)
|
|
3988
4413
|
});
|
|
@@ -3995,23 +4420,27 @@ var DataSpace = class {
|
|
|
3995
4420
|
}
|
|
3996
4421
|
async _close() {
|
|
3997
4422
|
await this._callbacks.beforeClose?.();
|
|
3998
|
-
this._state =
|
|
3999
|
-
|
|
4000
|
-
state:
|
|
4423
|
+
this._state = SpaceState2.CLOSED;
|
|
4424
|
+
log15("new state", {
|
|
4425
|
+
state: SpaceState2[this._state]
|
|
4001
4426
|
}, {
|
|
4002
|
-
F:
|
|
4003
|
-
L:
|
|
4427
|
+
F: __dxlog_file18,
|
|
4428
|
+
L: 231,
|
|
4004
4429
|
S: this,
|
|
4005
4430
|
C: (f, a) => f(...a)
|
|
4006
4431
|
});
|
|
4007
4432
|
await this._ctx.dispose();
|
|
4008
|
-
this._ctx = new Context8(
|
|
4433
|
+
this._ctx = new Context8(void 0, {
|
|
4434
|
+
F: __dxlog_file18,
|
|
4435
|
+
L: 233
|
|
4436
|
+
});
|
|
4009
4437
|
await this.authVerifier.close();
|
|
4010
4438
|
await this._inner.close();
|
|
4011
4439
|
await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
|
|
4440
|
+
await this._automergeSpaceState.close();
|
|
4012
4441
|
await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
|
|
4013
4442
|
await this._notarizationPlugin.close();
|
|
4014
|
-
await this._presence.
|
|
4443
|
+
await this._presence.close();
|
|
4015
4444
|
await this._gossip.close();
|
|
4016
4445
|
}
|
|
4017
4446
|
async postMessage(channel, message) {
|
|
@@ -4030,26 +4459,26 @@ var DataSpace = class {
|
|
|
4030
4459
|
await this.initializeDataPipeline();
|
|
4031
4460
|
} catch (err) {
|
|
4032
4461
|
if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
|
|
4033
|
-
|
|
4034
|
-
F:
|
|
4035
|
-
L:
|
|
4462
|
+
log15("data pipeline initialization cancelled", err, {
|
|
4463
|
+
F: __dxlog_file18,
|
|
4464
|
+
L: 265,
|
|
4036
4465
|
S: this,
|
|
4037
4466
|
C: (f, a) => f(...a)
|
|
4038
4467
|
});
|
|
4039
4468
|
return;
|
|
4040
4469
|
}
|
|
4041
|
-
|
|
4042
|
-
F:
|
|
4043
|
-
L:
|
|
4470
|
+
log15.error("Error initializing data pipeline", err, {
|
|
4471
|
+
F: __dxlog_file18,
|
|
4472
|
+
L: 269,
|
|
4044
4473
|
S: this,
|
|
4045
4474
|
C: (f, a) => f(...a)
|
|
4046
4475
|
});
|
|
4047
|
-
this._state =
|
|
4048
|
-
|
|
4049
|
-
state:
|
|
4476
|
+
this._state = SpaceState2.ERROR;
|
|
4477
|
+
log15("new state", {
|
|
4478
|
+
state: SpaceState2[this._state]
|
|
4050
4479
|
}, {
|
|
4051
|
-
F:
|
|
4052
|
-
L:
|
|
4480
|
+
F: __dxlog_file18,
|
|
4481
|
+
L: 271,
|
|
4053
4482
|
S: this,
|
|
4054
4483
|
C: (f, a) => f(...a)
|
|
4055
4484
|
});
|
|
@@ -4061,35 +4490,32 @@ var DataSpace = class {
|
|
|
4061
4490
|
});
|
|
4062
4491
|
}
|
|
4063
4492
|
async initializeDataPipeline() {
|
|
4064
|
-
if (this._state !==
|
|
4493
|
+
if (this._state !== SpaceState2.CONTROL_ONLY) {
|
|
4065
4494
|
throw new SystemError("Invalid operation");
|
|
4066
4495
|
}
|
|
4067
|
-
this._state =
|
|
4068
|
-
|
|
4069
|
-
state:
|
|
4496
|
+
this._state = SpaceState2.INITIALIZING;
|
|
4497
|
+
log15("new state", {
|
|
4498
|
+
state: SpaceState2[this._state]
|
|
4070
4499
|
}, {
|
|
4071
|
-
F:
|
|
4072
|
-
L:
|
|
4500
|
+
F: __dxlog_file18,
|
|
4501
|
+
L: 287,
|
|
4073
4502
|
S: this,
|
|
4074
4503
|
C: (f, a) => f(...a)
|
|
4075
4504
|
});
|
|
4076
4505
|
await this._initializeAndReadControlPipeline();
|
|
4077
|
-
await
|
|
4506
|
+
await sleep3(1);
|
|
4507
|
+
const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
|
|
4078
4508
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
4079
|
-
await
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
L: 287,
|
|
4083
|
-
S: this,
|
|
4084
|
-
C: (f, a) => f(...a)
|
|
4085
|
-
});
|
|
4509
|
+
await ready;
|
|
4510
|
+
}
|
|
4511
|
+
async _enterReadyState() {
|
|
4086
4512
|
await this._callbacks.beforeReady?.();
|
|
4087
|
-
this._state =
|
|
4088
|
-
|
|
4089
|
-
state:
|
|
4513
|
+
this._state = SpaceState2.READY;
|
|
4514
|
+
log15("new state", {
|
|
4515
|
+
state: SpaceState2[this._state]
|
|
4090
4516
|
}, {
|
|
4091
|
-
F:
|
|
4092
|
-
L:
|
|
4517
|
+
F: __dxlog_file18,
|
|
4518
|
+
L: 306,
|
|
4093
4519
|
S: this,
|
|
4094
4520
|
C: (f, a) => f(...a)
|
|
4095
4521
|
});
|
|
@@ -4103,9 +4529,9 @@ var DataSpace = class {
|
|
|
4103
4529
|
});
|
|
4104
4530
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
4105
4531
|
await this._createWritableFeeds();
|
|
4106
|
-
|
|
4107
|
-
F:
|
|
4108
|
-
L:
|
|
4532
|
+
log15("writable feeds created", void 0, {
|
|
4533
|
+
F: __dxlog_file18,
|
|
4534
|
+
L: 322,
|
|
4109
4535
|
S: this,
|
|
4110
4536
|
C: (f, a) => f(...a)
|
|
4111
4537
|
});
|
|
@@ -4163,57 +4589,66 @@ var DataSpace = class {
|
|
|
4163
4589
|
}
|
|
4164
4590
|
}
|
|
4165
4591
|
_onNewAutomergeRoot(rootUrl) {
|
|
4166
|
-
|
|
4592
|
+
log15("loading automerge root doc for space", {
|
|
4167
4593
|
space: this.key,
|
|
4168
4594
|
rootUrl
|
|
4169
4595
|
}, {
|
|
4170
|
-
F:
|
|
4171
|
-
L:
|
|
4596
|
+
F: __dxlog_file18,
|
|
4597
|
+
L: 388,
|
|
4172
4598
|
S: this,
|
|
4173
4599
|
C: (f, a) => f(...a)
|
|
4174
4600
|
});
|
|
4175
|
-
this._echoHost.replicateDocument(rootUrl);
|
|
4176
4601
|
const handle = this._echoHost.automergeRepo.find(rootUrl);
|
|
4177
4602
|
queueMicrotask(async () => {
|
|
4178
4603
|
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)
|
|
4604
|
+
try {
|
|
4605
|
+
var _usingCtx = _using_ctx();
|
|
4606
|
+
await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
|
|
4607
|
+
await cancelWithContext5(this._ctx, handle.whenReady());
|
|
4204
4608
|
});
|
|
4609
|
+
if (this._ctx.disposed) {
|
|
4610
|
+
return;
|
|
4611
|
+
}
|
|
4612
|
+
const _guard = (
|
|
4613
|
+
// Ensure only one root is processed at a time.
|
|
4614
|
+
_usingCtx.u(await this._epochProcessingMutex.acquire())
|
|
4615
|
+
);
|
|
4616
|
+
const doc = handle.docSync() ?? failedInvariant();
|
|
4617
|
+
if (!doc.access?.spaceKey) {
|
|
4618
|
+
handle.change((doc2) => {
|
|
4619
|
+
doc2.access = {
|
|
4620
|
+
spaceKey: this.key.toHex()
|
|
4621
|
+
};
|
|
4622
|
+
});
|
|
4623
|
+
}
|
|
4624
|
+
const root = await this._echoHost.openSpaceRoot(handle.url);
|
|
4625
|
+
this._databaseRoot = root;
|
|
4626
|
+
if (root.getVersion() !== SpaceDocVersion.CURRENT) {
|
|
4627
|
+
if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
|
|
4628
|
+
this._state = SpaceState2.REQUIRES_MIGRATION;
|
|
4629
|
+
this.stateUpdate.emit();
|
|
4630
|
+
}
|
|
4631
|
+
} else {
|
|
4632
|
+
if (this._state !== SpaceState2.READY) {
|
|
4633
|
+
await this._enterReadyState();
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
} catch (_) {
|
|
4637
|
+
_usingCtx.e = _;
|
|
4638
|
+
} finally {
|
|
4639
|
+
_usingCtx.d();
|
|
4205
4640
|
}
|
|
4206
4641
|
} catch (err) {
|
|
4207
4642
|
if (err instanceof ContextDisposedError3) {
|
|
4208
4643
|
return;
|
|
4209
4644
|
}
|
|
4210
|
-
|
|
4645
|
+
log15.warn("error loading automerge root doc", {
|
|
4211
4646
|
space: this.key,
|
|
4212
4647
|
rootUrl,
|
|
4213
4648
|
err
|
|
4214
4649
|
}, {
|
|
4215
|
-
F:
|
|
4216
|
-
L:
|
|
4650
|
+
F: __dxlog_file18,
|
|
4651
|
+
L: 431,
|
|
4217
4652
|
S: this,
|
|
4218
4653
|
C: (f, a) => f(...a)
|
|
4219
4654
|
});
|
|
@@ -4236,175 +4671,70 @@ var DataSpace = class {
|
|
|
4236
4671
|
});
|
|
4237
4672
|
}
|
|
4238
4673
|
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
|
-
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4270
|
-
F: __dxlog_file15,
|
|
4271
|
-
L: 456,
|
|
4272
|
-
S: this,
|
|
4273
|
-
A: [
|
|
4274
|
-
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4275
|
-
""
|
|
4276
|
-
]
|
|
4277
|
-
});
|
|
4278
|
-
epoch = {
|
|
4279
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4280
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4281
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4282
|
-
automergeRoot: newRoot.url
|
|
4283
|
-
};
|
|
4284
|
-
}
|
|
4285
|
-
break;
|
|
4286
|
-
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
4287
|
-
{
|
|
4288
|
-
log12.info("Fragmenting", void 0, {
|
|
4289
|
-
F: __dxlog_file15,
|
|
4290
|
-
L: 468,
|
|
4291
|
-
S: this,
|
|
4292
|
-
C: (f, a) => f(...a)
|
|
4293
|
-
});
|
|
4294
|
-
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4295
|
-
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4296
|
-
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4297
|
-
const objects = Object.entries(rootHandle.docSync().objects);
|
|
4298
|
-
const properties = findPropertiesObject(rootHandle.docSync());
|
|
4299
|
-
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
4300
|
-
invariant13(properties, "Properties not found", {
|
|
4301
|
-
F: __dxlog_file15,
|
|
4302
|
-
L: 478,
|
|
4303
|
-
S: this,
|
|
4304
|
-
A: [
|
|
4305
|
-
"properties",
|
|
4306
|
-
"'Properties not found'"
|
|
4307
|
-
]
|
|
4308
|
-
});
|
|
4309
|
-
const newSpaceDoc = {
|
|
4310
|
-
...rootHandle.docSync(),
|
|
4311
|
-
objects: Object.fromEntries([
|
|
4312
|
-
properties
|
|
4313
|
-
])
|
|
4314
|
-
};
|
|
4315
|
-
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
4316
|
-
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4317
|
-
F: __dxlog_file15,
|
|
4318
|
-
L: 483,
|
|
4319
|
-
S: this,
|
|
4320
|
-
A: [
|
|
4321
|
-
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4322
|
-
""
|
|
4323
|
-
]
|
|
4324
|
-
});
|
|
4325
|
-
const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
|
|
4326
|
-
await docLoader.loadSpaceRootDocHandle(this._ctx, {
|
|
4327
|
-
rootUrl: newRoot.url
|
|
4328
|
-
});
|
|
4329
|
-
otherObjects.forEach(([key, value]) => {
|
|
4330
|
-
const handle = docLoader.createDocumentForObject(key);
|
|
4331
|
-
handle.change((doc) => {
|
|
4332
|
-
assignDeep(doc, [
|
|
4333
|
-
"objects",
|
|
4334
|
-
key
|
|
4335
|
-
], value);
|
|
4336
|
-
});
|
|
4337
|
-
});
|
|
4338
|
-
epoch = {
|
|
4339
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4340
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4341
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4342
|
-
automergeRoot: newRoot.url
|
|
4343
|
-
};
|
|
4344
|
-
}
|
|
4345
|
-
break;
|
|
4346
|
-
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
|
|
4347
|
-
{
|
|
4348
|
-
invariant13(options.newAutomergeRoot, void 0, {
|
|
4349
|
-
F: __dxlog_file15,
|
|
4350
|
-
L: 513,
|
|
4351
|
-
S: this,
|
|
4352
|
-
A: [
|
|
4353
|
-
"options.newAutomergeRoot",
|
|
4354
|
-
""
|
|
4355
|
-
]
|
|
4356
|
-
});
|
|
4357
|
-
epoch = {
|
|
4358
|
-
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4359
|
-
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4360
|
-
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4361
|
-
automergeRoot: options.newAutomergeRoot
|
|
4362
|
-
};
|
|
4363
|
-
}
|
|
4364
|
-
break;
|
|
4365
|
-
}
|
|
4366
|
-
if (!epoch) {
|
|
4367
|
-
return;
|
|
4674
|
+
const ctx = this._ctx.derive();
|
|
4675
|
+
if (!options?.migration) {
|
|
4676
|
+
return null;
|
|
4368
4677
|
}
|
|
4678
|
+
const { newRoot } = await runEpochMigration(ctx, {
|
|
4679
|
+
repo: this._echoHost.automergeRepo,
|
|
4680
|
+
spaceId: this.id,
|
|
4681
|
+
spaceKey: this.key,
|
|
4682
|
+
migration: options.migration,
|
|
4683
|
+
currentRoot: this._automergeSpaceState.rootUrl ?? null,
|
|
4684
|
+
newAutomergeRoot: options.newAutomergeRoot
|
|
4685
|
+
});
|
|
4686
|
+
const epoch = {
|
|
4687
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4688
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4689
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
|
|
4690
|
+
automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
|
|
4691
|
+
};
|
|
4692
|
+
const credential = await this._signingContext.credentialSigner.createCredential({
|
|
4693
|
+
subject: this.key,
|
|
4694
|
+
assertion: {
|
|
4695
|
+
"@type": "dxos.halo.credentials.Epoch",
|
|
4696
|
+
...epoch
|
|
4697
|
+
}
|
|
4698
|
+
});
|
|
4369
4699
|
const receipt = await this.inner.controlPipeline.writer.write({
|
|
4370
4700
|
credential: {
|
|
4371
|
-
credential
|
|
4372
|
-
subject: this.key,
|
|
4373
|
-
assertion: {
|
|
4374
|
-
"@type": "dxos.halo.credentials.Epoch",
|
|
4375
|
-
...epoch
|
|
4376
|
-
}
|
|
4377
|
-
})
|
|
4701
|
+
credential
|
|
4378
4702
|
}
|
|
4379
4703
|
});
|
|
4380
|
-
await this.inner.controlPipeline.state.waitUntilTimeframe(new
|
|
4704
|
+
await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
|
|
4381
4705
|
[
|
|
4382
4706
|
receipt.feedKey,
|
|
4383
4707
|
receipt.seq
|
|
4384
4708
|
]
|
|
4385
4709
|
]));
|
|
4386
4710
|
await this._echoHost.updateIndexes();
|
|
4711
|
+
return credential;
|
|
4387
4712
|
}
|
|
4388
4713
|
async activate() {
|
|
4389
|
-
if (
|
|
4714
|
+
if (![
|
|
4715
|
+
SpaceState2.CLOSED,
|
|
4716
|
+
SpaceState2.INACTIVE
|
|
4717
|
+
].includes(this._state)) {
|
|
4390
4718
|
return;
|
|
4391
4719
|
}
|
|
4392
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
4720
|
+
await this._metadataStore.setSpaceState(this.key, SpaceState2.ACTIVE);
|
|
4393
4721
|
await this._open();
|
|
4394
4722
|
this.initializeDataPipelineAsync();
|
|
4395
4723
|
}
|
|
4396
4724
|
async deactivate() {
|
|
4397
|
-
if (this._state ===
|
|
4725
|
+
if (this._state === SpaceState2.INACTIVE) {
|
|
4398
4726
|
return;
|
|
4399
4727
|
}
|
|
4400
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4728
|
+
await this._metadataStore.setSpaceState(this.key, SpaceState2.INACTIVE);
|
|
4729
|
+
if (this._state !== SpaceState2.CLOSED) {
|
|
4730
|
+
await this._close();
|
|
4731
|
+
}
|
|
4732
|
+
this._state = SpaceState2.INACTIVE;
|
|
4733
|
+
log15("new state", {
|
|
4734
|
+
state: SpaceState2[this._state]
|
|
4405
4735
|
}, {
|
|
4406
|
-
F:
|
|
4407
|
-
L:
|
|
4736
|
+
F: __dxlog_file18,
|
|
4737
|
+
L: 512,
|
|
4408
4738
|
S: this,
|
|
4409
4739
|
C: (f, a) => f(...a)
|
|
4410
4740
|
});
|
|
@@ -4422,7 +4752,7 @@ _ts_decorate4([
|
|
|
4422
4752
|
], DataSpace.prototype, "key", null);
|
|
4423
4753
|
_ts_decorate4([
|
|
4424
4754
|
trace6.info({
|
|
4425
|
-
enum:
|
|
4755
|
+
enum: SpaceState2
|
|
4426
4756
|
})
|
|
4427
4757
|
], DataSpace.prototype, "state", null);
|
|
4428
4758
|
_ts_decorate4([
|
|
@@ -4459,39 +4789,31 @@ DataSpace = _ts_decorate4([
|
|
|
4459
4789
|
trackLeaks("open", "close"),
|
|
4460
4790
|
trace6.resource()
|
|
4461
4791
|
], DataSpace);
|
|
4462
|
-
var findPropertiesObject = (spaceDoc) => {
|
|
4463
|
-
for (const id in spaceDoc.objects ?? {}) {
|
|
4464
|
-
const obj = spaceDoc.objects[id];
|
|
4465
|
-
if (obj.system.type?.itemId === TYPE_PROPERTIES) {
|
|
4466
|
-
return [
|
|
4467
|
-
id,
|
|
4468
|
-
obj
|
|
4469
|
-
];
|
|
4470
|
-
}
|
|
4471
|
-
}
|
|
4472
|
-
return void 0;
|
|
4473
|
-
};
|
|
4474
4792
|
|
|
4475
4793
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
4476
4794
|
import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
4477
|
-
import {
|
|
4478
|
-
import {
|
|
4795
|
+
import { PropertiesType } from "@dxos/client-protocol";
|
|
4796
|
+
import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
|
|
4797
|
+
import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
4798
|
+
import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
|
|
4479
4799
|
import { AuthStatus } from "@dxos/echo-pipeline";
|
|
4800
|
+
import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
|
|
4801
|
+
import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
|
|
4480
4802
|
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4481
4803
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4482
|
-
import { log as
|
|
4804
|
+
import { log as log16 } from "@dxos/log";
|
|
4483
4805
|
import { trace as Trace2 } from "@dxos/protocols";
|
|
4484
|
-
import { Invitation as Invitation7, SpaceState as
|
|
4806
|
+
import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4485
4807
|
import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4486
4808
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
4487
4809
|
import { trace as trace7 } from "@dxos/tracing";
|
|
4488
|
-
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
4810
|
+
import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
4489
4811
|
|
|
4490
4812
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
4491
4813
|
import { createCredential } from "@dxos/credentials";
|
|
4492
4814
|
import { failUndefined } from "@dxos/debug";
|
|
4493
4815
|
import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4494
|
-
import { Timeframe as
|
|
4816
|
+
import { Timeframe as Timeframe4 } from "@dxos/timeframe";
|
|
4495
4817
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
4496
4818
|
const credentials = [
|
|
4497
4819
|
await createCredential({
|
|
@@ -4541,7 +4863,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
|
4541
4863
|
"@type": "dxos.halo.credentials.Epoch",
|
|
4542
4864
|
number: 0,
|
|
4543
4865
|
previousId: void 0,
|
|
4544
|
-
timeframe: new
|
|
4866
|
+
timeframe: new Timeframe4(),
|
|
4545
4867
|
snapshotCid: void 0,
|
|
4546
4868
|
automergeRoot
|
|
4547
4869
|
}
|
|
@@ -4568,11 +4890,12 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
4568
4890
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4569
4891
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4570
4892
|
}
|
|
4571
|
-
var
|
|
4893
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
4572
4894
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
4573
4895
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
4896
|
+
var DEFAULT_SPACE_KEY = "__DEFAULT__";
|
|
4574
4897
|
var DataSpaceManager = class {
|
|
4575
|
-
constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager,
|
|
4898
|
+
constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, _params) {
|
|
4576
4899
|
this._spaceManager = _spaceManager;
|
|
4577
4900
|
this._metadataStore = _metadataStore;
|
|
4578
4901
|
this._keyring = _keyring;
|
|
@@ -4580,14 +4903,15 @@ var DataSpaceManager = class {
|
|
|
4580
4903
|
this._feedStore = _feedStore;
|
|
4581
4904
|
this._echoHost = _echoHost;
|
|
4582
4905
|
this._invitationsManager = _invitationsManager;
|
|
4583
|
-
this.
|
|
4906
|
+
this._params = _params;
|
|
4907
|
+
this._ctx = new Context9(void 0, {
|
|
4908
|
+
F: __dxlog_file19,
|
|
4909
|
+
L: 94
|
|
4910
|
+
});
|
|
4584
4911
|
this.updated = new Event7();
|
|
4585
4912
|
this._spaces = new ComplexMap3(PublicKey11.hash);
|
|
4586
4913
|
this._isOpen = false;
|
|
4587
4914
|
this._instanceId = PublicKey11.random().toHex();
|
|
4588
|
-
const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
|
|
4589
|
-
this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
|
|
4590
|
-
this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
|
|
4591
4915
|
trace7.diagnostic({
|
|
4592
4916
|
id: "spaces",
|
|
4593
4917
|
name: "Spaces",
|
|
@@ -4596,10 +4920,10 @@ var DataSpaceManager = class {
|
|
|
4596
4920
|
const rootUrl = space.automergeSpaceState.rootUrl;
|
|
4597
4921
|
const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
|
|
4598
4922
|
const rootDoc = rootHandle?.docSync();
|
|
4599
|
-
const properties = rootDoc &&
|
|
4923
|
+
const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
|
|
4600
4924
|
return {
|
|
4601
4925
|
key: space.key.toHex(),
|
|
4602
|
-
state:
|
|
4926
|
+
state: SpaceState3[space.state],
|
|
4603
4927
|
name: properties?.[1].data.name ?? null,
|
|
4604
4928
|
inlineObjects: rootDoc ? Object.keys(rootDoc.objects ?? {}).length : null,
|
|
4605
4929
|
linkedObjects: rootDoc ? Object.keys(rootDoc.links ?? {}).length : null,
|
|
@@ -4616,46 +4940,46 @@ var DataSpaceManager = class {
|
|
|
4616
4940
|
return this._spaces;
|
|
4617
4941
|
}
|
|
4618
4942
|
async open() {
|
|
4619
|
-
|
|
4620
|
-
F:
|
|
4621
|
-
L:
|
|
4943
|
+
log16("open", void 0, {
|
|
4944
|
+
F: __dxlog_file19,
|
|
4945
|
+
L: 146,
|
|
4622
4946
|
S: this,
|
|
4623
4947
|
C: (f, a) => f(...a)
|
|
4624
4948
|
});
|
|
4625
|
-
|
|
4949
|
+
log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
|
|
4626
4950
|
id: this._instanceId
|
|
4627
4951
|
}), {
|
|
4628
|
-
F:
|
|
4629
|
-
L:
|
|
4952
|
+
F: __dxlog_file19,
|
|
4953
|
+
L: 147,
|
|
4630
4954
|
S: this,
|
|
4631
4955
|
C: (f, a) => f(...a)
|
|
4632
4956
|
});
|
|
4633
|
-
|
|
4957
|
+
log16("metadata loaded", {
|
|
4634
4958
|
spaces: this._metadataStore.spaces.length
|
|
4635
4959
|
}, {
|
|
4636
|
-
F:
|
|
4637
|
-
L:
|
|
4960
|
+
F: __dxlog_file19,
|
|
4961
|
+
L: 148,
|
|
4638
4962
|
S: this,
|
|
4639
4963
|
C: (f, a) => f(...a)
|
|
4640
4964
|
});
|
|
4641
4965
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
4642
4966
|
try {
|
|
4643
|
-
|
|
4967
|
+
log16("load space", {
|
|
4644
4968
|
spaceMetadata
|
|
4645
4969
|
}, {
|
|
4646
|
-
F:
|
|
4647
|
-
L:
|
|
4970
|
+
F: __dxlog_file19,
|
|
4971
|
+
L: 152,
|
|
4648
4972
|
S: this,
|
|
4649
4973
|
C: (f, a) => f(...a)
|
|
4650
4974
|
});
|
|
4651
4975
|
await this._constructSpace(spaceMetadata);
|
|
4652
4976
|
} catch (err) {
|
|
4653
|
-
|
|
4977
|
+
log16.error("Error loading space", {
|
|
4654
4978
|
spaceMetadata,
|
|
4655
4979
|
err
|
|
4656
4980
|
}, {
|
|
4657
|
-
F:
|
|
4658
|
-
L:
|
|
4981
|
+
F: __dxlog_file19,
|
|
4982
|
+
L: 155,
|
|
4659
4983
|
S: this,
|
|
4660
4984
|
C: (f, a) => f(...a)
|
|
4661
4985
|
});
|
|
@@ -4663,24 +4987,19 @@ var DataSpaceManager = class {
|
|
|
4663
4987
|
});
|
|
4664
4988
|
this._isOpen = true;
|
|
4665
4989
|
this.updated.emit();
|
|
4666
|
-
|
|
4667
|
-
if (space.state !== SpaceState2.INACTIVE) {
|
|
4668
|
-
space.initializeDataPipelineAsync();
|
|
4669
|
-
}
|
|
4670
|
-
}
|
|
4671
|
-
log13.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4990
|
+
log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4672
4991
|
id: this._instanceId
|
|
4673
4992
|
}), {
|
|
4674
|
-
F:
|
|
4675
|
-
L:
|
|
4993
|
+
F: __dxlog_file19,
|
|
4994
|
+
L: 162,
|
|
4676
4995
|
S: this,
|
|
4677
4996
|
C: (f, a) => f(...a)
|
|
4678
4997
|
});
|
|
4679
4998
|
}
|
|
4680
4999
|
async close() {
|
|
4681
|
-
|
|
4682
|
-
F:
|
|
4683
|
-
L:
|
|
5000
|
+
log16("close", void 0, {
|
|
5001
|
+
F: __dxlog_file19,
|
|
5002
|
+
L: 167,
|
|
4684
5003
|
S: this,
|
|
4685
5004
|
C: (f, a) => f(...a)
|
|
4686
5005
|
});
|
|
@@ -4689,14 +5008,15 @@ var DataSpaceManager = class {
|
|
|
4689
5008
|
for (const space of this._spaces.values()) {
|
|
4690
5009
|
await space.close();
|
|
4691
5010
|
}
|
|
5011
|
+
this._spaces.clear();
|
|
4692
5012
|
}
|
|
4693
5013
|
/**
|
|
4694
5014
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
4695
5015
|
*/
|
|
4696
5016
|
async createSpace() {
|
|
4697
5017
|
invariant14(this._isOpen, "Not open.", {
|
|
4698
|
-
F:
|
|
4699
|
-
L:
|
|
5018
|
+
F: __dxlog_file19,
|
|
5019
|
+
L: 181,
|
|
4700
5020
|
S: this,
|
|
4701
5021
|
A: [
|
|
4702
5022
|
"this._isOpen",
|
|
@@ -4711,24 +5031,25 @@ var DataSpaceManager = class {
|
|
|
4711
5031
|
genesisFeedKey: controlFeedKey,
|
|
4712
5032
|
controlFeedKey,
|
|
4713
5033
|
dataFeedKey,
|
|
4714
|
-
state:
|
|
5034
|
+
state: SpaceState3.ACTIVE
|
|
4715
5035
|
};
|
|
4716
|
-
|
|
5036
|
+
log16("creating space...", {
|
|
4717
5037
|
spaceKey
|
|
4718
5038
|
}, {
|
|
4719
|
-
F:
|
|
4720
|
-
L:
|
|
5039
|
+
F: __dxlog_file19,
|
|
5040
|
+
L: 193,
|
|
4721
5041
|
S: this,
|
|
4722
5042
|
C: (f, a) => f(...a)
|
|
4723
5043
|
});
|
|
4724
5044
|
const root = await this._echoHost.createSpaceRoot(spaceKey);
|
|
4725
5045
|
const space = await this._constructSpace(metadata);
|
|
5046
|
+
await space.open();
|
|
4726
5047
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
|
|
4727
5048
|
await this._metadataStore.addSpace(metadata);
|
|
4728
5049
|
const memberCredential = credentials[1];
|
|
4729
|
-
invariant14(
|
|
4730
|
-
F:
|
|
4731
|
-
L:
|
|
5050
|
+
invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5051
|
+
F: __dxlog_file19,
|
|
5052
|
+
L: 203,
|
|
4732
5053
|
S: this,
|
|
4733
5054
|
A: [
|
|
4734
5055
|
"getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -4740,19 +5061,85 @@ var DataSpaceManager = class {
|
|
|
4740
5061
|
this.updated.emit();
|
|
4741
5062
|
return space;
|
|
4742
5063
|
}
|
|
5064
|
+
async isDefaultSpace(space) {
|
|
5065
|
+
if (!space.databaseRoot) {
|
|
5066
|
+
return false;
|
|
5067
|
+
}
|
|
5068
|
+
switch (space.databaseRoot.getVersion()) {
|
|
5069
|
+
case SpaceDocVersion2.CURRENT: {
|
|
5070
|
+
const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
|
|
5071
|
+
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
5072
|
+
}
|
|
5073
|
+
case SpaceDocVersion2.LEGACY: {
|
|
5074
|
+
const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
|
|
5075
|
+
const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
|
|
5076
|
+
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
5077
|
+
}
|
|
5078
|
+
default:
|
|
5079
|
+
log16.warn("unknown space version", {
|
|
5080
|
+
version: space.databaseRoot.getVersion(),
|
|
5081
|
+
spaceId: space.id
|
|
5082
|
+
}, {
|
|
5083
|
+
F: __dxlog_file19,
|
|
5084
|
+
L: 228,
|
|
5085
|
+
S: this,
|
|
5086
|
+
C: (f, a) => f(...a)
|
|
5087
|
+
});
|
|
5088
|
+
return false;
|
|
5089
|
+
}
|
|
5090
|
+
}
|
|
5091
|
+
async createDefaultSpace() {
|
|
5092
|
+
const space = await this.createSpace();
|
|
5093
|
+
const document = await this._getSpaceRootDocument(space);
|
|
5094
|
+
const properties = {
|
|
5095
|
+
system: {
|
|
5096
|
+
type: encodeReference(getTypeReference(PropertiesType))
|
|
5097
|
+
},
|
|
5098
|
+
data: {
|
|
5099
|
+
[DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex()
|
|
5100
|
+
},
|
|
5101
|
+
meta: {
|
|
5102
|
+
keys: []
|
|
5103
|
+
}
|
|
5104
|
+
};
|
|
5105
|
+
const propertiesId = generateEchoId();
|
|
5106
|
+
document.change((doc) => {
|
|
5107
|
+
assignDeep2(doc, [
|
|
5108
|
+
"objects",
|
|
5109
|
+
propertiesId
|
|
5110
|
+
], properties);
|
|
5111
|
+
});
|
|
5112
|
+
await this._echoHost.flush();
|
|
5113
|
+
return space;
|
|
5114
|
+
}
|
|
5115
|
+
async _getSpaceRootDocument(space) {
|
|
5116
|
+
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5117
|
+
invariant14(automergeIndex, void 0, {
|
|
5118
|
+
F: __dxlog_file19,
|
|
5119
|
+
L: 261,
|
|
5120
|
+
S: this,
|
|
5121
|
+
A: [
|
|
5122
|
+
"automergeIndex",
|
|
5123
|
+
""
|
|
5124
|
+
]
|
|
5125
|
+
});
|
|
5126
|
+
const document = this._echoHost.automergeRepo.find(automergeIndex);
|
|
5127
|
+
await document.whenReady();
|
|
5128
|
+
return document;
|
|
5129
|
+
}
|
|
4743
5130
|
// TODO(burdon): Rename join space.
|
|
4744
5131
|
async acceptSpace(opts) {
|
|
4745
|
-
|
|
5132
|
+
log16("accept space", {
|
|
4746
5133
|
opts
|
|
4747
5134
|
}, {
|
|
4748
|
-
F:
|
|
4749
|
-
L:
|
|
5135
|
+
F: __dxlog_file19,
|
|
5136
|
+
L: 270,
|
|
4750
5137
|
S: this,
|
|
4751
5138
|
C: (f, a) => f(...a)
|
|
4752
5139
|
});
|
|
4753
5140
|
invariant14(this._isOpen, "Not open.", {
|
|
4754
|
-
F:
|
|
4755
|
-
L:
|
|
5141
|
+
F: __dxlog_file19,
|
|
5142
|
+
L: 271,
|
|
4756
5143
|
S: this,
|
|
4757
5144
|
A: [
|
|
4758
5145
|
"this._isOpen",
|
|
@@ -4760,8 +5147,8 @@ var DataSpaceManager = class {
|
|
|
4760
5147
|
]
|
|
4761
5148
|
});
|
|
4762
5149
|
invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4763
|
-
F:
|
|
4764
|
-
L:
|
|
5150
|
+
F: __dxlog_file19,
|
|
5151
|
+
L: 272,
|
|
4765
5152
|
S: this,
|
|
4766
5153
|
A: [
|
|
4767
5154
|
"!this._spaces.has(opts.spaceKey)",
|
|
@@ -4775,6 +5162,7 @@ var DataSpaceManager = class {
|
|
|
4775
5162
|
dataTimeframe: opts.dataTimeframe
|
|
4776
5163
|
};
|
|
4777
5164
|
const space = await this._constructSpace(metadata);
|
|
5165
|
+
await space.open();
|
|
4778
5166
|
await this._metadataStore.addSpace(metadata);
|
|
4779
5167
|
space.initializeDataPipelineAsync();
|
|
4780
5168
|
this.updated.emit();
|
|
@@ -4786,17 +5174,17 @@ var DataSpaceManager = class {
|
|
|
4786
5174
|
* TODO(dmaretskyi): Consider removing.
|
|
4787
5175
|
*/
|
|
4788
5176
|
async waitUntilSpaceReady(spaceKey) {
|
|
4789
|
-
await
|
|
5177
|
+
await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
|
|
4790
5178
|
const space = this._spaces.get(spaceKey);
|
|
4791
|
-
return !!space && space.state ===
|
|
5179
|
+
return !!space && space.state === SpaceState3.READY;
|
|
4792
5180
|
}));
|
|
4793
5181
|
}
|
|
4794
5182
|
async _constructSpace(metadata) {
|
|
4795
|
-
|
|
5183
|
+
log16("construct space", {
|
|
4796
5184
|
metadata
|
|
4797
5185
|
}, {
|
|
4798
|
-
F:
|
|
4799
|
-
L:
|
|
5186
|
+
F: __dxlog_file19,
|
|
5187
|
+
L: 306,
|
|
4800
5188
|
S: this,
|
|
4801
5189
|
C: (f, a) => f(...a)
|
|
4802
5190
|
});
|
|
@@ -4804,8 +5192,8 @@ var DataSpaceManager = class {
|
|
|
4804
5192
|
localPeerId: this._signingContext.deviceKey
|
|
4805
5193
|
});
|
|
4806
5194
|
const presence = new Presence2({
|
|
4807
|
-
announceInterval: this.
|
|
4808
|
-
offlineTimeout: this.
|
|
5195
|
+
announceInterval: this._params?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
|
|
5196
|
+
offlineTimeout: this._params?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
|
|
4809
5197
|
identityKey: this._signingContext.identityKey,
|
|
4810
5198
|
gossip
|
|
4811
5199
|
});
|
|
@@ -4832,15 +5220,15 @@ var DataSpaceManager = class {
|
|
|
4832
5220
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
4833
5221
|
},
|
|
4834
5222
|
onAuthFailure: () => {
|
|
4835
|
-
|
|
4836
|
-
F:
|
|
4837
|
-
L:
|
|
5223
|
+
log16.warn("auth failure", void 0, {
|
|
5224
|
+
F: __dxlog_file19,
|
|
5225
|
+
L: 343,
|
|
4838
5226
|
S: this,
|
|
4839
5227
|
C: (f, a) => f(...a)
|
|
4840
5228
|
});
|
|
4841
5229
|
},
|
|
4842
5230
|
onMemberRolesChanged: async (members) => {
|
|
4843
|
-
if (dataSpace?.state ===
|
|
5231
|
+
if (dataSpace?.state === SpaceState3.READY) {
|
|
4844
5232
|
this._handleMemberRoleChanges(presence, space.protocol, members);
|
|
4845
5233
|
}
|
|
4846
5234
|
},
|
|
@@ -4853,7 +5241,7 @@ var DataSpaceManager = class {
|
|
|
4853
5241
|
dataFeed && await space.setDataFeed(dataFeed);
|
|
4854
5242
|
const dataSpace = new DataSpace({
|
|
4855
5243
|
inner: space,
|
|
4856
|
-
initialState: metadata.state ===
|
|
5244
|
+
initialState: metadata.state === SpaceState3.INACTIVE ? SpaceState3.INACTIVE : SpaceState3.CLOSED,
|
|
4857
5245
|
metadataStore: this._metadataStore,
|
|
4858
5246
|
gossip,
|
|
4859
5247
|
presence,
|
|
@@ -4863,22 +5251,22 @@ var DataSpaceManager = class {
|
|
|
4863
5251
|
signingContext: this._signingContext,
|
|
4864
5252
|
callbacks: {
|
|
4865
5253
|
beforeReady: async () => {
|
|
4866
|
-
|
|
5254
|
+
log16("before space ready", {
|
|
4867
5255
|
space: space.key
|
|
4868
5256
|
}, {
|
|
4869
|
-
F:
|
|
4870
|
-
L:
|
|
5257
|
+
F: __dxlog_file19,
|
|
5258
|
+
L: 370,
|
|
4871
5259
|
S: this,
|
|
4872
5260
|
C: (f, a) => f(...a)
|
|
4873
5261
|
});
|
|
4874
5262
|
},
|
|
4875
5263
|
afterReady: async () => {
|
|
4876
|
-
|
|
5264
|
+
log16("after space ready", {
|
|
4877
5265
|
space: space.key,
|
|
4878
5266
|
open: this._isOpen
|
|
4879
5267
|
}, {
|
|
4880
|
-
F:
|
|
4881
|
-
L:
|
|
5268
|
+
F: __dxlog_file19,
|
|
5269
|
+
L: 373,
|
|
4882
5270
|
S: this,
|
|
4883
5271
|
C: (f, a) => f(...a)
|
|
4884
5272
|
});
|
|
@@ -4893,11 +5281,11 @@ var DataSpaceManager = class {
|
|
|
4893
5281
|
}
|
|
4894
5282
|
},
|
|
4895
5283
|
beforeClose: async () => {
|
|
4896
|
-
|
|
5284
|
+
log16("before space close", {
|
|
4897
5285
|
space: space.key
|
|
4898
5286
|
}, {
|
|
4899
|
-
F:
|
|
4900
|
-
L:
|
|
5287
|
+
F: __dxlog_file19,
|
|
5288
|
+
L: 381,
|
|
4901
5289
|
S: this,
|
|
4902
5290
|
C: (f, a) => f(...a)
|
|
4903
5291
|
});
|
|
@@ -4906,13 +5294,10 @@ var DataSpaceManager = class {
|
|
|
4906
5294
|
cache: metadata.cache
|
|
4907
5295
|
});
|
|
4908
5296
|
presence.newPeer.on((peerState) => {
|
|
4909
|
-
if (dataSpace.state ===
|
|
5297
|
+
if (dataSpace.state === SpaceState3.READY) {
|
|
4910
5298
|
this._handleNewPeerConnected(space, peerState);
|
|
4911
5299
|
}
|
|
4912
5300
|
});
|
|
4913
|
-
if (metadata.state !== SpaceState2.INACTIVE) {
|
|
4914
|
-
await dataSpace.open();
|
|
4915
|
-
}
|
|
4916
5301
|
if (metadata.controlTimeframe) {
|
|
4917
5302
|
dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
|
|
4918
5303
|
}
|
|
@@ -4931,17 +5316,17 @@ var DataSpaceManager = class {
|
|
|
4931
5316
|
return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
|
|
4932
5317
|
});
|
|
4933
5318
|
sessionsToClose.forEach((session) => {
|
|
4934
|
-
void session.close().catch(
|
|
5319
|
+
void session.close().catch(log16.error);
|
|
4935
5320
|
});
|
|
4936
5321
|
closedSessions += sessionsToClose.length;
|
|
4937
5322
|
}
|
|
4938
|
-
|
|
5323
|
+
log16("processed member role changes", {
|
|
4939
5324
|
roleChangeCount: memberInfo.length,
|
|
4940
5325
|
peersOnline: presence.getPeersOnline().length,
|
|
4941
5326
|
closedSessions
|
|
4942
5327
|
}, {
|
|
4943
|
-
F:
|
|
4944
|
-
L:
|
|
5328
|
+
F: __dxlog_file19,
|
|
5329
|
+
L: 417,
|
|
4945
5330
|
S: this,
|
|
4946
5331
|
C: (f, a) => f(...a)
|
|
4947
5332
|
});
|
|
@@ -4952,20 +5337,20 @@ var DataSpaceManager = class {
|
|
|
4952
5337
|
if (role === SpaceMember6.Role.REMOVED) {
|
|
4953
5338
|
const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
|
|
4954
5339
|
if (session != null) {
|
|
4955
|
-
|
|
5340
|
+
log16("closing a session with a removed peer", {
|
|
4956
5341
|
peerId: peerState.peerId
|
|
4957
5342
|
}, {
|
|
4958
|
-
F:
|
|
4959
|
-
L:
|
|
5343
|
+
F: __dxlog_file19,
|
|
5344
|
+
L: 431,
|
|
4960
5345
|
S: this,
|
|
4961
5346
|
C: (f, a) => f(...a)
|
|
4962
5347
|
});
|
|
4963
|
-
void session.close().catch(
|
|
5348
|
+
void session.close().catch(log16.error);
|
|
4964
5349
|
}
|
|
4965
5350
|
}
|
|
4966
5351
|
}
|
|
4967
5352
|
async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
|
|
4968
|
-
if (dataSpace?.state !==
|
|
5353
|
+
if (dataSpace?.state !== SpaceState3.READY) {
|
|
4969
5354
|
return;
|
|
4970
5355
|
}
|
|
4971
5356
|
if (isActive) {
|
|
@@ -5019,15 +5404,15 @@ DataSpaceManager = _ts_decorate5([
|
|
|
5019
5404
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
5020
5405
|
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
|
|
5021
5406
|
import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
5022
|
-
import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as
|
|
5407
|
+
import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
|
|
5023
5408
|
import { raise as raise2 } from "@dxos/debug";
|
|
5024
5409
|
import { writeMessages as writeMessages3 } from "@dxos/feed-store";
|
|
5025
5410
|
import { invariant as invariant15 } from "@dxos/invariant";
|
|
5026
|
-
import { log as
|
|
5411
|
+
import { log as log17 } from "@dxos/log";
|
|
5027
5412
|
import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
|
|
5028
|
-
import { SpaceMember as SpaceMember7, SpaceState as
|
|
5413
|
+
import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5029
5414
|
import { trace as trace8 } from "@dxos/tracing";
|
|
5030
|
-
var
|
|
5415
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
5031
5416
|
var SpacesServiceImpl = class {
|
|
5032
5417
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
5033
5418
|
this._identityManager = _identityManager;
|
|
@@ -5046,10 +5431,10 @@ var SpacesServiceImpl = class {
|
|
|
5046
5431
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
|
|
5047
5432
|
if (state) {
|
|
5048
5433
|
switch (state) {
|
|
5049
|
-
case
|
|
5434
|
+
case SpaceState4.ACTIVE:
|
|
5050
5435
|
await space.activate();
|
|
5051
5436
|
break;
|
|
5052
|
-
case
|
|
5437
|
+
case SpaceState4.INACTIVE:
|
|
5053
5438
|
await space.deactivate();
|
|
5054
5439
|
break;
|
|
5055
5440
|
default:
|
|
@@ -5071,8 +5456,8 @@ var SpacesServiceImpl = class {
|
|
|
5071
5456
|
}
|
|
5072
5457
|
const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
|
|
5073
5458
|
invariant15(credentials[0].credential, void 0, {
|
|
5074
|
-
F:
|
|
5075
|
-
L:
|
|
5459
|
+
F: __dxlog_file20,
|
|
5460
|
+
L: 98,
|
|
5076
5461
|
S: this,
|
|
5077
5462
|
A: [
|
|
5078
5463
|
"credentials[0].credential",
|
|
@@ -5080,9 +5465,9 @@ var SpacesServiceImpl = class {
|
|
|
5080
5465
|
]
|
|
5081
5466
|
});
|
|
5082
5467
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
5083
|
-
invariant15(
|
|
5084
|
-
F:
|
|
5085
|
-
L:
|
|
5468
|
+
invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5469
|
+
F: __dxlog_file20,
|
|
5470
|
+
L: 100,
|
|
5086
5471
|
S: this,
|
|
5087
5472
|
A: [
|
|
5088
5473
|
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -5096,11 +5481,11 @@ var SpacesServiceImpl = class {
|
|
|
5096
5481
|
const scheduler = new UpdateScheduler(ctx, async () => {
|
|
5097
5482
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5098
5483
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
5099
|
-
|
|
5484
|
+
log17("update", {
|
|
5100
5485
|
spaces
|
|
5101
5486
|
}, {
|
|
5102
|
-
F:
|
|
5103
|
-
L:
|
|
5487
|
+
F: __dxlog_file20,
|
|
5488
|
+
L: 111,
|
|
5104
5489
|
S: this,
|
|
5105
5490
|
C: (f, a) => f(...a)
|
|
5106
5491
|
});
|
|
@@ -5118,7 +5503,15 @@ var SpacesServiceImpl = class {
|
|
|
5118
5503
|
const subscribeSpaces = () => {
|
|
5119
5504
|
subscriptions.clear();
|
|
5120
5505
|
for (const space of dataSpaceManager.spaces.values()) {
|
|
5121
|
-
|
|
5506
|
+
let lastState;
|
|
5507
|
+
subscriptions.add(space.stateUpdate.on(ctx, () => {
|
|
5508
|
+
if (space.state !== lastState) {
|
|
5509
|
+
scheduler.forceTrigger();
|
|
5510
|
+
} else {
|
|
5511
|
+
scheduler.trigger();
|
|
5512
|
+
}
|
|
5513
|
+
lastState = space.state;
|
|
5514
|
+
}));
|
|
5122
5515
|
subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
|
|
5123
5516
|
subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
|
|
5124
5517
|
subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
|
|
@@ -5183,8 +5576,8 @@ var SpacesServiceImpl = class {
|
|
|
5183
5576
|
});
|
|
5184
5577
|
} else {
|
|
5185
5578
|
invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
5186
|
-
F:
|
|
5187
|
-
L:
|
|
5579
|
+
F: __dxlog_file20,
|
|
5580
|
+
L: 209,
|
|
5188
5581
|
S: this,
|
|
5189
5582
|
A: [
|
|
5190
5583
|
"!credential.id",
|
|
@@ -5192,8 +5585,8 @@ var SpacesServiceImpl = class {
|
|
|
5192
5585
|
]
|
|
5193
5586
|
});
|
|
5194
5587
|
invariant15(this._identityManager.identity, "Identity is not available", {
|
|
5195
|
-
F:
|
|
5196
|
-
L:
|
|
5588
|
+
F: __dxlog_file20,
|
|
5589
|
+
L: 210,
|
|
5197
5590
|
S: this,
|
|
5198
5591
|
A: [
|
|
5199
5592
|
"this._identityManager.identity",
|
|
@@ -5202,8 +5595,8 @@ var SpacesServiceImpl = class {
|
|
|
5202
5595
|
});
|
|
5203
5596
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
5204
5597
|
invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
5205
|
-
F:
|
|
5206
|
-
L:
|
|
5598
|
+
F: __dxlog_file20,
|
|
5599
|
+
L: 212,
|
|
5207
5600
|
S: this,
|
|
5208
5601
|
A: [
|
|
5209
5602
|
"credential.issuer.equals(signer.getIssuer())",
|
|
@@ -5225,10 +5618,13 @@ var SpacesServiceImpl = class {
|
|
|
5225
5618
|
async createEpoch({ spaceKey, migration, automergeRootUrl }) {
|
|
5226
5619
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
5227
5620
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
|
|
5228
|
-
await space.createEpoch({
|
|
5621
|
+
const credential = await space.createEpoch({
|
|
5229
5622
|
migration,
|
|
5230
5623
|
newAutomergeRoot: automergeRootUrl
|
|
5231
5624
|
});
|
|
5625
|
+
return {
|
|
5626
|
+
epochCredential: credential ?? void 0
|
|
5627
|
+
};
|
|
5232
5628
|
}
|
|
5233
5629
|
_serializeSpace(space) {
|
|
5234
5630
|
return {
|
|
@@ -5291,9 +5687,9 @@ var SpacesServiceImpl = class {
|
|
|
5291
5687
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
5292
5688
|
|
|
5293
5689
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
5294
|
-
import { Trigger as
|
|
5295
|
-
import { Context as Context10, Resource } from "@dxos/context";
|
|
5296
|
-
import { getCredentialAssertion as
|
|
5690
|
+
import { Trigger as Trigger8 } from "@dxos/async";
|
|
5691
|
+
import { Context as Context10, Resource as Resource3 } from "@dxos/context";
|
|
5692
|
+
import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
|
|
5297
5693
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
5298
5694
|
import { EchoHost } from "@dxos/echo-db";
|
|
5299
5695
|
import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
@@ -5301,7 +5697,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
|
5301
5697
|
import { invariant as invariant16 } from "@dxos/invariant";
|
|
5302
5698
|
import { Keyring } from "@dxos/keyring";
|
|
5303
5699
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5304
|
-
import { log as
|
|
5700
|
+
import { log as log18 } from "@dxos/log";
|
|
5305
5701
|
import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
|
|
5306
5702
|
import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5307
5703
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
@@ -5317,8 +5713,8 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
5317
5713
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5318
5714
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5319
5715
|
}
|
|
5320
|
-
var
|
|
5321
|
-
var ServiceContext = class extends
|
|
5716
|
+
var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
5717
|
+
var ServiceContext = class extends Resource3 {
|
|
5322
5718
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
5323
5719
|
super();
|
|
5324
5720
|
this.storage = storage;
|
|
@@ -5326,7 +5722,7 @@ var ServiceContext = class extends Resource {
|
|
|
5326
5722
|
this.networkManager = networkManager;
|
|
5327
5723
|
this.signalManager = signalManager;
|
|
5328
5724
|
this._runtimeParams = _runtimeParams;
|
|
5329
|
-
this.initialized = new
|
|
5725
|
+
this.initialized = new Trigger8();
|
|
5330
5726
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
5331
5727
|
this._instanceId = PublicKey12.random().toHex();
|
|
5332
5728
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
@@ -5352,8 +5748,7 @@ var ServiceContext = class extends Resource {
|
|
|
5352
5748
|
});
|
|
5353
5749
|
this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
|
|
5354
5750
|
this.echoHost = new EchoHost({
|
|
5355
|
-
kv: this.level
|
|
5356
|
-
storage: this.storage
|
|
5751
|
+
kv: this.level
|
|
5357
5752
|
});
|
|
5358
5753
|
this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
|
|
5359
5754
|
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
@@ -5361,17 +5756,17 @@ var ServiceContext = class extends Resource {
|
|
|
5361
5756
|
}
|
|
5362
5757
|
async _open(ctx) {
|
|
5363
5758
|
await this._checkStorageVersion();
|
|
5364
|
-
|
|
5365
|
-
F:
|
|
5366
|
-
L:
|
|
5759
|
+
log18("opening...", void 0, {
|
|
5760
|
+
F: __dxlog_file21,
|
|
5761
|
+
L: 149,
|
|
5367
5762
|
S: this,
|
|
5368
5763
|
C: (f, a) => f(...a)
|
|
5369
5764
|
});
|
|
5370
|
-
|
|
5765
|
+
log18.trace("dxos.sdk.service-context.open", trace9.begin({
|
|
5371
5766
|
id: this._instanceId
|
|
5372
5767
|
}), {
|
|
5373
|
-
F:
|
|
5374
|
-
L:
|
|
5768
|
+
F: __dxlog_file21,
|
|
5769
|
+
L: 150,
|
|
5375
5770
|
S: this,
|
|
5376
5771
|
C: (f, a) => f(...a)
|
|
5377
5772
|
});
|
|
@@ -5385,33 +5780,33 @@ var ServiceContext = class extends Resource {
|
|
|
5385
5780
|
await this._initialize(ctx);
|
|
5386
5781
|
}
|
|
5387
5782
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
5388
|
-
|
|
5783
|
+
log18("loaded persistent invitations", {
|
|
5389
5784
|
count: loadedInvitations.invitations?.length
|
|
5390
5785
|
}, {
|
|
5391
|
-
F:
|
|
5392
|
-
L:
|
|
5786
|
+
F: __dxlog_file21,
|
|
5787
|
+
L: 163,
|
|
5393
5788
|
S: this,
|
|
5394
5789
|
C: (f, a) => f(...a)
|
|
5395
5790
|
});
|
|
5396
|
-
|
|
5791
|
+
log18.trace("dxos.sdk.service-context.open", trace9.end({
|
|
5397
5792
|
id: this._instanceId
|
|
5398
5793
|
}), {
|
|
5399
|
-
F:
|
|
5400
|
-
L:
|
|
5794
|
+
F: __dxlog_file21,
|
|
5795
|
+
L: 165,
|
|
5401
5796
|
S: this,
|
|
5402
5797
|
C: (f, a) => f(...a)
|
|
5403
5798
|
});
|
|
5404
|
-
|
|
5405
|
-
F:
|
|
5406
|
-
L:
|
|
5799
|
+
log18("opened", void 0, {
|
|
5800
|
+
F: __dxlog_file21,
|
|
5801
|
+
L: 166,
|
|
5407
5802
|
S: this,
|
|
5408
5803
|
C: (f, a) => f(...a)
|
|
5409
5804
|
});
|
|
5410
5805
|
}
|
|
5411
5806
|
async _close(ctx) {
|
|
5412
|
-
|
|
5413
|
-
F:
|
|
5414
|
-
L:
|
|
5807
|
+
log18("closing...", void 0, {
|
|
5808
|
+
F: __dxlog_file21,
|
|
5809
|
+
L: 170,
|
|
5415
5810
|
S: this,
|
|
5416
5811
|
C: (f, a) => f(...a)
|
|
5417
5812
|
});
|
|
@@ -5426,23 +5821,26 @@ var ServiceContext = class extends Resource {
|
|
|
5426
5821
|
await this.echoHost.close(ctx);
|
|
5427
5822
|
await this.networkManager.close();
|
|
5428
5823
|
await this.signalManager.close();
|
|
5429
|
-
|
|
5430
|
-
F:
|
|
5431
|
-
L:
|
|
5824
|
+
log18("closed", void 0, {
|
|
5825
|
+
F: __dxlog_file21,
|
|
5826
|
+
L: 182,
|
|
5432
5827
|
S: this,
|
|
5433
5828
|
C: (f, a) => f(...a)
|
|
5434
5829
|
});
|
|
5435
5830
|
}
|
|
5436
5831
|
async createIdentity(params = {}) {
|
|
5437
5832
|
const identity = await this.identityManager.createIdentity(params);
|
|
5438
|
-
await this._initialize(new Context10(
|
|
5833
|
+
await this._initialize(new Context10(void 0, {
|
|
5834
|
+
F: __dxlog_file21,
|
|
5835
|
+
L: 187
|
|
5836
|
+
}));
|
|
5439
5837
|
return identity;
|
|
5440
5838
|
}
|
|
5441
5839
|
getInvitationHandler(invitation) {
|
|
5442
5840
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
5443
5841
|
invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
5444
|
-
F:
|
|
5445
|
-
L:
|
|
5842
|
+
F: __dxlog_file21,
|
|
5843
|
+
L: 193,
|
|
5446
5844
|
S: this,
|
|
5447
5845
|
A: [
|
|
5448
5846
|
"factory",
|
|
@@ -5461,7 +5859,10 @@ var ServiceContext = class extends Resource {
|
|
|
5461
5859
|
}
|
|
5462
5860
|
async _acceptIdentity(params) {
|
|
5463
5861
|
const identity = await this.identityManager.acceptIdentity(params);
|
|
5464
|
-
await this._initialize(new Context10(
|
|
5862
|
+
await this._initialize(new Context10(void 0, {
|
|
5863
|
+
F: __dxlog_file21,
|
|
5864
|
+
L: 209
|
|
5865
|
+
}));
|
|
5465
5866
|
return identity;
|
|
5466
5867
|
}
|
|
5467
5868
|
async _checkStorageVersion() {
|
|
@@ -5472,9 +5873,9 @@ var ServiceContext = class extends Resource {
|
|
|
5472
5873
|
}
|
|
5473
5874
|
// Called when identity is created.
|
|
5474
5875
|
async _initialize(ctx) {
|
|
5475
|
-
|
|
5476
|
-
F:
|
|
5477
|
-
L:
|
|
5876
|
+
log18("initializing spaces...", void 0, {
|
|
5877
|
+
F: __dxlog_file21,
|
|
5878
|
+
L: 224,
|
|
5478
5879
|
S: this,
|
|
5479
5880
|
C: (f, a) => f(...a)
|
|
5480
5881
|
});
|
|
@@ -5496,8 +5897,8 @@ var ServiceContext = class extends Resource {
|
|
|
5496
5897
|
await this.dataSpaceManager.open();
|
|
5497
5898
|
this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
|
|
5498
5899
|
invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5499
|
-
F:
|
|
5500
|
-
L:
|
|
5900
|
+
F: __dxlog_file21,
|
|
5901
|
+
L: 249,
|
|
5501
5902
|
S: this,
|
|
5502
5903
|
A: [
|
|
5503
5904
|
"this.dataSpaceManager",
|
|
@@ -5509,7 +5910,7 @@ var ServiceContext = class extends Resource {
|
|
|
5509
5910
|
this.initialized.wake();
|
|
5510
5911
|
this._deviceSpaceSync = {
|
|
5511
5912
|
processCredential: async (credential) => {
|
|
5512
|
-
const assertion =
|
|
5913
|
+
const assertion = getCredentialAssertion5(credential);
|
|
5513
5914
|
if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
|
|
5514
5915
|
return;
|
|
5515
5916
|
}
|
|
@@ -5517,33 +5918,33 @@ var ServiceContext = class extends Resource {
|
|
|
5517
5918
|
return;
|
|
5518
5919
|
}
|
|
5519
5920
|
if (!this.dataSpaceManager) {
|
|
5520
|
-
|
|
5921
|
+
log18("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
5521
5922
|
details: assertion
|
|
5522
5923
|
}, {
|
|
5523
|
-
F:
|
|
5524
|
-
L:
|
|
5924
|
+
F: __dxlog_file21,
|
|
5925
|
+
L: 265,
|
|
5525
5926
|
S: this,
|
|
5526
5927
|
C: (f, a) => f(...a)
|
|
5527
5928
|
});
|
|
5528
5929
|
return;
|
|
5529
5930
|
}
|
|
5530
5931
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
5531
|
-
|
|
5932
|
+
log18("space already exists, ignoring space admission", {
|
|
5532
5933
|
details: assertion
|
|
5533
5934
|
}, {
|
|
5534
|
-
F:
|
|
5535
|
-
L:
|
|
5935
|
+
F: __dxlog_file21,
|
|
5936
|
+
L: 269,
|
|
5536
5937
|
S: this,
|
|
5537
5938
|
C: (f, a) => f(...a)
|
|
5538
5939
|
});
|
|
5539
5940
|
return;
|
|
5540
5941
|
}
|
|
5541
5942
|
try {
|
|
5542
|
-
|
|
5943
|
+
log18("accepting space recorded in halo", {
|
|
5543
5944
|
details: assertion
|
|
5544
5945
|
}, {
|
|
5545
|
-
F:
|
|
5546
|
-
L:
|
|
5946
|
+
F: __dxlog_file21,
|
|
5947
|
+
L: 274,
|
|
5547
5948
|
S: this,
|
|
5548
5949
|
C: (f, a) => f(...a)
|
|
5549
5950
|
});
|
|
@@ -5552,9 +5953,9 @@ var ServiceContext = class extends Resource {
|
|
|
5552
5953
|
genesisFeedKey: assertion.genesisFeedKey
|
|
5553
5954
|
});
|
|
5554
5955
|
} catch (err) {
|
|
5555
|
-
|
|
5556
|
-
F:
|
|
5557
|
-
L:
|
|
5956
|
+
log18.catch(err, void 0, {
|
|
5957
|
+
F: __dxlog_file21,
|
|
5958
|
+
L: 280,
|
|
5558
5959
|
S: this,
|
|
5559
5960
|
C: (f, a) => f(...a)
|
|
5560
5961
|
});
|
|
@@ -5600,9 +6001,9 @@ var ServiceRegistry = class {
|
|
|
5600
6001
|
};
|
|
5601
6002
|
|
|
5602
6003
|
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5603
|
-
import { asyncTimeout as asyncTimeout3, Trigger as
|
|
6004
|
+
import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
|
|
5604
6005
|
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5605
|
-
import { log as
|
|
6006
|
+
import { log as log19, logInfo } from "@dxos/log";
|
|
5606
6007
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
5607
6008
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5608
6009
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -5613,7 +6014,7 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
5613
6014
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5614
6015
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5615
6016
|
}
|
|
5616
|
-
var
|
|
6017
|
+
var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5617
6018
|
var Message;
|
|
5618
6019
|
(function(Message2) {
|
|
5619
6020
|
Message2["ACQUIRING"] = "acquiring";
|
|
@@ -5621,7 +6022,7 @@ var Message;
|
|
|
5621
6022
|
var Lock = class {
|
|
5622
6023
|
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5623
6024
|
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5624
|
-
this._releaseTrigger = new
|
|
6025
|
+
this._releaseTrigger = new Trigger9();
|
|
5625
6026
|
this._lockKey = lockKey;
|
|
5626
6027
|
this._onAcquire = onAcquire;
|
|
5627
6028
|
this._onRelease = onRelease;
|
|
@@ -5635,29 +6036,29 @@ var Lock = class {
|
|
|
5635
6036
|
message: "acquiring"
|
|
5636
6037
|
});
|
|
5637
6038
|
try {
|
|
5638
|
-
|
|
5639
|
-
F:
|
|
6039
|
+
log19("aquiring lock...", void 0, {
|
|
6040
|
+
F: __dxlog_file22,
|
|
5640
6041
|
L: 42,
|
|
5641
6042
|
S: this,
|
|
5642
6043
|
C: (f, a) => f(...a)
|
|
5643
6044
|
});
|
|
5644
6045
|
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5645
|
-
|
|
5646
|
-
F:
|
|
6046
|
+
log19("acquired lock", void 0, {
|
|
6047
|
+
F: __dxlog_file22,
|
|
5647
6048
|
L: 44,
|
|
5648
6049
|
S: this,
|
|
5649
6050
|
C: (f, a) => f(...a)
|
|
5650
6051
|
});
|
|
5651
6052
|
} catch {
|
|
5652
|
-
|
|
5653
|
-
F:
|
|
6053
|
+
log19("stealing lock...", void 0, {
|
|
6054
|
+
F: __dxlog_file22,
|
|
5654
6055
|
L: 46,
|
|
5655
6056
|
S: this,
|
|
5656
6057
|
C: (f, a) => f(...a)
|
|
5657
6058
|
});
|
|
5658
6059
|
await this._requestLock(true);
|
|
5659
|
-
|
|
5660
|
-
F:
|
|
6060
|
+
log19("stolen lock", void 0, {
|
|
6061
|
+
F: __dxlog_file22,
|
|
5661
6062
|
L: 48,
|
|
5662
6063
|
S: this,
|
|
5663
6064
|
C: (f, a) => f(...a)
|
|
@@ -5673,31 +6074,31 @@ var Lock = class {
|
|
|
5673
6074
|
}
|
|
5674
6075
|
}
|
|
5675
6076
|
async _requestLock(steal = false) {
|
|
5676
|
-
|
|
6077
|
+
log19("requesting lock...", {
|
|
5677
6078
|
steal
|
|
5678
6079
|
}, {
|
|
5679
|
-
F:
|
|
6080
|
+
F: __dxlog_file22,
|
|
5680
6081
|
L: 63,
|
|
5681
6082
|
S: this,
|
|
5682
6083
|
C: (f, a) => f(...a)
|
|
5683
6084
|
});
|
|
5684
|
-
const acquired = new
|
|
6085
|
+
const acquired = new Trigger9();
|
|
5685
6086
|
void navigator.locks.request(this._lockKey, {
|
|
5686
6087
|
steal
|
|
5687
6088
|
}, async () => {
|
|
5688
6089
|
await this._onAcquire?.();
|
|
5689
6090
|
acquired.wake();
|
|
5690
|
-
this._releaseTrigger = new
|
|
6091
|
+
this._releaseTrigger = new Trigger9();
|
|
5691
6092
|
await this._releaseTrigger.wait();
|
|
5692
|
-
|
|
5693
|
-
F:
|
|
6093
|
+
log19("releasing lock...", void 0, {
|
|
6094
|
+
F: __dxlog_file22,
|
|
5694
6095
|
L: 72,
|
|
5695
6096
|
S: this,
|
|
5696
6097
|
C: (f, a) => f(...a)
|
|
5697
6098
|
});
|
|
5698
6099
|
await this._onRelease?.();
|
|
5699
|
-
|
|
5700
|
-
F:
|
|
6100
|
+
log19("released lock", void 0, {
|
|
6101
|
+
F: __dxlog_file22,
|
|
5701
6102
|
L: 74,
|
|
5702
6103
|
S: this,
|
|
5703
6104
|
C: (f, a) => f(...a)
|
|
@@ -5706,10 +6107,10 @@ var Lock = class {
|
|
|
5706
6107
|
await this._onRelease?.();
|
|
5707
6108
|
});
|
|
5708
6109
|
await acquired.wait();
|
|
5709
|
-
|
|
6110
|
+
log19("recieved lock", {
|
|
5710
6111
|
steal
|
|
5711
6112
|
}, {
|
|
5712
|
-
F:
|
|
6113
|
+
F: __dxlog_file22,
|
|
5713
6114
|
L: 81,
|
|
5714
6115
|
S: this,
|
|
5715
6116
|
C: (f, a) => f(...a)
|
|
@@ -5799,19 +6200,16 @@ var createLevel = async (config) => {
|
|
|
5799
6200
|
|
|
5800
6201
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
5801
6202
|
import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
|
|
5802
|
-
import { clientServiceBundle
|
|
6203
|
+
import { clientServiceBundle } from "@dxos/client-protocol";
|
|
5803
6204
|
import { Context as Context11 } from "@dxos/context";
|
|
5804
|
-
import { encodeReference } from "@dxos/echo-protocol";
|
|
5805
|
-
import { getTypeReference } from "@dxos/echo-schema";
|
|
5806
6205
|
import { invariant as invariant18 } from "@dxos/invariant";
|
|
5807
6206
|
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
5808
|
-
import { log as
|
|
6207
|
+
import { log as log21 } from "@dxos/log";
|
|
5809
6208
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
5810
6209
|
import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
5811
6210
|
import { trace as trace10 } from "@dxos/protocols";
|
|
5812
6211
|
import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
5813
6212
|
import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
|
|
5814
|
-
import { assignDeep as assignDeep2 } from "@dxos/util";
|
|
5815
6213
|
import { WebsocketRpcClient } from "@dxos/websocket-rpc";
|
|
5816
6214
|
|
|
5817
6215
|
// packages/sdk/client-services/src/packlets/devices/devices-service.ts
|
|
@@ -5819,7 +6217,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
|
|
|
5819
6217
|
import { Stream as Stream11 } from "@dxos/codec-protobuf";
|
|
5820
6218
|
import { invariant as invariant17 } from "@dxos/invariant";
|
|
5821
6219
|
import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5822
|
-
var
|
|
6220
|
+
var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
5823
6221
|
var DevicesServiceImpl = class {
|
|
5824
6222
|
constructor(_identityManager) {
|
|
5825
6223
|
this._identityManager = _identityManager;
|
|
@@ -5837,7 +6235,7 @@ var DevicesServiceImpl = class {
|
|
|
5837
6235
|
});
|
|
5838
6236
|
} else {
|
|
5839
6237
|
invariant17(this._identityManager.identity?.presence, "presence not present", {
|
|
5840
|
-
F:
|
|
6238
|
+
F: __dxlog_file23,
|
|
5841
6239
|
L: 32,
|
|
5842
6240
|
S: this,
|
|
5843
6241
|
A: [
|
|
@@ -5947,7 +6345,7 @@ var findConfigs = () => {
|
|
|
5947
6345
|
import { Event as Event8 } from "@dxos/async";
|
|
5948
6346
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5949
6347
|
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5950
|
-
import { getContextFromEntry, log as
|
|
6348
|
+
import { getContextFromEntry, log as log20 } from "@dxos/log";
|
|
5951
6349
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5952
6350
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
5953
6351
|
var LoggingServiceImpl = class {
|
|
@@ -5960,11 +6358,11 @@ var LoggingServiceImpl = class {
|
|
|
5960
6358
|
};
|
|
5961
6359
|
}
|
|
5962
6360
|
async open() {
|
|
5963
|
-
|
|
6361
|
+
log20.runtimeConfig.processors.push(this._logProcessor);
|
|
5964
6362
|
}
|
|
5965
6363
|
async close() {
|
|
5966
|
-
const index =
|
|
5967
|
-
|
|
6364
|
+
const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
6365
|
+
log20.runtimeConfig.processors.splice(index, 1);
|
|
5968
6366
|
}
|
|
5969
6367
|
async controlMetrics({ reset, record }) {
|
|
5970
6368
|
if (reset) {
|
|
@@ -6168,7 +6566,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
6168
6566
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6169
6567
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6170
6568
|
}
|
|
6171
|
-
var
|
|
6569
|
+
var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
|
|
6172
6570
|
var ClientServicesHost = class {
|
|
6173
6571
|
constructor({
|
|
6174
6572
|
config,
|
|
@@ -6188,7 +6586,7 @@ var ClientServicesHost = class {
|
|
|
6188
6586
|
this._storage = storage;
|
|
6189
6587
|
this._level = level;
|
|
6190
6588
|
this._callbacks = callbacks;
|
|
6191
|
-
this._runtimeParams = runtimeParams;
|
|
6589
|
+
this._runtimeParams = runtimeParams ?? {};
|
|
6192
6590
|
if (config) {
|
|
6193
6591
|
this.initialize({
|
|
6194
6592
|
config,
|
|
@@ -6201,7 +6599,10 @@ var ClientServicesHost = class {
|
|
|
6201
6599
|
lockKey,
|
|
6202
6600
|
onAcquire: () => {
|
|
6203
6601
|
if (!this._opening) {
|
|
6204
|
-
void this.open(new Context11(
|
|
6602
|
+
void this.open(new Context11(void 0, {
|
|
6603
|
+
F: __dxlog_file24,
|
|
6604
|
+
L: 120
|
|
6605
|
+
}));
|
|
6205
6606
|
}
|
|
6206
6607
|
},
|
|
6207
6608
|
onRelease: () => this.close()
|
|
@@ -6257,24 +6658,24 @@ var ClientServicesHost = class {
|
|
|
6257
6658
|
*/
|
|
6258
6659
|
initialize({ config, ...options }) {
|
|
6259
6660
|
invariant18(!this._open, "service host is open", {
|
|
6260
|
-
F:
|
|
6261
|
-
L:
|
|
6661
|
+
F: __dxlog_file24,
|
|
6662
|
+
L: 186,
|
|
6262
6663
|
S: this,
|
|
6263
6664
|
A: [
|
|
6264
6665
|
"!this._open",
|
|
6265
6666
|
"'service host is open'"
|
|
6266
6667
|
]
|
|
6267
6668
|
});
|
|
6268
|
-
|
|
6269
|
-
F:
|
|
6270
|
-
L:
|
|
6669
|
+
log21("initializing...", void 0, {
|
|
6670
|
+
F: __dxlog_file24,
|
|
6671
|
+
L: 187,
|
|
6271
6672
|
S: this,
|
|
6272
6673
|
C: (f, a) => f(...a)
|
|
6273
6674
|
});
|
|
6274
6675
|
if (config) {
|
|
6275
6676
|
invariant18(!this._config, "config already set", {
|
|
6276
|
-
F:
|
|
6277
|
-
L:
|
|
6677
|
+
F: __dxlog_file24,
|
|
6678
|
+
L: 190,
|
|
6278
6679
|
S: this,
|
|
6279
6680
|
A: [
|
|
6280
6681
|
"!this._config",
|
|
@@ -6287,9 +6688,9 @@ var ClientServicesHost = class {
|
|
|
6287
6688
|
}
|
|
6288
6689
|
}
|
|
6289
6690
|
if (!options.signalManager) {
|
|
6290
|
-
|
|
6291
|
-
F:
|
|
6292
|
-
L:
|
|
6691
|
+
log21.warn("running signaling without telemetry metadata.", void 0, {
|
|
6692
|
+
F: __dxlog_file24,
|
|
6693
|
+
L: 198,
|
|
6293
6694
|
S: this,
|
|
6294
6695
|
C: (f, a) => f(...a)
|
|
6295
6696
|
});
|
|
@@ -6299,8 +6700,8 @@ var ClientServicesHost = class {
|
|
|
6299
6700
|
}), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
|
|
6300
6701
|
this._signalManager = signalManager;
|
|
6301
6702
|
invariant18(!this._networkManager, "network manager already set", {
|
|
6302
|
-
F:
|
|
6303
|
-
L:
|
|
6703
|
+
F: __dxlog_file24,
|
|
6704
|
+
L: 209,
|
|
6304
6705
|
S: this,
|
|
6305
6706
|
A: [
|
|
6306
6707
|
"!this._networkManager",
|
|
@@ -6312,9 +6713,9 @@ var ClientServicesHost = class {
|
|
|
6312
6713
|
transportFactory,
|
|
6313
6714
|
signalManager
|
|
6314
6715
|
});
|
|
6315
|
-
|
|
6316
|
-
F:
|
|
6317
|
-
L:
|
|
6716
|
+
log21("initialized", void 0, {
|
|
6717
|
+
F: __dxlog_file24,
|
|
6718
|
+
L: 216,
|
|
6318
6719
|
S: this,
|
|
6319
6720
|
C: (f, a) => f(...a)
|
|
6320
6721
|
});
|
|
@@ -6324,17 +6725,17 @@ var ClientServicesHost = class {
|
|
|
6324
6725
|
return;
|
|
6325
6726
|
}
|
|
6326
6727
|
const traceId = PublicKey16.random().toHex();
|
|
6327
|
-
|
|
6728
|
+
log21.trace("dxos.client-services.host.open", trace10.begin({
|
|
6328
6729
|
id: traceId
|
|
6329
6730
|
}), {
|
|
6330
|
-
F:
|
|
6331
|
-
L:
|
|
6731
|
+
F: __dxlog_file24,
|
|
6732
|
+
L: 227,
|
|
6332
6733
|
S: this,
|
|
6333
6734
|
C: (f, a) => f(...a)
|
|
6334
6735
|
});
|
|
6335
6736
|
invariant18(this._config, "config not set", {
|
|
6336
|
-
F:
|
|
6337
|
-
L:
|
|
6737
|
+
F: __dxlog_file24,
|
|
6738
|
+
L: 229,
|
|
6338
6739
|
S: this,
|
|
6339
6740
|
A: [
|
|
6340
6741
|
"this._config",
|
|
@@ -6342,8 +6743,8 @@ var ClientServicesHost = class {
|
|
|
6342
6743
|
]
|
|
6343
6744
|
});
|
|
6344
6745
|
invariant18(this._storage, "storage not set", {
|
|
6345
|
-
F:
|
|
6346
|
-
L:
|
|
6746
|
+
F: __dxlog_file24,
|
|
6747
|
+
L: 230,
|
|
6347
6748
|
S: this,
|
|
6348
6749
|
A: [
|
|
6349
6750
|
"this._storage",
|
|
@@ -6351,8 +6752,8 @@ var ClientServicesHost = class {
|
|
|
6351
6752
|
]
|
|
6352
6753
|
});
|
|
6353
6754
|
invariant18(this._signalManager, "signal manager not set", {
|
|
6354
|
-
F:
|
|
6355
|
-
L:
|
|
6755
|
+
F: __dxlog_file24,
|
|
6756
|
+
L: 231,
|
|
6356
6757
|
S: this,
|
|
6357
6758
|
A: [
|
|
6358
6759
|
"this._signalManager",
|
|
@@ -6360,8 +6761,8 @@ var ClientServicesHost = class {
|
|
|
6360
6761
|
]
|
|
6361
6762
|
});
|
|
6362
6763
|
invariant18(this._networkManager, "network manager not set", {
|
|
6363
|
-
F:
|
|
6364
|
-
L:
|
|
6764
|
+
F: __dxlog_file24,
|
|
6765
|
+
L: 232,
|
|
6365
6766
|
S: this,
|
|
6366
6767
|
A: [
|
|
6367
6768
|
"this._networkManager",
|
|
@@ -6369,11 +6770,11 @@ var ClientServicesHost = class {
|
|
|
6369
6770
|
]
|
|
6370
6771
|
});
|
|
6371
6772
|
this._opening = true;
|
|
6372
|
-
|
|
6773
|
+
log21("opening...", {
|
|
6373
6774
|
lockKey: this._resourceLock?.lockKey
|
|
6374
6775
|
}, {
|
|
6375
|
-
F:
|
|
6376
|
-
L:
|
|
6776
|
+
F: __dxlog_file24,
|
|
6777
|
+
L: 235,
|
|
6377
6778
|
S: this,
|
|
6378
6779
|
C: (f, a) => f(...a)
|
|
6379
6780
|
});
|
|
@@ -6384,9 +6785,10 @@ var ClientServicesHost = class {
|
|
|
6384
6785
|
await this._level.open();
|
|
6385
6786
|
await this._loggingService.open();
|
|
6386
6787
|
this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
|
|
6788
|
+
const identityService = new IdentityServiceImpl(this._serviceContext.identityManager, this._serviceContext.keyring, () => this._serviceContext.dataSpaceManager, (params) => this._createIdentity(params), (profile) => this._serviceContext.broadcastProfileUpdate(profile));
|
|
6387
6789
|
this._serviceRegistry.setServices({
|
|
6388
6790
|
SystemService: this._systemService,
|
|
6389
|
-
IdentityService:
|
|
6791
|
+
IdentityService: identityService,
|
|
6390
6792
|
InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
|
|
6391
6793
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
6392
6794
|
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
|
|
@@ -6406,6 +6808,7 @@ var ClientServicesHost = class {
|
|
|
6406
6808
|
})
|
|
6407
6809
|
});
|
|
6408
6810
|
await this._serviceContext.open(ctx);
|
|
6811
|
+
await identityService.open();
|
|
6409
6812
|
const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
|
|
6410
6813
|
if (devtoolsProxy) {
|
|
6411
6814
|
this._devtoolsProxy = new WebsocketRpcClient({
|
|
@@ -6421,18 +6824,18 @@ var ClientServicesHost = class {
|
|
|
6421
6824
|
this._open = true;
|
|
6422
6825
|
this._statusUpdate.emit();
|
|
6423
6826
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
6424
|
-
|
|
6827
|
+
log21("opened", {
|
|
6425
6828
|
deviceKey
|
|
6426
6829
|
}, {
|
|
6427
|
-
F:
|
|
6830
|
+
F: __dxlog_file24,
|
|
6428
6831
|
L: 314,
|
|
6429
6832
|
S: this,
|
|
6430
6833
|
C: (f, a) => f(...a)
|
|
6431
6834
|
});
|
|
6432
|
-
|
|
6835
|
+
log21.trace("dxos.client-services.host.open", trace10.end({
|
|
6433
6836
|
id: traceId
|
|
6434
6837
|
}), {
|
|
6435
|
-
F:
|
|
6838
|
+
F: __dxlog_file24,
|
|
6436
6839
|
L: 315,
|
|
6437
6840
|
S: this,
|
|
6438
6841
|
C: (f, a) => f(...a)
|
|
@@ -6443,10 +6846,10 @@ var ClientServicesHost = class {
|
|
|
6443
6846
|
return;
|
|
6444
6847
|
}
|
|
6445
6848
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
6446
|
-
|
|
6849
|
+
log21("closing...", {
|
|
6447
6850
|
deviceKey
|
|
6448
6851
|
}, {
|
|
6449
|
-
F:
|
|
6852
|
+
F: __dxlog_file24,
|
|
6450
6853
|
L: 326,
|
|
6451
6854
|
S: this,
|
|
6452
6855
|
C: (f, a) => f(...a)
|
|
@@ -6461,10 +6864,10 @@ var ClientServicesHost = class {
|
|
|
6461
6864
|
await this._level?.close();
|
|
6462
6865
|
this._open = false;
|
|
6463
6866
|
this._statusUpdate.emit();
|
|
6464
|
-
|
|
6867
|
+
log21("closed", {
|
|
6465
6868
|
deviceKey
|
|
6466
6869
|
}, {
|
|
6467
|
-
F:
|
|
6870
|
+
F: __dxlog_file24,
|
|
6468
6871
|
L: 335,
|
|
6469
6872
|
S: this,
|
|
6470
6873
|
C: (f, a) => f(...a)
|
|
@@ -6472,32 +6875,32 @@ var ClientServicesHost = class {
|
|
|
6472
6875
|
}
|
|
6473
6876
|
async reset() {
|
|
6474
6877
|
const traceId = PublicKey16.random().toHex();
|
|
6475
|
-
|
|
6878
|
+
log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
|
|
6476
6879
|
id: traceId
|
|
6477
6880
|
}), {
|
|
6478
|
-
F:
|
|
6881
|
+
F: __dxlog_file24,
|
|
6479
6882
|
L: 340,
|
|
6480
6883
|
S: this,
|
|
6481
6884
|
C: (f, a) => f(...a)
|
|
6482
6885
|
});
|
|
6483
|
-
|
|
6484
|
-
F:
|
|
6886
|
+
log21.info("resetting...", void 0, {
|
|
6887
|
+
F: __dxlog_file24,
|
|
6485
6888
|
L: 342,
|
|
6486
6889
|
S: this,
|
|
6487
6890
|
C: (f, a) => f(...a)
|
|
6488
6891
|
});
|
|
6489
6892
|
await this._serviceContext?.close();
|
|
6490
6893
|
await this._storage.reset();
|
|
6491
|
-
|
|
6492
|
-
F:
|
|
6894
|
+
log21.info("reset", void 0, {
|
|
6895
|
+
F: __dxlog_file24,
|
|
6493
6896
|
L: 345,
|
|
6494
6897
|
S: this,
|
|
6495
6898
|
C: (f, a) => f(...a)
|
|
6496
6899
|
});
|
|
6497
|
-
|
|
6900
|
+
log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
|
|
6498
6901
|
id: traceId
|
|
6499
6902
|
}), {
|
|
6500
|
-
F:
|
|
6903
|
+
F: __dxlog_file24,
|
|
6501
6904
|
L: 346,
|
|
6502
6905
|
S: this,
|
|
6503
6906
|
C: (f, a) => f(...a)
|
|
@@ -6507,38 +6910,6 @@ var ClientServicesHost = class {
|
|
|
6507
6910
|
async _createIdentity(params) {
|
|
6508
6911
|
const identity = await this._serviceContext.createIdentity(params);
|
|
6509
6912
|
await this._serviceContext.initialized.wait();
|
|
6510
|
-
const space = await this._serviceContext.dataSpaceManager.createSpace();
|
|
6511
|
-
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
6512
|
-
invariant18(automergeIndex, void 0, {
|
|
6513
|
-
F: __dxlog_file21,
|
|
6514
|
-
L: 358,
|
|
6515
|
-
S: this,
|
|
6516
|
-
A: [
|
|
6517
|
-
"automergeIndex",
|
|
6518
|
-
""
|
|
6519
|
-
]
|
|
6520
|
-
});
|
|
6521
|
-
const document = this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
|
|
6522
|
-
await document.whenReady();
|
|
6523
|
-
const properties = {
|
|
6524
|
-
system: {
|
|
6525
|
-
type: encodeReference(getTypeReference(PropertiesType))
|
|
6526
|
-
},
|
|
6527
|
-
data: {
|
|
6528
|
-
[defaultKey]: identity.identityKey.toHex()
|
|
6529
|
-
},
|
|
6530
|
-
meta: {
|
|
6531
|
-
keys: []
|
|
6532
|
-
}
|
|
6533
|
-
};
|
|
6534
|
-
const propertiesId = PublicKey16.random().toHex();
|
|
6535
|
-
document.change((doc) => {
|
|
6536
|
-
assignDeep2(doc, [
|
|
6537
|
-
"objects",
|
|
6538
|
-
propertiesId
|
|
6539
|
-
], properties);
|
|
6540
|
-
});
|
|
6541
|
-
await this._serviceContext.echoHost.flush();
|
|
6542
6913
|
return identity;
|
|
6543
6914
|
}
|
|
6544
6915
|
};
|
|
@@ -6588,7 +6959,6 @@ export {
|
|
|
6588
6959
|
SpaceInvitationProtocol,
|
|
6589
6960
|
InvitationsManager,
|
|
6590
6961
|
DataSpace,
|
|
6591
|
-
findPropertiesObject,
|
|
6592
6962
|
DataSpaceManager,
|
|
6593
6963
|
SpacesServiceImpl,
|
|
6594
6964
|
ServiceContext,
|
|
@@ -6601,4 +6971,4 @@ export {
|
|
|
6601
6971
|
ClientServicesProviderResource,
|
|
6602
6972
|
DiagnosticsCollector
|
|
6603
6973
|
};
|
|
6604
|
-
//# sourceMappingURL=chunk-
|
|
6974
|
+
//# sourceMappingURL=chunk-J4DDMC6A.mjs.map
|