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