@dxos/client-services 0.1.41 → 0.1.45-next.45667d4
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-T73F4MV4.mjs → chunk-IHSMRQ3L.mjs} +985 -867
- package/dist/lib/browser/chunk-IHSMRQ3L.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +7 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +121 -297
- package/dist/lib/browser/packlets/testing/index.mjs.map +4 -4
- package/dist/lib/node/index.cjs +589 -469
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +688 -740
- package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +4 -2
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +5 -4
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +2 -4
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts +2 -3
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -3
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -2
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +6 -4
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/index.d.ts +0 -1
- package/dist/types/src/packlets/services/index.d.ts.map +1 -1
- package/dist/types/src/packlets/services/local-client-services.d.ts +1 -1
- package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +4 -2
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +16 -9
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +12 -7
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +15 -10
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +5 -0
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +4 -4
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/credential-utils.d.ts +1 -1
- package/dist/types/src/packlets/testing/index.d.ts +0 -1
- package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +13 -7
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +35 -32
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +1 -1
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts +5 -2
- package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +1 -1
- package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-runtime.d.ts +1 -1
- package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-session.d.ts +4 -7
- package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
- package/package.json +30 -31
- package/src/index.ts +1 -0
- package/src/packlets/devices/devices-service.ts +5 -5
- package/src/packlets/devtools/devtools.ts +25 -4
- package/src/packlets/devtools/feeds.ts +10 -10
- package/src/packlets/devtools/keys.ts +6 -6
- package/src/packlets/devtools/network.ts +14 -13
- package/src/packlets/devtools/spaces.ts +4 -4
- package/src/packlets/identity/authenticator.test.ts +1 -1
- package/src/packlets/identity/authenticator.ts +2 -2
- package/src/packlets/identity/identity-manager.test.ts +17 -13
- package/src/packlets/identity/identity-manager.ts +21 -22
- package/src/packlets/identity/identity-service.ts +3 -3
- package/src/packlets/identity/identity.test.ts +65 -36
- package/src/packlets/identity/identity.ts +17 -17
- package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
- package/src/packlets/invitations/device-invitation-protocol.ts +7 -7
- package/src/packlets/invitations/invitation-extension.ts +16 -27
- package/src/packlets/invitations/invitations-handler.ts +17 -25
- package/src/packlets/invitations/invitations-service.ts +11 -11
- package/src/packlets/invitations/space-invitation-protocol.test.ts +9 -9
- package/src/packlets/invitations/space-invitation-protocol.ts +11 -12
- package/src/packlets/logging/logging-service.ts +8 -3
- package/src/packlets/network/network-service.test.ts +8 -8
- package/src/packlets/network/network-service.ts +20 -8
- package/src/packlets/services/client-rpc-server.ts +5 -5
- package/src/packlets/services/index.ts +0 -1
- package/src/packlets/services/local-client-services.ts +1 -1
- package/src/packlets/services/service-context.test.ts +3 -3
- package/src/packlets/services/service-context.ts +26 -24
- package/src/packlets/services/service-host.test.ts +6 -6
- package/src/packlets/services/service-host.ts +57 -31
- package/src/packlets/services/service-registry.test.ts +20 -38
- package/src/packlets/spaces/data-space-manager.test.ts +17 -29
- package/src/packlets/spaces/data-space-manager.ts +29 -35
- package/src/packlets/spaces/data-space.ts +73 -47
- package/src/packlets/spaces/genesis.ts +81 -0
- package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.ts +12 -12
- package/src/packlets/spaces/spaces-service.test.ts +2 -2
- package/src/packlets/spaces/spaces-service.ts +21 -10
- package/src/packlets/storage/storage.ts +3 -3
- package/src/packlets/system/system-service.test.ts +1 -1
- package/src/packlets/system/system-service.ts +1 -1
- package/src/packlets/testing/credential-utils.ts +4 -4
- package/src/packlets/testing/index.ts +0 -1
- package/src/packlets/testing/invitation-utils.ts +28 -33
- package/src/packlets/testing/test-builder.ts +132 -168
- package/src/packlets/vault/iframe-host-runtime.ts +8 -11
- package/src/packlets/vault/iframe-proxy-runtime.ts +25 -9
- package/src/packlets/vault/shell-runtime.ts +4 -4
- package/src/packlets/vault/vault-resource-lock.ts +2 -2
- package/src/packlets/vault/worker-runtime.ts +7 -9
- package/src/packlets/vault/worker-session.ts +24 -45
- package/dist/lib/browser/chunk-T73F4MV4.mjs.map +0 -7
- package/dist/types/src/packlets/services/utils.d.ts +0 -7
- package/dist/types/src/packlets/services/utils.d.ts.map +0 -1
- package/dist/types/src/packlets/testing/host-test-builder.d.ts +0 -43
- package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/client-services.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/client-services.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/client.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/client.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/halo-credentials.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/halo-credentials.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/halo-persistent.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/halo-persistent.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/halo-profile.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/halo-profile.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/invitations.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/invitations.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/shared-worker.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/shared-worker.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/spaces.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/spaces.test.d.ts.map +0 -1
- package/dist/types/src/packlets/tests/text.test.d.ts +0 -2
- package/dist/types/src/packlets/tests/text.test.d.ts.map +0 -1
- package/src/packlets/services/utils.ts +0 -53
- package/src/packlets/testing/host-test-builder.ts +0 -163
- package/src/packlets/tests/client-services.test.ts +0 -222
- package/src/packlets/tests/client.test.ts +0 -140
- package/src/packlets/tests/halo-credentials.test.ts +0 -94
- package/src/packlets/tests/halo-persistent.test.ts +0 -53
- package/src/packlets/tests/halo-profile.test.ts +0 -48
- package/src/packlets/tests/invitations.test.ts +0 -389
- package/src/packlets/tests/shared-worker.test.ts +0 -92
- package/src/packlets/tests/spaces-invitations.test.ts +0 -46
- package/src/packlets/tests/spaces.test.ts +0 -147
- package/src/packlets/tests/text.test.ts +0 -206
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
import assert from 'node:assert';
|
|
6
6
|
|
|
7
7
|
import { Event } from '@dxos/async';
|
|
8
|
-
import { AuthenticatingInvitationObservable, CancellableInvitationObservable } from '@dxos/client';
|
|
8
|
+
import { AuthenticatingInvitationObservable, CancellableInvitationObservable } from '@dxos/client-protocol';
|
|
9
9
|
import { Stream } from '@dxos/codec-protobuf';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import {
|
|
12
12
|
AuthenticationRequest,
|
|
13
13
|
Invitation,
|
|
14
14
|
InvitationsService,
|
|
15
|
-
QueryInvitationsResponse
|
|
15
|
+
QueryInvitationsResponse,
|
|
16
16
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
17
17
|
|
|
18
18
|
import { InvitationProtocol } from './invitation-protocol';
|
|
@@ -31,7 +31,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
31
31
|
|
|
32
32
|
constructor(
|
|
33
33
|
private readonly _invitationsHandler: InvitationsHandler,
|
|
34
|
-
private readonly _getHandler: (invitation: Invitation) => InvitationProtocol
|
|
34
|
+
private readonly _getHandler: (invitation: Invitation) => InvitationProtocol,
|
|
35
35
|
) {}
|
|
36
36
|
|
|
37
37
|
// TODO(burdon): Guest/host label.
|
|
@@ -65,7 +65,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
65
65
|
() => {
|
|
66
66
|
close();
|
|
67
67
|
this._createInvitations.delete(invitation.get().invitationId);
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
69
|
);
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -94,7 +94,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
94
94
|
() => {
|
|
95
95
|
close();
|
|
96
96
|
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
97
|
-
}
|
|
97
|
+
},
|
|
98
98
|
);
|
|
99
99
|
});
|
|
100
100
|
}
|
|
@@ -135,7 +135,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
135
135
|
next({
|
|
136
136
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
137
137
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
138
|
-
invitations: [invitation]
|
|
138
|
+
invitations: [invitation],
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
|
|
@@ -143,7 +143,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
143
143
|
next({
|
|
144
144
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
145
145
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
146
|
-
invitations: [invitation]
|
|
146
|
+
invitations: [invitation],
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
@@ -152,7 +152,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
152
152
|
next({
|
|
153
153
|
action: QueryInvitationsResponse.Action.REMOVED,
|
|
154
154
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
155
|
-
invitations: [invitation]
|
|
155
|
+
invitations: [invitation],
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
|
|
@@ -160,7 +160,7 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
160
160
|
next({
|
|
161
161
|
action: QueryInvitationsResponse.Action.REMOVED,
|
|
162
162
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
163
|
-
invitations: [invitation]
|
|
163
|
+
invitations: [invitation],
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
166
|
|
|
@@ -168,13 +168,13 @@ export class InvitationsServiceImpl implements InvitationsService {
|
|
|
168
168
|
next({
|
|
169
169
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
170
170
|
type: QueryInvitationsResponse.Type.CREATED,
|
|
171
|
-
invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
|
|
171
|
+
invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
next({
|
|
175
175
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
176
176
|
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
177
|
-
invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
|
|
177
|
+
invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
180
|
}
|
|
@@ -94,10 +94,10 @@ describe('services/space-invitations-protocol', () => {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
})
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
101
|
);
|
|
102
102
|
|
|
103
103
|
expect(attempt).to.eq(1);
|
|
@@ -121,7 +121,7 @@ describe('services/space-invitations-protocol', () => {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
expect(
|
|
124
|
-
guest.identityManager.identity?.space.spaceState.getCredentialsOfType('dxos.halo.credentials.SpaceMember').length
|
|
124
|
+
guest.identityManager.identity?.space.spaceState.getCredentialsOfType('dxos.halo.credentials.SpaceMember').length,
|
|
125
125
|
).to.equal(2); // own halo + newly joined space.
|
|
126
126
|
});
|
|
127
127
|
|
|
@@ -146,14 +146,14 @@ describe('services/space-invitations-protocol', () => {
|
|
|
146
146
|
void invitation.cancel();
|
|
147
147
|
return true;
|
|
148
148
|
},
|
|
149
|
-
onSuccess: () => raise(new Error('invitation success'))
|
|
149
|
+
onSuccess: () => raise(new Error('invitation success')),
|
|
150
150
|
},
|
|
151
151
|
guest: {
|
|
152
152
|
onConnecting: (invitation) => {
|
|
153
153
|
guestConnected.wake(invitation.get());
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
const { swarmKey: swarmKey1 } = await hostConnected.wait();
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import assert from 'node:assert';
|
|
6
6
|
|
|
7
7
|
import { createAdmissionCredentials, getCredentialAssertion } from '@dxos/credentials';
|
|
8
|
-
import { SigningContext } from '@dxos/echo-pipeline';
|
|
9
8
|
import { writeMessages } from '@dxos/feed-store';
|
|
10
9
|
import { Keyring } from '@dxos/keyring';
|
|
11
10
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -15,7 +14,7 @@ import { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
|
15
14
|
import { ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
16
15
|
import { AdmissionRequest, AdmissionResponse, IntroductionRequest } from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
17
16
|
|
|
18
|
-
import { DataSpaceManager } from '../spaces';
|
|
17
|
+
import { DataSpaceManager, SigningContext } from '../spaces';
|
|
19
18
|
import { InvitationProtocol } from './invitation-protocol';
|
|
20
19
|
|
|
21
20
|
export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
@@ -23,20 +22,20 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
23
22
|
private readonly _spaceManager: DataSpaceManager,
|
|
24
23
|
private readonly _signingContext: SigningContext,
|
|
25
24
|
private readonly _keyring: Keyring,
|
|
26
|
-
private readonly _spaceKey?: PublicKey
|
|
25
|
+
private readonly _spaceKey?: PublicKey,
|
|
27
26
|
) {}
|
|
28
27
|
|
|
29
28
|
toJSON(): object {
|
|
30
29
|
return {
|
|
31
30
|
deviceKey: this._signingContext.deviceKey,
|
|
32
|
-
spaceKey: this._spaceKey
|
|
31
|
+
spaceKey: this._spaceKey,
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
getInvitationContext(): Partial<Invitation> & Pick<Invitation, 'kind'> {
|
|
37
36
|
return {
|
|
38
37
|
kind: Invitation.Kind.SPACE,
|
|
39
|
-
spaceKey: this._spaceKey
|
|
38
|
+
spaceKey: this._spaceKey,
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -55,7 +54,7 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
55
54
|
identityKey,
|
|
56
55
|
space.key,
|
|
57
56
|
space.inner.genesisFeedKey,
|
|
58
|
-
guestProfile
|
|
57
|
+
guestProfile,
|
|
59
58
|
);
|
|
60
59
|
|
|
61
60
|
// TODO(dmaretskyi): Refactor.
|
|
@@ -69,14 +68,14 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
69
68
|
space: {
|
|
70
69
|
credential: spaceMemberCredential,
|
|
71
70
|
controlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
72
|
-
dataTimeframe: space.dataPipeline.pipelineState?.timeframe
|
|
73
|
-
}
|
|
71
|
+
dataTimeframe: space.dataPipeline.pipelineState?.timeframe,
|
|
72
|
+
},
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
createIntroduction(): IntroductionRequest {
|
|
78
77
|
return {
|
|
79
|
-
profile: this._signingContext.profile
|
|
78
|
+
profile: this._signingContext.profile,
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
81
|
|
|
@@ -90,8 +89,8 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
90
89
|
identityKey: this._signingContext.identityKey,
|
|
91
90
|
deviceKey: this._signingContext.deviceKey,
|
|
92
91
|
controlFeedKey,
|
|
93
|
-
dataFeedKey
|
|
94
|
-
}
|
|
92
|
+
dataFeedKey,
|
|
93
|
+
},
|
|
95
94
|
};
|
|
96
95
|
}
|
|
97
96
|
|
|
@@ -107,7 +106,7 @@ export class SpaceInvitationProtocol implements InvitationProtocol {
|
|
|
107
106
|
spaceKey: assertion.spaceKey,
|
|
108
107
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
109
108
|
controlTimeframe,
|
|
110
|
-
dataTimeframe
|
|
109
|
+
dataTimeframe,
|
|
111
110
|
});
|
|
112
111
|
|
|
113
112
|
await this._signingContext.recordCredential(credential);
|
|
@@ -56,19 +56,24 @@ export class LoggingServiceImpl implements LoggingService {
|
|
|
56
56
|
/**
|
|
57
57
|
* Recursively converts an object into a JSON-compatible object.
|
|
58
58
|
*/
|
|
59
|
-
const jsonify = (value: any): any => {
|
|
59
|
+
const jsonify = (value: any, handles = new WeakSet<any>()): any => {
|
|
60
60
|
if (typeof value === 'function') {
|
|
61
61
|
return null;
|
|
62
62
|
} else if (typeof value === 'object' && value !== null) {
|
|
63
|
+
if (handles.has(value)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
handles.add(value);
|
|
67
|
+
|
|
63
68
|
if (Array.isArray(value)) {
|
|
64
|
-
return value.map(jsonify);
|
|
69
|
+
return value.map((x) => jsonify(x, handles));
|
|
65
70
|
} else {
|
|
66
71
|
if (typeof value.toJSON === 'function') {
|
|
67
72
|
return value.toJSON();
|
|
68
73
|
}
|
|
69
74
|
const res: any = {};
|
|
70
75
|
for (const key of Object.keys(value)) {
|
|
71
|
-
res[key] = jsonify(value[key]);
|
|
76
|
+
res[key] = jsonify(value[key], handles);
|
|
72
77
|
}
|
|
73
78
|
return res;
|
|
74
79
|
}
|
|
@@ -19,7 +19,7 @@ describe('NetworkService', () => {
|
|
|
19
19
|
beforeEach(async () => {
|
|
20
20
|
serviceContext = createServiceContext();
|
|
21
21
|
await serviceContext.open();
|
|
22
|
-
networkService = new NetworkServiceImpl(serviceContext.networkManager);
|
|
22
|
+
networkService = new NetworkServiceImpl(serviceContext.networkManager, serviceContext.signalManager);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
afterEach(async () => {
|
|
@@ -27,25 +27,25 @@ describe('NetworkService', () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('setNetworkOptions changes network status', async () => {
|
|
30
|
-
await networkService.
|
|
31
|
-
|
|
30
|
+
await networkService.updateConfig({
|
|
31
|
+
swarm: ConnectionState.OFFLINE,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
expect(serviceContext.networkManager.connectionState).to.equal(ConnectionState.OFFLINE);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('subscribeToNetworkStatus returns current network status', async () => {
|
|
38
|
-
const query = networkService.
|
|
38
|
+
const query = networkService.queryStatus();
|
|
39
39
|
let result = new Trigger<ConnectionState | undefined>();
|
|
40
|
-
query.subscribe(({
|
|
41
|
-
result.wake(
|
|
40
|
+
query.subscribe(({ swarm }) => {
|
|
41
|
+
result.wake(swarm);
|
|
42
42
|
});
|
|
43
43
|
afterTest(() => query.close());
|
|
44
44
|
expect(await result.wait()).to.equal(ConnectionState.ONLINE);
|
|
45
45
|
|
|
46
46
|
result = new Trigger<ConnectionState | undefined>();
|
|
47
|
-
await networkService.
|
|
48
|
-
|
|
47
|
+
await networkService.updateConfig({
|
|
48
|
+
swarm: ConnectionState.OFFLINE,
|
|
49
49
|
});
|
|
50
50
|
expect(await result.wait()).to.equal(ConnectionState.OFFLINE);
|
|
51
51
|
});
|
|
@@ -3,22 +3,34 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Stream } from '@dxos/codec-protobuf';
|
|
6
|
+
import { SignalManager } from '@dxos/messaging';
|
|
6
7
|
import { NetworkManager } from '@dxos/network-manager';
|
|
7
|
-
import { NetworkService, NetworkStatus,
|
|
8
|
+
import { NetworkService, NetworkStatus, UpdateConfigRequest } from '@dxos/protocols/proto/dxos/client/services';
|
|
8
9
|
|
|
9
10
|
export class NetworkServiceImpl implements NetworkService {
|
|
10
|
-
constructor(private readonly networkManager: NetworkManager) {}
|
|
11
|
+
constructor(private readonly networkManager: NetworkManager, private readonly signalManager: SignalManager) {}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
queryStatus() {
|
|
13
14
|
return new Stream<NetworkStatus>(({ next }) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const update = () => {
|
|
16
|
+
next({
|
|
17
|
+
swarm: this.networkManager.connectionState,
|
|
18
|
+
signaling: this.signalManager.getStatus().map(({ host, state }) => ({ server: host, state })),
|
|
19
|
+
});
|
|
20
|
+
};
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
const unsubscribeSwarm = this.networkManager.connectionStateChanged.on(() => update());
|
|
23
|
+
const unsubscribeSignal = this.signalManager.statusChanged.on(() => update());
|
|
24
|
+
update();
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
unsubscribeSwarm();
|
|
28
|
+
unsubscribeSignal();
|
|
29
|
+
};
|
|
18
30
|
});
|
|
19
31
|
}
|
|
20
32
|
|
|
21
|
-
async
|
|
22
|
-
await this.networkManager.setConnectionState(request.
|
|
33
|
+
async updateConfig(request: UpdateConfigRequest) {
|
|
34
|
+
await this.networkManager.setConnectionState(request.swarm);
|
|
23
35
|
}
|
|
24
36
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { ClientServices } from '@dxos/client';
|
|
5
|
+
import { ClientServices } from '@dxos/client-protocol';
|
|
6
6
|
import { Any, ServiceHandler, Stream } from '@dxos/codec-protobuf';
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
8
|
import { parseMethodName, RpcPeer, RpcPeerOptions } from '@dxos/rpc';
|
|
@@ -15,12 +15,12 @@ export type ClientRpcServerParams = {
|
|
|
15
15
|
handleCall?: (
|
|
16
16
|
method: string,
|
|
17
17
|
params: Any,
|
|
18
|
-
handler: (method: string, params: Any) => MaybePromise<Any
|
|
18
|
+
handler: (method: string, params: Any) => MaybePromise<Any>,
|
|
19
19
|
) => Promise<Any>;
|
|
20
20
|
handleStream?: (
|
|
21
21
|
method: string,
|
|
22
22
|
params: Any,
|
|
23
|
-
handler: (method: string, params: Any) => Stream<Any
|
|
23
|
+
handler: (method: string, params: Any) => Stream<Any>,
|
|
24
24
|
) => MaybePromise<Stream<Any>>;
|
|
25
25
|
} & Omit<RpcPeerOptions, 'callHandler' | 'streamHandler'>;
|
|
26
26
|
|
|
@@ -59,7 +59,7 @@ export class ClientRpcServer {
|
|
|
59
59
|
} else {
|
|
60
60
|
return handler(methodName, params);
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
},
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -75,7 +75,7 @@ export class ClientRpcServer {
|
|
|
75
75
|
if (!this._handlerCache.has(serviceName)) {
|
|
76
76
|
const [key, descriptor] =
|
|
77
77
|
Object.entries(this._serviceRegistry.descriptors).find(
|
|
78
|
-
([key, descriptor]) => descriptor.name === serviceName
|
|
78
|
+
([key, descriptor]) => descriptor.name === serviceName,
|
|
79
79
|
) ?? raise(new Error(`Service not available: ${serviceName}`));
|
|
80
80
|
|
|
81
81
|
const service = this._serviceRegistry.services[key as keyof ClientServices];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { ClientServices, ClientServicesProvider } from '@dxos/client';
|
|
5
|
+
import { ClientServices, ClientServicesProvider } from '@dxos/client-protocol';
|
|
6
6
|
import { ServiceBundle } from '@dxos/rpc';
|
|
7
7
|
|
|
8
8
|
import { ClientServicesHost, ClientServicesHostParams } from './service-host';
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Invitation } from '@dxos/client';
|
|
6
5
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
6
|
+
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
7
7
|
import { describe, test } from '@dxos/test';
|
|
8
8
|
|
|
9
9
|
import { createServiceContext, syncItemsLocal } from '../testing';
|
|
@@ -53,8 +53,8 @@ describe('services/ServiceContext', () => {
|
|
|
53
53
|
performInvitation({
|
|
54
54
|
host: identity2,
|
|
55
55
|
guest: device1,
|
|
56
|
-
options: { kind: Invitation.Kind.SPACE, spaceKey: space1.key }
|
|
57
|
-
})
|
|
56
|
+
options: { kind: Invitation.Kind.SPACE, spaceKey: space1.key },
|
|
57
|
+
}),
|
|
58
58
|
);
|
|
59
59
|
|
|
60
60
|
await device2.dataSpaceManager!.waitUntilSpaceReady(space1!.key);
|
|
@@ -5,24 +5,24 @@
|
|
|
5
5
|
import assert from 'node:assert';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
|
-
import { Invitation } from '@dxos/client';
|
|
9
8
|
import { CredentialConsumer, getCredentialAssertion } from '@dxos/credentials';
|
|
10
9
|
import { failUndefined } from '@dxos/debug';
|
|
11
10
|
import {
|
|
12
11
|
valueEncoding,
|
|
13
12
|
MetadataStore,
|
|
14
13
|
SpaceManager,
|
|
15
|
-
SigningContext,
|
|
16
14
|
DataServiceSubscriptions,
|
|
17
|
-
SnapshotStore
|
|
15
|
+
SnapshotStore,
|
|
18
16
|
} from '@dxos/echo-pipeline';
|
|
19
17
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
18
|
import { Keyring } from '@dxos/keyring';
|
|
21
19
|
import { PublicKey } from '@dxos/keys';
|
|
22
20
|
import { log } from '@dxos/log';
|
|
21
|
+
import { SignalManager } from '@dxos/messaging';
|
|
23
22
|
import { ModelFactory } from '@dxos/model-factory';
|
|
24
23
|
import { NetworkManager } from '@dxos/network-manager';
|
|
25
24
|
import { trace } from '@dxos/protocols';
|
|
25
|
+
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
26
26
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
27
27
|
import { Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
28
28
|
import { Storage } from '@dxos/random-access-storage';
|
|
@@ -32,9 +32,9 @@ import {
|
|
|
32
32
|
DeviceInvitationProtocol,
|
|
33
33
|
InvitationsHandler,
|
|
34
34
|
InvitationProtocol,
|
|
35
|
-
SpaceInvitationProtocol
|
|
35
|
+
SpaceInvitationProtocol,
|
|
36
36
|
} from '../invitations';
|
|
37
|
-
import { DataSpaceManager } from '../spaces';
|
|
37
|
+
import { DataSpaceManager, SigningContext } from '../spaces';
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Shared backend for all client services.
|
|
@@ -67,9 +67,9 @@ export class ServiceContext {
|
|
|
67
67
|
constructor(
|
|
68
68
|
public readonly storage: Storage,
|
|
69
69
|
public readonly networkManager: NetworkManager,
|
|
70
|
+
public readonly signalManager: SignalManager,
|
|
70
71
|
public readonly modelFactory: ModelFactory
|
|
71
72
|
) {
|
|
72
|
-
networkManager._traceParent = this._instanceId;
|
|
73
73
|
// TODO(burdon): Move strings to constants.
|
|
74
74
|
this.metadataStore = new MetadataStore(storage.createDirectory('metadata'));
|
|
75
75
|
this.snapshotStore = new SnapshotStore(storage.createDirectory('snapshots'));
|
|
@@ -87,9 +87,11 @@ export class ServiceContext {
|
|
|
87
87
|
|
|
88
88
|
this.spaceManager = new SpaceManager({
|
|
89
89
|
feedStore: this.feedStore,
|
|
90
|
-
networkManager: this.networkManager
|
|
90
|
+
networkManager: this.networkManager,
|
|
91
|
+
metadataStore: this.metadataStore,
|
|
92
|
+
modelFactory: this.modelFactory,
|
|
93
|
+
snapshotStore: this.snapshotStore,
|
|
91
94
|
});
|
|
92
|
-
this.spaceManager._traceParent = this._instanceId;
|
|
93
95
|
|
|
94
96
|
this.identityManager = new IdentityManager(
|
|
95
97
|
this.metadataStore,
|
|
@@ -97,24 +99,27 @@ export class ServiceContext {
|
|
|
97
99
|
this.feedStore,
|
|
98
100
|
this.spaceManager
|
|
99
101
|
);
|
|
100
|
-
this.identityManager._traceParent = this._instanceId;
|
|
101
102
|
|
|
102
103
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
103
|
-
this.invitations._traceParent = this._instanceId;
|
|
104
104
|
|
|
105
105
|
// TODO(burdon): _initialize called in multiple places.
|
|
106
106
|
// TODO(burdon): Call _initialize on success.
|
|
107
|
-
this._handlerFactories.set(
|
|
108
|
-
|
|
109
|
-
() =>
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
this._handlerFactories.set(
|
|
108
|
+
Invitation.Kind.DEVICE,
|
|
109
|
+
() =>
|
|
110
|
+
new DeviceInvitationProtocol(
|
|
111
|
+
this.keyring,
|
|
112
|
+
() => this.identityManager.identity ?? failUndefined(),
|
|
113
|
+
this._acceptIdentity.bind(this)
|
|
114
|
+
)
|
|
115
|
+
);
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
async open() {
|
|
115
|
-
log.trace('dxos.sdk.service-context', trace.begin({ id: this._instanceId }));
|
|
119
|
+
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
116
120
|
|
|
117
121
|
log('opening...');
|
|
122
|
+
await this.signalManager.open();
|
|
118
123
|
await this.networkManager.open();
|
|
119
124
|
await this.spaceManager.open();
|
|
120
125
|
await this.identityManager.open();
|
|
@@ -122,6 +127,7 @@ export class ServiceContext {
|
|
|
122
127
|
await this._initialize();
|
|
123
128
|
}
|
|
124
129
|
log('opened');
|
|
130
|
+
log.trace('dxos.sdk.service-context.open', trace.end({ id: this._instanceId }));
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
async close() {
|
|
@@ -132,10 +138,9 @@ export class ServiceContext {
|
|
|
132
138
|
await this.spaceManager.close();
|
|
133
139
|
await this.feedStore.close();
|
|
134
140
|
await this.networkManager.close();
|
|
141
|
+
await this.signalManager.close();
|
|
135
142
|
this.dataServiceSubscriptions.clear();
|
|
136
143
|
log('closed');
|
|
137
|
-
|
|
138
|
-
log.trace('dxos.sdk.service-context', trace.end({ id: this._instanceId }));
|
|
139
144
|
}
|
|
140
145
|
|
|
141
146
|
async createIdentity(params: CreateIdentityOptions = {}) {
|
|
@@ -169,7 +174,7 @@ export class ServiceContext {
|
|
|
169
174
|
profile: identity.profileDocument,
|
|
170
175
|
recordCredential: async (credential) => {
|
|
171
176
|
await identity.controlPipeline.writer.write({ credential: { credential } });
|
|
172
|
-
}
|
|
177
|
+
},
|
|
173
178
|
};
|
|
174
179
|
|
|
175
180
|
this.dataSpaceManager = new DataSpaceManager(
|
|
@@ -178,11 +183,8 @@ export class ServiceContext {
|
|
|
178
183
|
this.dataServiceSubscriptions,
|
|
179
184
|
this.keyring,
|
|
180
185
|
signingContext,
|
|
181
|
-
this.modelFactory,
|
|
182
186
|
this.feedStore,
|
|
183
|
-
this.snapshotStore
|
|
184
187
|
);
|
|
185
|
-
this.dataSpaceManager._traceParent = this._instanceId;
|
|
186
188
|
await this.dataSpaceManager.open();
|
|
187
189
|
|
|
188
190
|
this._handlerFactories.set(Invitation.Kind.SPACE, (invitation) => {
|
|
@@ -214,12 +216,12 @@ export class ServiceContext {
|
|
|
214
216
|
log('accepting space recorded in halo', { details: assertion });
|
|
215
217
|
await this.dataSpaceManager.acceptSpace({
|
|
216
218
|
spaceKey: assertion.spaceKey,
|
|
217
|
-
genesisFeedKey: assertion.genesisFeedKey
|
|
219
|
+
genesisFeedKey: assertion.genesisFeedKey,
|
|
218
220
|
});
|
|
219
221
|
} catch (err) {
|
|
220
222
|
log.catch(err);
|
|
221
223
|
}
|
|
222
|
-
}
|
|
224
|
+
},
|
|
223
225
|
});
|
|
224
226
|
await this._deviceSpaceSync.open();
|
|
225
227
|
}
|
|
@@ -43,7 +43,7 @@ describe('ClientServicesHost', () => {
|
|
|
43
43
|
|
|
44
44
|
const testCredential = await createMockCredential({
|
|
45
45
|
signer: host._serviceContext.keyring,
|
|
46
|
-
issuer: host._serviceContext.identityManager.identity!.deviceKey
|
|
46
|
+
issuer: host._serviceContext.identityManager.identity!.deviceKey,
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
// Test if Identity exposes haloSpace key.
|
|
@@ -56,7 +56,7 @@ describe('ClientServicesHost', () => {
|
|
|
56
56
|
|
|
57
57
|
await host.services.SpacesService?.writeCredentials({
|
|
58
58
|
spaceKey: await haloSpace.wait(),
|
|
59
|
-
credentials: [testCredential]
|
|
59
|
+
credentials: [testCredential],
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
const credentials = host.services.SpacesService!.queryCredentials({ spaceKey: await haloSpace.wait() });
|
|
@@ -80,21 +80,21 @@ describe('ClientServicesHost', () => {
|
|
|
80
80
|
|
|
81
81
|
const testCredential = await createMockCredential({
|
|
82
82
|
signer: host._serviceContext.keyring,
|
|
83
|
-
issuer: host._serviceContext.identityManager.identity!.deviceKey
|
|
83
|
+
issuer: host._serviceContext.identityManager.identity!.deviceKey,
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
const nonce = new Uint8Array([0, 0, 0, 0]);
|
|
87
87
|
|
|
88
88
|
const presentation = await host.services.IdentityService!.signPresentation({
|
|
89
89
|
presentation: {
|
|
90
|
-
credentials: [testCredential]
|
|
90
|
+
credentials: [testCredential],
|
|
91
91
|
},
|
|
92
|
-
nonce
|
|
92
|
+
nonce,
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
expect(presentation.proofs?.[0].nonce).to.deep.equal(nonce);
|
|
96
96
|
expect(await verifyPresentation(presentation)).to.deep.equal({
|
|
97
|
-
kind: 'pass'
|
|
97
|
+
kind: 'pass',
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
100
|
});
|