@dxos/client-services 0.1.22 → 0.1.23
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/index.mjs +79 -38
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +82 -41
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +8 -8
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +2 -2
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.test.d.ts +2 -0
- package/dist/types/src/packlets/spaces/data-space-manager.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/data-space.d.ts +2 -0
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +30 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/packlets/identity/authenticator.test.ts +4 -4
- package/src/packlets/identity/authenticator.ts +18 -13
- package/src/packlets/identity/identity-manager.ts +2 -4
- package/src/packlets/identity/identity.ts +4 -4
- package/src/packlets/services/service-context.ts +0 -4
- package/src/packlets/spaces/data-space-manager.test.ts +74 -0
- package/src/packlets/spaces/data-space-manager.ts +8 -3
- package/src/packlets/spaces/data-space.ts +12 -0
- package/src/packlets/testing/test-builder.ts +87 -1
|
@@ -486,7 +486,7 @@ import { Context } from "@dxos/context";
|
|
|
486
486
|
import { verifyCredential } from "@dxos/credentials";
|
|
487
487
|
import { log as log2 } from "@dxos/log";
|
|
488
488
|
import { schema } from "@dxos/protocols";
|
|
489
|
-
var
|
|
489
|
+
var createAuthProvider = (signer) => async (nonce) => {
|
|
490
490
|
const credential = await signer.createCredential({
|
|
491
491
|
assertion: {
|
|
492
492
|
"@type": "dxos.halo.credentials.Auth"
|
|
@@ -496,7 +496,7 @@ var createHaloAuthProvider = (signer) => async (nonce) => {
|
|
|
496
496
|
});
|
|
497
497
|
return schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
|
|
498
498
|
};
|
|
499
|
-
var
|
|
499
|
+
var TrustedKeySetAuthVerifier = class {
|
|
500
500
|
constructor(_params) {
|
|
501
501
|
this._params = _params;
|
|
502
502
|
this._ctx = new Context();
|
|
@@ -504,20 +504,28 @@ var HaloAuthVerifier = class {
|
|
|
504
504
|
async close() {
|
|
505
505
|
await this._ctx.dispose();
|
|
506
506
|
}
|
|
507
|
-
|
|
508
|
-
const deviceSet = this._params.
|
|
507
|
+
_isTrustedKey(deviceKey) {
|
|
508
|
+
const deviceSet = this._params.trustedKeysProvider();
|
|
509
509
|
return deviceSet.has(deviceKey);
|
|
510
510
|
}
|
|
511
511
|
get verifier() {
|
|
512
512
|
return async (nonce, auth) => {
|
|
513
513
|
const credential = schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
|
|
514
|
+
log2("authenticating...", {
|
|
515
|
+
credential
|
|
516
|
+
}, {
|
|
517
|
+
file: "authenticator.ts",
|
|
518
|
+
line: 59,
|
|
519
|
+
scope: this,
|
|
520
|
+
callSite: (f, a) => f(...a)
|
|
521
|
+
});
|
|
514
522
|
const result = await verifyCredential(credential);
|
|
515
523
|
if (result.kind === "fail") {
|
|
516
524
|
log2("Invalid credential", {
|
|
517
525
|
result
|
|
518
526
|
}, {
|
|
519
527
|
file: "authenticator.ts",
|
|
520
|
-
line:
|
|
528
|
+
line: 63,
|
|
521
529
|
scope: this,
|
|
522
530
|
callSite: (f, a) => f(...a)
|
|
523
531
|
});
|
|
@@ -529,13 +537,21 @@ var HaloAuthVerifier = class {
|
|
|
529
537
|
credential
|
|
530
538
|
}, {
|
|
531
539
|
file: "authenticator.ts",
|
|
532
|
-
line:
|
|
540
|
+
line: 68,
|
|
533
541
|
scope: this,
|
|
534
542
|
callSite: (f, a) => f(...a)
|
|
535
543
|
});
|
|
536
544
|
return false;
|
|
537
545
|
}
|
|
538
|
-
if (this.
|
|
546
|
+
if (this._isTrustedKey(credential.issuer)) {
|
|
547
|
+
log2("key is not currently in trusted set, waiting...", {
|
|
548
|
+
key: credential.issuer
|
|
549
|
+
}, {
|
|
550
|
+
file: "authenticator.ts",
|
|
551
|
+
line: 73,
|
|
552
|
+
scope: this,
|
|
553
|
+
callSite: (f, a) => f(...a)
|
|
554
|
+
});
|
|
539
555
|
return true;
|
|
540
556
|
}
|
|
541
557
|
const trigger = new Trigger();
|
|
@@ -543,15 +559,31 @@ var HaloAuthVerifier = class {
|
|
|
543
559
|
trigger.wake(false);
|
|
544
560
|
});
|
|
545
561
|
const clear = this._params.update.on(this._ctx, () => {
|
|
546
|
-
if (this.
|
|
562
|
+
if (this._isTrustedKey(credential.issuer)) {
|
|
563
|
+
log2("auth success", {
|
|
564
|
+
key: credential.issuer
|
|
565
|
+
}, {
|
|
566
|
+
file: "authenticator.ts",
|
|
567
|
+
line: 83,
|
|
568
|
+
scope: this,
|
|
569
|
+
callSite: (f, a) => f(...a)
|
|
570
|
+
});
|
|
547
571
|
trigger.wake(true);
|
|
572
|
+
} else {
|
|
573
|
+
log2("key is not currently in trusted set, waiting...", {
|
|
574
|
+
key: credential.issuer
|
|
575
|
+
}, {
|
|
576
|
+
file: "authenticator.ts",
|
|
577
|
+
line: 86,
|
|
578
|
+
scope: this,
|
|
579
|
+
callSite: (f, a) => f(...a)
|
|
580
|
+
});
|
|
548
581
|
}
|
|
549
582
|
});
|
|
550
583
|
try {
|
|
551
|
-
await trigger.wait({
|
|
584
|
+
return await trigger.wait({
|
|
552
585
|
timeout: this._params.authTimeout
|
|
553
586
|
});
|
|
554
|
-
return true;
|
|
555
587
|
} catch (e) {
|
|
556
588
|
return false;
|
|
557
589
|
} finally {
|
|
@@ -585,8 +617,8 @@ var Identity = class {
|
|
|
585
617
|
identityKey: this.identityKey,
|
|
586
618
|
onUpdate: () => this.stateUpdate.emit()
|
|
587
619
|
}));
|
|
588
|
-
this.authVerifier = new
|
|
589
|
-
|
|
620
|
+
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
621
|
+
trustedKeysProvider: () => this.authorizedDeviceKeys,
|
|
590
622
|
update: this.stateUpdate,
|
|
591
623
|
authTimeout: AUTH_TIMEOUT
|
|
592
624
|
});
|
|
@@ -837,7 +869,7 @@ var IdentityManager = class {
|
|
|
837
869
|
spaceRecord: identityRecord.haloSpace,
|
|
838
870
|
swarmIdentity: {
|
|
839
871
|
peerKey: identityRecord.deviceKey,
|
|
840
|
-
credentialProvider:
|
|
872
|
+
credentialProvider: createAuthProvider(createCredentialSignerWithKey2(this._keyring, identityRecord.deviceKey)),
|
|
841
873
|
credentialAuthenticator: deferFunction(() => identity.authVerifier.verifier)
|
|
842
874
|
},
|
|
843
875
|
identityKey: identityRecord.identityKey
|
|
@@ -852,7 +884,7 @@ var IdentityManager = class {
|
|
|
852
884
|
identityKey: identityRecord.identityKey
|
|
853
885
|
}, {
|
|
854
886
|
file: "identity-manager.ts",
|
|
855
|
-
line:
|
|
887
|
+
line: 180,
|
|
856
888
|
scope: this,
|
|
857
889
|
callSite: (f, a) => f(...a)
|
|
858
890
|
});
|
|
@@ -2085,25 +2117,28 @@ var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
|
|
|
2085
2117
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
2086
2118
|
import { Trigger as Trigger4 } from "@dxos/async";
|
|
2087
2119
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
2088
|
-
import {
|
|
2120
|
+
import { valueEncoding, DataServiceSubscriptions, MetadataStore, SpaceManager, SnapshotStore } from "@dxos/echo-db";
|
|
2089
2121
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
2090
2122
|
import { Keyring } from "@dxos/keyring";
|
|
2091
2123
|
import { log as log10 } from "@dxos/log";
|
|
2092
2124
|
|
|
2093
2125
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
2126
|
+
import assert11 from "@dxos/node-std/assert";
|
|
2094
2127
|
import { Event as Event3, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
2095
2128
|
import { Context as Context5 } from "@dxos/context";
|
|
2096
2129
|
import { spaceGenesis, SnapshotManager } from "@dxos/echo-db";
|
|
2097
|
-
import { PublicKey as
|
|
2130
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2098
2131
|
import { log as log9 } from "@dxos/log";
|
|
2099
2132
|
import { Presence } from "@dxos/teleport-extension-presence";
|
|
2100
|
-
import { ComplexMap as ComplexMap2 } from "@dxos/util";
|
|
2133
|
+
import { ComplexMap as ComplexMap2, deferFunction as deferFunction2 } from "@dxos/util";
|
|
2101
2134
|
|
|
2102
2135
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2103
2136
|
import assert10 from "@dxos/node-std/assert";
|
|
2104
2137
|
import { trackLeaks } from "@dxos/async";
|
|
2105
2138
|
import { Context as Context4 } from "@dxos/context";
|
|
2106
2139
|
import { DataPipelineControllerImpl } from "@dxos/echo-db";
|
|
2140
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
2141
|
+
import { ComplexSet } from "@dxos/util";
|
|
2107
2142
|
var __decorate = function(decorators, target, key, desc) {
|
|
2108
2143
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2109
2144
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2114,6 +2149,7 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
2114
2149
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2115
2150
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2116
2151
|
};
|
|
2152
|
+
var AUTH_TIMEOUT2 = 3e4;
|
|
2117
2153
|
var DataSpace = class DataSpace2 {
|
|
2118
2154
|
constructor(params) {
|
|
2119
2155
|
this._ctx = new Context4();
|
|
@@ -2128,6 +2164,11 @@ var DataSpace = class DataSpace2 {
|
|
|
2128
2164
|
feedInfoProvider: (feedKey) => this._inner.spaceState.feeds.get(feedKey),
|
|
2129
2165
|
snapshotId: params.snapshotId
|
|
2130
2166
|
});
|
|
2167
|
+
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
2168
|
+
trustedKeysProvider: () => new ComplexSet(PublicKey5.hash, Array.from(this._inner.spaceState.members.keys())),
|
|
2169
|
+
update: this._inner.stateUpdate,
|
|
2170
|
+
authTimeout: AUTH_TIMEOUT2
|
|
2171
|
+
});
|
|
2131
2172
|
}
|
|
2132
2173
|
get key() {
|
|
2133
2174
|
return this._inner.key;
|
|
@@ -2157,6 +2198,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2157
2198
|
}
|
|
2158
2199
|
async close() {
|
|
2159
2200
|
await this._ctx.dispose();
|
|
2201
|
+
await this.authVerifier.close();
|
|
2160
2202
|
await this._inner.close();
|
|
2161
2203
|
await this._presence.destroy();
|
|
2162
2204
|
}
|
|
@@ -2187,7 +2229,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2187
2229
|
this._snapshotStore = _snapshotStore;
|
|
2188
2230
|
this._ctx = new Context5();
|
|
2189
2231
|
this.updated = new Event3();
|
|
2190
|
-
this._spaces = new ComplexMap2(
|
|
2232
|
+
this._spaces = new ComplexMap2(PublicKey6.hash);
|
|
2191
2233
|
}
|
|
2192
2234
|
// TODO(burdon): Remove.
|
|
2193
2235
|
get spaces() {
|
|
@@ -2199,7 +2241,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2199
2241
|
spaces: this._metadataStore.spaces.length
|
|
2200
2242
|
}, {
|
|
2201
2243
|
file: "data-space-manager.ts",
|
|
2202
|
-
line:
|
|
2244
|
+
line: 57,
|
|
2203
2245
|
scope: this,
|
|
2204
2246
|
callSite: (f, a) => f(...a)
|
|
2205
2247
|
});
|
|
@@ -2208,7 +2250,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2208
2250
|
spaceMetadata
|
|
2209
2251
|
}, {
|
|
2210
2252
|
file: "data-space-manager.ts",
|
|
2211
|
-
line:
|
|
2253
|
+
line: 60,
|
|
2212
2254
|
scope: this,
|
|
2213
2255
|
callSite: (f, a) => f(...a)
|
|
2214
2256
|
});
|
|
@@ -2218,7 +2260,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2218
2260
|
spaceMetadata
|
|
2219
2261
|
}, {
|
|
2220
2262
|
file: "data-space-manager.ts",
|
|
2221
|
-
line:
|
|
2263
|
+
line: 63,
|
|
2222
2264
|
scope: this,
|
|
2223
2265
|
callSite: (f, a) => f(...a)
|
|
2224
2266
|
});
|
|
@@ -2249,7 +2291,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2249
2291
|
spaceKey
|
|
2250
2292
|
}, {
|
|
2251
2293
|
file: "data-space-manager.ts",
|
|
2252
|
-
line:
|
|
2294
|
+
line: 92,
|
|
2253
2295
|
scope: this,
|
|
2254
2296
|
callSite: (f, a) => f(...a)
|
|
2255
2297
|
});
|
|
@@ -2261,6 +2303,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2261
2303
|
}
|
|
2262
2304
|
// TODO(burdon): Rename join space.
|
|
2263
2305
|
async acceptSpace(opts) {
|
|
2306
|
+
assert11(!this._spaces.has(opts.spaceKey), "Space already exists.");
|
|
2264
2307
|
const metadata = {
|
|
2265
2308
|
key: opts.spaceKey,
|
|
2266
2309
|
genesisFeedKey: opts.genesisFeedKey,
|
|
@@ -2284,8 +2327,8 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2284
2327
|
metadata,
|
|
2285
2328
|
swarmIdentity: {
|
|
2286
2329
|
peerKey: this._signingContext.deviceKey,
|
|
2287
|
-
credentialProvider: this._signingContext.
|
|
2288
|
-
credentialAuthenticator:
|
|
2330
|
+
credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
|
|
2331
|
+
credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
|
|
2289
2332
|
},
|
|
2290
2333
|
onNetworkConnection: (session) => {
|
|
2291
2334
|
session.addExtension("dxos.mesh.teleport.presence", presence.createExtension({
|
|
@@ -2356,7 +2399,7 @@ var ServiceContext = class {
|
|
|
2356
2399
|
async open() {
|
|
2357
2400
|
log10("opening...", {}, {
|
|
2358
2401
|
file: "service-context.ts",
|
|
2359
|
-
line:
|
|
2402
|
+
line: 83,
|
|
2360
2403
|
scope: this,
|
|
2361
2404
|
callSite: (f, a) => f(...a)
|
|
2362
2405
|
});
|
|
@@ -2368,7 +2411,7 @@ var ServiceContext = class {
|
|
|
2368
2411
|
}
|
|
2369
2412
|
log10("opened", {}, {
|
|
2370
2413
|
file: "service-context.ts",
|
|
2371
|
-
line:
|
|
2414
|
+
line: 90,
|
|
2372
2415
|
scope: this,
|
|
2373
2416
|
callSite: (f, a) => f(...a)
|
|
2374
2417
|
});
|
|
@@ -2377,7 +2420,7 @@ var ServiceContext = class {
|
|
|
2377
2420
|
var _a;
|
|
2378
2421
|
log10("closing...", {}, {
|
|
2379
2422
|
file: "service-context.ts",
|
|
2380
|
-
line:
|
|
2423
|
+
line: 94,
|
|
2381
2424
|
scope: this,
|
|
2382
2425
|
callSite: (f, a) => f(...a)
|
|
2383
2426
|
});
|
|
@@ -2389,7 +2432,7 @@ var ServiceContext = class {
|
|
|
2389
2432
|
this.dataServiceSubscriptions.clear();
|
|
2390
2433
|
log10("closed", {}, {
|
|
2391
2434
|
file: "service-context.ts",
|
|
2392
|
-
line:
|
|
2435
|
+
line: 101,
|
|
2393
2436
|
scope: this,
|
|
2394
2437
|
callSite: (f, a) => f(...a)
|
|
2395
2438
|
});
|
|
@@ -2397,7 +2440,7 @@ var ServiceContext = class {
|
|
|
2397
2440
|
async reset() {
|
|
2398
2441
|
log10("resetting...", {}, {
|
|
2399
2442
|
file: "service-context.ts",
|
|
2400
|
-
line:
|
|
2443
|
+
line: 105,
|
|
2401
2444
|
scope: this,
|
|
2402
2445
|
callSite: (f, a) => f(...a)
|
|
2403
2446
|
});
|
|
@@ -2405,7 +2448,7 @@ var ServiceContext = class {
|
|
|
2405
2448
|
await this.storage.reset();
|
|
2406
2449
|
log10("reset", {}, {
|
|
2407
2450
|
file: "service-context.ts",
|
|
2408
|
-
line:
|
|
2451
|
+
line: 108,
|
|
2409
2452
|
scope: this,
|
|
2410
2453
|
callSite: (f, a) => f(...a)
|
|
2411
2454
|
});
|
|
@@ -2420,14 +2463,12 @@ var ServiceContext = class {
|
|
|
2420
2463
|
var _a;
|
|
2421
2464
|
log10("initializing spaces...", {}, {
|
|
2422
2465
|
file: "service-context.ts",
|
|
2423
|
-
line:
|
|
2466
|
+
line: 120,
|
|
2424
2467
|
scope: this,
|
|
2425
2468
|
callSite: (f, a) => f(...a)
|
|
2426
2469
|
});
|
|
2427
2470
|
const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined2();
|
|
2428
2471
|
const signingContext = {
|
|
2429
|
-
credentialProvider: MOCK_AUTH_PROVIDER,
|
|
2430
|
-
credentialAuthenticator: MOCK_AUTH_VERIFIER,
|
|
2431
2472
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
2432
2473
|
identityKey: identity.identityKey,
|
|
2433
2474
|
deviceKey: identity.deviceKey,
|
|
@@ -2804,7 +2845,7 @@ import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager
|
|
|
2804
2845
|
import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manager";
|
|
2805
2846
|
|
|
2806
2847
|
// packages/sdk/client-services/src/packlets/vault/worker-session.ts
|
|
2807
|
-
import
|
|
2848
|
+
import assert12 from "@dxos/node-std/assert";
|
|
2808
2849
|
import { Trigger as Trigger5 } from "@dxos/async";
|
|
2809
2850
|
import { log as log12, logInfo } from "@dxos/log";
|
|
2810
2851
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
@@ -2825,8 +2866,8 @@ var WorkerSession = class {
|
|
|
2825
2866
|
} }) {
|
|
2826
2867
|
this._startTrigger = new Trigger5();
|
|
2827
2868
|
this.onClose = new Callback();
|
|
2828
|
-
|
|
2829
|
-
|
|
2869
|
+
assert12(options);
|
|
2870
|
+
assert12(getServices);
|
|
2830
2871
|
this._options = options;
|
|
2831
2872
|
this._getServices = getServices;
|
|
2832
2873
|
this._clientRpc = createProtoRpcPeer3({
|
|
@@ -3032,7 +3073,6 @@ export {
|
|
|
3032
3073
|
ClientServicesProxy,
|
|
3033
3074
|
DevtoolsHostEvents,
|
|
3034
3075
|
DevtoolsServiceImpl,
|
|
3035
|
-
HaloAuthVerifier,
|
|
3036
3076
|
HaloInvitationsHandler,
|
|
3037
3077
|
HaloInvitationsProxy,
|
|
3038
3078
|
HaloInvitationsServiceImpl,
|
|
@@ -3052,11 +3092,12 @@ export {
|
|
|
3052
3092
|
SpaceServiceImpl,
|
|
3053
3093
|
SystemServiceImpl,
|
|
3054
3094
|
TracingServiceImpl,
|
|
3095
|
+
TrustedKeySetAuthVerifier,
|
|
3055
3096
|
WorkerRuntime,
|
|
3056
3097
|
WorkerSession,
|
|
3057
3098
|
clientServiceBundle,
|
|
3099
|
+
createAuthProvider,
|
|
3058
3100
|
createDefaultModelFactory,
|
|
3059
|
-
createHaloAuthProvider,
|
|
3060
3101
|
createStorageObjects,
|
|
3061
3102
|
getNetworkPeers,
|
|
3062
3103
|
subscribeToFeedBlocks,
|