@dxos/client-services 0.1.52-main.e73bc9f → 0.1.52
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-2GQ7337P.mjs → chunk-C3SPTMW3.mjs} +238 -261
- package/dist/lib/browser/{chunk-2GQ7337P.mjs.map → chunk-C3SPTMW3.mjs.map} +4 -4
- package/dist/lib/browser/index.mjs +3 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +440 -462
- 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 +1496 -1494
- package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
- package/dist/types/src/packlets/services/index.d.ts +0 -1
- package/dist/types/src/packlets/services/index.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +2 -2
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
- package/package.json +32 -32
- package/src/packlets/services/index.ts +0 -1
- package/src/packlets/vault/iframe-host-runtime.ts +4 -4
- package/dist/types/src/packlets/services/local-client-services.d.ts +0 -16
- package/dist/types/src/packlets/services/local-client-services.d.ts.map +0 -1
- package/src/packlets/services/local-client-services.ts +0 -39
|
@@ -65,597 +65,241 @@ var import_node_assert14 = __toESM(require("node:assert"));
|
|
|
65
65
|
var import_async18 = require("@dxos/async");
|
|
66
66
|
var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
|
|
67
67
|
|
|
68
|
-
// packages/sdk/client-services/src/packlets/services/service-
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
var
|
|
68
|
+
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
69
|
+
var import_node_assert11 = __toESM(require("node:assert"));
|
|
70
|
+
var import_async11 = require("@dxos/async");
|
|
71
|
+
var import_credentials14 = require("@dxos/credentials");
|
|
72
|
+
var import_debug6 = require("@dxos/debug");
|
|
73
|
+
var import_echo_pipeline3 = require("@dxos/echo-pipeline");
|
|
74
|
+
var import_feed_store3 = require("@dxos/feed-store");
|
|
75
|
+
var import_keyring = require("@dxos/keyring");
|
|
76
|
+
var import_keys8 = require("@dxos/keys");
|
|
77
|
+
var import_log12 = require("@dxos/log");
|
|
78
|
+
var import_protocols8 = require("@dxos/protocols");
|
|
79
|
+
var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
|
|
80
|
+
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
79
81
|
|
|
80
|
-
// packages/sdk/client-services/src/packlets/
|
|
82
|
+
// packages/sdk/client-services/src/packlets/identity/authenticator.ts
|
|
81
83
|
var import_async = require("@dxos/async");
|
|
82
|
-
var
|
|
83
|
-
var
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
var import_context = require("@dxos/context");
|
|
85
|
+
var import_credentials2 = require("@dxos/credentials");
|
|
86
|
+
var import_log = require("@dxos/log");
|
|
87
|
+
var import_protocols = require("@dxos/protocols");
|
|
88
|
+
var createAuthProvider = (signer) => async (nonce) => {
|
|
89
|
+
const credential = await signer.createCredential({
|
|
90
|
+
assertion: {
|
|
91
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
92
|
+
},
|
|
93
|
+
subject: signer.getIssuer(),
|
|
94
|
+
nonce
|
|
95
|
+
});
|
|
96
|
+
return import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
|
|
97
|
+
};
|
|
98
|
+
var TrustedKeySetAuthVerifier = class {
|
|
99
|
+
// prettier-ignore
|
|
100
|
+
constructor(_params) {
|
|
101
|
+
this._params = _params;
|
|
102
|
+
this._ctx = new import_context.Context();
|
|
87
103
|
}
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
async close() {
|
|
105
|
+
await this._ctx.dispose();
|
|
90
106
|
}
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
get verifier() {
|
|
108
|
+
return async (nonce, auth) => {
|
|
109
|
+
const credential = import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
|
|
110
|
+
(0, import_log.log)("authenticating...", {
|
|
111
|
+
credential
|
|
112
|
+
}, {
|
|
113
|
+
file: "authenticator.ts",
|
|
114
|
+
line: 57,
|
|
115
|
+
scope: this,
|
|
116
|
+
callSite: (f, a) => f(...a)
|
|
117
|
+
});
|
|
118
|
+
const result = await (0, import_credentials2.verifyCredential)(credential);
|
|
119
|
+
if (result.kind === "fail") {
|
|
120
|
+
(0, import_log.log)("Invalid credential", {
|
|
121
|
+
result
|
|
122
|
+
}, {
|
|
123
|
+
file: "authenticator.ts",
|
|
124
|
+
line: 61,
|
|
125
|
+
scope: this,
|
|
126
|
+
callSite: (f, a) => f(...a)
|
|
127
|
+
});
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
|
|
131
|
+
(0, import_log.log)("Invalid nonce", {
|
|
132
|
+
nonce,
|
|
133
|
+
credential
|
|
134
|
+
}, {
|
|
135
|
+
file: "authenticator.ts",
|
|
136
|
+
line: 66,
|
|
137
|
+
scope: this,
|
|
138
|
+
callSite: (f, a) => f(...a)
|
|
139
|
+
});
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (this._isTrustedKey(credential.issuer)) {
|
|
143
|
+
(0, import_log.log)("key is not currently in trusted set, waiting...", {
|
|
144
|
+
key: credential.issuer
|
|
145
|
+
}, {
|
|
146
|
+
file: "authenticator.ts",
|
|
147
|
+
line: 71,
|
|
148
|
+
scope: this,
|
|
149
|
+
callSite: (f, a) => f(...a)
|
|
150
|
+
});
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
const trigger = new import_async.Trigger();
|
|
154
|
+
this._ctx.onDispose(() => {
|
|
155
|
+
trigger.wake(false);
|
|
156
|
+
});
|
|
157
|
+
const clear = this._params.update.on(this._ctx, () => {
|
|
158
|
+
if (this._isTrustedKey(credential.issuer)) {
|
|
159
|
+
(0, import_log.log)("auth success", {
|
|
160
|
+
key: credential.issuer
|
|
161
|
+
}, {
|
|
162
|
+
file: "authenticator.ts",
|
|
163
|
+
line: 82,
|
|
164
|
+
scope: this,
|
|
165
|
+
callSite: (f, a) => f(...a)
|
|
99
166
|
});
|
|
167
|
+
trigger.wake(true);
|
|
100
168
|
} else {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
169
|
+
(0, import_log.log)("key is not currently in trusted set, waiting...", {
|
|
170
|
+
key: credential.issuer
|
|
171
|
+
}, {
|
|
172
|
+
file: "authenticator.ts",
|
|
173
|
+
line: 85,
|
|
174
|
+
scope: this,
|
|
175
|
+
callSite: (f, a) => f(...a)
|
|
109
176
|
});
|
|
110
177
|
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
178
|
+
});
|
|
179
|
+
try {
|
|
180
|
+
return await trigger.wait({
|
|
181
|
+
timeout: this._params.authTimeout
|
|
182
|
+
});
|
|
183
|
+
} catch (e) {
|
|
184
|
+
return false;
|
|
185
|
+
} finally {
|
|
186
|
+
clear();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
_isTrustedKey(deviceKey) {
|
|
191
|
+
const deviceSet = this._params.trustedKeysProvider();
|
|
192
|
+
return deviceSet.has(deviceKey);
|
|
124
193
|
}
|
|
125
194
|
};
|
|
126
195
|
|
|
127
|
-
// packages/sdk/client-services/src/packlets/
|
|
128
|
-
var
|
|
129
|
-
var import_codec_protobuf7 = require("@dxos/codec-protobuf");
|
|
130
|
-
|
|
131
|
-
// packages/sdk/client-services/src/packlets/devtools/feeds.ts
|
|
196
|
+
// packages/sdk/client-services/src/packlets/identity/identity.ts
|
|
197
|
+
var import_node_assert = __toESM(require("node:assert"));
|
|
132
198
|
var import_async2 = require("@dxos/async");
|
|
133
|
-
var
|
|
199
|
+
var import_client_protocol = require("@dxos/client-protocol");
|
|
200
|
+
var import_credentials3 = require("@dxos/credentials");
|
|
201
|
+
var import_debug = require("@dxos/debug");
|
|
134
202
|
var import_feed_store = require("@dxos/feed-store");
|
|
135
|
-
var
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
|
|
158
|
-
};
|
|
159
|
-
})
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
subscriptions.add(feedStore.feedOpened.on(update));
|
|
163
|
-
update();
|
|
164
|
-
return () => {
|
|
165
|
-
subscriptions.clear();
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
|
|
170
|
-
return new import_codec_protobuf2.Stream(({ next }) => {
|
|
171
|
-
if (!feedKey) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const subscriptions = new import_async2.EventSubscriptions();
|
|
175
|
-
const timeout = setTimeout(async () => {
|
|
176
|
-
const feed = feedStore.getFeed(feedKey);
|
|
177
|
-
if (!feed) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const update = async () => {
|
|
181
|
-
const iterator = new import_feed_store.FeedIterator(feed);
|
|
182
|
-
await iterator.open();
|
|
183
|
-
const blocks = [];
|
|
184
|
-
for await (const block of iterator) {
|
|
185
|
-
blocks.push(block);
|
|
186
|
-
if (blocks.length >= feed.properties.length) {
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
next({
|
|
191
|
-
blocks: blocks.slice(-maxBlocks)
|
|
192
|
-
});
|
|
193
|
-
await iterator.close();
|
|
194
|
-
};
|
|
195
|
-
feed.on("append", update);
|
|
196
|
-
subscriptions.add(() => feed.off("append", update));
|
|
197
|
-
feed.on("truncate", update);
|
|
198
|
-
subscriptions.add(() => feed.off("truncate", update));
|
|
199
|
-
await update();
|
|
203
|
+
var import_log2 = require("@dxos/log");
|
|
204
|
+
var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
205
|
+
var Identity = class {
|
|
206
|
+
constructor({ space, signer, identityKey, deviceKey }) {
|
|
207
|
+
this.stateUpdate = new import_async2.Event();
|
|
208
|
+
this.space = space;
|
|
209
|
+
this._signer = signer;
|
|
210
|
+
this.identityKey = identityKey;
|
|
211
|
+
this.deviceKey = deviceKey;
|
|
212
|
+
this._deviceStateMachine = this.space.spaceState.registerProcessor(new import_credentials3.DeviceStateMachine({
|
|
213
|
+
identityKey: this.identityKey,
|
|
214
|
+
deviceKey: this.deviceKey,
|
|
215
|
+
onUpdate: () => this.stateUpdate.emit()
|
|
216
|
+
}));
|
|
217
|
+
this._profileStateMachine = this.space.spaceState.registerProcessor(new import_credentials3.ProfileStateMachine({
|
|
218
|
+
identityKey: this.identityKey,
|
|
219
|
+
onUpdate: () => this.stateUpdate.emit()
|
|
220
|
+
}));
|
|
221
|
+
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
222
|
+
trustedKeysProvider: () => this.authorizedDeviceKeys,
|
|
223
|
+
update: this.stateUpdate,
|
|
224
|
+
authTimeout: import_client_protocol.AUTH_TIMEOUT
|
|
200
225
|
});
|
|
201
|
-
return () => {
|
|
202
|
-
subscriptions.clear();
|
|
203
|
-
clearTimeout(timeout);
|
|
204
|
-
};
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// packages/sdk/client-services/src/packlets/devtools/keys.ts
|
|
209
|
-
var import_async3 = require("@dxos/async");
|
|
210
|
-
var import_codec_protobuf3 = require("@dxos/codec-protobuf");
|
|
211
|
-
var subscribeToKeyringKeys = ({ keyring }) => new import_codec_protobuf3.Stream(({ next, ctx }) => {
|
|
212
|
-
const update = async () => {
|
|
213
|
-
next({
|
|
214
|
-
keys: await keyring.list()
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
keyring.keysUpdate.on(ctx, update);
|
|
218
|
-
(0, import_async3.scheduleTask)(ctx, update);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// packages/sdk/client-services/src/packlets/devtools/metadata.ts
|
|
222
|
-
var import_codec_protobuf4 = require("@dxos/codec-protobuf");
|
|
223
|
-
var subscribeToMetadata = ({ context }) => new import_codec_protobuf4.Stream(({ next, ctx }) => {
|
|
224
|
-
context.metadataStore.update.on(ctx, (data) => next({
|
|
225
|
-
metadata: data
|
|
226
|
-
}));
|
|
227
|
-
next({
|
|
228
|
-
metadata: context.metadataStore.metadata
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// packages/sdk/client-services/src/packlets/devtools/network.ts
|
|
233
|
-
var import_codec_protobuf5 = require("@dxos/codec-protobuf");
|
|
234
|
-
var import_context = require("@dxos/context");
|
|
235
|
-
var import_keys3 = require("@dxos/keys");
|
|
236
|
-
var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf5.Stream(({ next, close }) => {
|
|
237
|
-
const update = () => {
|
|
238
|
-
try {
|
|
239
|
-
const status = signalManager.getStatus();
|
|
240
|
-
next({
|
|
241
|
-
servers: status
|
|
242
|
-
});
|
|
243
|
-
} catch (err) {
|
|
244
|
-
close(err);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
signalManager.statusChanged.on(() => update());
|
|
248
|
-
update();
|
|
249
|
-
});
|
|
250
|
-
var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf5.Stream(({ next }) => {
|
|
251
|
-
const ctx = new import_context.Context();
|
|
252
|
-
signalManager.onMessage.on(ctx, (message) => {
|
|
253
|
-
next({
|
|
254
|
-
message: {
|
|
255
|
-
author: message.author.asUint8Array(),
|
|
256
|
-
recipient: message.recipient.asUint8Array(),
|
|
257
|
-
payload: message.payload
|
|
258
|
-
},
|
|
259
|
-
receivedAt: new Date()
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
signalManager.swarmEvent.on(ctx, (swarmEvent) => {
|
|
263
|
-
next({
|
|
264
|
-
swarmEvent: swarmEvent.swarmEvent,
|
|
265
|
-
receivedAt: new Date()
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
return () => {
|
|
269
|
-
return ctx.dispose();
|
|
270
|
-
};
|
|
271
|
-
});
|
|
272
|
-
var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf5.Stream(({ next }) => {
|
|
273
|
-
var _a;
|
|
274
|
-
const update = () => {
|
|
275
|
-
var _a2;
|
|
276
|
-
const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
|
|
277
|
-
if (info) {
|
|
278
|
-
next({
|
|
279
|
-
data: info
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
(_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
|
|
284
|
-
update();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// packages/sdk/client-services/src/packlets/devtools/spaces.ts
|
|
288
|
-
var import_codec_protobuf6 = require("@dxos/codec-protobuf");
|
|
289
|
-
var subscribeToSpaces = (context, { spaceKeys = [] }) => {
|
|
290
|
-
return new import_codec_protobuf6.Stream(({ next }) => {
|
|
291
|
-
let unsubscribe;
|
|
292
|
-
const update = async () => {
|
|
293
|
-
const spaces = [
|
|
294
|
-
...context.spaceManager.spaces.values()
|
|
295
|
-
];
|
|
296
|
-
const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
|
|
297
|
-
next({
|
|
298
|
-
spaces: filteredSpaces.map((space) => {
|
|
299
|
-
const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
|
|
300
|
-
return {
|
|
301
|
-
key: space.key,
|
|
302
|
-
isOpen: space.isOpen,
|
|
303
|
-
timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
|
|
304
|
-
genesisFeed: space.genesisFeedKey,
|
|
305
|
-
controlFeed: space.controlFeedKey,
|
|
306
|
-
dataFeed: space.dataFeedKey
|
|
307
|
-
};
|
|
308
|
-
})
|
|
309
|
-
});
|
|
310
|
-
};
|
|
311
|
-
const timeout = setTimeout(async () => {
|
|
312
|
-
await context.initialized.wait();
|
|
313
|
-
unsubscribe = context.dataSpaceManager.updated.on(() => update());
|
|
314
|
-
await update();
|
|
315
|
-
});
|
|
316
|
-
return () => {
|
|
317
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
318
|
-
clearTimeout(timeout);
|
|
319
|
-
};
|
|
320
|
-
});
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
// packages/sdk/client-services/src/packlets/devtools/devtools.ts
|
|
324
|
-
var DevtoolsHostEvents = class {
|
|
325
|
-
constructor() {
|
|
326
|
-
this.ready = new import_async4.Event();
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
var DevtoolsServiceImpl = class {
|
|
330
|
-
constructor(params) {
|
|
331
|
-
this.params = params;
|
|
332
|
-
}
|
|
333
|
-
events(request) {
|
|
334
|
-
return new import_codec_protobuf7.Stream(({ next }) => {
|
|
335
|
-
this.params.events.ready.on(() => {
|
|
336
|
-
next({
|
|
337
|
-
ready: {}
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
getConfig(request) {
|
|
343
|
-
throw new Error();
|
|
344
|
-
}
|
|
345
|
-
async getStorageInfo() {
|
|
346
|
-
var _a, _b, _c, _d, _e;
|
|
347
|
-
const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
|
|
348
|
-
used: 0
|
|
349
|
-
};
|
|
350
|
-
const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
|
|
351
|
-
return {
|
|
352
|
-
type: this.params.context.storage.type,
|
|
353
|
-
storageUsage: storageUsage.used,
|
|
354
|
-
originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
|
|
355
|
-
usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
async getBlobs() {
|
|
359
|
-
return {
|
|
360
|
-
blobs: await this.params.context.blobStore.list()
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
async getSnapshots() {
|
|
364
|
-
return {
|
|
365
|
-
snapshots: await this.params.context.snapshotStore.listSnapshots()
|
|
366
|
-
};
|
|
367
226
|
}
|
|
368
|
-
|
|
369
|
-
|
|
227
|
+
// TODO(burdon): Expose state object?
|
|
228
|
+
get authorizedDeviceKeys() {
|
|
229
|
+
return this._deviceStateMachine.processor.authorizedDeviceKeys;
|
|
370
230
|
}
|
|
371
|
-
|
|
372
|
-
|
|
231
|
+
async open() {
|
|
232
|
+
await this._deviceStateMachine.open();
|
|
233
|
+
await this._profileStateMachine.open();
|
|
234
|
+
await this.space.open();
|
|
373
235
|
}
|
|
374
|
-
|
|
375
|
-
|
|
236
|
+
async close() {
|
|
237
|
+
await this.authVerifier.close();
|
|
238
|
+
await this._deviceStateMachine.close();
|
|
239
|
+
await this._profileStateMachine.close();
|
|
240
|
+
await this.space.close();
|
|
376
241
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
242
|
+
async ready() {
|
|
243
|
+
await this._deviceStateMachine.processor.deviceChainReady.wait();
|
|
244
|
+
await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
245
|
+
timeout: import_client_protocol.LOAD_CONTROL_FEEDS_TIMEOUT
|
|
380
246
|
});
|
|
381
247
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
subscribeToSpaces(request) {
|
|
386
|
-
return subscribeToSpaces(this.params.context, request);
|
|
387
|
-
}
|
|
388
|
-
subscribeToItems(request) {
|
|
389
|
-
throw new Error();
|
|
390
|
-
}
|
|
391
|
-
subscribeToFeeds(request) {
|
|
392
|
-
return subscribeToFeeds({
|
|
393
|
-
feedStore: this.params.context.feedStore
|
|
394
|
-
}, request);
|
|
248
|
+
get profileDocument() {
|
|
249
|
+
return this._profileStateMachine.processor.profile;
|
|
395
250
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
251
|
+
/**
|
|
252
|
+
* @test-only
|
|
253
|
+
*/
|
|
254
|
+
get controlPipeline() {
|
|
255
|
+
return this.space.controlPipeline;
|
|
400
256
|
}
|
|
401
|
-
|
|
402
|
-
|
|
257
|
+
get haloSpaceKey() {
|
|
258
|
+
return this.space.key;
|
|
403
259
|
}
|
|
404
|
-
|
|
405
|
-
|
|
260
|
+
get haloGenesisFeedKey() {
|
|
261
|
+
return this.space.genesisFeedKey;
|
|
406
262
|
}
|
|
407
|
-
|
|
408
|
-
|
|
263
|
+
get deviceCredentialChain() {
|
|
264
|
+
return this._deviceStateMachine.processor.deviceCredentialChain;
|
|
409
265
|
}
|
|
410
|
-
|
|
411
|
-
|
|
266
|
+
getAdmissionCredentials() {
|
|
267
|
+
var _a, _b;
|
|
268
|
+
return {
|
|
269
|
+
deviceKey: this.deviceKey,
|
|
270
|
+
controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : (0, import_debug.failUndefined)(),
|
|
271
|
+
dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : (0, import_debug.failUndefined)()
|
|
272
|
+
};
|
|
412
273
|
}
|
|
413
|
-
|
|
414
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Issues credentials as identity.
|
|
276
|
+
* Requires identity to be ready.
|
|
277
|
+
*/
|
|
278
|
+
getIdentityCredentialSigner() {
|
|
279
|
+
(0, import_node_assert.default)(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
|
|
280
|
+
return (0, import_credentials3.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
|
|
415
281
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Issues credentials as device.
|
|
284
|
+
*/
|
|
285
|
+
getDeviceCredentialSigner() {
|
|
286
|
+
return (0, import_credentials3.createCredentialSignerWithKey)(this._signer, this.deviceKey);
|
|
420
287
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
context: this.params.context
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
// packages/sdk/client-services/src/packlets/identity/authenticator.ts
|
|
439
|
-
var import_async5 = require("@dxos/async");
|
|
440
|
-
var import_context2 = require("@dxos/context");
|
|
441
|
-
var import_credentials2 = require("@dxos/credentials");
|
|
442
|
-
var import_log = require("@dxos/log");
|
|
443
|
-
var import_protocols = require("@dxos/protocols");
|
|
444
|
-
var createAuthProvider = (signer) => async (nonce) => {
|
|
445
|
-
const credential = await signer.createCredential({
|
|
446
|
-
assertion: {
|
|
447
|
-
"@type": "dxos.halo.credentials.Auth"
|
|
448
|
-
},
|
|
449
|
-
subject: signer.getIssuer(),
|
|
450
|
-
nonce
|
|
451
|
-
});
|
|
452
|
-
return import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
|
|
453
|
-
};
|
|
454
|
-
var TrustedKeySetAuthVerifier = class {
|
|
455
|
-
// prettier-ignore
|
|
456
|
-
constructor(_params) {
|
|
457
|
-
this._params = _params;
|
|
458
|
-
this._ctx = new import_context2.Context();
|
|
459
|
-
}
|
|
460
|
-
async close() {
|
|
461
|
-
await this._ctx.dispose();
|
|
462
|
-
}
|
|
463
|
-
get verifier() {
|
|
464
|
-
return async (nonce, auth) => {
|
|
465
|
-
const credential = import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
|
|
466
|
-
(0, import_log.log)("authenticating...", {
|
|
467
|
-
credential
|
|
468
|
-
}, {
|
|
469
|
-
file: "authenticator.ts",
|
|
470
|
-
line: 57,
|
|
471
|
-
scope: this,
|
|
472
|
-
callSite: (f, a) => f(...a)
|
|
473
|
-
});
|
|
474
|
-
const result = await (0, import_credentials2.verifyCredential)(credential);
|
|
475
|
-
if (result.kind === "fail") {
|
|
476
|
-
(0, import_log.log)("Invalid credential", {
|
|
477
|
-
result
|
|
478
|
-
}, {
|
|
479
|
-
file: "authenticator.ts",
|
|
480
|
-
line: 61,
|
|
481
|
-
scope: this,
|
|
482
|
-
callSite: (f, a) => f(...a)
|
|
483
|
-
});
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
|
|
487
|
-
(0, import_log.log)("Invalid nonce", {
|
|
488
|
-
nonce,
|
|
489
|
-
credential
|
|
490
|
-
}, {
|
|
491
|
-
file: "authenticator.ts",
|
|
492
|
-
line: 66,
|
|
493
|
-
scope: this,
|
|
494
|
-
callSite: (f, a) => f(...a)
|
|
495
|
-
});
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
if (this._isTrustedKey(credential.issuer)) {
|
|
499
|
-
(0, import_log.log)("key is not currently in trusted set, waiting...", {
|
|
500
|
-
key: credential.issuer
|
|
501
|
-
}, {
|
|
502
|
-
file: "authenticator.ts",
|
|
503
|
-
line: 71,
|
|
504
|
-
scope: this,
|
|
505
|
-
callSite: (f, a) => f(...a)
|
|
506
|
-
});
|
|
507
|
-
return true;
|
|
508
|
-
}
|
|
509
|
-
const trigger = new import_async5.Trigger();
|
|
510
|
-
this._ctx.onDispose(() => {
|
|
511
|
-
trigger.wake(false);
|
|
512
|
-
});
|
|
513
|
-
const clear = this._params.update.on(this._ctx, () => {
|
|
514
|
-
if (this._isTrustedKey(credential.issuer)) {
|
|
515
|
-
(0, import_log.log)("auth success", {
|
|
516
|
-
key: credential.issuer
|
|
517
|
-
}, {
|
|
518
|
-
file: "authenticator.ts",
|
|
519
|
-
line: 82,
|
|
520
|
-
scope: this,
|
|
521
|
-
callSite: (f, a) => f(...a)
|
|
522
|
-
});
|
|
523
|
-
trigger.wake(true);
|
|
524
|
-
} else {
|
|
525
|
-
(0, import_log.log)("key is not currently in trusted set, waiting...", {
|
|
526
|
-
key: credential.issuer
|
|
527
|
-
}, {
|
|
528
|
-
file: "authenticator.ts",
|
|
529
|
-
line: 85,
|
|
530
|
-
scope: this,
|
|
531
|
-
callSite: (f, a) => f(...a)
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
try {
|
|
536
|
-
return await trigger.wait({
|
|
537
|
-
timeout: this._params.authTimeout
|
|
538
|
-
});
|
|
539
|
-
} catch (e) {
|
|
540
|
-
return false;
|
|
541
|
-
} finally {
|
|
542
|
-
clear();
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
_isTrustedKey(deviceKey) {
|
|
547
|
-
const deviceSet = this._params.trustedKeysProvider();
|
|
548
|
-
return deviceSet.has(deviceKey);
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
// packages/sdk/client-services/src/packlets/identity/identity.ts
|
|
553
|
-
var import_node_assert = __toESM(require("node:assert"));
|
|
554
|
-
var import_async6 = require("@dxos/async");
|
|
555
|
-
var import_client_protocol = require("@dxos/client-protocol");
|
|
556
|
-
var import_credentials3 = require("@dxos/credentials");
|
|
557
|
-
var import_debug = require("@dxos/debug");
|
|
558
|
-
var import_feed_store2 = require("@dxos/feed-store");
|
|
559
|
-
var import_log2 = require("@dxos/log");
|
|
560
|
-
var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
561
|
-
var Identity = class {
|
|
562
|
-
constructor({ space, signer, identityKey, deviceKey }) {
|
|
563
|
-
this.stateUpdate = new import_async6.Event();
|
|
564
|
-
this.space = space;
|
|
565
|
-
this._signer = signer;
|
|
566
|
-
this.identityKey = identityKey;
|
|
567
|
-
this.deviceKey = deviceKey;
|
|
568
|
-
this._deviceStateMachine = this.space.spaceState.registerProcessor(new import_credentials3.DeviceStateMachine({
|
|
569
|
-
identityKey: this.identityKey,
|
|
570
|
-
deviceKey: this.deviceKey,
|
|
571
|
-
onUpdate: () => this.stateUpdate.emit()
|
|
572
|
-
}));
|
|
573
|
-
this._profileStateMachine = this.space.spaceState.registerProcessor(new import_credentials3.ProfileStateMachine({
|
|
574
|
-
identityKey: this.identityKey,
|
|
575
|
-
onUpdate: () => this.stateUpdate.emit()
|
|
576
|
-
}));
|
|
577
|
-
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
578
|
-
trustedKeysProvider: () => this.authorizedDeviceKeys,
|
|
579
|
-
update: this.stateUpdate,
|
|
580
|
-
authTimeout: import_client_protocol.AUTH_TIMEOUT
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
// TODO(burdon): Expose state object?
|
|
584
|
-
get authorizedDeviceKeys() {
|
|
585
|
-
return this._deviceStateMachine.processor.authorizedDeviceKeys;
|
|
586
|
-
}
|
|
587
|
-
async open() {
|
|
588
|
-
await this._deviceStateMachine.open();
|
|
589
|
-
await this._profileStateMachine.open();
|
|
590
|
-
await this.space.open();
|
|
591
|
-
}
|
|
592
|
-
async close() {
|
|
593
|
-
await this.authVerifier.close();
|
|
594
|
-
await this._deviceStateMachine.close();
|
|
595
|
-
await this._profileStateMachine.close();
|
|
596
|
-
await this.space.close();
|
|
597
|
-
}
|
|
598
|
-
async ready() {
|
|
599
|
-
await this._deviceStateMachine.processor.deviceChainReady.wait();
|
|
600
|
-
await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
601
|
-
timeout: import_client_protocol.LOAD_CONTROL_FEEDS_TIMEOUT
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
get profileDocument() {
|
|
605
|
-
return this._profileStateMachine.processor.profile;
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* @test-only
|
|
609
|
-
*/
|
|
610
|
-
get controlPipeline() {
|
|
611
|
-
return this.space.controlPipeline;
|
|
612
|
-
}
|
|
613
|
-
get haloSpaceKey() {
|
|
614
|
-
return this.space.key;
|
|
615
|
-
}
|
|
616
|
-
get haloGenesisFeedKey() {
|
|
617
|
-
return this.space.genesisFeedKey;
|
|
618
|
-
}
|
|
619
|
-
get deviceCredentialChain() {
|
|
620
|
-
return this._deviceStateMachine.processor.deviceCredentialChain;
|
|
621
|
-
}
|
|
622
|
-
getAdmissionCredentials() {
|
|
623
|
-
var _a, _b;
|
|
624
|
-
return {
|
|
625
|
-
deviceKey: this.deviceKey,
|
|
626
|
-
controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : (0, import_debug.failUndefined)(),
|
|
627
|
-
dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : (0, import_debug.failUndefined)()
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* Issues credentials as identity.
|
|
632
|
-
* Requires identity to be ready.
|
|
633
|
-
*/
|
|
634
|
-
getIdentityCredentialSigner() {
|
|
635
|
-
(0, import_node_assert.default)(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
|
|
636
|
-
return (0, import_credentials3.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Issues credentials as device.
|
|
640
|
-
*/
|
|
641
|
-
getDeviceCredentialSigner() {
|
|
642
|
-
return (0, import_credentials3.createCredentialSignerWithKey)(this._signer, this.deviceKey);
|
|
643
|
-
}
|
|
644
|
-
async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
|
|
645
|
-
(0, import_log2.log)("Admitting device:", {
|
|
646
|
-
identityKey: this.identityKey,
|
|
647
|
-
hostDevice: this.deviceKey,
|
|
648
|
-
deviceKey,
|
|
649
|
-
controlFeedKey,
|
|
650
|
-
dataFeedKey
|
|
651
|
-
}, {
|
|
652
|
-
file: "identity.ts",
|
|
653
|
-
line: 156,
|
|
654
|
-
scope: this,
|
|
655
|
-
callSite: (f, a) => f(...a)
|
|
288
|
+
async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
|
|
289
|
+
(0, import_log2.log)("Admitting device:", {
|
|
290
|
+
identityKey: this.identityKey,
|
|
291
|
+
hostDevice: this.deviceKey,
|
|
292
|
+
deviceKey,
|
|
293
|
+
controlFeedKey,
|
|
294
|
+
dataFeedKey
|
|
295
|
+
}, {
|
|
296
|
+
file: "identity.ts",
|
|
297
|
+
line: 156,
|
|
298
|
+
scope: this,
|
|
299
|
+
callSite: (f, a) => f(...a)
|
|
656
300
|
});
|
|
657
301
|
const signer = this.getIdentityCredentialSigner();
|
|
658
|
-
await (0,
|
|
302
|
+
await (0, import_feed_store.writeMessages)(this.controlPipeline.writer, [
|
|
659
303
|
await signer.createCredential({
|
|
660
304
|
subject: deviceKey,
|
|
661
305
|
assertion: {
|
|
@@ -694,13 +338,13 @@ var Identity = class {
|
|
|
694
338
|
|
|
695
339
|
// packages/sdk/client-services/src/packlets/identity/identity-manager.ts
|
|
696
340
|
var import_node_assert2 = __toESM(require("node:assert"));
|
|
697
|
-
var
|
|
341
|
+
var import_async3 = require("@dxos/async");
|
|
698
342
|
var import_credentials5 = require("@dxos/credentials");
|
|
699
|
-
var
|
|
343
|
+
var import_keys2 = require("@dxos/keys");
|
|
700
344
|
var import_log3 = require("@dxos/log");
|
|
701
345
|
var import_protocols2 = require("@dxos/protocols");
|
|
702
346
|
var import_credentials6 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
703
|
-
var
|
|
347
|
+
var import_util = require("@dxos/util");
|
|
704
348
|
var IdentityManager = class {
|
|
705
349
|
// TODO(burdon): IdentityManagerParams.
|
|
706
350
|
// TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
|
|
@@ -709,14 +353,14 @@ var IdentityManager = class {
|
|
|
709
353
|
this._keyring = _keyring;
|
|
710
354
|
this._feedStore = _feedStore;
|
|
711
355
|
this._spaceManager = _spaceManager;
|
|
712
|
-
this.stateUpdate = new
|
|
356
|
+
this.stateUpdate = new import_async3.Event();
|
|
713
357
|
}
|
|
714
358
|
get identity() {
|
|
715
359
|
return this._identity;
|
|
716
360
|
}
|
|
717
361
|
async open() {
|
|
718
362
|
var _a;
|
|
719
|
-
const traceId =
|
|
363
|
+
const traceId = import_keys2.PublicKey.random().toHex();
|
|
720
364
|
import_log3.log.trace("dxos.halo.identity-manager.open", import_protocols2.trace.begin({
|
|
721
365
|
id: traceId
|
|
722
366
|
}), {
|
|
@@ -908,7 +552,7 @@ var IdentityManager = class {
|
|
|
908
552
|
swarmIdentity: {
|
|
909
553
|
peerKey: identityRecord.deviceKey,
|
|
910
554
|
credentialProvider: createAuthProvider((0, import_credentials5.createCredentialSignerWithKey)(this._keyring, identityRecord.deviceKey)),
|
|
911
|
-
credentialAuthenticator: (0,
|
|
555
|
+
credentialAuthenticator: (0, import_util.deferFunction)(() => identity.authVerifier.verifier)
|
|
912
556
|
},
|
|
913
557
|
identityKey: identityRecord.identityKey
|
|
914
558
|
});
|
|
@@ -957,7 +601,7 @@ var IdentityManager = class {
|
|
|
957
601
|
|
|
958
602
|
// packages/sdk/client-services/src/packlets/identity/identity-service.ts
|
|
959
603
|
var import_node_assert3 = __toESM(require("node:assert"));
|
|
960
|
-
var
|
|
604
|
+
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
961
605
|
var import_credentials7 = require("@dxos/credentials");
|
|
962
606
|
var import_debug2 = require("@dxos/debug");
|
|
963
607
|
var IdentityServiceImpl = class {
|
|
@@ -973,7 +617,7 @@ var IdentityServiceImpl = class {
|
|
|
973
617
|
return (0, import_debug2.todo)();
|
|
974
618
|
}
|
|
975
619
|
queryIdentity() {
|
|
976
|
-
return new
|
|
620
|
+
return new import_codec_protobuf.Stream(({ next }) => {
|
|
977
621
|
const emitNext = () => next({
|
|
978
622
|
identity: this._getIdentity()
|
|
979
623
|
});
|
|
@@ -1005,7 +649,7 @@ var IdentityServiceImpl = class {
|
|
|
1005
649
|
|
|
1006
650
|
// packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
|
|
1007
651
|
var import_node_assert4 = __toESM(require("node:assert"));
|
|
1008
|
-
var
|
|
652
|
+
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
1009
653
|
var DeviceInvitationProtocol = class {
|
|
1010
654
|
constructor(_keyring, _getIdentity, _acceptIdentity) {
|
|
1011
655
|
this._keyring = _keyring;
|
|
@@ -1017,7 +661,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1017
661
|
}
|
|
1018
662
|
getInvitationContext() {
|
|
1019
663
|
return {
|
|
1020
|
-
kind:
|
|
664
|
+
kind: import_services.Invitation.Kind.DEVICE
|
|
1021
665
|
};
|
|
1022
666
|
}
|
|
1023
667
|
async admit(request) {
|
|
@@ -1070,27 +714,27 @@ var DeviceInvitationProtocol = class {
|
|
|
1070
714
|
|
|
1071
715
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1072
716
|
var import_node_assert6 = __toESM(require("node:assert"));
|
|
1073
|
-
var
|
|
717
|
+
var import_async5 = require("@dxos/async");
|
|
1074
718
|
var import_client_protocol2 = require("@dxos/client-protocol");
|
|
1075
|
-
var
|
|
719
|
+
var import_context3 = require("@dxos/context");
|
|
1076
720
|
var import_credentials8 = require("@dxos/credentials");
|
|
1077
721
|
var import_errors2 = require("@dxos/errors");
|
|
1078
|
-
var
|
|
722
|
+
var import_keys4 = require("@dxos/keys");
|
|
1079
723
|
var import_log5 = require("@dxos/log");
|
|
1080
724
|
var import_network_manager = require("@dxos/network-manager");
|
|
1081
725
|
var import_protocols4 = require("@dxos/protocols");
|
|
1082
|
-
var
|
|
726
|
+
var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1083
727
|
var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
1084
728
|
|
|
1085
729
|
// packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
|
|
1086
730
|
var import_node_assert5 = __toESM(require("node:assert"));
|
|
1087
|
-
var
|
|
1088
|
-
var
|
|
731
|
+
var import_async4 = require("@dxos/async");
|
|
732
|
+
var import_context2 = require("@dxos/context");
|
|
1089
733
|
var import_errors = require("@dxos/errors");
|
|
1090
|
-
var
|
|
734
|
+
var import_keys3 = require("@dxos/keys");
|
|
1091
735
|
var import_log4 = require("@dxos/log");
|
|
1092
736
|
var import_protocols3 = require("@dxos/protocols");
|
|
1093
|
-
var
|
|
737
|
+
var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1094
738
|
var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
1095
739
|
var import_teleport = require("@dxos/teleport");
|
|
1096
740
|
var OPTIONS_TIMEOUT = 1e4;
|
|
@@ -1106,13 +750,13 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1106
750
|
}
|
|
1107
751
|
});
|
|
1108
752
|
this._callbacks = _callbacks;
|
|
1109
|
-
this._ctx = new
|
|
1110
|
-
this._remoteOptionsTrigger = new
|
|
753
|
+
this._ctx = new import_context2.Context();
|
|
754
|
+
this._remoteOptionsTrigger = new import_async4.Trigger();
|
|
1111
755
|
this.invitation = void 0;
|
|
1112
756
|
this.guestProfile = void 0;
|
|
1113
757
|
this.authenticationPassed = false;
|
|
1114
758
|
this.authenticationRetry = 0;
|
|
1115
|
-
this.completedTrigger = new
|
|
759
|
+
this.completedTrigger = new import_async4.Trigger();
|
|
1116
760
|
}
|
|
1117
761
|
async getHandlers() {
|
|
1118
762
|
return {
|
|
@@ -1126,7 +770,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1126
770
|
},
|
|
1127
771
|
introduce: async (request) => {
|
|
1128
772
|
const { profile, invitationId } = request;
|
|
1129
|
-
const traceId =
|
|
773
|
+
const traceId = import_keys3.PublicKey.random().toHex();
|
|
1130
774
|
import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
|
|
1131
775
|
id: traceId
|
|
1132
776
|
}), {
|
|
@@ -1147,7 +791,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1147
791
|
});
|
|
1148
792
|
this._callbacks.onError(new Error("Invitation not found."));
|
|
1149
793
|
return {
|
|
1150
|
-
authMethod:
|
|
794
|
+
authMethod: import_services2.Invitation.AuthMethod.NONE
|
|
1151
795
|
};
|
|
1152
796
|
}
|
|
1153
797
|
this.invitation = invitation;
|
|
@@ -1162,7 +806,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1162
806
|
this.guestProfile = profile;
|
|
1163
807
|
this._callbacks.onStateUpdate({
|
|
1164
808
|
...this.invitation,
|
|
1165
|
-
state:
|
|
809
|
+
state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1166
810
|
});
|
|
1167
811
|
import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
|
|
1168
812
|
id: traceId
|
|
@@ -1173,12 +817,12 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1173
817
|
callSite: (f, a) => f(...a)
|
|
1174
818
|
});
|
|
1175
819
|
return {
|
|
1176
|
-
spaceKey: this.invitation.authMethod ===
|
|
820
|
+
spaceKey: this.invitation.authMethod === import_services2.Invitation.AuthMethod.NONE ? this.invitation.spaceKey : void 0,
|
|
1177
821
|
authMethod: this.invitation.authMethod
|
|
1178
822
|
};
|
|
1179
823
|
},
|
|
1180
824
|
authenticate: async ({ authCode: code }) => {
|
|
1181
|
-
const traceId =
|
|
825
|
+
const traceId = import_keys3.PublicKey.random().toHex();
|
|
1182
826
|
import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
|
|
1183
827
|
id: traceId
|
|
1184
828
|
}), {
|
|
@@ -1198,7 +842,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1198
842
|
let status = import_invitations.AuthenticationResponse.Status.OK;
|
|
1199
843
|
(0, import_node_assert5.default)(this.invitation, "Invitation is not set.");
|
|
1200
844
|
switch (this.invitation.authMethod) {
|
|
1201
|
-
case
|
|
845
|
+
case import_services2.Invitation.AuthMethod.NONE: {
|
|
1202
846
|
(0, import_log4.log)("authentication not required", {}, {
|
|
1203
847
|
file: "invitation-extension.ts",
|
|
1204
848
|
line: 134,
|
|
@@ -1209,7 +853,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1209
853
|
status: import_invitations.AuthenticationResponse.Status.OK
|
|
1210
854
|
};
|
|
1211
855
|
}
|
|
1212
|
-
case
|
|
856
|
+
case import_services2.Invitation.AuthMethod.SHARED_SECRET: {
|
|
1213
857
|
if (this.invitation.authCode) {
|
|
1214
858
|
if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
|
|
1215
859
|
status = import_invitations.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
|
|
@@ -1250,7 +894,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1250
894
|
};
|
|
1251
895
|
},
|
|
1252
896
|
admit: async (request) => {
|
|
1253
|
-
const traceId =
|
|
897
|
+
const traceId = import_keys3.PublicKey.random().toHex();
|
|
1254
898
|
import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
|
|
1255
899
|
id: traceId
|
|
1256
900
|
}), {
|
|
@@ -1289,7 +933,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1289
933
|
await this.rpc.InvitationHostService.options({
|
|
1290
934
|
role: import_invitations.Options.Role.HOST
|
|
1291
935
|
});
|
|
1292
|
-
await (0,
|
|
936
|
+
await (0, import_context2.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1293
937
|
timeout: OPTIONS_TIMEOUT
|
|
1294
938
|
}));
|
|
1295
939
|
if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
|
|
@@ -1318,8 +962,8 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1318
962
|
}
|
|
1319
963
|
});
|
|
1320
964
|
this._callbacks = _callbacks;
|
|
1321
|
-
this._ctx = new
|
|
1322
|
-
this._remoteOptionsTrigger = new
|
|
965
|
+
this._ctx = new import_context2.Context();
|
|
966
|
+
this._remoteOptionsTrigger = new import_async4.Trigger();
|
|
1323
967
|
}
|
|
1324
968
|
async getHandlers() {
|
|
1325
969
|
return {
|
|
@@ -1351,10 +995,10 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1351
995
|
scope: this,
|
|
1352
996
|
callSite: (f, a) => f(...a)
|
|
1353
997
|
});
|
|
1354
|
-
await (0,
|
|
998
|
+
await (0, import_context2.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
|
|
1355
999
|
role: import_invitations.Options.Role.GUEST
|
|
1356
1000
|
}));
|
|
1357
|
-
await (0,
|
|
1001
|
+
await (0, import_context2.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1358
1002
|
timeout: OPTIONS_TIMEOUT
|
|
1359
1003
|
}));
|
|
1360
1004
|
(0, import_log4.log)("end options", {}, {
|
|
@@ -1390,7 +1034,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1390
1034
|
await this._ctx.dispose();
|
|
1391
1035
|
}
|
|
1392
1036
|
};
|
|
1393
|
-
var isAuthenticationRequired = (invitation) => invitation.authMethod !==
|
|
1037
|
+
var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services2.Invitation.AuthMethod.NONE;
|
|
1394
1038
|
|
|
1395
1039
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1396
1040
|
var InvitationsHandler = class {
|
|
@@ -1402,8 +1046,8 @@ var InvitationsHandler = class {
|
|
|
1402
1046
|
}
|
|
1403
1047
|
createInvitation(protocol, options) {
|
|
1404
1048
|
var _a;
|
|
1405
|
-
const { invitationId =
|
|
1406
|
-
const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod ===
|
|
1049
|
+
const { invitationId = import_keys4.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys4.PublicKey.random() } = options != null ? options : {};
|
|
1050
|
+
const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials8.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0;
|
|
1407
1051
|
(0, import_node_assert6.default)(protocol);
|
|
1408
1052
|
const invitation = {
|
|
1409
1053
|
invitationId,
|
|
@@ -1415,8 +1059,8 @@ var InvitationsHandler = class {
|
|
|
1415
1059
|
timeout,
|
|
1416
1060
|
...protocol.getInvitationContext()
|
|
1417
1061
|
};
|
|
1418
|
-
const stream = new
|
|
1419
|
-
const ctx = new
|
|
1062
|
+
const stream = new import_async5.PushStream();
|
|
1063
|
+
const ctx = new import_context3.Context({
|
|
1420
1064
|
onError: (err) => {
|
|
1421
1065
|
void ctx.dispose();
|
|
1422
1066
|
stream.error(err);
|
|
@@ -1438,7 +1082,7 @@ var InvitationsHandler = class {
|
|
|
1438
1082
|
onStateUpdate: (invitation2) => {
|
|
1439
1083
|
stream.next({
|
|
1440
1084
|
...invitation2,
|
|
1441
|
-
state:
|
|
1085
|
+
state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1442
1086
|
});
|
|
1443
1087
|
},
|
|
1444
1088
|
resolveInvitation: async ({ invitationId: invitationId2 }) => {
|
|
@@ -1461,8 +1105,8 @@ var InvitationsHandler = class {
|
|
|
1461
1105
|
}
|
|
1462
1106
|
},
|
|
1463
1107
|
onOpen: () => {
|
|
1464
|
-
(0,
|
|
1465
|
-
const traceId =
|
|
1108
|
+
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1109
|
+
const traceId = import_keys4.PublicKey.random().toHex();
|
|
1466
1110
|
try {
|
|
1467
1111
|
import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
|
|
1468
1112
|
id: traceId
|
|
@@ -1482,7 +1126,7 @@ var InvitationsHandler = class {
|
|
|
1482
1126
|
});
|
|
1483
1127
|
stream.next({
|
|
1484
1128
|
...invitation,
|
|
1485
|
-
state:
|
|
1129
|
+
state: import_services3.Invitation.State.CONNECTED
|
|
1486
1130
|
});
|
|
1487
1131
|
const deviceKey = await extension.completedTrigger.wait({
|
|
1488
1132
|
timeout
|
|
@@ -1498,7 +1142,7 @@ var InvitationsHandler = class {
|
|
|
1498
1142
|
});
|
|
1499
1143
|
stream.next({
|
|
1500
1144
|
...invitation,
|
|
1501
|
-
state:
|
|
1145
|
+
state: import_services3.Invitation.State.SUCCESS
|
|
1502
1146
|
});
|
|
1503
1147
|
import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
|
|
1504
1148
|
id: traceId
|
|
@@ -1509,7 +1153,7 @@ var InvitationsHandler = class {
|
|
|
1509
1153
|
callSite: (f, a) => f(...a)
|
|
1510
1154
|
});
|
|
1511
1155
|
} catch (err) {
|
|
1512
|
-
if (err instanceof
|
|
1156
|
+
if (err instanceof import_async5.TimeoutError) {
|
|
1513
1157
|
(0, import_log5.log)("timeout", {
|
|
1514
1158
|
...protocol.toJSON()
|
|
1515
1159
|
}, {
|
|
@@ -1520,7 +1164,7 @@ var InvitationsHandler = class {
|
|
|
1520
1164
|
});
|
|
1521
1165
|
stream.next({
|
|
1522
1166
|
...invitation,
|
|
1523
|
-
state:
|
|
1167
|
+
state: import_services3.Invitation.State.TIMEOUT
|
|
1524
1168
|
});
|
|
1525
1169
|
} else {
|
|
1526
1170
|
import_log5.log.error("failed", err, {
|
|
@@ -1541,7 +1185,7 @@ var InvitationsHandler = class {
|
|
|
1541
1185
|
callSite: (f, a) => f(...a)
|
|
1542
1186
|
});
|
|
1543
1187
|
} finally {
|
|
1544
|
-
if (type !==
|
|
1188
|
+
if (type !== import_services3.Invitation.Type.MULTIUSE) {
|
|
1545
1189
|
await swarmConnection.close();
|
|
1546
1190
|
await ctx.dispose();
|
|
1547
1191
|
}
|
|
@@ -1552,7 +1196,7 @@ var InvitationsHandler = class {
|
|
|
1552
1196
|
if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
|
|
1553
1197
|
return;
|
|
1554
1198
|
}
|
|
1555
|
-
if (err instanceof
|
|
1199
|
+
if (err instanceof import_async5.TimeoutError) {
|
|
1556
1200
|
(0, import_log5.log)("timeout", {
|
|
1557
1201
|
...protocol.toJSON()
|
|
1558
1202
|
}, {
|
|
@@ -1563,7 +1207,7 @@ var InvitationsHandler = class {
|
|
|
1563
1207
|
});
|
|
1564
1208
|
stream.next({
|
|
1565
1209
|
...invitation,
|
|
1566
|
-
state:
|
|
1210
|
+
state: import_services3.Invitation.State.TIMEOUT
|
|
1567
1211
|
});
|
|
1568
1212
|
} else {
|
|
1569
1213
|
import_log5.log.error("failed", err, {
|
|
@@ -1579,7 +1223,7 @@ var InvitationsHandler = class {
|
|
|
1579
1223
|
return extension;
|
|
1580
1224
|
};
|
|
1581
1225
|
let swarmConnection;
|
|
1582
|
-
(0,
|
|
1226
|
+
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1583
1227
|
const topic = invitation.swarmKey;
|
|
1584
1228
|
swarmConnection = await this._networkManager.joinSwarm({
|
|
1585
1229
|
topic,
|
|
@@ -1592,7 +1236,7 @@ var InvitationsHandler = class {
|
|
|
1592
1236
|
ctx.onDispose(() => swarmConnection.close());
|
|
1593
1237
|
stream.next({
|
|
1594
1238
|
...invitation,
|
|
1595
|
-
state:
|
|
1239
|
+
state: import_services3.Invitation.State.CONNECTING
|
|
1596
1240
|
});
|
|
1597
1241
|
});
|
|
1598
1242
|
const observable = new import_client_protocol2.CancellableInvitationObservable({
|
|
@@ -1601,7 +1245,7 @@ var InvitationsHandler = class {
|
|
|
1601
1245
|
onCancel: async () => {
|
|
1602
1246
|
stream.next({
|
|
1603
1247
|
...invitation,
|
|
1604
|
-
state:
|
|
1248
|
+
state: import_services3.Invitation.State.CANCELLED
|
|
1605
1249
|
});
|
|
1606
1250
|
await ctx.dispose();
|
|
1607
1251
|
}
|
|
@@ -1611,10 +1255,10 @@ var InvitationsHandler = class {
|
|
|
1611
1255
|
acceptInvitation(protocol, invitation) {
|
|
1612
1256
|
const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
|
|
1613
1257
|
(0, import_node_assert6.default)(protocol);
|
|
1614
|
-
const authenticated = new
|
|
1258
|
+
const authenticated = new import_async5.Trigger();
|
|
1615
1259
|
let admitted = false;
|
|
1616
1260
|
let currentState;
|
|
1617
|
-
const stream = new
|
|
1261
|
+
const stream = new import_async5.PushStream();
|
|
1618
1262
|
const setState = (newData) => {
|
|
1619
1263
|
(0, import_node_assert6.default)(newData.state !== void 0);
|
|
1620
1264
|
currentState = newData.state;
|
|
@@ -1623,9 +1267,9 @@ var InvitationsHandler = class {
|
|
|
1623
1267
|
...newData
|
|
1624
1268
|
});
|
|
1625
1269
|
};
|
|
1626
|
-
const ctx = new
|
|
1270
|
+
const ctx = new import_context3.Context({
|
|
1627
1271
|
onError: (err) => {
|
|
1628
|
-
if (err instanceof
|
|
1272
|
+
if (err instanceof import_async5.TimeoutError) {
|
|
1629
1273
|
(0, import_log5.log)("timeout", {
|
|
1630
1274
|
...protocol.toJSON()
|
|
1631
1275
|
}, {
|
|
@@ -1635,7 +1279,7 @@ var InvitationsHandler = class {
|
|
|
1635
1279
|
callSite: (f, a) => f(...a)
|
|
1636
1280
|
});
|
|
1637
1281
|
setState({
|
|
1638
|
-
state:
|
|
1282
|
+
state: import_services3.Invitation.State.TIMEOUT
|
|
1639
1283
|
});
|
|
1640
1284
|
} else {
|
|
1641
1285
|
import_log5.log.warn("auth failed", err, {
|
|
@@ -1677,8 +1321,8 @@ var InvitationsHandler = class {
|
|
|
1677
1321
|
stream.error(new Error("Remote peer disconnected."));
|
|
1678
1322
|
}
|
|
1679
1323
|
});
|
|
1680
|
-
(0,
|
|
1681
|
-
const traceId =
|
|
1324
|
+
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1325
|
+
const traceId = import_keys4.PublicKey.random().toHex();
|
|
1682
1326
|
try {
|
|
1683
1327
|
import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
|
|
1684
1328
|
id: traceId
|
|
@@ -1691,7 +1335,7 @@ var InvitationsHandler = class {
|
|
|
1691
1335
|
if (++connectionCount > 1) {
|
|
1692
1336
|
throw new Error(`multiple connections detected: ${connectionCount}`);
|
|
1693
1337
|
}
|
|
1694
|
-
(0,
|
|
1338
|
+
(0, import_async5.scheduleTask)(ctx, () => ctx.raise(new import_async5.TimeoutError(timeout)), timeout);
|
|
1695
1339
|
(0, import_log5.log)("connected", {
|
|
1696
1340
|
...protocol.toJSON()
|
|
1697
1341
|
}, {
|
|
@@ -1701,7 +1345,7 @@ var InvitationsHandler = class {
|
|
|
1701
1345
|
callSite: (f, a) => f(...a)
|
|
1702
1346
|
});
|
|
1703
1347
|
setState({
|
|
1704
|
-
state:
|
|
1348
|
+
state: import_services3.Invitation.State.CONNECTED
|
|
1705
1349
|
});
|
|
1706
1350
|
(0, import_log5.log)("introduce", {
|
|
1707
1351
|
...protocol.toJSON()
|
|
@@ -1734,7 +1378,7 @@ var InvitationsHandler = class {
|
|
|
1734
1378
|
callSite: (f, a) => f(...a)
|
|
1735
1379
|
});
|
|
1736
1380
|
setState({
|
|
1737
|
-
state:
|
|
1381
|
+
state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1738
1382
|
});
|
|
1739
1383
|
const authCode = await authenticated.wait({
|
|
1740
1384
|
timeout
|
|
@@ -1746,7 +1390,7 @@ var InvitationsHandler = class {
|
|
|
1746
1390
|
callSite: (f, a) => f(...a)
|
|
1747
1391
|
});
|
|
1748
1392
|
setState({
|
|
1749
|
-
state:
|
|
1393
|
+
state: import_services3.Invitation.State.AUTHENTICATING
|
|
1750
1394
|
});
|
|
1751
1395
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
1752
1396
|
authCode
|
|
@@ -1772,7 +1416,7 @@ var InvitationsHandler = class {
|
|
|
1772
1416
|
}
|
|
1773
1417
|
} else {
|
|
1774
1418
|
setState({
|
|
1775
|
-
state:
|
|
1419
|
+
state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1776
1420
|
});
|
|
1777
1421
|
}
|
|
1778
1422
|
(0, import_log5.log)("request admission", {
|
|
@@ -1797,7 +1441,7 @@ var InvitationsHandler = class {
|
|
|
1797
1441
|
});
|
|
1798
1442
|
setState({
|
|
1799
1443
|
...result,
|
|
1800
|
-
state:
|
|
1444
|
+
state: import_services3.Invitation.State.SUCCESS
|
|
1801
1445
|
});
|
|
1802
1446
|
import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
|
|
1803
1447
|
id: traceId
|
|
@@ -1808,7 +1452,7 @@ var InvitationsHandler = class {
|
|
|
1808
1452
|
callSite: (f, a) => f(...a)
|
|
1809
1453
|
});
|
|
1810
1454
|
} catch (err) {
|
|
1811
|
-
if (err instanceof
|
|
1455
|
+
if (err instanceof import_async5.TimeoutError) {
|
|
1812
1456
|
(0, import_log5.log)("timeout", {
|
|
1813
1457
|
...protocol.toJSON()
|
|
1814
1458
|
}, {
|
|
@@ -1818,7 +1462,7 @@ var InvitationsHandler = class {
|
|
|
1818
1462
|
callSite: (f, a) => f(...a)
|
|
1819
1463
|
});
|
|
1820
1464
|
setState({
|
|
1821
|
-
state:
|
|
1465
|
+
state: import_services3.Invitation.State.TIMEOUT
|
|
1822
1466
|
});
|
|
1823
1467
|
} else {
|
|
1824
1468
|
(0, import_log5.log)("auth failed", err, {
|
|
@@ -1847,7 +1491,7 @@ var InvitationsHandler = class {
|
|
|
1847
1491
|
if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
|
|
1848
1492
|
return;
|
|
1849
1493
|
}
|
|
1850
|
-
if (err instanceof
|
|
1494
|
+
if (err instanceof import_async5.TimeoutError) {
|
|
1851
1495
|
(0, import_log5.log)("timeout", {
|
|
1852
1496
|
...protocol.toJSON()
|
|
1853
1497
|
}, {
|
|
@@ -1857,7 +1501,7 @@ var InvitationsHandler = class {
|
|
|
1857
1501
|
callSite: (f, a) => f(...a)
|
|
1858
1502
|
});
|
|
1859
1503
|
setState({
|
|
1860
|
-
state:
|
|
1504
|
+
state: import_services3.Invitation.State.TIMEOUT
|
|
1861
1505
|
});
|
|
1862
1506
|
} else {
|
|
1863
1507
|
(0, import_log5.log)("auth failed", err, {
|
|
@@ -1872,12 +1516,12 @@ var InvitationsHandler = class {
|
|
|
1872
1516
|
});
|
|
1873
1517
|
return extension;
|
|
1874
1518
|
};
|
|
1875
|
-
(0,
|
|
1519
|
+
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1876
1520
|
(0, import_node_assert6.default)(invitation.swarmKey);
|
|
1877
1521
|
const topic = invitation.swarmKey;
|
|
1878
1522
|
const swarmConnection = await this._networkManager.joinSwarm({
|
|
1879
1523
|
topic,
|
|
1880
|
-
peerId:
|
|
1524
|
+
peerId: import_keys4.PublicKey.random(),
|
|
1881
1525
|
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
1882
1526
|
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
1883
1527
|
}),
|
|
@@ -1885,7 +1529,7 @@ var InvitationsHandler = class {
|
|
|
1885
1529
|
});
|
|
1886
1530
|
ctx.onDispose(() => swarmConnection.close());
|
|
1887
1531
|
setState({
|
|
1888
|
-
state:
|
|
1532
|
+
state: import_services3.Invitation.State.CONNECTING
|
|
1889
1533
|
});
|
|
1890
1534
|
});
|
|
1891
1535
|
const observable = new import_client_protocol2.AuthenticatingInvitationObservable({
|
|
@@ -1893,7 +1537,7 @@ var InvitationsHandler = class {
|
|
|
1893
1537
|
subscriber: stream.observable,
|
|
1894
1538
|
onCancel: async () => {
|
|
1895
1539
|
setState({
|
|
1896
|
-
state:
|
|
1540
|
+
state: import_services3.Invitation.State.CANCELLED
|
|
1897
1541
|
});
|
|
1898
1542
|
await ctx.dispose();
|
|
1899
1543
|
},
|
|
@@ -1907,20 +1551,20 @@ var InvitationsHandler = class {
|
|
|
1907
1551
|
|
|
1908
1552
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
1909
1553
|
var import_node_assert7 = __toESM(require("node:assert"));
|
|
1910
|
-
var
|
|
1911
|
-
var
|
|
1554
|
+
var import_async6 = require("@dxos/async");
|
|
1555
|
+
var import_codec_protobuf2 = require("@dxos/codec-protobuf");
|
|
1912
1556
|
var import_log6 = require("@dxos/log");
|
|
1913
|
-
var
|
|
1557
|
+
var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1914
1558
|
var InvitationsServiceImpl = class {
|
|
1915
1559
|
constructor(_invitationsHandler, _getHandler) {
|
|
1916
1560
|
this._invitationsHandler = _invitationsHandler;
|
|
1917
1561
|
this._getHandler = _getHandler;
|
|
1918
1562
|
this._createInvitations = /* @__PURE__ */ new Map();
|
|
1919
1563
|
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
1920
|
-
this._invitationCreated = new
|
|
1921
|
-
this._invitationAccepted = new
|
|
1922
|
-
this._removedCreated = new
|
|
1923
|
-
this._removedAccepted = new
|
|
1564
|
+
this._invitationCreated = new import_async6.Event();
|
|
1565
|
+
this._invitationAccepted = new import_async6.Event();
|
|
1566
|
+
this._removedCreated = new import_async6.Event();
|
|
1567
|
+
this._removedAccepted = new import_async6.Event();
|
|
1924
1568
|
}
|
|
1925
1569
|
// TODO(burdon): Guest/host label.
|
|
1926
1570
|
getLoggingContext() {
|
|
@@ -1937,7 +1581,7 @@ var InvitationsServiceImpl = class {
|
|
|
1937
1581
|
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
1938
1582
|
this._invitationCreated.emit(invitation.get());
|
|
1939
1583
|
}
|
|
1940
|
-
return new
|
|
1584
|
+
return new import_codec_protobuf2.Stream(({ next, close }) => {
|
|
1941
1585
|
invitation.subscribe((invitation2) => {
|
|
1942
1586
|
next(invitation2);
|
|
1943
1587
|
}, (err) => {
|
|
@@ -1959,7 +1603,7 @@ var InvitationsServiceImpl = class {
|
|
|
1959
1603
|
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
1960
1604
|
this._invitationAccepted.emit(invitation.get());
|
|
1961
1605
|
}
|
|
1962
|
-
return new
|
|
1606
|
+
return new import_codec_protobuf2.Stream(({ next, close }) => {
|
|
1963
1607
|
invitation.subscribe((invitation2) => {
|
|
1964
1608
|
next(invitation2);
|
|
1965
1609
|
}, (err) => {
|
|
@@ -2022,11 +1666,11 @@ var InvitationsServiceImpl = class {
|
|
|
2022
1666
|
}
|
|
2023
1667
|
}
|
|
2024
1668
|
queryInvitations() {
|
|
2025
|
-
return new
|
|
1669
|
+
return new import_codec_protobuf2.Stream(({ next, ctx }) => {
|
|
2026
1670
|
this._invitationCreated.on(ctx, (invitation) => {
|
|
2027
1671
|
next({
|
|
2028
|
-
action:
|
|
2029
|
-
type:
|
|
1672
|
+
action: import_services4.QueryInvitationsResponse.Action.ADDED,
|
|
1673
|
+
type: import_services4.QueryInvitationsResponse.Type.CREATED,
|
|
2030
1674
|
invitations: [
|
|
2031
1675
|
invitation
|
|
2032
1676
|
]
|
|
@@ -2034,8 +1678,8 @@ var InvitationsServiceImpl = class {
|
|
|
2034
1678
|
});
|
|
2035
1679
|
this._invitationAccepted.on(ctx, (invitation) => {
|
|
2036
1680
|
next({
|
|
2037
|
-
action:
|
|
2038
|
-
type:
|
|
1681
|
+
action: import_services4.QueryInvitationsResponse.Action.ADDED,
|
|
1682
|
+
type: import_services4.QueryInvitationsResponse.Type.ACCEPTED,
|
|
2039
1683
|
invitations: [
|
|
2040
1684
|
invitation
|
|
2041
1685
|
]
|
|
@@ -2043,8 +1687,8 @@ var InvitationsServiceImpl = class {
|
|
|
2043
1687
|
});
|
|
2044
1688
|
this._removedCreated.on(ctx, (invitation) => {
|
|
2045
1689
|
next({
|
|
2046
|
-
action:
|
|
2047
|
-
type:
|
|
1690
|
+
action: import_services4.QueryInvitationsResponse.Action.REMOVED,
|
|
1691
|
+
type: import_services4.QueryInvitationsResponse.Type.CREATED,
|
|
2048
1692
|
invitations: [
|
|
2049
1693
|
invitation
|
|
2050
1694
|
]
|
|
@@ -2052,21 +1696,21 @@ var InvitationsServiceImpl = class {
|
|
|
2052
1696
|
});
|
|
2053
1697
|
this._removedAccepted.on(ctx, (invitation) => {
|
|
2054
1698
|
next({
|
|
2055
|
-
action:
|
|
2056
|
-
type:
|
|
1699
|
+
action: import_services4.QueryInvitationsResponse.Action.REMOVED,
|
|
1700
|
+
type: import_services4.QueryInvitationsResponse.Type.ACCEPTED,
|
|
2057
1701
|
invitations: [
|
|
2058
1702
|
invitation
|
|
2059
1703
|
]
|
|
2060
1704
|
});
|
|
2061
1705
|
});
|
|
2062
1706
|
next({
|
|
2063
|
-
action:
|
|
2064
|
-
type:
|
|
1707
|
+
action: import_services4.QueryInvitationsResponse.Action.ADDED,
|
|
1708
|
+
type: import_services4.QueryInvitationsResponse.Type.CREATED,
|
|
2065
1709
|
invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
|
|
2066
1710
|
});
|
|
2067
1711
|
next({
|
|
2068
|
-
action:
|
|
2069
|
-
type:
|
|
1712
|
+
action: import_services4.QueryInvitationsResponse.Action.ADDED,
|
|
1713
|
+
type: import_services4.QueryInvitationsResponse.Type.ACCEPTED,
|
|
2070
1714
|
invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
|
|
2071
1715
|
});
|
|
2072
1716
|
});
|
|
@@ -2076,9 +1720,9 @@ var InvitationsServiceImpl = class {
|
|
|
2076
1720
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2077
1721
|
var import_node_assert8 = __toESM(require("node:assert"));
|
|
2078
1722
|
var import_credentials9 = require("@dxos/credentials");
|
|
2079
|
-
var
|
|
1723
|
+
var import_feed_store2 = require("@dxos/feed-store");
|
|
2080
1724
|
var import_log7 = require("@dxos/log");
|
|
2081
|
-
var
|
|
1725
|
+
var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2082
1726
|
var SpaceInvitationProtocol = class {
|
|
2083
1727
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2084
1728
|
this._spaceManager = _spaceManager;
|
|
@@ -2094,7 +1738,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2094
1738
|
}
|
|
2095
1739
|
getInvitationContext() {
|
|
2096
1740
|
return {
|
|
2097
|
-
kind:
|
|
1741
|
+
kind: import_services5.Invitation.Kind.SPACE,
|
|
2098
1742
|
spaceKey: this._spaceKey
|
|
2099
1743
|
};
|
|
2100
1744
|
}
|
|
@@ -2118,7 +1762,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2118
1762
|
(0, import_node_assert8.default)(credentials[0].credential);
|
|
2119
1763
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2120
1764
|
(0, import_node_assert8.default)((0, import_credentials9.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
2121
|
-
await (0,
|
|
1765
|
+
await (0, import_feed_store2.writeMessages)(space.inner.controlPipeline.writer, credentials);
|
|
2122
1766
|
return {
|
|
2123
1767
|
space: {
|
|
2124
1768
|
credential: spaceMemberCredential,
|
|
@@ -2163,211 +1807,52 @@ var SpaceInvitationProtocol = class {
|
|
|
2163
1807
|
}
|
|
2164
1808
|
};
|
|
2165
1809
|
|
|
2166
|
-
// packages/sdk/client-services/src/packlets/locks/node.ts
|
|
2167
|
-
var import_node_assert9 = __toESM(require("node:assert"));
|
|
2168
|
-
var import_lock_file = require("@dxos/lock-file");
|
|
2169
|
-
var import_log8 = require("@dxos/log");
|
|
2170
|
-
var __decorate = function(decorators, target, key, desc) {
|
|
2171
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2172
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2173
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
2174
|
-
else
|
|
2175
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2176
|
-
if (d = decorators[i])
|
|
2177
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2178
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2179
|
-
};
|
|
2180
|
-
var Lock = class {
|
|
2181
|
-
constructor({ lockKey: lockPath, onAcquire, onRelease }) {
|
|
2182
|
-
this._lockPath = lockPath;
|
|
2183
|
-
this._onAcquire = onAcquire;
|
|
2184
|
-
this._onRelease = onRelease;
|
|
2185
|
-
}
|
|
2186
|
-
get lockKey() {
|
|
2187
|
-
return this._lockPath;
|
|
2188
|
-
}
|
|
2189
|
-
async acquire() {
|
|
2190
|
-
var _a;
|
|
2191
|
-
(0, import_log8.log)("acquiring lock...", {}, {
|
|
2192
|
-
file: "node.ts",
|
|
2193
|
-
line: 32,
|
|
2194
|
-
scope: this,
|
|
2195
|
-
callSite: (f, a) => f(...a)
|
|
2196
|
-
});
|
|
2197
|
-
this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
|
|
2198
|
-
await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
|
|
2199
|
-
(0, import_log8.log)("acquired lock", {}, {
|
|
2200
|
-
file: "node.ts",
|
|
2201
|
-
line: 37,
|
|
2202
|
-
scope: this,
|
|
2203
|
-
callSite: (f, a) => f(...a)
|
|
2204
|
-
});
|
|
2205
|
-
}
|
|
2206
|
-
async release() {
|
|
2207
|
-
var _a;
|
|
2208
|
-
await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
|
|
2209
|
-
(0, import_node_assert9.default)(this._fileHandle, "Lock is not acquired");
|
|
2210
|
-
await import_lock_file.LockFile.release(this._fileHandle);
|
|
2211
|
-
}
|
|
2212
|
-
};
|
|
2213
|
-
__decorate([
|
|
2214
|
-
import_log8.logInfo
|
|
2215
|
-
], Lock.prototype, "lockKey", null);
|
|
2216
|
-
|
|
2217
|
-
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
2218
|
-
var import_async11 = require("@dxos/async");
|
|
2219
|
-
var import_codec_protobuf10 = require("@dxos/codec-protobuf");
|
|
2220
|
-
var import_log9 = require("@dxos/log");
|
|
2221
|
-
var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2222
|
-
var import_util3 = require("@dxos/util");
|
|
2223
|
-
var LoggingServiceImpl = class {
|
|
2224
|
-
constructor() {
|
|
2225
|
-
this._logs = new import_async11.Event();
|
|
2226
|
-
this._logProcessor = (_config, entry2) => {
|
|
2227
|
-
this._logs.emit(entry2);
|
|
2228
|
-
};
|
|
2229
|
-
}
|
|
2230
|
-
async open() {
|
|
2231
|
-
import_log9.log.runtimeConfig.processors.push(this._logProcessor);
|
|
2232
|
-
}
|
|
2233
|
-
async close() {
|
|
2234
|
-
const index = import_log9.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
2235
|
-
import_log9.log.runtimeConfig.processors.splice(index, 1);
|
|
2236
|
-
}
|
|
2237
|
-
queryLogs(request) {
|
|
2238
|
-
return new import_codec_protobuf10.Stream(({ ctx, next }) => {
|
|
2239
|
-
const handler = (entry2) => {
|
|
2240
|
-
var _a, _b, _c, _d, _e;
|
|
2241
|
-
if (LOG_PROCESSING > 0) {
|
|
2242
|
-
return;
|
|
2243
|
-
}
|
|
2244
|
-
if (((_a = entry2.meta) == null ? void 0 : _a.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
|
|
2245
|
-
return;
|
|
2246
|
-
}
|
|
2247
|
-
if (!shouldLog(entry2, request)) {
|
|
2248
|
-
return;
|
|
2249
|
-
}
|
|
2250
|
-
const record = {
|
|
2251
|
-
...entry2,
|
|
2252
|
-
context: (0, import_util3.jsonify)((0, import_log9.getContextFromEntry)(entry2)),
|
|
2253
|
-
timestamp: new Date(),
|
|
2254
|
-
meta: {
|
|
2255
|
-
// TODO(dmaretskyi): Fix proto.
|
|
2256
|
-
file: (_c = (_b = entry2.meta) == null ? void 0 : _b.file) != null ? _c : "",
|
|
2257
|
-
line: (_e = (_d = entry2.meta) == null ? void 0 : _d.line) != null ? _e : 0
|
|
2258
|
-
}
|
|
2259
|
-
};
|
|
2260
|
-
try {
|
|
2261
|
-
LOG_PROCESSING++;
|
|
2262
|
-
next(record);
|
|
2263
|
-
} finally {
|
|
2264
|
-
LOG_PROCESSING--;
|
|
2265
|
-
}
|
|
2266
|
-
};
|
|
2267
|
-
this._logs.on(ctx, handler);
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
};
|
|
2271
|
-
var matchFilter = (filter, level, path, options) => {
|
|
2272
|
-
switch (options) {
|
|
2273
|
-
case import_services7.QueryLogsRequest.MatchingOptions.INCLUSIVE:
|
|
2274
|
-
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
2275
|
-
case import_services7.QueryLogsRequest.MatchingOptions.EXPLICIT:
|
|
2276
|
-
return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
2277
|
-
}
|
|
2278
|
-
};
|
|
2279
|
-
var shouldLog = (entry2, request) => {
|
|
2280
|
-
var _a;
|
|
2281
|
-
const options = (_a = request.options) != null ? _a : import_services7.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
2282
|
-
if (request.filters === void 0) {
|
|
2283
|
-
return options === import_services7.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
2284
|
-
} else {
|
|
2285
|
-
return request.filters.some((filter) => {
|
|
2286
|
-
var _a2, _b;
|
|
2287
|
-
return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.file) != null ? _b : "", options);
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
};
|
|
2291
|
-
var LOG_PROCESSING = 0;
|
|
2292
|
-
|
|
2293
|
-
// packages/sdk/client-services/src/packlets/network/network-service.ts
|
|
2294
|
-
var import_codec_protobuf11 = require("@dxos/codec-protobuf");
|
|
2295
|
-
var NetworkServiceImpl = class {
|
|
2296
|
-
constructor(networkManager, signalManager) {
|
|
2297
|
-
this.networkManager = networkManager;
|
|
2298
|
-
this.signalManager = signalManager;
|
|
2299
|
-
}
|
|
2300
|
-
queryStatus() {
|
|
2301
|
-
return new import_codec_protobuf11.Stream(({ next }) => {
|
|
2302
|
-
const update = () => {
|
|
2303
|
-
next({
|
|
2304
|
-
swarm: this.networkManager.connectionState,
|
|
2305
|
-
signaling: this.signalManager.getStatus().map(({ host, state }) => ({
|
|
2306
|
-
server: host,
|
|
2307
|
-
state
|
|
2308
|
-
}))
|
|
2309
|
-
});
|
|
2310
|
-
};
|
|
2311
|
-
const unsubscribeSwarm = this.networkManager.connectionStateChanged.on(() => update());
|
|
2312
|
-
const unsubscribeSignal = this.signalManager.statusChanged.on(() => update());
|
|
2313
|
-
update();
|
|
2314
|
-
return () => {
|
|
2315
|
-
unsubscribeSwarm();
|
|
2316
|
-
unsubscribeSignal();
|
|
2317
|
-
};
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
async updateConfig(request) {
|
|
2321
|
-
await this.networkManager.setConnectionState(request.swarm);
|
|
2322
|
-
}
|
|
2323
|
-
};
|
|
2324
|
-
|
|
2325
1810
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
2326
|
-
var
|
|
2327
|
-
var
|
|
2328
|
-
var
|
|
1811
|
+
var import_node_assert10 = __toESM(require("node:assert"));
|
|
1812
|
+
var import_async9 = require("@dxos/async");
|
|
1813
|
+
var import_context6 = require("@dxos/context");
|
|
2329
1814
|
var import_credentials13 = require("@dxos/credentials");
|
|
2330
|
-
var
|
|
2331
|
-
var
|
|
1815
|
+
var import_keys7 = require("@dxos/keys");
|
|
1816
|
+
var import_log10 = require("@dxos/log");
|
|
2332
1817
|
var import_protocols6 = require("@dxos/protocols");
|
|
2333
|
-
var
|
|
1818
|
+
var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2334
1819
|
var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
|
|
2335
|
-
var
|
|
1820
|
+
var import_util4 = require("@dxos/util");
|
|
2336
1821
|
|
|
2337
1822
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2338
|
-
var
|
|
1823
|
+
var import_async8 = require("@dxos/async");
|
|
2339
1824
|
var import_client_protocol3 = require("@dxos/client-protocol");
|
|
2340
|
-
var
|
|
1825
|
+
var import_context5 = require("@dxos/context");
|
|
2341
1826
|
var import_debug3 = require("@dxos/debug");
|
|
2342
1827
|
var import_echo_pipeline = require("@dxos/echo-pipeline");
|
|
2343
1828
|
var import_errors3 = require("@dxos/errors");
|
|
2344
|
-
var
|
|
2345
|
-
var
|
|
2346
|
-
var
|
|
1829
|
+
var import_keys6 = require("@dxos/keys");
|
|
1830
|
+
var import_log9 = require("@dxos/log");
|
|
1831
|
+
var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2347
1832
|
var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
2348
1833
|
var import_timeframe = require("@dxos/timeframe");
|
|
2349
|
-
var
|
|
1834
|
+
var import_util3 = require("@dxos/util");
|
|
2350
1835
|
|
|
2351
1836
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
2352
|
-
var
|
|
2353
|
-
var
|
|
2354
|
-
var
|
|
2355
|
-
var
|
|
2356
|
-
var
|
|
1837
|
+
var import_node_assert9 = __toESM(require("node:assert"));
|
|
1838
|
+
var import_async7 = require("@dxos/async");
|
|
1839
|
+
var import_context4 = require("@dxos/context");
|
|
1840
|
+
var import_keys5 = require("@dxos/keys");
|
|
1841
|
+
var import_log8 = require("@dxos/log");
|
|
2357
1842
|
var import_protocols5 = require("@dxos/protocols");
|
|
2358
1843
|
var import_teleport2 = require("@dxos/teleport");
|
|
2359
|
-
var
|
|
1844
|
+
var import_util2 = require("@dxos/util");
|
|
2360
1845
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
2361
1846
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
2362
1847
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
2363
1848
|
var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
|
|
2364
1849
|
var NotarizationPlugin = class {
|
|
2365
1850
|
constructor() {
|
|
2366
|
-
this._ctx = new
|
|
2367
|
-
this._extensionOpened = new
|
|
1851
|
+
this._ctx = new import_context4.Context();
|
|
1852
|
+
this._extensionOpened = new import_async7.Event();
|
|
2368
1853
|
this._extensions = /* @__PURE__ */ new Set();
|
|
2369
|
-
this._processedCredentials = new
|
|
2370
|
-
this._processCredentialsTriggers = new
|
|
1854
|
+
this._processedCredentials = new import_util2.ComplexSet(import_keys5.PublicKey.hash);
|
|
1855
|
+
this._processCredentialsTriggers = new import_util2.ComplexMap(import_keys5.PublicKey.hash);
|
|
2371
1856
|
}
|
|
2372
1857
|
async open() {
|
|
2373
1858
|
}
|
|
@@ -2378,7 +1863,7 @@ var NotarizationPlugin = class {
|
|
|
2378
1863
|
* Request credentials to be notarized.
|
|
2379
1864
|
*/
|
|
2380
1865
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
2381
|
-
(0,
|
|
1866
|
+
(0, import_log8.log)("notarize", {
|
|
2382
1867
|
credentials
|
|
2383
1868
|
}, {
|
|
2384
1869
|
file: "notarization-plugin.ts",
|
|
@@ -2386,11 +1871,11 @@ var NotarizationPlugin = class {
|
|
|
2386
1871
|
scope: this,
|
|
2387
1872
|
callSite: (f, a) => f(...a)
|
|
2388
1873
|
});
|
|
2389
|
-
(0,
|
|
2390
|
-
const errors = new
|
|
1874
|
+
(0, import_node_assert9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
|
|
1875
|
+
const errors = new import_async7.Trigger();
|
|
2391
1876
|
const ctx = this._ctx.derive({
|
|
2392
1877
|
onError: (err) => {
|
|
2393
|
-
|
|
1878
|
+
import_log8.log.warn("Notarization error", {
|
|
2394
1879
|
err
|
|
2395
1880
|
}, {
|
|
2396
1881
|
file: "notarization-plugin.ts",
|
|
@@ -2404,8 +1889,8 @@ var NotarizationPlugin = class {
|
|
|
2404
1889
|
});
|
|
2405
1890
|
opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
|
|
2406
1891
|
if (timeout !== 0) {
|
|
2407
|
-
(0,
|
|
2408
|
-
|
|
1892
|
+
(0, import_async7.scheduleTask)(ctx, () => {
|
|
1893
|
+
import_log8.log.warn("Notarization timeout", {
|
|
2409
1894
|
timeout,
|
|
2410
1895
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
2411
1896
|
}, {
|
|
@@ -2415,12 +1900,12 @@ var NotarizationPlugin = class {
|
|
|
2415
1900
|
callSite: (f, a) => f(...a)
|
|
2416
1901
|
});
|
|
2417
1902
|
void ctx.dispose();
|
|
2418
|
-
errors.throw(new
|
|
1903
|
+
errors.throw(new import_async7.TimeoutError(timeout, "Notarization timed out"));
|
|
2419
1904
|
}, timeout);
|
|
2420
1905
|
}
|
|
2421
1906
|
const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
|
|
2422
1907
|
const peersTried = /* @__PURE__ */ new Set();
|
|
2423
|
-
const notarizeTask = new
|
|
1908
|
+
const notarizeTask = new import_async7.DeferredTask(ctx, async () => {
|
|
2424
1909
|
try {
|
|
2425
1910
|
if (this._extensions.size === 0) {
|
|
2426
1911
|
return;
|
|
@@ -2429,7 +1914,7 @@ var NotarizationPlugin = class {
|
|
|
2429
1914
|
...this._extensions
|
|
2430
1915
|
].find((peer2) => !peersTried.has(peer2));
|
|
2431
1916
|
if (!peer) {
|
|
2432
|
-
|
|
1917
|
+
import_log8.log.warn("Exhausted all peers to notarize with", {
|
|
2433
1918
|
retryIn: retryTimeout
|
|
2434
1919
|
}, {
|
|
2435
1920
|
file: "notarization-plugin.ts",
|
|
@@ -2438,11 +1923,11 @@ var NotarizationPlugin = class {
|
|
|
2438
1923
|
callSite: (f, a) => f(...a)
|
|
2439
1924
|
});
|
|
2440
1925
|
peersTried.clear();
|
|
2441
|
-
(0,
|
|
1926
|
+
(0, import_async7.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
|
|
2442
1927
|
return;
|
|
2443
1928
|
}
|
|
2444
1929
|
peersTried.add(peer);
|
|
2445
|
-
(0,
|
|
1930
|
+
(0, import_log8.log)("try notarizing", {
|
|
2446
1931
|
peer: peer.localPeerId,
|
|
2447
1932
|
credentialId: credentials.map((credential) => credential.id)
|
|
2448
1933
|
}, {
|
|
@@ -2454,16 +1939,16 @@ var NotarizationPlugin = class {
|
|
|
2454
1939
|
await peer.rpc.NotarizationService.notarize({
|
|
2455
1940
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
2456
1941
|
});
|
|
2457
|
-
(0,
|
|
1942
|
+
(0, import_log8.log)("success", {}, {
|
|
2458
1943
|
file: "notarization-plugin.ts",
|
|
2459
1944
|
line: 144,
|
|
2460
1945
|
scope: this,
|
|
2461
1946
|
callSite: (f, a) => f(...a)
|
|
2462
1947
|
});
|
|
2463
|
-
await (0,
|
|
1948
|
+
await (0, import_async7.sleep)(successDelay);
|
|
2464
1949
|
} catch (err) {
|
|
2465
1950
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
2466
|
-
|
|
1951
|
+
import_log8.log.warn("error notarizing (recoverable)", err, {
|
|
2467
1952
|
file: "notarization-plugin.ts",
|
|
2468
1953
|
line: 148,
|
|
2469
1954
|
scope: this,
|
|
@@ -2477,11 +1962,11 @@ var NotarizationPlugin = class {
|
|
|
2477
1962
|
this._extensionOpened.on(ctx, () => notarizeTask.schedule());
|
|
2478
1963
|
try {
|
|
2479
1964
|
await Promise.race([
|
|
2480
|
-
(0,
|
|
1965
|
+
(0, import_context4.rejectOnDispose)(ctx),
|
|
2481
1966
|
allNotarized,
|
|
2482
1967
|
errors.wait()
|
|
2483
1968
|
]);
|
|
2484
|
-
(0,
|
|
1969
|
+
(0, import_log8.log)("done", {}, {
|
|
2485
1970
|
file: "notarization-plugin.ts",
|
|
2486
1971
|
line: 159,
|
|
2487
1972
|
scope: this,
|
|
@@ -2504,14 +1989,14 @@ var NotarizationPlugin = class {
|
|
|
2504
1989
|
this._processCredentialsTriggers.delete(credential.id);
|
|
2505
1990
|
}
|
|
2506
1991
|
setWriter(writer) {
|
|
2507
|
-
(0,
|
|
1992
|
+
(0, import_node_assert9.default)(!this._writer, "Writer already set.");
|
|
2508
1993
|
this._writer = writer;
|
|
2509
1994
|
}
|
|
2510
1995
|
async _waitUntilProcessed(id) {
|
|
2511
1996
|
if (this._processedCredentials.has(id)) {
|
|
2512
1997
|
return;
|
|
2513
1998
|
}
|
|
2514
|
-
await (0,
|
|
1999
|
+
await (0, import_util2.entry)(this._processCredentialsTriggers, id).orInsert(new import_async7.Trigger()).value.wait();
|
|
2515
2000
|
}
|
|
2516
2001
|
/**
|
|
2517
2002
|
* Requests from other peers to notarize credentials.
|
|
@@ -2522,7 +2007,7 @@ var NotarizationPlugin = class {
|
|
|
2522
2007
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
2523
2008
|
}
|
|
2524
2009
|
for (const credential of (_a = request.credentials) != null ? _a : []) {
|
|
2525
|
-
(0,
|
|
2010
|
+
(0, import_node_assert9.default)(credential.id, "Credential must have an id");
|
|
2526
2011
|
if (this._processedCredentials.has(credential.id)) {
|
|
2527
2012
|
continue;
|
|
2528
2013
|
}
|
|
@@ -2532,7 +2017,7 @@ var NotarizationPlugin = class {
|
|
|
2532
2017
|
createExtension() {
|
|
2533
2018
|
const extension = new NotarizationTeleportExtension({
|
|
2534
2019
|
onOpen: async () => {
|
|
2535
|
-
(0,
|
|
2020
|
+
(0, import_log8.log)("extension opened", {
|
|
2536
2021
|
peer: extension.localPeerId
|
|
2537
2022
|
}, {
|
|
2538
2023
|
file: "notarization-plugin.ts",
|
|
@@ -2544,7 +2029,7 @@ var NotarizationPlugin = class {
|
|
|
2544
2029
|
this._extensionOpened.emit();
|
|
2545
2030
|
},
|
|
2546
2031
|
onClose: async () => {
|
|
2547
|
-
(0,
|
|
2032
|
+
(0, import_log8.log)("extension closed", {
|
|
2548
2033
|
peer: extension.localPeerId
|
|
2549
2034
|
}, {
|
|
2550
2035
|
file: "notarization-plugin.ts",
|
|
@@ -2591,7 +2076,7 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
|
|
|
2591
2076
|
};
|
|
2592
2077
|
|
|
2593
2078
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2594
|
-
var
|
|
2079
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
2595
2080
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2596
2081
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2597
2082
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2603,13 +2088,13 @@ var __decorate2 = function(decorators, target, key, desc) {
|
|
|
2603
2088
|
};
|
|
2604
2089
|
var DataSpace = class DataSpace2 {
|
|
2605
2090
|
constructor(params) {
|
|
2606
|
-
this._ctx = new
|
|
2607
|
-
this._state =
|
|
2091
|
+
this._ctx = new import_context5.Context();
|
|
2092
|
+
this._state = import_services6.SpaceState.CLOSED;
|
|
2608
2093
|
/**
|
|
2609
2094
|
* Error for _state === SpaceState.ERROR.
|
|
2610
2095
|
*/
|
|
2611
2096
|
this.error = void 0;
|
|
2612
|
-
this.stateUpdate = new
|
|
2097
|
+
this.stateUpdate = new import_async8.Event();
|
|
2613
2098
|
this.metrics = {};
|
|
2614
2099
|
var _a;
|
|
2615
2100
|
this._inner = params.inner;
|
|
@@ -2622,7 +2107,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2622
2107
|
this._signingContext = params.signingContext;
|
|
2623
2108
|
this._callbacks = (_a = params.callbacks) != null ? _a : {};
|
|
2624
2109
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
2625
|
-
trustedKeysProvider: () => new
|
|
2110
|
+
trustedKeysProvider: () => new import_util3.ComplexSet(import_keys6.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
|
|
2626
2111
|
update: this._inner.stateUpdate,
|
|
2627
2112
|
authTimeout: import_client_protocol3.AUTH_TIMEOUT
|
|
2628
2113
|
});
|
|
@@ -2658,11 +2143,11 @@ var DataSpace = class DataSpace2 {
|
|
|
2658
2143
|
await this.notarizationPlugin.open();
|
|
2659
2144
|
await this._notarizationPluginConsumer.open();
|
|
2660
2145
|
await this._inner.open();
|
|
2661
|
-
this._state =
|
|
2146
|
+
this._state = import_services6.SpaceState.INACTIVE;
|
|
2662
2147
|
this.metrics.open = new Date();
|
|
2663
2148
|
}
|
|
2664
2149
|
async close() {
|
|
2665
|
-
this._state =
|
|
2150
|
+
this._state = import_services6.SpaceState.CLOSED;
|
|
2666
2151
|
await this._ctx.dispose();
|
|
2667
2152
|
await this.authVerifier.close();
|
|
2668
2153
|
await this._inner.close();
|
|
@@ -2680,13 +2165,13 @@ var DataSpace = class DataSpace2 {
|
|
|
2680
2165
|
* Initialize the data pipeline in a separate task.
|
|
2681
2166
|
*/
|
|
2682
2167
|
initializeDataPipelineAsync() {
|
|
2683
|
-
(0,
|
|
2168
|
+
(0, import_async8.scheduleTask)(this._ctx, async () => {
|
|
2684
2169
|
try {
|
|
2685
2170
|
this.metrics.pipelineInitBegin = new Date();
|
|
2686
2171
|
await this.initializeDataPipeline();
|
|
2687
2172
|
} catch (err) {
|
|
2688
2173
|
if (err instanceof import_errors3.CancelledError) {
|
|
2689
|
-
(0,
|
|
2174
|
+
(0, import_log9.log)("Data pipeline initialization cancelled", err, {
|
|
2690
2175
|
file: "data-space.ts",
|
|
2691
2176
|
line: 173,
|
|
2692
2177
|
scope: this,
|
|
@@ -2694,13 +2179,13 @@ var DataSpace = class DataSpace2 {
|
|
|
2694
2179
|
});
|
|
2695
2180
|
return;
|
|
2696
2181
|
}
|
|
2697
|
-
|
|
2182
|
+
import_log9.log.error("Error initializing data pipeline", err, {
|
|
2698
2183
|
file: "data-space.ts",
|
|
2699
2184
|
line: 177,
|
|
2700
2185
|
scope: this,
|
|
2701
2186
|
callSite: (f, a) => f(...a)
|
|
2702
2187
|
});
|
|
2703
|
-
this._state =
|
|
2188
|
+
this._state = import_services6.SpaceState.ERROR;
|
|
2704
2189
|
this.error = err;
|
|
2705
2190
|
this.stateUpdate.emit();
|
|
2706
2191
|
} finally {
|
|
@@ -2710,17 +2195,17 @@ var DataSpace = class DataSpace2 {
|
|
|
2710
2195
|
}
|
|
2711
2196
|
async initializeDataPipeline() {
|
|
2712
2197
|
var _a, _b, _c, _d;
|
|
2713
|
-
if (this._state !==
|
|
2198
|
+
if (this._state !== import_services6.SpaceState.INACTIVE) {
|
|
2714
2199
|
throw new import_errors3.SystemError("Invalid operation");
|
|
2715
2200
|
}
|
|
2716
|
-
this._state =
|
|
2201
|
+
this._state = import_services6.SpaceState.INITIALIZING;
|
|
2717
2202
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
2718
2203
|
ctx: this._ctx,
|
|
2719
2204
|
breakOnStall: false
|
|
2720
2205
|
});
|
|
2721
2206
|
this.metrics.controlPipelineReady = new Date();
|
|
2722
2207
|
await this._createWritableFeeds();
|
|
2723
|
-
(0,
|
|
2208
|
+
(0, import_log9.log)("Writable feeds created", {}, {
|
|
2724
2209
|
file: "data-space.ts",
|
|
2725
2210
|
line: 201,
|
|
2726
2211
|
scope: this,
|
|
@@ -2734,8 +2219,8 @@ var DataSpace = class DataSpace2 {
|
|
|
2734
2219
|
}), this._inner.controlPipeline.writer));
|
|
2735
2220
|
await this._inner.initializeDataPipeline();
|
|
2736
2221
|
this.metrics.dataPipelineOpen = new Date();
|
|
2737
|
-
await (0,
|
|
2738
|
-
(0,
|
|
2222
|
+
await (0, import_context5.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
|
|
2223
|
+
(0, import_log9.log)("waiting for data pipeline to reach target timeframe", {}, {
|
|
2739
2224
|
file: "data-space.ts",
|
|
2740
2225
|
line: 220,
|
|
2741
2226
|
scope: this,
|
|
@@ -2746,14 +2231,14 @@ var DataSpace = class DataSpace2 {
|
|
|
2746
2231
|
breakOnStall: false
|
|
2747
2232
|
});
|
|
2748
2233
|
this.metrics.dataPipelineReady = new Date();
|
|
2749
|
-
(0,
|
|
2234
|
+
(0, import_log9.log)("data pipeline ready", {}, {
|
|
2750
2235
|
file: "data-space.ts",
|
|
2751
2236
|
line: 229,
|
|
2752
2237
|
scope: this,
|
|
2753
2238
|
callSite: (f, a) => f(...a)
|
|
2754
2239
|
});
|
|
2755
2240
|
await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
|
|
2756
|
-
this._state =
|
|
2241
|
+
this._state = import_services6.SpaceState.READY;
|
|
2757
2242
|
this.stateUpdate.emit();
|
|
2758
2243
|
await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
|
|
2759
2244
|
}
|
|
@@ -2829,11 +2314,11 @@ var DataSpace = class DataSpace2 {
|
|
|
2829
2314
|
}
|
|
2830
2315
|
}
|
|
2831
2316
|
};
|
|
2832
|
-
|
|
2317
|
+
__decorate([
|
|
2833
2318
|
(0, import_debug3.timed)(1e4)
|
|
2834
2319
|
], DataSpace.prototype, "_createWritableFeeds", null);
|
|
2835
|
-
DataSpace =
|
|
2836
|
-
(0,
|
|
2320
|
+
DataSpace = __decorate([
|
|
2321
|
+
(0, import_async8.trackLeaks)("open", "close")
|
|
2837
2322
|
], DataSpace);
|
|
2838
2323
|
|
|
2839
2324
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
@@ -2907,7 +2392,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
|
|
|
2907
2392
|
};
|
|
2908
2393
|
|
|
2909
2394
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
2910
|
-
var
|
|
2395
|
+
var __decorate2 = function(decorators, target, key, desc) {
|
|
2911
2396
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2912
2397
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2913
2398
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2925,431 +2410,1170 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2925
2410
|
this._keyring = _keyring;
|
|
2926
2411
|
this._signingContext = _signingContext;
|
|
2927
2412
|
this._feedStore = _feedStore;
|
|
2928
|
-
this._ctx = new
|
|
2929
|
-
this.updated = new
|
|
2930
|
-
this._spaces = new
|
|
2413
|
+
this._ctx = new import_context6.Context();
|
|
2414
|
+
this.updated = new import_async9.Event();
|
|
2415
|
+
this._spaces = new import_util4.ComplexMap(import_keys7.PublicKey.hash);
|
|
2931
2416
|
this._isOpen = false;
|
|
2932
|
-
this._instanceId =
|
|
2417
|
+
this._instanceId = import_keys7.PublicKey.random().toHex();
|
|
2418
|
+
}
|
|
2419
|
+
// TODO(burdon): Remove.
|
|
2420
|
+
get spaces() {
|
|
2421
|
+
return this._spaces;
|
|
2422
|
+
}
|
|
2423
|
+
async open() {
|
|
2424
|
+
(0, import_log10.log)("open", {}, {
|
|
2425
|
+
file: "data-space-manager.ts",
|
|
2426
|
+
line: 80,
|
|
2427
|
+
scope: this,
|
|
2428
|
+
callSite: (f, a) => f(...a)
|
|
2429
|
+
});
|
|
2430
|
+
import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.begin({
|
|
2431
|
+
id: this._instanceId
|
|
2432
|
+
}), {
|
|
2433
|
+
file: "data-space-manager.ts",
|
|
2434
|
+
line: 81,
|
|
2435
|
+
scope: this,
|
|
2436
|
+
callSite: (f, a) => f(...a)
|
|
2437
|
+
});
|
|
2438
|
+
await this._metadataStore.load();
|
|
2439
|
+
(0, import_log10.log)("metadata loaded", {
|
|
2440
|
+
spaces: this._metadataStore.spaces.length
|
|
2441
|
+
}, {
|
|
2442
|
+
file: "data-space-manager.ts",
|
|
2443
|
+
line: 83,
|
|
2444
|
+
scope: this,
|
|
2445
|
+
callSite: (f, a) => f(...a)
|
|
2446
|
+
});
|
|
2447
|
+
for (const spaceMetadata of this._metadataStore.spaces) {
|
|
2448
|
+
try {
|
|
2449
|
+
(0, import_log10.log)("load space", {
|
|
2450
|
+
spaceMetadata
|
|
2451
|
+
}, {
|
|
2452
|
+
file: "data-space-manager.ts",
|
|
2453
|
+
line: 87,
|
|
2454
|
+
scope: this,
|
|
2455
|
+
callSite: (f, a) => f(...a)
|
|
2456
|
+
});
|
|
2457
|
+
const space = await this._constructSpace(spaceMetadata);
|
|
2458
|
+
space.initializeDataPipelineAsync();
|
|
2459
|
+
} catch (err) {
|
|
2460
|
+
import_log10.log.error("Error loading space", {
|
|
2461
|
+
spaceMetadata,
|
|
2462
|
+
err
|
|
2463
|
+
}, {
|
|
2464
|
+
file: "data-space-manager.ts",
|
|
2465
|
+
line: 91,
|
|
2466
|
+
scope: this,
|
|
2467
|
+
callSite: (f, a) => f(...a)
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
this._isOpen = true;
|
|
2472
|
+
this.updated.emit();
|
|
2473
|
+
import_log10.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.end({
|
|
2474
|
+
id: this._instanceId
|
|
2475
|
+
}), {
|
|
2476
|
+
file: "data-space-manager.ts",
|
|
2477
|
+
line: 97,
|
|
2478
|
+
scope: this,
|
|
2479
|
+
callSite: (f, a) => f(...a)
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
async close() {
|
|
2483
|
+
(0, import_log10.log)("close", {}, {
|
|
2484
|
+
file: "data-space-manager.ts",
|
|
2485
|
+
line: 102,
|
|
2486
|
+
scope: this,
|
|
2487
|
+
callSite: (f, a) => f(...a)
|
|
2488
|
+
});
|
|
2489
|
+
this._isOpen = false;
|
|
2490
|
+
await this._ctx.dispose();
|
|
2491
|
+
for (const space of this._spaces.values()) {
|
|
2492
|
+
await space.close();
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Creates a new space writing the genesis credentials to the control feed.
|
|
2497
|
+
*/
|
|
2498
|
+
async createSpace() {
|
|
2499
|
+
(0, import_node_assert10.default)(this._isOpen, "Not open.");
|
|
2500
|
+
const spaceKey = await this._keyring.createKey();
|
|
2501
|
+
const controlFeedKey = await this._keyring.createKey();
|
|
2502
|
+
const dataFeedKey = await this._keyring.createKey();
|
|
2503
|
+
const metadata = {
|
|
2504
|
+
key: spaceKey,
|
|
2505
|
+
genesisFeedKey: controlFeedKey,
|
|
2506
|
+
controlFeedKey,
|
|
2507
|
+
dataFeedKey
|
|
2508
|
+
};
|
|
2509
|
+
(0, import_log10.log)("creating space...", {
|
|
2510
|
+
spaceKey
|
|
2511
|
+
}, {
|
|
2512
|
+
file: "data-space-manager.ts",
|
|
2513
|
+
line: 126,
|
|
2514
|
+
scope: this,
|
|
2515
|
+
callSite: (f, a) => f(...a)
|
|
2516
|
+
});
|
|
2517
|
+
const space = await this._constructSpace(metadata);
|
|
2518
|
+
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
|
|
2519
|
+
await this._metadataStore.addSpace(metadata);
|
|
2520
|
+
const memberCredential = credentials[1];
|
|
2521
|
+
(0, import_node_assert10.default)((0, import_credentials13.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
2522
|
+
await this._signingContext.recordCredential(memberCredential);
|
|
2523
|
+
await space.initializeDataPipeline();
|
|
2524
|
+
this.updated.emit();
|
|
2525
|
+
return space;
|
|
2526
|
+
}
|
|
2527
|
+
// TODO(burdon): Rename join space.
|
|
2528
|
+
async acceptSpace(opts) {
|
|
2529
|
+
(0, import_log10.log)("accept space", {
|
|
2530
|
+
opts
|
|
2531
|
+
}, {
|
|
2532
|
+
file: "data-space-manager.ts",
|
|
2533
|
+
line: 145,
|
|
2534
|
+
scope: this,
|
|
2535
|
+
callSite: (f, a) => f(...a)
|
|
2536
|
+
});
|
|
2537
|
+
(0, import_node_assert10.default)(this._isOpen, "Not open.");
|
|
2538
|
+
(0, import_node_assert10.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
|
|
2539
|
+
const metadata = {
|
|
2540
|
+
key: opts.spaceKey,
|
|
2541
|
+
genesisFeedKey: opts.genesisFeedKey,
|
|
2542
|
+
controlTimeframe: opts.controlTimeframe,
|
|
2543
|
+
dataTimeframe: opts.dataTimeframe
|
|
2544
|
+
};
|
|
2545
|
+
const space = await this._constructSpace(metadata);
|
|
2546
|
+
await this._metadataStore.addSpace(metadata);
|
|
2547
|
+
space.initializeDataPipelineAsync();
|
|
2548
|
+
this.updated.emit();
|
|
2549
|
+
return space;
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Wait until the space data pipeline is fully initialized.
|
|
2553
|
+
* Used by invitation handler.
|
|
2554
|
+
* TODO(dmaretskyi): Consider removing.
|
|
2555
|
+
*/
|
|
2556
|
+
async waitUntilSpaceReady(spaceKey) {
|
|
2557
|
+
await (0, import_context6.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
|
|
2558
|
+
const space = this._spaces.get(spaceKey);
|
|
2559
|
+
return !!space && space.state === import_services7.SpaceState.READY;
|
|
2560
|
+
}));
|
|
2561
|
+
}
|
|
2562
|
+
async _constructSpace(metadata) {
|
|
2563
|
+
(0, import_log10.log)("construct space", {
|
|
2564
|
+
metadata
|
|
2565
|
+
}, {
|
|
2566
|
+
file: "data-space-manager.ts",
|
|
2567
|
+
line: 181,
|
|
2568
|
+
scope: this,
|
|
2569
|
+
callSite: (f, a) => f(...a)
|
|
2570
|
+
});
|
|
2571
|
+
const gossip = new import_teleport_extension_gossip.Gossip({
|
|
2572
|
+
localPeerId: this._signingContext.deviceKey
|
|
2573
|
+
});
|
|
2574
|
+
const presence = new import_teleport_extension_gossip.Presence({
|
|
2575
|
+
announceInterval: 500,
|
|
2576
|
+
offlineTimeout: 5e3,
|
|
2577
|
+
identityKey: this._signingContext.identityKey,
|
|
2578
|
+
gossip
|
|
2579
|
+
});
|
|
2580
|
+
const controlFeed = metadata.controlFeedKey && await this._feedStore.openFeed(metadata.controlFeedKey, {
|
|
2581
|
+
writable: true
|
|
2582
|
+
});
|
|
2583
|
+
const dataFeed = metadata.dataFeedKey && await this._feedStore.openFeed(metadata.dataFeedKey, {
|
|
2584
|
+
writable: true,
|
|
2585
|
+
sparse: true
|
|
2586
|
+
});
|
|
2587
|
+
const space = await this._spaceManager.constructSpace({
|
|
2588
|
+
metadata,
|
|
2589
|
+
swarmIdentity: {
|
|
2590
|
+
peerKey: this._signingContext.deviceKey,
|
|
2591
|
+
credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
|
|
2592
|
+
credentialAuthenticator: (0, import_util4.deferFunction)(() => dataSpace.authVerifier.verifier)
|
|
2593
|
+
},
|
|
2594
|
+
onNetworkConnection: (session) => {
|
|
2595
|
+
session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
|
|
2596
|
+
remotePeerId: session.remotePeerId
|
|
2597
|
+
}));
|
|
2598
|
+
session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
|
|
2599
|
+
},
|
|
2600
|
+
onAuthFailure: () => {
|
|
2601
|
+
import_log10.log.warn("auth failure", {}, {
|
|
2602
|
+
file: "data-space-manager.ts",
|
|
2603
|
+
line: 212,
|
|
2604
|
+
scope: this,
|
|
2605
|
+
callSite: (f, a) => f(...a)
|
|
2606
|
+
});
|
|
2607
|
+
},
|
|
2608
|
+
memberKey: this._signingContext.identityKey
|
|
2609
|
+
});
|
|
2610
|
+
controlFeed && space.setControlFeed(controlFeed);
|
|
2611
|
+
dataFeed && space.setDataFeed(dataFeed);
|
|
2612
|
+
const dataSpace = new DataSpace({
|
|
2613
|
+
inner: space,
|
|
2614
|
+
metadataStore: this._metadataStore,
|
|
2615
|
+
gossip,
|
|
2616
|
+
presence,
|
|
2617
|
+
keyring: this._keyring,
|
|
2618
|
+
feedStore: this._feedStore,
|
|
2619
|
+
signingContext: this._signingContext,
|
|
2620
|
+
callbacks: {
|
|
2621
|
+
beforeReady: async () => {
|
|
2622
|
+
(0, import_log10.log)("before space ready", {
|
|
2623
|
+
space: space.key
|
|
2624
|
+
}, {
|
|
2625
|
+
file: "data-space-manager.ts",
|
|
2626
|
+
line: 229,
|
|
2627
|
+
scope: this,
|
|
2628
|
+
callSite: (f, a) => f(...a)
|
|
2629
|
+
});
|
|
2630
|
+
this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
|
|
2631
|
+
},
|
|
2632
|
+
afterReady: async () => {
|
|
2633
|
+
(0, import_log10.log)("after space ready", {
|
|
2634
|
+
space: space.key,
|
|
2635
|
+
open: this._isOpen
|
|
2636
|
+
}, {
|
|
2637
|
+
file: "data-space-manager.ts",
|
|
2638
|
+
line: 236,
|
|
2639
|
+
scope: this,
|
|
2640
|
+
callSite: (f, a) => f(...a)
|
|
2641
|
+
});
|
|
2642
|
+
if (this._isOpen) {
|
|
2643
|
+
this.updated.emit();
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
},
|
|
2647
|
+
cache: metadata.cache
|
|
2648
|
+
});
|
|
2649
|
+
await dataSpace.open();
|
|
2650
|
+
if (metadata.controlTimeframe) {
|
|
2651
|
+
dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
|
|
2652
|
+
}
|
|
2653
|
+
if (metadata.dataTimeframe) {
|
|
2654
|
+
dataSpace.dataPipeline.setTargetTimeframe(metadata.dataTimeframe);
|
|
2655
|
+
}
|
|
2656
|
+
this._spaces.set(metadata.key, dataSpace);
|
|
2657
|
+
return dataSpace;
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
__decorate2([
|
|
2661
|
+
import_async9.synchronized
|
|
2662
|
+
], DataSpaceManager.prototype, "open", null);
|
|
2663
|
+
__decorate2([
|
|
2664
|
+
import_async9.synchronized
|
|
2665
|
+
], DataSpaceManager.prototype, "close", null);
|
|
2666
|
+
__decorate2([
|
|
2667
|
+
import_async9.synchronized
|
|
2668
|
+
], DataSpaceManager.prototype, "createSpace", null);
|
|
2669
|
+
__decorate2([
|
|
2670
|
+
import_async9.synchronized
|
|
2671
|
+
], DataSpaceManager.prototype, "acceptSpace", null);
|
|
2672
|
+
DataSpaceManager = __decorate2([
|
|
2673
|
+
(0, import_async9.trackLeaks)("open", "close")
|
|
2674
|
+
], DataSpaceManager);
|
|
2675
|
+
|
|
2676
|
+
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
2677
|
+
var import_async10 = require("@dxos/async");
|
|
2678
|
+
var import_codec_protobuf3 = require("@dxos/codec-protobuf");
|
|
2679
|
+
var import_debug5 = require("@dxos/debug");
|
|
2680
|
+
var import_echo_pipeline2 = require("@dxos/echo-pipeline");
|
|
2681
|
+
var import_log11 = require("@dxos/log");
|
|
2682
|
+
var import_protocols7 = require("@dxos/protocols");
|
|
2683
|
+
var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2684
|
+
var import_util5 = require("@dxos/util");
|
|
2685
|
+
var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
|
|
2686
|
+
var SpacesServiceImpl = class {
|
|
2687
|
+
constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
|
|
2688
|
+
this._identityManager = _identityManager;
|
|
2689
|
+
this._spaceManager = _spaceManager;
|
|
2690
|
+
this._dataServiceSubscriptions = _dataServiceSubscriptions;
|
|
2691
|
+
this._getDataSpaceManager = _getDataSpaceManager;
|
|
2692
|
+
}
|
|
2693
|
+
async createSpace() {
|
|
2694
|
+
if (!this._identityManager.identity) {
|
|
2695
|
+
throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
|
|
2696
|
+
}
|
|
2697
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2698
|
+
const space = await dataSpaceManager.createSpace();
|
|
2699
|
+
return this._transformSpace(space);
|
|
2700
|
+
}
|
|
2701
|
+
async updateSpace(request) {
|
|
2702
|
+
(0, import_debug5.todo)();
|
|
2703
|
+
}
|
|
2704
|
+
querySpaces() {
|
|
2705
|
+
return new import_codec_protobuf3.Stream(({ next, ctx }) => {
|
|
2706
|
+
const onUpdate = async () => {
|
|
2707
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2708
|
+
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
|
|
2709
|
+
(0, import_log11.log)("update", {
|
|
2710
|
+
spaces
|
|
2711
|
+
}, {
|
|
2712
|
+
file: "spaces-service.ts",
|
|
2713
|
+
line: 60,
|
|
2714
|
+
scope: this,
|
|
2715
|
+
callSite: (f, a) => f(...a)
|
|
2716
|
+
});
|
|
2717
|
+
next({
|
|
2718
|
+
spaces
|
|
2719
|
+
});
|
|
2720
|
+
};
|
|
2721
|
+
(0, import_async10.scheduleTask)(ctx, async () => {
|
|
2722
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2723
|
+
const subscriptions = new import_async10.EventSubscriptions();
|
|
2724
|
+
ctx.onDispose(() => subscriptions.clear());
|
|
2725
|
+
const subscribeSpaces = () => {
|
|
2726
|
+
subscriptions.clear();
|
|
2727
|
+
for (const space of dataSpaceManager.spaces.values()) {
|
|
2728
|
+
subscriptions.add(space.stateUpdate.on(ctx, onUpdate));
|
|
2729
|
+
subscriptions.add(space.presence.updated.on(ctx, onUpdate));
|
|
2730
|
+
subscriptions.add(space.dataPipeline.onNewEpoch.on(ctx, onUpdate));
|
|
2731
|
+
space.inner.controlPipeline.state.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate);
|
|
2732
|
+
if (space.dataPipeline.pipelineState) {
|
|
2733
|
+
subscriptions.add(space.dataPipeline.pipelineState.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate));
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
};
|
|
2737
|
+
dataSpaceManager.updated.on(ctx, () => {
|
|
2738
|
+
subscribeSpaces();
|
|
2739
|
+
void onUpdate();
|
|
2740
|
+
});
|
|
2741
|
+
subscribeSpaces();
|
|
2742
|
+
void onUpdate();
|
|
2743
|
+
});
|
|
2744
|
+
if (!this._identityManager.identity) {
|
|
2745
|
+
next({
|
|
2746
|
+
spaces: []
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
async postMessage({ spaceKey, channel, message }) {
|
|
2752
|
+
var _a;
|
|
2753
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2754
|
+
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2755
|
+
await space.postMessage(getChannelId(channel), message);
|
|
2756
|
+
}
|
|
2757
|
+
subscribeMessages({ spaceKey, channel }) {
|
|
2758
|
+
return new import_codec_protobuf3.Stream(({ ctx, next }) => {
|
|
2759
|
+
(0, import_async10.scheduleTask)(ctx, async () => {
|
|
2760
|
+
var _a;
|
|
2761
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2762
|
+
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2763
|
+
const handle = space.listen(getChannelId(channel), (message) => {
|
|
2764
|
+
next(message);
|
|
2765
|
+
});
|
|
2766
|
+
ctx.onDispose(() => handle.unsubscribe());
|
|
2767
|
+
});
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2770
|
+
queryCredentials({ spaceKey }) {
|
|
2771
|
+
return new import_codec_protobuf3.Stream(({ ctx, next }) => {
|
|
2772
|
+
var _a;
|
|
2773
|
+
const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2774
|
+
const processor = space.spaceState.registerProcessor({
|
|
2775
|
+
process: async (credential) => {
|
|
2776
|
+
next(credential);
|
|
2777
|
+
}
|
|
2778
|
+
});
|
|
2779
|
+
ctx.onDispose(() => processor.close());
|
|
2780
|
+
(0, import_async10.scheduleTask)(ctx, () => processor.open());
|
|
2781
|
+
});
|
|
2782
|
+
}
|
|
2783
|
+
async writeCredentials({ spaceKey, credentials }) {
|
|
2784
|
+
var _a;
|
|
2785
|
+
const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2786
|
+
for (const credential of credentials != null ? credentials : []) {
|
|
2787
|
+
await space.controlPipeline.writer.write({
|
|
2788
|
+
credential: {
|
|
2789
|
+
credential
|
|
2790
|
+
}
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
async createEpoch({ spaceKey }) {
|
|
2795
|
+
var _a;
|
|
2796
|
+
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2797
|
+
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2798
|
+
await space.createEpoch();
|
|
2799
|
+
}
|
|
2800
|
+
_transformSpace(space) {
|
|
2801
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
2802
|
+
return {
|
|
2803
|
+
spaceKey: space.key,
|
|
2804
|
+
state: space.state,
|
|
2805
|
+
error: space.error ? (0, import_protocols7.encodeError)(space.error) : void 0,
|
|
2806
|
+
pipeline: {
|
|
2807
|
+
currentEpoch: space.dataPipeline.currentEpoch,
|
|
2808
|
+
appliedEpoch: space.dataPipeline.appliedEpoch,
|
|
2809
|
+
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
2810
|
+
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
2811
|
+
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
2812
|
+
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
|
|
2813
|
+
dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
|
|
2814
|
+
startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
|
|
2815
|
+
currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
|
|
2816
|
+
targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
|
|
2817
|
+
totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
|
|
2818
|
+
},
|
|
2819
|
+
members: Array.from(space.inner.spaceState.members.values()).map((member) => {
|
|
2820
|
+
var _a2, _b2, _c2;
|
|
2821
|
+
return {
|
|
2822
|
+
identity: {
|
|
2823
|
+
identityKey: member.key,
|
|
2824
|
+
profile: {
|
|
2825
|
+
displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : (0, import_util5.humanize)(member.key)
|
|
2826
|
+
}
|
|
2827
|
+
},
|
|
2828
|
+
presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services8.SpaceMember.PresenceState.ONLINE : import_services8.SpaceMember.PresenceState.OFFLINE
|
|
2829
|
+
};
|
|
2830
|
+
}),
|
|
2831
|
+
creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
|
|
2832
|
+
cache: space.cache,
|
|
2833
|
+
metrics: space.metrics
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
2838
|
+
|
|
2839
|
+
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
2840
|
+
var ServiceContext = class {
|
|
2841
|
+
// prettier-ignore
|
|
2842
|
+
constructor(storage, networkManager, signalManager, modelFactory) {
|
|
2843
|
+
this.storage = storage;
|
|
2844
|
+
this.networkManager = networkManager;
|
|
2845
|
+
this.signalManager = signalManager;
|
|
2846
|
+
this.modelFactory = modelFactory;
|
|
2847
|
+
this.initialized = new import_async11.Trigger();
|
|
2848
|
+
this.dataServiceSubscriptions = new import_echo_pipeline3.DataServiceSubscriptions();
|
|
2849
|
+
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
2850
|
+
this._instanceId = import_keys8.PublicKey.random().toHex();
|
|
2851
|
+
this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
|
|
2852
|
+
this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
|
|
2853
|
+
this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
|
|
2854
|
+
this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
|
|
2855
|
+
this.feedStore = new import_feed_store3.FeedStore({
|
|
2856
|
+
factory: new import_feed_store3.FeedFactory({
|
|
2857
|
+
root: storage.createDirectory("feeds"),
|
|
2858
|
+
signer: this.keyring,
|
|
2859
|
+
hypercore: {
|
|
2860
|
+
valueEncoding: import_echo_pipeline3.valueEncoding
|
|
2861
|
+
}
|
|
2862
|
+
})
|
|
2863
|
+
});
|
|
2864
|
+
this.spaceManager = new import_echo_pipeline3.SpaceManager({
|
|
2865
|
+
feedStore: this.feedStore,
|
|
2866
|
+
networkManager: this.networkManager,
|
|
2867
|
+
blobStore: this.blobStore,
|
|
2868
|
+
metadataStore: this.metadataStore,
|
|
2869
|
+
modelFactory: this.modelFactory,
|
|
2870
|
+
snapshotStore: this.snapshotStore
|
|
2871
|
+
});
|
|
2872
|
+
this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
|
|
2873
|
+
this.invitations = new InvitationsHandler(this.networkManager);
|
|
2874
|
+
this._handlerFactories.set(import_services9.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
|
|
2875
|
+
var _a;
|
|
2876
|
+
return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
|
|
2877
|
+
}, this._acceptIdentity.bind(this)));
|
|
2878
|
+
}
|
|
2879
|
+
async open() {
|
|
2880
|
+
import_log12.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.begin({
|
|
2881
|
+
id: this._instanceId
|
|
2882
|
+
}), {
|
|
2883
|
+
file: "service-context.ts",
|
|
2884
|
+
line: 126,
|
|
2885
|
+
scope: this,
|
|
2886
|
+
callSite: (f, a) => f(...a)
|
|
2887
|
+
});
|
|
2888
|
+
await this._checkStorageVersion();
|
|
2889
|
+
(0, import_log12.log)("opening...", {}, {
|
|
2890
|
+
file: "service-context.ts",
|
|
2891
|
+
line: 130,
|
|
2892
|
+
scope: this,
|
|
2893
|
+
callSite: (f, a) => f(...a)
|
|
2894
|
+
});
|
|
2895
|
+
await this.signalManager.open();
|
|
2896
|
+
await this.networkManager.open();
|
|
2897
|
+
await this.spaceManager.open();
|
|
2898
|
+
await this.identityManager.open();
|
|
2899
|
+
if (this.identityManager.identity) {
|
|
2900
|
+
await this._initialize();
|
|
2901
|
+
}
|
|
2902
|
+
(0, import_log12.log)("opened", {}, {
|
|
2903
|
+
file: "service-context.ts",
|
|
2904
|
+
line: 138,
|
|
2905
|
+
scope: this,
|
|
2906
|
+
callSite: (f, a) => f(...a)
|
|
2907
|
+
});
|
|
2908
|
+
import_log12.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.end({
|
|
2909
|
+
id: this._instanceId
|
|
2910
|
+
}), {
|
|
2911
|
+
file: "service-context.ts",
|
|
2912
|
+
line: 139,
|
|
2913
|
+
scope: this,
|
|
2914
|
+
callSite: (f, a) => f(...a)
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
async close() {
|
|
2918
|
+
var _a, _b;
|
|
2919
|
+
(0, import_log12.log)("closing...", {}, {
|
|
2920
|
+
file: "service-context.ts",
|
|
2921
|
+
line: 143,
|
|
2922
|
+
scope: this,
|
|
2923
|
+
callSite: (f, a) => f(...a)
|
|
2924
|
+
});
|
|
2925
|
+
await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
|
|
2926
|
+
await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
|
|
2927
|
+
await this.identityManager.close();
|
|
2928
|
+
await this.spaceManager.close();
|
|
2929
|
+
await this.feedStore.close();
|
|
2930
|
+
await this.networkManager.close();
|
|
2931
|
+
await this.signalManager.close();
|
|
2932
|
+
this.dataServiceSubscriptions.clear();
|
|
2933
|
+
(0, import_log12.log)("closed", {}, {
|
|
2934
|
+
file: "service-context.ts",
|
|
2935
|
+
line: 152,
|
|
2936
|
+
scope: this,
|
|
2937
|
+
callSite: (f, a) => f(...a)
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
async createIdentity(params = {}) {
|
|
2941
|
+
const identity = await this.identityManager.createIdentity(params);
|
|
2942
|
+
await this._initialize();
|
|
2943
|
+
return identity;
|
|
2944
|
+
}
|
|
2945
|
+
getInvitationHandler(invitation) {
|
|
2946
|
+
const factory = this._handlerFactories.get(invitation.kind);
|
|
2947
|
+
(0, import_node_assert11.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
|
|
2948
|
+
return factory(invitation);
|
|
2949
|
+
}
|
|
2950
|
+
async _acceptIdentity(params) {
|
|
2951
|
+
const identity = await this.identityManager.acceptIdentity(params);
|
|
2952
|
+
await this._initialize();
|
|
2953
|
+
return identity;
|
|
2954
|
+
}
|
|
2955
|
+
async _checkStorageVersion() {
|
|
2956
|
+
await this.metadataStore.load();
|
|
2957
|
+
if (this.metadataStore.version !== import_protocols8.STORAGE_VERSION) {
|
|
2958
|
+
throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${import_protocols8.STORAGE_VERSION}`);
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
// Called when identity is created.
|
|
2962
|
+
async _initialize() {
|
|
2963
|
+
var _a;
|
|
2964
|
+
(0, import_log12.log)("initializing spaces...", {}, {
|
|
2965
|
+
file: "service-context.ts",
|
|
2966
|
+
line: 185,
|
|
2967
|
+
scope: this,
|
|
2968
|
+
callSite: (f, a) => f(...a)
|
|
2969
|
+
});
|
|
2970
|
+
const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
|
|
2971
|
+
const signingContext = {
|
|
2972
|
+
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
2973
|
+
identityKey: identity.identityKey,
|
|
2974
|
+
deviceKey: identity.deviceKey,
|
|
2975
|
+
profile: identity.profileDocument,
|
|
2976
|
+
recordCredential: async (credential) => {
|
|
2977
|
+
await identity.controlPipeline.writer.write({
|
|
2978
|
+
credential: {
|
|
2979
|
+
credential
|
|
2980
|
+
}
|
|
2981
|
+
});
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
|
|
2985
|
+
await this.dataSpaceManager.open();
|
|
2986
|
+
this._handlerFactories.set(import_services9.Invitation.Kind.SPACE, (invitation) => {
|
|
2987
|
+
(0, import_node_assert11.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
|
|
2988
|
+
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
2989
|
+
});
|
|
2990
|
+
this.initialized.wake();
|
|
2991
|
+
this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
|
|
2992
|
+
process: async (credential) => {
|
|
2993
|
+
const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
|
|
2994
|
+
if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
if (assertion.spaceKey.equals(identity.space.key)) {
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
if (!this.dataSpaceManager) {
|
|
3001
|
+
(0, import_log12.log)("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
3002
|
+
details: assertion
|
|
3003
|
+
}, {
|
|
3004
|
+
file: "service-context.ts",
|
|
3005
|
+
line: 224,
|
|
3006
|
+
scope: this,
|
|
3007
|
+
callSite: (f, a) => f(...a)
|
|
3008
|
+
});
|
|
3009
|
+
return;
|
|
3010
|
+
}
|
|
3011
|
+
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
3012
|
+
(0, import_log12.log)("space already exists, ignoring space admission", {
|
|
3013
|
+
details: assertion
|
|
3014
|
+
}, {
|
|
3015
|
+
file: "service-context.ts",
|
|
3016
|
+
line: 228,
|
|
3017
|
+
scope: this,
|
|
3018
|
+
callSite: (f, a) => f(...a)
|
|
3019
|
+
});
|
|
3020
|
+
return;
|
|
3021
|
+
}
|
|
3022
|
+
try {
|
|
3023
|
+
(0, import_log12.log)("accepting space recorded in halo", {
|
|
3024
|
+
details: assertion
|
|
3025
|
+
}, {
|
|
3026
|
+
file: "service-context.ts",
|
|
3027
|
+
line: 233,
|
|
3028
|
+
scope: this,
|
|
3029
|
+
callSite: (f, a) => f(...a)
|
|
3030
|
+
});
|
|
3031
|
+
await this.dataSpaceManager.acceptSpace({
|
|
3032
|
+
spaceKey: assertion.spaceKey,
|
|
3033
|
+
genesisFeedKey: assertion.genesisFeedKey
|
|
3034
|
+
});
|
|
3035
|
+
} catch (err) {
|
|
3036
|
+
import_log12.log.catch(err, {}, {
|
|
3037
|
+
file: "service-context.ts",
|
|
3038
|
+
line: 239,
|
|
3039
|
+
scope: this,
|
|
3040
|
+
callSite: (f, a) => f(...a)
|
|
3041
|
+
});
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
});
|
|
3045
|
+
await this._deviceSpaceSync.open();
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
|
|
3049
|
+
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
3050
|
+
var import_node_assert13 = __toESM(require("node:assert"));
|
|
3051
|
+
var import_async17 = require("@dxos/async");
|
|
3052
|
+
var import_client_protocol5 = require("@dxos/client-protocol");
|
|
3053
|
+
var import_echo_pipeline4 = require("@dxos/echo-pipeline");
|
|
3054
|
+
var import_keys12 = require("@dxos/keys");
|
|
3055
|
+
var import_log15 = require("@dxos/log");
|
|
3056
|
+
var import_messaging = require("@dxos/messaging");
|
|
3057
|
+
var import_network_manager2 = require("@dxos/network-manager");
|
|
3058
|
+
var import_protocols9 = require("@dxos/protocols");
|
|
3059
|
+
var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3060
|
+
|
|
3061
|
+
// packages/sdk/client-services/src/packlets/devices/devices-service.ts
|
|
3062
|
+
var import_async12 = require("@dxos/async");
|
|
3063
|
+
var import_codec_protobuf4 = require("@dxos/codec-protobuf");
|
|
3064
|
+
var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3065
|
+
var DevicesServiceImpl = class {
|
|
3066
|
+
constructor(_identityManager) {
|
|
3067
|
+
this._identityManager = _identityManager;
|
|
3068
|
+
}
|
|
3069
|
+
updateDevice(request) {
|
|
3070
|
+
throw new Error("Method not implemented.");
|
|
3071
|
+
}
|
|
3072
|
+
queryDevices() {
|
|
3073
|
+
return new import_codec_protobuf4.Stream(({ next }) => {
|
|
3074
|
+
const update = () => {
|
|
3075
|
+
var _a;
|
|
3076
|
+
const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
|
|
3077
|
+
if (!deviceKeys) {
|
|
3078
|
+
next({
|
|
3079
|
+
devices: []
|
|
3080
|
+
});
|
|
3081
|
+
} else {
|
|
3082
|
+
next({
|
|
3083
|
+
devices: Array.from(deviceKeys.values()).map((key) => {
|
|
3084
|
+
var _a2;
|
|
3085
|
+
return {
|
|
3086
|
+
deviceKey: key,
|
|
3087
|
+
kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services10.DeviceKind.CURRENT : import_services10.DeviceKind.TRUSTED
|
|
3088
|
+
};
|
|
3089
|
+
})
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
};
|
|
3093
|
+
const subscriptions = new import_async12.EventSubscriptions();
|
|
3094
|
+
subscriptions.add(this._identityManager.stateUpdate.on(() => {
|
|
3095
|
+
update();
|
|
3096
|
+
if (this._identityManager.identity) {
|
|
3097
|
+
subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
|
|
3098
|
+
update();
|
|
3099
|
+
}));
|
|
3100
|
+
}
|
|
3101
|
+
}));
|
|
3102
|
+
update();
|
|
3103
|
+
return () => subscriptions.clear();
|
|
3104
|
+
});
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
|
|
3108
|
+
// packages/sdk/client-services/src/packlets/devtools/devtools.ts
|
|
3109
|
+
var import_async15 = require("@dxos/async");
|
|
3110
|
+
var import_codec_protobuf10 = require("@dxos/codec-protobuf");
|
|
3111
|
+
|
|
3112
|
+
// packages/sdk/client-services/src/packlets/devtools/feeds.ts
|
|
3113
|
+
var import_async13 = require("@dxos/async");
|
|
3114
|
+
var import_codec_protobuf5 = require("@dxos/codec-protobuf");
|
|
3115
|
+
var import_feed_store4 = require("@dxos/feed-store");
|
|
3116
|
+
var import_keys9 = require("@dxos/keys");
|
|
3117
|
+
var import_util6 = require("@dxos/util");
|
|
3118
|
+
var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
|
|
3119
|
+
return new import_codec_protobuf5.Stream(({ next }) => {
|
|
3120
|
+
const subscriptions = new import_async13.EventSubscriptions();
|
|
3121
|
+
const feedMap = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
|
|
3122
|
+
const update = () => {
|
|
3123
|
+
const { feeds } = feedStore;
|
|
3124
|
+
feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
|
|
3125
|
+
if (!feedMap.has(feed.key)) {
|
|
3126
|
+
feedMap.set(feed.key, feed);
|
|
3127
|
+
feed.on("close", update);
|
|
3128
|
+
subscriptions.add(() => feed.off("close", update));
|
|
3129
|
+
}
|
|
3130
|
+
});
|
|
3131
|
+
next({
|
|
3132
|
+
feeds: Array.from(feedMap.values()).map((feed) => {
|
|
3133
|
+
var _a, _b;
|
|
3134
|
+
return {
|
|
3135
|
+
feedKey: feed.key,
|
|
3136
|
+
length: feed.properties.length,
|
|
3137
|
+
bytes: feed.core.byteLength,
|
|
3138
|
+
downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
|
|
3139
|
+
};
|
|
3140
|
+
})
|
|
3141
|
+
});
|
|
3142
|
+
};
|
|
3143
|
+
subscriptions.add(feedStore.feedOpened.on(update));
|
|
3144
|
+
update();
|
|
3145
|
+
return () => {
|
|
3146
|
+
subscriptions.clear();
|
|
3147
|
+
};
|
|
3148
|
+
});
|
|
3149
|
+
};
|
|
3150
|
+
var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
|
|
3151
|
+
return new import_codec_protobuf5.Stream(({ next }) => {
|
|
3152
|
+
if (!feedKey) {
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
const subscriptions = new import_async13.EventSubscriptions();
|
|
3156
|
+
const timeout = setTimeout(async () => {
|
|
3157
|
+
const feed = feedStore.getFeed(feedKey);
|
|
3158
|
+
if (!feed) {
|
|
3159
|
+
return;
|
|
3160
|
+
}
|
|
3161
|
+
const update = async () => {
|
|
3162
|
+
const iterator = new import_feed_store4.FeedIterator(feed);
|
|
3163
|
+
await iterator.open();
|
|
3164
|
+
const blocks = [];
|
|
3165
|
+
for await (const block of iterator) {
|
|
3166
|
+
blocks.push(block);
|
|
3167
|
+
if (blocks.length >= feed.properties.length) {
|
|
3168
|
+
break;
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
next({
|
|
3172
|
+
blocks: blocks.slice(-maxBlocks)
|
|
3173
|
+
});
|
|
3174
|
+
await iterator.close();
|
|
3175
|
+
};
|
|
3176
|
+
feed.on("append", update);
|
|
3177
|
+
subscriptions.add(() => feed.off("append", update));
|
|
3178
|
+
feed.on("truncate", update);
|
|
3179
|
+
subscriptions.add(() => feed.off("truncate", update));
|
|
3180
|
+
await update();
|
|
3181
|
+
});
|
|
3182
|
+
return () => {
|
|
3183
|
+
subscriptions.clear();
|
|
3184
|
+
clearTimeout(timeout);
|
|
3185
|
+
};
|
|
3186
|
+
});
|
|
3187
|
+
};
|
|
3188
|
+
|
|
3189
|
+
// packages/sdk/client-services/src/packlets/devtools/keys.ts
|
|
3190
|
+
var import_async14 = require("@dxos/async");
|
|
3191
|
+
var import_codec_protobuf6 = require("@dxos/codec-protobuf");
|
|
3192
|
+
var subscribeToKeyringKeys = ({ keyring }) => new import_codec_protobuf6.Stream(({ next, ctx }) => {
|
|
3193
|
+
const update = async () => {
|
|
3194
|
+
next({
|
|
3195
|
+
keys: await keyring.list()
|
|
3196
|
+
});
|
|
3197
|
+
};
|
|
3198
|
+
keyring.keysUpdate.on(ctx, update);
|
|
3199
|
+
(0, import_async14.scheduleTask)(ctx, update);
|
|
3200
|
+
});
|
|
3201
|
+
|
|
3202
|
+
// packages/sdk/client-services/src/packlets/devtools/metadata.ts
|
|
3203
|
+
var import_codec_protobuf7 = require("@dxos/codec-protobuf");
|
|
3204
|
+
var subscribeToMetadata = ({ context }) => new import_codec_protobuf7.Stream(({ next, ctx }) => {
|
|
3205
|
+
context.metadataStore.update.on(ctx, (data) => next({
|
|
3206
|
+
metadata: data
|
|
3207
|
+
}));
|
|
3208
|
+
next({
|
|
3209
|
+
metadata: context.metadataStore.metadata
|
|
3210
|
+
});
|
|
3211
|
+
});
|
|
3212
|
+
|
|
3213
|
+
// packages/sdk/client-services/src/packlets/devtools/network.ts
|
|
3214
|
+
var import_codec_protobuf8 = require("@dxos/codec-protobuf");
|
|
3215
|
+
var import_context7 = require("@dxos/context");
|
|
3216
|
+
var import_keys10 = require("@dxos/keys");
|
|
3217
|
+
var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf8.Stream(({ next, close }) => {
|
|
3218
|
+
const update = () => {
|
|
3219
|
+
try {
|
|
3220
|
+
const status = signalManager.getStatus();
|
|
3221
|
+
next({
|
|
3222
|
+
servers: status
|
|
3223
|
+
});
|
|
3224
|
+
} catch (err) {
|
|
3225
|
+
close(err);
|
|
3226
|
+
}
|
|
3227
|
+
};
|
|
3228
|
+
signalManager.statusChanged.on(() => update());
|
|
3229
|
+
update();
|
|
3230
|
+
});
|
|
3231
|
+
var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf8.Stream(({ next }) => {
|
|
3232
|
+
const ctx = new import_context7.Context();
|
|
3233
|
+
signalManager.onMessage.on(ctx, (message) => {
|
|
3234
|
+
next({
|
|
3235
|
+
message: {
|
|
3236
|
+
author: message.author.asUint8Array(),
|
|
3237
|
+
recipient: message.recipient.asUint8Array(),
|
|
3238
|
+
payload: message.payload
|
|
3239
|
+
},
|
|
3240
|
+
receivedAt: new Date()
|
|
3241
|
+
});
|
|
3242
|
+
});
|
|
3243
|
+
signalManager.swarmEvent.on(ctx, (swarmEvent) => {
|
|
3244
|
+
next({
|
|
3245
|
+
swarmEvent: swarmEvent.swarmEvent,
|
|
3246
|
+
receivedAt: new Date()
|
|
3247
|
+
});
|
|
3248
|
+
});
|
|
3249
|
+
return () => {
|
|
3250
|
+
return ctx.dispose();
|
|
3251
|
+
};
|
|
3252
|
+
});
|
|
3253
|
+
var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf8.Stream(({ next }) => {
|
|
3254
|
+
var _a;
|
|
3255
|
+
const update = () => {
|
|
3256
|
+
var _a2;
|
|
3257
|
+
const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
|
|
3258
|
+
if (info) {
|
|
3259
|
+
next({
|
|
3260
|
+
data: info
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
};
|
|
3264
|
+
(_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
|
|
3265
|
+
update();
|
|
3266
|
+
});
|
|
3267
|
+
|
|
3268
|
+
// packages/sdk/client-services/src/packlets/devtools/spaces.ts
|
|
3269
|
+
var import_codec_protobuf9 = require("@dxos/codec-protobuf");
|
|
3270
|
+
var subscribeToSpaces = (context, { spaceKeys = [] }) => {
|
|
3271
|
+
return new import_codec_protobuf9.Stream(({ next }) => {
|
|
3272
|
+
let unsubscribe;
|
|
3273
|
+
const update = async () => {
|
|
3274
|
+
const spaces = [
|
|
3275
|
+
...context.spaceManager.spaces.values()
|
|
3276
|
+
];
|
|
3277
|
+
const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
|
|
3278
|
+
next({
|
|
3279
|
+
spaces: filteredSpaces.map((space) => {
|
|
3280
|
+
const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
|
|
3281
|
+
return {
|
|
3282
|
+
key: space.key,
|
|
3283
|
+
isOpen: space.isOpen,
|
|
3284
|
+
timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
|
|
3285
|
+
genesisFeed: space.genesisFeedKey,
|
|
3286
|
+
controlFeed: space.controlFeedKey,
|
|
3287
|
+
dataFeed: space.dataFeedKey
|
|
3288
|
+
};
|
|
3289
|
+
})
|
|
3290
|
+
});
|
|
3291
|
+
};
|
|
3292
|
+
const timeout = setTimeout(async () => {
|
|
3293
|
+
await context.initialized.wait();
|
|
3294
|
+
unsubscribe = context.dataSpaceManager.updated.on(() => update());
|
|
3295
|
+
await update();
|
|
3296
|
+
});
|
|
3297
|
+
return () => {
|
|
3298
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
3299
|
+
clearTimeout(timeout);
|
|
3300
|
+
};
|
|
3301
|
+
});
|
|
3302
|
+
};
|
|
3303
|
+
|
|
3304
|
+
// packages/sdk/client-services/src/packlets/devtools/devtools.ts
|
|
3305
|
+
var DevtoolsHostEvents = class {
|
|
3306
|
+
constructor() {
|
|
3307
|
+
this.ready = new import_async15.Event();
|
|
2933
3308
|
}
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
3309
|
+
};
|
|
3310
|
+
var DevtoolsServiceImpl = class {
|
|
3311
|
+
constructor(params) {
|
|
3312
|
+
this.params = params;
|
|
2937
3313
|
}
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
callSite: (f, a) => f(...a)
|
|
2944
|
-
});
|
|
2945
|
-
import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.begin({
|
|
2946
|
-
id: this._instanceId
|
|
2947
|
-
}), {
|
|
2948
|
-
file: "data-space-manager.ts",
|
|
2949
|
-
line: 81,
|
|
2950
|
-
scope: this,
|
|
2951
|
-
callSite: (f, a) => f(...a)
|
|
2952
|
-
});
|
|
2953
|
-
await this._metadataStore.load();
|
|
2954
|
-
(0, import_log12.log)("metadata loaded", {
|
|
2955
|
-
spaces: this._metadataStore.spaces.length
|
|
2956
|
-
}, {
|
|
2957
|
-
file: "data-space-manager.ts",
|
|
2958
|
-
line: 83,
|
|
2959
|
-
scope: this,
|
|
2960
|
-
callSite: (f, a) => f(...a)
|
|
2961
|
-
});
|
|
2962
|
-
for (const spaceMetadata of this._metadataStore.spaces) {
|
|
2963
|
-
try {
|
|
2964
|
-
(0, import_log12.log)("load space", {
|
|
2965
|
-
spaceMetadata
|
|
2966
|
-
}, {
|
|
2967
|
-
file: "data-space-manager.ts",
|
|
2968
|
-
line: 87,
|
|
2969
|
-
scope: this,
|
|
2970
|
-
callSite: (f, a) => f(...a)
|
|
2971
|
-
});
|
|
2972
|
-
const space = await this._constructSpace(spaceMetadata);
|
|
2973
|
-
space.initializeDataPipelineAsync();
|
|
2974
|
-
} catch (err) {
|
|
2975
|
-
import_log12.log.error("Error loading space", {
|
|
2976
|
-
spaceMetadata,
|
|
2977
|
-
err
|
|
2978
|
-
}, {
|
|
2979
|
-
file: "data-space-manager.ts",
|
|
2980
|
-
line: 91,
|
|
2981
|
-
scope: this,
|
|
2982
|
-
callSite: (f, a) => f(...a)
|
|
3314
|
+
events(request) {
|
|
3315
|
+
return new import_codec_protobuf10.Stream(({ next }) => {
|
|
3316
|
+
this.params.events.ready.on(() => {
|
|
3317
|
+
next({
|
|
3318
|
+
ready: {}
|
|
2983
3319
|
});
|
|
2984
|
-
}
|
|
2985
|
-
}
|
|
2986
|
-
this._isOpen = true;
|
|
2987
|
-
this.updated.emit();
|
|
2988
|
-
import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.end({
|
|
2989
|
-
id: this._instanceId
|
|
2990
|
-
}), {
|
|
2991
|
-
file: "data-space-manager.ts",
|
|
2992
|
-
line: 97,
|
|
2993
|
-
scope: this,
|
|
2994
|
-
callSite: (f, a) => f(...a)
|
|
3320
|
+
});
|
|
2995
3321
|
});
|
|
2996
3322
|
}
|
|
2997
|
-
|
|
2998
|
-
(
|
|
2999
|
-
file: "data-space-manager.ts",
|
|
3000
|
-
line: 102,
|
|
3001
|
-
scope: this,
|
|
3002
|
-
callSite: (f, a) => f(...a)
|
|
3003
|
-
});
|
|
3004
|
-
this._isOpen = false;
|
|
3005
|
-
await this._ctx.dispose();
|
|
3006
|
-
for (const space of this._spaces.values()) {
|
|
3007
|
-
await space.close();
|
|
3008
|
-
}
|
|
3323
|
+
getConfig(request) {
|
|
3324
|
+
throw new Error();
|
|
3009
3325
|
}
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
const
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
controlFeedKey,
|
|
3022
|
-
dataFeedKey
|
|
3326
|
+
async getStorageInfo() {
|
|
3327
|
+
var _a, _b, _c, _d, _e;
|
|
3328
|
+
const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
|
|
3329
|
+
used: 0
|
|
3330
|
+
};
|
|
3331
|
+
const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
|
|
3332
|
+
return {
|
|
3333
|
+
type: this.params.context.storage.type,
|
|
3334
|
+
storageUsage: storageUsage.used,
|
|
3335
|
+
originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
|
|
3336
|
+
usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
|
|
3023
3337
|
};
|
|
3024
|
-
(0, import_log12.log)("creating space...", {
|
|
3025
|
-
spaceKey
|
|
3026
|
-
}, {
|
|
3027
|
-
file: "data-space-manager.ts",
|
|
3028
|
-
line: 126,
|
|
3029
|
-
scope: this,
|
|
3030
|
-
callSite: (f, a) => f(...a)
|
|
3031
|
-
});
|
|
3032
|
-
const space = await this._constructSpace(metadata);
|
|
3033
|
-
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
|
|
3034
|
-
await this._metadataStore.addSpace(metadata);
|
|
3035
|
-
const memberCredential = credentials[1];
|
|
3036
|
-
(0, import_node_assert11.default)((0, import_credentials13.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
3037
|
-
await this._signingContext.recordCredential(memberCredential);
|
|
3038
|
-
await space.initializeDataPipeline();
|
|
3039
|
-
this.updated.emit();
|
|
3040
|
-
return space;
|
|
3041
3338
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
opts
|
|
3046
|
-
}, {
|
|
3047
|
-
file: "data-space-manager.ts",
|
|
3048
|
-
line: 145,
|
|
3049
|
-
scope: this,
|
|
3050
|
-
callSite: (f, a) => f(...a)
|
|
3051
|
-
});
|
|
3052
|
-
(0, import_node_assert11.default)(this._isOpen, "Not open.");
|
|
3053
|
-
(0, import_node_assert11.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
|
|
3054
|
-
const metadata = {
|
|
3055
|
-
key: opts.spaceKey,
|
|
3056
|
-
genesisFeedKey: opts.genesisFeedKey,
|
|
3057
|
-
controlTimeframe: opts.controlTimeframe,
|
|
3058
|
-
dataTimeframe: opts.dataTimeframe
|
|
3339
|
+
async getBlobs() {
|
|
3340
|
+
return {
|
|
3341
|
+
blobs: await this.params.context.blobStore.list()
|
|
3059
3342
|
};
|
|
3060
|
-
const space = await this._constructSpace(metadata);
|
|
3061
|
-
await this._metadataStore.addSpace(metadata);
|
|
3062
|
-
space.initializeDataPipelineAsync();
|
|
3063
|
-
this.updated.emit();
|
|
3064
|
-
return space;
|
|
3065
3343
|
}
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
*/
|
|
3071
|
-
async waitUntilSpaceReady(spaceKey) {
|
|
3072
|
-
await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
|
|
3073
|
-
const space = this._spaces.get(spaceKey);
|
|
3074
|
-
return !!space && space.state === import_services9.SpaceState.READY;
|
|
3075
|
-
}));
|
|
3344
|
+
async getSnapshots() {
|
|
3345
|
+
return {
|
|
3346
|
+
snapshots: await this.params.context.snapshotStore.listSnapshots()
|
|
3347
|
+
};
|
|
3076
3348
|
}
|
|
3077
|
-
|
|
3078
|
-
(
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3349
|
+
resetStorage(request) {
|
|
3350
|
+
throw new Error();
|
|
3351
|
+
}
|
|
3352
|
+
enableDebugLogging(request) {
|
|
3353
|
+
throw new Error();
|
|
3354
|
+
}
|
|
3355
|
+
disableDebugLogging(request) {
|
|
3356
|
+
throw new Error();
|
|
3357
|
+
}
|
|
3358
|
+
subscribeToKeyringKeys(request) {
|
|
3359
|
+
return subscribeToKeyringKeys({
|
|
3360
|
+
keyring: this.params.context.keyring
|
|
3085
3361
|
});
|
|
3086
|
-
|
|
3087
|
-
|
|
3362
|
+
}
|
|
3363
|
+
subscribeToCredentialMessages(request) {
|
|
3364
|
+
throw new Error();
|
|
3365
|
+
}
|
|
3366
|
+
subscribeToSpaces(request) {
|
|
3367
|
+
return subscribeToSpaces(this.params.context, request);
|
|
3368
|
+
}
|
|
3369
|
+
subscribeToItems(request) {
|
|
3370
|
+
throw new Error();
|
|
3371
|
+
}
|
|
3372
|
+
subscribeToFeeds(request) {
|
|
3373
|
+
return subscribeToFeeds({
|
|
3374
|
+
feedStore: this.params.context.feedStore
|
|
3375
|
+
}, request);
|
|
3376
|
+
}
|
|
3377
|
+
subscribeToFeedBlocks(request) {
|
|
3378
|
+
return subscribeToFeedBlocks({
|
|
3379
|
+
feedStore: this.params.context.feedStore
|
|
3380
|
+
}, request);
|
|
3381
|
+
}
|
|
3382
|
+
getSpaceSnapshot(request) {
|
|
3383
|
+
throw new Error();
|
|
3384
|
+
}
|
|
3385
|
+
saveSpaceSnapshot(request) {
|
|
3386
|
+
throw new Error();
|
|
3387
|
+
}
|
|
3388
|
+
clearSnapshots(request) {
|
|
3389
|
+
throw new Error();
|
|
3390
|
+
}
|
|
3391
|
+
getNetworkPeers(request) {
|
|
3392
|
+
throw new Error();
|
|
3393
|
+
}
|
|
3394
|
+
subscribeToNetworkTopics(request) {
|
|
3395
|
+
throw new Error();
|
|
3396
|
+
}
|
|
3397
|
+
subscribeToSignalStatus(request) {
|
|
3398
|
+
return subscribeToNetworkStatus({
|
|
3399
|
+
signalManager: this.params.context.signalManager
|
|
3088
3400
|
});
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
gossip
|
|
3401
|
+
}
|
|
3402
|
+
subscribeToSignal() {
|
|
3403
|
+
return subscribeToSignal({
|
|
3404
|
+
signalManager: this.params.context.signalManager
|
|
3094
3405
|
});
|
|
3095
|
-
|
|
3096
|
-
|
|
3406
|
+
}
|
|
3407
|
+
subscribeToSwarmInfo() {
|
|
3408
|
+
return subscribeToSwarmInfo({
|
|
3409
|
+
networkManager: this.params.context.networkManager
|
|
3097
3410
|
});
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3411
|
+
}
|
|
3412
|
+
subscribeToMetadata() {
|
|
3413
|
+
return subscribeToMetadata({
|
|
3414
|
+
context: this.params.context
|
|
3101
3415
|
});
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3416
|
+
}
|
|
3417
|
+
};
|
|
3418
|
+
|
|
3419
|
+
// packages/sdk/client-services/src/packlets/locks/node.ts
|
|
3420
|
+
var import_node_assert12 = __toESM(require("node:assert"));
|
|
3421
|
+
var import_lock_file = require("@dxos/lock-file");
|
|
3422
|
+
var import_log13 = require("@dxos/log");
|
|
3423
|
+
var __decorate3 = function(decorators, target, key, desc) {
|
|
3424
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3425
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3426
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
3427
|
+
else
|
|
3428
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
3429
|
+
if (d = decorators[i])
|
|
3430
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3431
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3432
|
+
};
|
|
3433
|
+
var Lock = class {
|
|
3434
|
+
constructor({ lockKey: lockPath, onAcquire, onRelease }) {
|
|
3435
|
+
this._lockPath = lockPath;
|
|
3436
|
+
this._onAcquire = onAcquire;
|
|
3437
|
+
this._onRelease = onRelease;
|
|
3438
|
+
}
|
|
3439
|
+
get lockKey() {
|
|
3440
|
+
return this._lockPath;
|
|
3441
|
+
}
|
|
3442
|
+
async acquire() {
|
|
3443
|
+
var _a;
|
|
3444
|
+
(0, import_log13.log)("acquiring lock...", {}, {
|
|
3445
|
+
file: "node.ts",
|
|
3446
|
+
line: 32,
|
|
3447
|
+
scope: this,
|
|
3448
|
+
callSite: (f, a) => f(...a)
|
|
3124
3449
|
});
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
keyring: this._keyring,
|
|
3133
|
-
feedStore: this._feedStore,
|
|
3134
|
-
signingContext: this._signingContext,
|
|
3135
|
-
callbacks: {
|
|
3136
|
-
beforeReady: async () => {
|
|
3137
|
-
(0, import_log12.log)("before space ready", {
|
|
3138
|
-
space: space.key
|
|
3139
|
-
}, {
|
|
3140
|
-
file: "data-space-manager.ts",
|
|
3141
|
-
line: 229,
|
|
3142
|
-
scope: this,
|
|
3143
|
-
callSite: (f, a) => f(...a)
|
|
3144
|
-
});
|
|
3145
|
-
this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
|
|
3146
|
-
},
|
|
3147
|
-
afterReady: async () => {
|
|
3148
|
-
(0, import_log12.log)("after space ready", {
|
|
3149
|
-
space: space.key,
|
|
3150
|
-
open: this._isOpen
|
|
3151
|
-
}, {
|
|
3152
|
-
file: "data-space-manager.ts",
|
|
3153
|
-
line: 236,
|
|
3154
|
-
scope: this,
|
|
3155
|
-
callSite: (f, a) => f(...a)
|
|
3156
|
-
});
|
|
3157
|
-
if (this._isOpen) {
|
|
3158
|
-
this.updated.emit();
|
|
3159
|
-
}
|
|
3160
|
-
}
|
|
3161
|
-
},
|
|
3162
|
-
cache: metadata.cache
|
|
3450
|
+
this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
|
|
3451
|
+
await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
|
|
3452
|
+
(0, import_log13.log)("acquired lock", {}, {
|
|
3453
|
+
file: "node.ts",
|
|
3454
|
+
line: 37,
|
|
3455
|
+
scope: this,
|
|
3456
|
+
callSite: (f, a) => f(...a)
|
|
3163
3457
|
});
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
}
|
|
3171
|
-
this._spaces.set(metadata.key, dataSpace);
|
|
3172
|
-
return dataSpace;
|
|
3458
|
+
}
|
|
3459
|
+
async release() {
|
|
3460
|
+
var _a;
|
|
3461
|
+
await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
|
|
3462
|
+
(0, import_node_assert12.default)(this._fileHandle, "Lock is not acquired");
|
|
3463
|
+
await import_lock_file.LockFile.release(this._fileHandle);
|
|
3173
3464
|
}
|
|
3174
3465
|
};
|
|
3175
3466
|
__decorate3([
|
|
3176
|
-
|
|
3177
|
-
],
|
|
3178
|
-
__decorate3([
|
|
3179
|
-
import_async14.synchronized
|
|
3180
|
-
], DataSpaceManager.prototype, "close", null);
|
|
3181
|
-
__decorate3([
|
|
3182
|
-
import_async14.synchronized
|
|
3183
|
-
], DataSpaceManager.prototype, "createSpace", null);
|
|
3184
|
-
__decorate3([
|
|
3185
|
-
import_async14.synchronized
|
|
3186
|
-
], DataSpaceManager.prototype, "acceptSpace", null);
|
|
3187
|
-
DataSpaceManager = __decorate3([
|
|
3188
|
-
(0, import_async14.trackLeaks)("open", "close")
|
|
3189
|
-
], DataSpaceManager);
|
|
3467
|
+
import_log13.logInfo
|
|
3468
|
+
], Lock.prototype, "lockKey", null);
|
|
3190
3469
|
|
|
3191
|
-
// packages/sdk/client-services/src/packlets/
|
|
3192
|
-
var
|
|
3193
|
-
var
|
|
3194
|
-
var
|
|
3195
|
-
var
|
|
3196
|
-
var import_log13 = require("@dxos/log");
|
|
3197
|
-
var import_protocols7 = require("@dxos/protocols");
|
|
3198
|
-
var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3470
|
+
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
3471
|
+
var import_async16 = require("@dxos/async");
|
|
3472
|
+
var import_codec_protobuf11 = require("@dxos/codec-protobuf");
|
|
3473
|
+
var import_log14 = require("@dxos/log");
|
|
3474
|
+
var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3199
3475
|
var import_util7 = require("@dxos/util");
|
|
3200
|
-
var
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
this.
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
this._getDataSpaceManager = _getDataSpaceManager;
|
|
3476
|
+
var LoggingServiceImpl = class {
|
|
3477
|
+
constructor() {
|
|
3478
|
+
this._logs = new import_async16.Event();
|
|
3479
|
+
this._logProcessor = (_config, entry2) => {
|
|
3480
|
+
this._logs.emit(entry2);
|
|
3481
|
+
};
|
|
3207
3482
|
}
|
|
3208
|
-
async
|
|
3209
|
-
|
|
3210
|
-
throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
|
|
3211
|
-
}
|
|
3212
|
-
const dataSpaceManager = await this._getDataSpaceManager();
|
|
3213
|
-
const space = await dataSpaceManager.createSpace();
|
|
3214
|
-
return this._transformSpace(space);
|
|
3483
|
+
async open() {
|
|
3484
|
+
import_log14.log.runtimeConfig.processors.push(this._logProcessor);
|
|
3215
3485
|
}
|
|
3216
|
-
async
|
|
3217
|
-
(
|
|
3486
|
+
async close() {
|
|
3487
|
+
const index = import_log14.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
3488
|
+
import_log14.log.runtimeConfig.processors.splice(index, 1);
|
|
3218
3489
|
}
|
|
3219
|
-
|
|
3220
|
-
return new
|
|
3221
|
-
const
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
}
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
const subscribeSpaces = () => {
|
|
3241
|
-
subscriptions.clear();
|
|
3242
|
-
for (const space of dataSpaceManager.spaces.values()) {
|
|
3243
|
-
subscriptions.add(space.stateUpdate.on(ctx, onUpdate));
|
|
3244
|
-
subscriptions.add(space.presence.updated.on(ctx, onUpdate));
|
|
3245
|
-
subscriptions.add(space.dataPipeline.onNewEpoch.on(ctx, onUpdate));
|
|
3246
|
-
space.inner.controlPipeline.state.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate);
|
|
3247
|
-
if (space.dataPipeline.pipelineState) {
|
|
3248
|
-
subscriptions.add(space.dataPipeline.pipelineState.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate));
|
|
3249
|
-
}
|
|
3490
|
+
queryLogs(request) {
|
|
3491
|
+
return new import_codec_protobuf11.Stream(({ ctx, next }) => {
|
|
3492
|
+
const handler = (entry2) => {
|
|
3493
|
+
var _a, _b, _c, _d, _e;
|
|
3494
|
+
if (LOG_PROCESSING > 0) {
|
|
3495
|
+
return;
|
|
3496
|
+
}
|
|
3497
|
+
if (((_a = entry2.meta) == null ? void 0 : _a.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3500
|
+
if (!shouldLog(entry2, request)) {
|
|
3501
|
+
return;
|
|
3502
|
+
}
|
|
3503
|
+
const record = {
|
|
3504
|
+
...entry2,
|
|
3505
|
+
context: (0, import_util7.jsonify)((0, import_log14.getContextFromEntry)(entry2)),
|
|
3506
|
+
timestamp: new Date(),
|
|
3507
|
+
meta: {
|
|
3508
|
+
// TODO(dmaretskyi): Fix proto.
|
|
3509
|
+
file: (_c = (_b = entry2.meta) == null ? void 0 : _b.file) != null ? _c : "",
|
|
3510
|
+
line: (_e = (_d = entry2.meta) == null ? void 0 : _d.line) != null ? _e : 0
|
|
3250
3511
|
}
|
|
3251
3512
|
};
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
}
|
|
3259
|
-
|
|
3260
|
-
next({
|
|
3261
|
-
spaces: []
|
|
3262
|
-
});
|
|
3263
|
-
}
|
|
3513
|
+
try {
|
|
3514
|
+
LOG_PROCESSING++;
|
|
3515
|
+
next(record);
|
|
3516
|
+
} finally {
|
|
3517
|
+
LOG_PROCESSING--;
|
|
3518
|
+
}
|
|
3519
|
+
};
|
|
3520
|
+
this._logs.on(ctx, handler);
|
|
3264
3521
|
});
|
|
3265
3522
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3523
|
+
};
|
|
3524
|
+
var matchFilter = (filter, level, path, options) => {
|
|
3525
|
+
switch (options) {
|
|
3526
|
+
case import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE:
|
|
3527
|
+
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
3528
|
+
case import_services11.QueryLogsRequest.MatchingOptions.EXPLICIT:
|
|
3529
|
+
return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
3271
3530
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
});
|
|
3531
|
+
};
|
|
3532
|
+
var shouldLog = (entry2, request) => {
|
|
3533
|
+
var _a;
|
|
3534
|
+
const options = (_a = request.options) != null ? _a : import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
3535
|
+
if (request.filters === void 0) {
|
|
3536
|
+
return options === import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
3537
|
+
} else {
|
|
3538
|
+
return request.filters.some((filter) => {
|
|
3539
|
+
var _a2, _b;
|
|
3540
|
+
return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.file) != null ? _b : "", options);
|
|
3283
3541
|
});
|
|
3284
3542
|
}
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3543
|
+
};
|
|
3544
|
+
var LOG_PROCESSING = 0;
|
|
3545
|
+
|
|
3546
|
+
// packages/sdk/client-services/src/packlets/network/network-service.ts
|
|
3547
|
+
var import_codec_protobuf12 = require("@dxos/codec-protobuf");
|
|
3548
|
+
var NetworkServiceImpl = class {
|
|
3549
|
+
constructor(networkManager, signalManager) {
|
|
3550
|
+
this.networkManager = networkManager;
|
|
3551
|
+
this.signalManager = signalManager;
|
|
3552
|
+
}
|
|
3553
|
+
queryStatus() {
|
|
3554
|
+
return new import_codec_protobuf12.Stream(({ next }) => {
|
|
3555
|
+
const update = () => {
|
|
3556
|
+
next({
|
|
3557
|
+
swarm: this.networkManager.connectionState,
|
|
3558
|
+
signaling: this.signalManager.getStatus().map(({ host, state }) => ({
|
|
3559
|
+
server: host,
|
|
3560
|
+
state
|
|
3561
|
+
}))
|
|
3562
|
+
});
|
|
3563
|
+
};
|
|
3564
|
+
const unsubscribeSwarm = this.networkManager.connectionStateChanged.on(() => update());
|
|
3565
|
+
const unsubscribeSignal = this.signalManager.statusChanged.on(() => update());
|
|
3566
|
+
update();
|
|
3567
|
+
return () => {
|
|
3568
|
+
unsubscribeSwarm();
|
|
3569
|
+
unsubscribeSignal();
|
|
3570
|
+
};
|
|
3296
3571
|
});
|
|
3297
3572
|
}
|
|
3298
|
-
async
|
|
3299
|
-
|
|
3300
|
-
const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
3301
|
-
for (const credential of credentials != null ? credentials : []) {
|
|
3302
|
-
await space.controlPipeline.writer.write({
|
|
3303
|
-
credential: {
|
|
3304
|
-
credential
|
|
3305
|
-
}
|
|
3306
|
-
});
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
async createEpoch({ spaceKey }) {
|
|
3310
|
-
var _a;
|
|
3311
|
-
const dataSpaceManager = await this._getDataSpaceManager();
|
|
3312
|
-
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
3313
|
-
await space.createEpoch();
|
|
3314
|
-
}
|
|
3315
|
-
_transformSpace(space) {
|
|
3316
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
3317
|
-
return {
|
|
3318
|
-
spaceKey: space.key,
|
|
3319
|
-
state: space.state,
|
|
3320
|
-
error: space.error ? (0, import_protocols7.encodeError)(space.error) : void 0,
|
|
3321
|
-
pipeline: {
|
|
3322
|
-
currentEpoch: space.dataPipeline.currentEpoch,
|
|
3323
|
-
appliedEpoch: space.dataPipeline.appliedEpoch,
|
|
3324
|
-
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
3325
|
-
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
3326
|
-
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
3327
|
-
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
|
|
3328
|
-
dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
|
|
3329
|
-
startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
|
|
3330
|
-
currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
|
|
3331
|
-
targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
|
|
3332
|
-
totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
|
|
3333
|
-
},
|
|
3334
|
-
members: Array.from(space.inner.spaceState.members.values()).map((member) => {
|
|
3335
|
-
var _a2, _b2, _c2;
|
|
3336
|
-
return {
|
|
3337
|
-
identity: {
|
|
3338
|
-
identityKey: member.key,
|
|
3339
|
-
profile: {
|
|
3340
|
-
displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : (0, import_util7.humanize)(member.key)
|
|
3341
|
-
}
|
|
3342
|
-
},
|
|
3343
|
-
presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE
|
|
3344
|
-
};
|
|
3345
|
-
}),
|
|
3346
|
-
creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
|
|
3347
|
-
cache: space.cache,
|
|
3348
|
-
metrics: space.metrics
|
|
3349
|
-
};
|
|
3573
|
+
async updateConfig(request) {
|
|
3574
|
+
await this.networkManager.setConnectionState(request.swarm);
|
|
3350
3575
|
}
|
|
3351
3576
|
};
|
|
3352
|
-
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
3353
3577
|
|
|
3354
3578
|
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
3355
3579
|
var import_client_protocol4 = require("@dxos/client-protocol");
|
|
@@ -3438,228 +3662,6 @@ var SystemServiceImpl = class {
|
|
|
3438
3662
|
}
|
|
3439
3663
|
};
|
|
3440
3664
|
|
|
3441
|
-
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
3442
|
-
var import_node_assert12 = __toESM(require("node:assert"));
|
|
3443
|
-
var import_async16 = require("@dxos/async");
|
|
3444
|
-
var import_credentials14 = require("@dxos/credentials");
|
|
3445
|
-
var import_debug6 = require("@dxos/debug");
|
|
3446
|
-
var import_echo_pipeline3 = require("@dxos/echo-pipeline");
|
|
3447
|
-
var import_feed_store4 = require("@dxos/feed-store");
|
|
3448
|
-
var import_keyring = require("@dxos/keyring");
|
|
3449
|
-
var import_keys11 = require("@dxos/keys");
|
|
3450
|
-
var import_log14 = require("@dxos/log");
|
|
3451
|
-
var import_protocols8 = require("@dxos/protocols");
|
|
3452
|
-
var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3453
|
-
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
3454
|
-
var ServiceContext = class {
|
|
3455
|
-
// prettier-ignore
|
|
3456
|
-
constructor(storage, networkManager, signalManager, modelFactory) {
|
|
3457
|
-
this.storage = storage;
|
|
3458
|
-
this.networkManager = networkManager;
|
|
3459
|
-
this.signalManager = signalManager;
|
|
3460
|
-
this.modelFactory = modelFactory;
|
|
3461
|
-
this.initialized = new import_async16.Trigger();
|
|
3462
|
-
this.dataServiceSubscriptions = new import_echo_pipeline3.DataServiceSubscriptions();
|
|
3463
|
-
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
3464
|
-
this._instanceId = import_keys11.PublicKey.random().toHex();
|
|
3465
|
-
this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
|
|
3466
|
-
this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
|
|
3467
|
-
this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
|
|
3468
|
-
this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
|
|
3469
|
-
this.feedStore = new import_feed_store4.FeedStore({
|
|
3470
|
-
factory: new import_feed_store4.FeedFactory({
|
|
3471
|
-
root: storage.createDirectory("feeds"),
|
|
3472
|
-
signer: this.keyring,
|
|
3473
|
-
hypercore: {
|
|
3474
|
-
valueEncoding: import_echo_pipeline3.valueEncoding
|
|
3475
|
-
}
|
|
3476
|
-
})
|
|
3477
|
-
});
|
|
3478
|
-
this.spaceManager = new import_echo_pipeline3.SpaceManager({
|
|
3479
|
-
feedStore: this.feedStore,
|
|
3480
|
-
networkManager: this.networkManager,
|
|
3481
|
-
blobStore: this.blobStore,
|
|
3482
|
-
metadataStore: this.metadataStore,
|
|
3483
|
-
modelFactory: this.modelFactory,
|
|
3484
|
-
snapshotStore: this.snapshotStore
|
|
3485
|
-
});
|
|
3486
|
-
this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
|
|
3487
|
-
this.invitations = new InvitationsHandler(this.networkManager);
|
|
3488
|
-
this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
|
|
3489
|
-
var _a;
|
|
3490
|
-
return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
|
|
3491
|
-
}, this._acceptIdentity.bind(this)));
|
|
3492
|
-
}
|
|
3493
|
-
async open() {
|
|
3494
|
-
import_log14.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.begin({
|
|
3495
|
-
id: this._instanceId
|
|
3496
|
-
}), {
|
|
3497
|
-
file: "service-context.ts",
|
|
3498
|
-
line: 126,
|
|
3499
|
-
scope: this,
|
|
3500
|
-
callSite: (f, a) => f(...a)
|
|
3501
|
-
});
|
|
3502
|
-
await this._checkStorageVersion();
|
|
3503
|
-
(0, import_log14.log)("opening...", {}, {
|
|
3504
|
-
file: "service-context.ts",
|
|
3505
|
-
line: 130,
|
|
3506
|
-
scope: this,
|
|
3507
|
-
callSite: (f, a) => f(...a)
|
|
3508
|
-
});
|
|
3509
|
-
await this.signalManager.open();
|
|
3510
|
-
await this.networkManager.open();
|
|
3511
|
-
await this.spaceManager.open();
|
|
3512
|
-
await this.identityManager.open();
|
|
3513
|
-
if (this.identityManager.identity) {
|
|
3514
|
-
await this._initialize();
|
|
3515
|
-
}
|
|
3516
|
-
(0, import_log14.log)("opened", {}, {
|
|
3517
|
-
file: "service-context.ts",
|
|
3518
|
-
line: 138,
|
|
3519
|
-
scope: this,
|
|
3520
|
-
callSite: (f, a) => f(...a)
|
|
3521
|
-
});
|
|
3522
|
-
import_log14.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.end({
|
|
3523
|
-
id: this._instanceId
|
|
3524
|
-
}), {
|
|
3525
|
-
file: "service-context.ts",
|
|
3526
|
-
line: 139,
|
|
3527
|
-
scope: this,
|
|
3528
|
-
callSite: (f, a) => f(...a)
|
|
3529
|
-
});
|
|
3530
|
-
}
|
|
3531
|
-
async close() {
|
|
3532
|
-
var _a, _b;
|
|
3533
|
-
(0, import_log14.log)("closing...", {}, {
|
|
3534
|
-
file: "service-context.ts",
|
|
3535
|
-
line: 143,
|
|
3536
|
-
scope: this,
|
|
3537
|
-
callSite: (f, a) => f(...a)
|
|
3538
|
-
});
|
|
3539
|
-
await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
|
|
3540
|
-
await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
|
|
3541
|
-
await this.identityManager.close();
|
|
3542
|
-
await this.spaceManager.close();
|
|
3543
|
-
await this.feedStore.close();
|
|
3544
|
-
await this.networkManager.close();
|
|
3545
|
-
await this.signalManager.close();
|
|
3546
|
-
this.dataServiceSubscriptions.clear();
|
|
3547
|
-
(0, import_log14.log)("closed", {}, {
|
|
3548
|
-
file: "service-context.ts",
|
|
3549
|
-
line: 152,
|
|
3550
|
-
scope: this,
|
|
3551
|
-
callSite: (f, a) => f(...a)
|
|
3552
|
-
});
|
|
3553
|
-
}
|
|
3554
|
-
async createIdentity(params = {}) {
|
|
3555
|
-
const identity = await this.identityManager.createIdentity(params);
|
|
3556
|
-
await this._initialize();
|
|
3557
|
-
return identity;
|
|
3558
|
-
}
|
|
3559
|
-
getInvitationHandler(invitation) {
|
|
3560
|
-
const factory = this._handlerFactories.get(invitation.kind);
|
|
3561
|
-
(0, import_node_assert12.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
|
|
3562
|
-
return factory(invitation);
|
|
3563
|
-
}
|
|
3564
|
-
async _acceptIdentity(params) {
|
|
3565
|
-
const identity = await this.identityManager.acceptIdentity(params);
|
|
3566
|
-
await this._initialize();
|
|
3567
|
-
return identity;
|
|
3568
|
-
}
|
|
3569
|
-
async _checkStorageVersion() {
|
|
3570
|
-
await this.metadataStore.load();
|
|
3571
|
-
if (this.metadataStore.version !== import_protocols8.STORAGE_VERSION) {
|
|
3572
|
-
throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${import_protocols8.STORAGE_VERSION}`);
|
|
3573
|
-
}
|
|
3574
|
-
}
|
|
3575
|
-
// Called when identity is created.
|
|
3576
|
-
async _initialize() {
|
|
3577
|
-
var _a;
|
|
3578
|
-
(0, import_log14.log)("initializing spaces...", {}, {
|
|
3579
|
-
file: "service-context.ts",
|
|
3580
|
-
line: 185,
|
|
3581
|
-
scope: this,
|
|
3582
|
-
callSite: (f, a) => f(...a)
|
|
3583
|
-
});
|
|
3584
|
-
const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
|
|
3585
|
-
const signingContext = {
|
|
3586
|
-
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
3587
|
-
identityKey: identity.identityKey,
|
|
3588
|
-
deviceKey: identity.deviceKey,
|
|
3589
|
-
profile: identity.profileDocument,
|
|
3590
|
-
recordCredential: async (credential) => {
|
|
3591
|
-
await identity.controlPipeline.writer.write({
|
|
3592
|
-
credential: {
|
|
3593
|
-
credential
|
|
3594
|
-
}
|
|
3595
|
-
});
|
|
3596
|
-
}
|
|
3597
|
-
};
|
|
3598
|
-
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
|
|
3599
|
-
await this.dataSpaceManager.open();
|
|
3600
|
-
this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
|
|
3601
|
-
(0, import_node_assert12.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
|
|
3602
|
-
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
3603
|
-
});
|
|
3604
|
-
this.initialized.wake();
|
|
3605
|
-
this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
|
|
3606
|
-
process: async (credential) => {
|
|
3607
|
-
const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
|
|
3608
|
-
if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
|
|
3609
|
-
return;
|
|
3610
|
-
}
|
|
3611
|
-
if (assertion.spaceKey.equals(identity.space.key)) {
|
|
3612
|
-
return;
|
|
3613
|
-
}
|
|
3614
|
-
if (!this.dataSpaceManager) {
|
|
3615
|
-
(0, import_log14.log)("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
3616
|
-
details: assertion
|
|
3617
|
-
}, {
|
|
3618
|
-
file: "service-context.ts",
|
|
3619
|
-
line: 224,
|
|
3620
|
-
scope: this,
|
|
3621
|
-
callSite: (f, a) => f(...a)
|
|
3622
|
-
});
|
|
3623
|
-
return;
|
|
3624
|
-
}
|
|
3625
|
-
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
3626
|
-
(0, import_log14.log)("space already exists, ignoring space admission", {
|
|
3627
|
-
details: assertion
|
|
3628
|
-
}, {
|
|
3629
|
-
file: "service-context.ts",
|
|
3630
|
-
line: 228,
|
|
3631
|
-
scope: this,
|
|
3632
|
-
callSite: (f, a) => f(...a)
|
|
3633
|
-
});
|
|
3634
|
-
return;
|
|
3635
|
-
}
|
|
3636
|
-
try {
|
|
3637
|
-
(0, import_log14.log)("accepting space recorded in halo", {
|
|
3638
|
-
details: assertion
|
|
3639
|
-
}, {
|
|
3640
|
-
file: "service-context.ts",
|
|
3641
|
-
line: 233,
|
|
3642
|
-
scope: this,
|
|
3643
|
-
callSite: (f, a) => f(...a)
|
|
3644
|
-
});
|
|
3645
|
-
await this.dataSpaceManager.acceptSpace({
|
|
3646
|
-
spaceKey: assertion.spaceKey,
|
|
3647
|
-
genesisFeedKey: assertion.genesisFeedKey
|
|
3648
|
-
});
|
|
3649
|
-
} catch (err) {
|
|
3650
|
-
import_log14.log.catch(err, {}, {
|
|
3651
|
-
file: "service-context.ts",
|
|
3652
|
-
line: 239,
|
|
3653
|
-
scope: this,
|
|
3654
|
-
callSite: (f, a) => f(...a)
|
|
3655
|
-
});
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
});
|
|
3659
|
-
await this._deviceSpaceSync.open();
|
|
3660
|
-
}
|
|
3661
|
-
};
|
|
3662
|
-
|
|
3663
3665
|
// packages/sdk/client-services/src/packlets/services/service-registry.ts
|
|
3664
3666
|
var ServiceRegistry = class {
|
|
3665
3667
|
// prettier-ignore
|