@dxos/client-services 0.1.0
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/LICENSE +21 -0
- package/README.md +20 -0
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +21 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/packlets/devtools/devtools-host-events.d.ts +5 -0
- package/dist/src/packlets/devtools/devtools-host-events.d.ts.map +1 -0
- package/dist/src/packlets/devtools/devtools-host-events.js +14 -0
- package/dist/src/packlets/devtools/devtools-host-events.js.map +1 -0
- package/dist/src/packlets/devtools/feeds.d.ts +11 -0
- package/dist/src/packlets/devtools/feeds.d.ts.map +1 -0
- package/dist/src/packlets/devtools/feeds.js +72 -0
- package/dist/src/packlets/devtools/feeds.js.map +1 -0
- package/dist/src/packlets/devtools/index.d.ts +5 -0
- package/dist/src/packlets/devtools/index.d.ts.map +1 -0
- package/dist/src/packlets/devtools/index.js +24 -0
- package/dist/src/packlets/devtools/index.js.map +1 -0
- package/dist/src/packlets/devtools/network.d.ts +19 -0
- package/dist/src/packlets/devtools/network.d.ts.map +1 -0
- package/dist/src/packlets/devtools/network.js +79 -0
- package/dist/src/packlets/devtools/network.js.map +1 -0
- package/dist/src/packlets/devtools/spaces.d.ts +5 -0
- package/dist/src/packlets/devtools/spaces.d.ts.map +1 -0
- package/dist/src/packlets/devtools/spaces.js +38 -0
- package/dist/src/packlets/devtools/spaces.js.map +1 -0
- package/dist/src/packlets/identity/authenticator.d.ts +7 -0
- package/dist/src/packlets/identity/authenticator.d.ts.map +1 -0
- package/dist/src/packlets/identity/authenticator.js +40 -0
- package/dist/src/packlets/identity/authenticator.js.map +1 -0
- package/dist/src/packlets/identity/authenticator.test.d.ts +2 -0
- package/dist/src/packlets/identity/authenticator.test.d.ts.map +1 -0
- package/dist/src/packlets/identity/authenticator.test.js +32 -0
- package/dist/src/packlets/identity/authenticator.test.js.map +1 -0
- package/dist/src/packlets/identity/identity-manager.d.ts +35 -0
- package/dist/src/packlets/identity/identity-manager.d.ts.map +1 -0
- package/dist/src/packlets/identity/identity-manager.js +151 -0
- package/dist/src/packlets/identity/identity-manager.js.map +1 -0
- package/dist/src/packlets/identity/identity-manager.test.d.ts +2 -0
- package/dist/src/packlets/identity/identity-manager.test.d.ts.map +1 -0
- package/dist/src/packlets/identity/identity-manager.test.js +92 -0
- package/dist/src/packlets/identity/identity-manager.test.js.map +1 -0
- package/dist/src/packlets/identity/identity.d.ts +43 -0
- package/dist/src/packlets/identity/identity.d.ts.map +1 -0
- package/dist/src/packlets/identity/identity.js +74 -0
- package/dist/src/packlets/identity/identity.js.map +1 -0
- package/dist/src/packlets/identity/identity.test.d.ts +2 -0
- package/dist/src/packlets/identity/identity.test.d.ts.map +1 -0
- package/dist/src/packlets/identity/identity.test.js +258 -0
- package/dist/src/packlets/identity/identity.test.js.map +1 -0
- package/dist/src/packlets/identity/index.d.ts +4 -0
- package/dist/src/packlets/identity/index.d.ts.map +1 -0
- package/dist/src/packlets/identity/index.js +23 -0
- package/dist/src/packlets/identity/index.js.map +1 -0
- package/dist/src/packlets/invitations/common.d.ts +35 -0
- package/dist/src/packlets/invitations/common.d.ts.map +1 -0
- package/dist/src/packlets/invitations/common.js +12 -0
- package/dist/src/packlets/invitations/common.js.map +1 -0
- package/dist/src/packlets/invitations/halo-invitations.d.ts +23 -0
- package/dist/src/packlets/invitations/halo-invitations.d.ts.map +1 -0
- package/dist/src/packlets/invitations/halo-invitations.js +150 -0
- package/dist/src/packlets/invitations/halo-invitations.js.map +1 -0
- package/dist/src/packlets/invitations/index.d.ts +5 -0
- package/dist/src/packlets/invitations/index.d.ts.map +1 -0
- package/dist/src/packlets/invitations/index.js +24 -0
- package/dist/src/packlets/invitations/index.js.map +1 -0
- package/dist/src/packlets/invitations/invitation-wrapper.d.ts +36 -0
- package/dist/src/packlets/invitations/invitation-wrapper.d.ts.map +1 -0
- package/dist/src/packlets/invitations/invitation-wrapper.js +104 -0
- package/dist/src/packlets/invitations/invitation-wrapper.js.map +1 -0
- package/dist/src/packlets/invitations/observable.test.d.ts +2 -0
- package/dist/src/packlets/invitations/observable.test.d.ts.map +1 -0
- package/dist/src/packlets/invitations/observable.test.js +43 -0
- package/dist/src/packlets/invitations/observable.test.js.map +1 -0
- package/dist/src/packlets/invitations/space-invitations.d.ts +25 -0
- package/dist/src/packlets/invitations/space-invitations.d.ts.map +1 -0
- package/dist/src/packlets/invitations/space-invitations.js +136 -0
- package/dist/src/packlets/invitations/space-invitations.js.map +1 -0
- package/dist/src/packlets/services/impl/devtools.d.ts +34 -0
- package/dist/src/packlets/services/impl/devtools.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/devtools.js +77 -0
- package/dist/src/packlets/services/impl/devtools.js.map +1 -0
- package/dist/src/packlets/services/impl/halo.d.ts +20 -0
- package/dist/src/packlets/services/impl/halo.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/halo.js +93 -0
- package/dist/src/packlets/services/impl/halo.js.map +1 -0
- package/dist/src/packlets/services/impl/index.d.ts +6 -0
- package/dist/src/packlets/services/impl/index.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/index.js +26 -0
- package/dist/src/packlets/services/impl/index.js.map +1 -0
- package/dist/src/packlets/services/impl/party.d.ts +25 -0
- package/dist/src/packlets/services/impl/party.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/party.js +265 -0
- package/dist/src/packlets/services/impl/party.js.map +1 -0
- package/dist/src/packlets/services/impl/profile.d.ts +19 -0
- package/dist/src/packlets/services/impl/profile.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/profile.js +120 -0
- package/dist/src/packlets/services/impl/profile.js.map +1 -0
- package/dist/src/packlets/services/impl/system.d.ts +9 -0
- package/dist/src/packlets/services/impl/system.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/system.js +20 -0
- package/dist/src/packlets/services/impl/system.js.map +1 -0
- package/dist/src/packlets/services/impl/tracing.d.ts +12 -0
- package/dist/src/packlets/services/impl/tracing.d.ts.map +1 -0
- package/dist/src/packlets/services/impl/tracing.js +22 -0
- package/dist/src/packlets/services/impl/tracing.js.map +1 -0
- package/dist/src/packlets/services/index.d.ts +6 -0
- package/dist/src/packlets/services/index.d.ts.map +1 -0
- package/dist/src/packlets/services/index.js +25 -0
- package/dist/src/packlets/services/index.js.map +1 -0
- package/dist/src/packlets/services/service-context.d.ts +36 -0
- package/dist/src/packlets/services/service-context.d.ts.map +1 -0
- package/dist/src/packlets/services/service-context.js +112 -0
- package/dist/src/packlets/services/service-context.js.map +1 -0
- package/dist/src/packlets/services/service-factory.d.ts +15 -0
- package/dist/src/packlets/services/service-factory.d.ts.map +1 -0
- package/dist/src/packlets/services/service-factory.js +25 -0
- package/dist/src/packlets/services/service-factory.js.map +1 -0
- package/dist/src/packlets/services/service-host.d.ts +27 -0
- package/dist/src/packlets/services/service-host.d.ts.map +1 -0
- package/dist/src/packlets/services/service-host.js +78 -0
- package/dist/src/packlets/services/service-host.js.map +1 -0
- package/dist/src/packlets/services/service-host.test.d.ts +2 -0
- package/dist/src/packlets/services/service-host.test.d.ts.map +1 -0
- package/dist/src/packlets/services/service-host.test.js +78 -0
- package/dist/src/packlets/services/service-host.test.js.map +1 -0
- package/dist/src/packlets/services/services.d.ts +19 -0
- package/dist/src/packlets/services/services.d.ts.map +1 -0
- package/dist/src/packlets/services/services.js +19 -0
- package/dist/src/packlets/services/services.js.map +1 -0
- package/dist/src/packlets/services/signer.d.ts +9 -0
- package/dist/src/packlets/services/signer.d.ts.map +1 -0
- package/dist/src/packlets/services/signer.js +6 -0
- package/dist/src/packlets/services/signer.js.map +1 -0
- package/dist/src/packlets/services/testing/halo.test.d.ts +2 -0
- package/dist/src/packlets/services/testing/halo.test.d.ts.map +1 -0
- package/dist/src/packlets/services/testing/halo.test.js +34 -0
- package/dist/src/packlets/services/testing/halo.test.js.map +1 -0
- package/dist/src/packlets/services/testing/spaces.test.d.ts +2 -0
- package/dist/src/packlets/services/testing/spaces.test.d.ts.map +1 -0
- package/dist/src/packlets/services/testing/spaces.test.js +68 -0
- package/dist/src/packlets/services/testing/spaces.test.js.map +1 -0
- package/dist/src/packlets/services/testing/testing.d.ts +8 -0
- package/dist/src/packlets/services/testing/testing.d.ts.map +1 -0
- package/dist/src/packlets/services/testing/testing.js +23 -0
- package/dist/src/packlets/services/testing/testing.js.map +1 -0
- package/dist/src/packlets/storage/index.d.ts +2 -0
- package/dist/src/packlets/storage/index.d.ts.map +1 -0
- package/dist/src/packlets/storage/index.js +21 -0
- package/dist/src/packlets/storage/index.js.map +1 -0
- package/dist/src/packlets/storage/storage.d.ts +7 -0
- package/dist/src/packlets/storage/storage.d.ts.map +1 -0
- package/dist/src/packlets/storage/storage.js +89 -0
- package/dist/src/packlets/storage/storage.js.map +1 -0
- package/package.json +61 -0
- package/src/errors.ts +19 -0
- package/src/index.ts +11 -0
- package/src/packlets/devtools/devtools-host-events.ts +8 -0
- package/src/packlets/devtools/feeds.ts +91 -0
- package/src/packlets/devtools/index.ts +8 -0
- package/src/packlets/devtools/network.ts +89 -0
- package/src/packlets/devtools/spaces.ts +50 -0
- package/src/packlets/identity/authenticator.test.ts +32 -0
- package/src/packlets/identity/authenticator.ts +49 -0
- package/src/packlets/identity/identity-manager.test.ts +121 -0
- package/src/packlets/identity/identity-manager.ts +207 -0
- package/src/packlets/identity/identity.test.ts +295 -0
- package/src/packlets/identity/identity.ts +109 -0
- package/src/packlets/identity/index.ts +7 -0
- package/src/packlets/invitations/common.ts +48 -0
- package/src/packlets/invitations/halo-invitations.ts +162 -0
- package/src/packlets/invitations/index.ts +8 -0
- package/src/packlets/invitations/invitation-wrapper.ts +140 -0
- package/src/packlets/invitations/observable.test.ts +67 -0
- package/src/packlets/invitations/space-invitations.ts +159 -0
- package/src/packlets/services/impl/devtools.ts +141 -0
- package/src/packlets/services/impl/halo.ts +107 -0
- package/src/packlets/services/impl/index.ts +11 -0
- package/src/packlets/services/impl/party.ts +305 -0
- package/src/packlets/services/impl/profile.ts +141 -0
- package/src/packlets/services/impl/system.ts +19 -0
- package/src/packlets/services/impl/tracing.ts +21 -0
- package/src/packlets/services/index.ts +9 -0
- package/src/packlets/services/service-context.ts +151 -0
- package/src/packlets/services/service-factory.ts +35 -0
- package/src/packlets/services/service-host.test.ts +88 -0
- package/src/packlets/services/service-host.ts +101 -0
- package/src/packlets/services/services.ts +39 -0
- package/src/packlets/services/signer.ts +13 -0
- package/src/packlets/services/testing/halo.test.ts +40 -0
- package/src/packlets/services/testing/spaces.test.ts +87 -0
- package/src/packlets/services/testing/testing.ts +28 -0
- package/src/packlets/storage/index.ts +5 -0
- package/src/packlets/storage/storage.ts +97 -0
- package/src/typings.d.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../../src/packlets/services/testing/testing.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,+CAAkF;AAClF,uDAAmD;AACnD,2DAA+E;AAC/E,qDAAiD;AACjD,uEAAkF;AAElF,wDAAoD;AAEpD,qCAAqC;AAC9B,MAAM,oBAAoB,GAAG,KAAK,EAAE,EACzC,aAAa,GAAG,IAAI,sCAA0B,EAAE,EAChD,OAAO,GAAG,IAAA,qCAAa,EAAC,EAAE,IAAI,EAAE,mCAAW,CAAC,GAAG,EAAE,CAAC,KAIhD,EAAE,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,IAAI,gCAAc,CAAC;QACxC,aAAa,EAAE,IAAI,+BAAmB,CAAC,aAAa,CAAC;QACrD,gBAAgB,EAAE,wCAAsB;KACzC,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAI,4BAAY,EAAE,CAAC,aAAa,CAAC,0BAAW,CAAC,CAAC;IACnE,OAAO,IAAI,gCAAc,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;AACnE,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/packlets/storage/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./storage"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/packlets/storage/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,4CAA0B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
2
|
+
export declare type KeyStorageType = 'ram' | 'leveljs' | 'jsondown';
|
|
3
|
+
export declare const createStorageObjects: (config: Runtime.Client.Storage) => {
|
|
4
|
+
storage: import("@dxos/random-access-storage").Storage;
|
|
5
|
+
keyStorage: any;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../../src/packlets/storage/storage.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAO5D,oBAAY,cAAc,GAAG,KAAK,GAAG,SAAS,GAAG,UAAU,CAAC;AAG5D,eAAO,MAAM,oBAAoB,WAAY,QAAQ,MAAM,QAAQ;;;CA4BlE,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2021 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createStorageObjects = void 0;
|
|
10
|
+
const jsondown_1 = __importDefault(require("jsondown"));
|
|
11
|
+
const level_js_1 = __importDefault(require("level-js"));
|
|
12
|
+
const memdown_1 = __importDefault(require("memdown"));
|
|
13
|
+
const config_1 = require("@dxos/protocols/proto/dxos/config");
|
|
14
|
+
const random_access_storage_1 = require("@dxos/random-access-storage");
|
|
15
|
+
const util_1 = require("@dxos/util");
|
|
16
|
+
var StorageDriver = config_1.Runtime.Client.Storage.StorageDriver;
|
|
17
|
+
const errors_1 = require("../../errors");
|
|
18
|
+
// TODO(burdon): Factor out.
|
|
19
|
+
const createStorageObjects = (config) => {
|
|
20
|
+
const { path = 'dxos/storage', // TODO(burdon): Factor out const.
|
|
21
|
+
storageType, keyStorage, persistent = false } = config !== null && config !== void 0 ? config : {};
|
|
22
|
+
if (persistent && storageType === StorageDriver.RAM) {
|
|
23
|
+
throw new errors_1.InvalidConfigurationError('RAM storage cannot be used in persistent mode.');
|
|
24
|
+
}
|
|
25
|
+
if (!persistent && storageType !== undefined && storageType !== StorageDriver.RAM) {
|
|
26
|
+
throw new errors_1.InvalidConfigurationError('Cannot use a persistent storage in not persistent mode.');
|
|
27
|
+
}
|
|
28
|
+
if (persistent && keyStorage === StorageDriver.RAM) {
|
|
29
|
+
throw new errors_1.InvalidConfigurationError('RAM key storage cannot be used in persistent mode.');
|
|
30
|
+
}
|
|
31
|
+
if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== undefined) {
|
|
32
|
+
throw new errors_1.InvalidConfigurationError('Cannot use a persistent key storage in not persistent mode.');
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
storage: (0, random_access_storage_1.createStorage)({
|
|
36
|
+
type: persistent ? toStorageType(storageType) : random_access_storage_1.StorageType.RAM,
|
|
37
|
+
root: `${path}/`
|
|
38
|
+
}),
|
|
39
|
+
keyStorage: createKeyStorage(`${path}/keystore`, persistent ? toKeyStorageType(keyStorage) : 'ram')
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.createStorageObjects = createStorageObjects;
|
|
43
|
+
// TODO(burdon): Factor out.
|
|
44
|
+
const createKeyStorage = (path, type) => {
|
|
45
|
+
const defaultedType = type !== null && type !== void 0 ? type : ((0, util_1.isNode)() ? 'jsondown' : 'leveljs');
|
|
46
|
+
switch (defaultedType) {
|
|
47
|
+
case 'leveljs':
|
|
48
|
+
return (0, level_js_1.default)(path);
|
|
49
|
+
case 'jsondown':
|
|
50
|
+
return (0, jsondown_1.default)(path);
|
|
51
|
+
case 'ram':
|
|
52
|
+
return (0, memdown_1.default)();
|
|
53
|
+
default:
|
|
54
|
+
throw new errors_1.InvalidConfigurationError(`Invalid key storage type: ${defaultedType}`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const toStorageType = (type) => {
|
|
58
|
+
switch (type) {
|
|
59
|
+
case undefined:
|
|
60
|
+
return undefined;
|
|
61
|
+
case StorageDriver.RAM:
|
|
62
|
+
return random_access_storage_1.StorageType.RAM;
|
|
63
|
+
case StorageDriver.CHROME:
|
|
64
|
+
return random_access_storage_1.StorageType.CHROME;
|
|
65
|
+
case StorageDriver.FIREFOX:
|
|
66
|
+
return random_access_storage_1.StorageType.FIREFOX;
|
|
67
|
+
case StorageDriver.IDB:
|
|
68
|
+
return random_access_storage_1.StorageType.IDB;
|
|
69
|
+
case StorageDriver.NODE:
|
|
70
|
+
return random_access_storage_1.StorageType.NODE;
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const toKeyStorageType = (type) => {
|
|
76
|
+
switch (type) {
|
|
77
|
+
case undefined:
|
|
78
|
+
return undefined;
|
|
79
|
+
case StorageDriver.RAM:
|
|
80
|
+
return 'ram';
|
|
81
|
+
case StorageDriver.LEVELJS:
|
|
82
|
+
return 'leveljs';
|
|
83
|
+
case StorageDriver.JSONDOWN:
|
|
84
|
+
return 'jsondown';
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(`Invalid key storage type: ${StorageDriver[type]}`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../../src/packlets/storage/storage.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/client-services",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"homepage": "https://dxos.org",
|
|
5
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "DXOS.org",
|
|
8
|
+
"main": "dist/src/index.js",
|
|
9
|
+
"browser": {
|
|
10
|
+
"node:assert": "assert"
|
|
11
|
+
},
|
|
12
|
+
"types": "dist/src/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@dxos/async": "0.1.0",
|
|
19
|
+
"@dxos/codec-protobuf": "0.1.0",
|
|
20
|
+
"@dxos/config": "0.1.0",
|
|
21
|
+
"@dxos/credentials": "0.1.0",
|
|
22
|
+
"@dxos/crypto": "0.1.0",
|
|
23
|
+
"@dxos/debug": "0.1.0",
|
|
24
|
+
"@dxos/echo-db": "0.1.0",
|
|
25
|
+
"@dxos/feed-store": "0.1.0",
|
|
26
|
+
"@dxos/keyring": "0.1.0",
|
|
27
|
+
"@dxos/keys": "0.1.0",
|
|
28
|
+
"@dxos/log": "0.1.0",
|
|
29
|
+
"@dxos/messaging": "0.1.0",
|
|
30
|
+
"@dxos/model-factory": "0.1.0",
|
|
31
|
+
"@dxos/network-manager": "0.1.0",
|
|
32
|
+
"@dxos/object-model": "0.1.0",
|
|
33
|
+
"@dxos/protocol-plugin-rpc": "0.1.0",
|
|
34
|
+
"@dxos/protocols": "0.1.0",
|
|
35
|
+
"@dxos/random-access-storage": "0.1.0",
|
|
36
|
+
"@dxos/rpc": "0.1.0",
|
|
37
|
+
"@dxos/testutils": "0.1.0",
|
|
38
|
+
"@dxos/timeframe": "0.1.0",
|
|
39
|
+
"@dxos/util": "0.1.0",
|
|
40
|
+
"abstract-leveldown": "~7.0.0",
|
|
41
|
+
"assert": "^2.0.0",
|
|
42
|
+
"base-x": "~3.0.9",
|
|
43
|
+
"json-stable-stringify": "^1.0.1",
|
|
44
|
+
"jsondown": "dxos/jsondown#main",
|
|
45
|
+
"level-js": "^5.0.2",
|
|
46
|
+
"memdown": "^5.1.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@dxos/signal": "0.1.0",
|
|
50
|
+
"@types/json-stable-stringify": "^1.0.32",
|
|
51
|
+
"@types/level-js": "~4.0.1",
|
|
52
|
+
"@types/memdown": "^3.0.0",
|
|
53
|
+
"@types/readable-stream": "^2.3.9"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"check": "true"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2021 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { DXOSError } from '@dxos/debug';
|
|
6
|
+
|
|
7
|
+
// TODO(burdon): Consolidate with @dxos/echo-db.
|
|
8
|
+
|
|
9
|
+
export class InvalidConfigurationError extends DXOSError {
|
|
10
|
+
constructor(message: string) {
|
|
11
|
+
super('INVALID_CONFIGURATION', message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class RemoteServiceConnectionTimeout extends DXOSError {
|
|
16
|
+
constructor(message?: string) {
|
|
17
|
+
super('REMOTE_SERVICE_CONNECTION_TIMEOUT', message);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export * from './packlets/devtools';
|
|
6
|
+
export * from './packlets/identity';
|
|
7
|
+
export * from './packlets/invitations';
|
|
8
|
+
export * from './packlets/services';
|
|
9
|
+
export * from './packlets/storage';
|
|
10
|
+
|
|
11
|
+
export * from './errors';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2021 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { EventSubscriptions } from '@dxos/async';
|
|
6
|
+
import { Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { FeedIterator, FeedStore, FeedWrapper } from '@dxos/feed-store';
|
|
8
|
+
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
import {
|
|
10
|
+
SubscribeToFeedsRequest,
|
|
11
|
+
SubscribeToFeedsResponse,
|
|
12
|
+
SubscribeToFeedBlocksRequest,
|
|
13
|
+
SubscribeToFeedBlocksResponse
|
|
14
|
+
} from '@dxos/protocols/proto/dxos/devtools/host';
|
|
15
|
+
import { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
16
|
+
import { ComplexMap } from '@dxos/util';
|
|
17
|
+
|
|
18
|
+
export const subscribeToFeeds = (
|
|
19
|
+
{ feedStore }: { feedStore: FeedStore<FeedMessage> },
|
|
20
|
+
{ feedKeys }: SubscribeToFeedsRequest
|
|
21
|
+
) =>
|
|
22
|
+
new Stream<SubscribeToFeedsResponse>(({ next }) => {
|
|
23
|
+
if (feedKeys?.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const feedMap = new ComplexMap<PublicKey, FeedWrapper<FeedMessage>>(PublicKey.hash);
|
|
28
|
+
const subscriptions = new EventSubscriptions();
|
|
29
|
+
|
|
30
|
+
const update = async () => {
|
|
31
|
+
const feeds = await feedStore.feeds;
|
|
32
|
+
feeds
|
|
33
|
+
.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key)))
|
|
34
|
+
.forEach((feed) => {
|
|
35
|
+
if (!feedMap.has(feed.key)) {
|
|
36
|
+
feedMap.set(feed.key, feed);
|
|
37
|
+
feed.on('close', update); // TODO(mykola): Unsubscribe.
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
next({
|
|
41
|
+
feeds: Array.from(feedMap.values()).map((feed) => ({ feedKey: feed.key, length: feed.properties.length }))
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
setImmediate(async () => {
|
|
46
|
+
subscriptions.add(feedStore.feedOpened.on(update));
|
|
47
|
+
await update();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return () => {
|
|
51
|
+
subscriptions.clear();
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const subscribeToFeedBlocks = (
|
|
56
|
+
{ feedStore }: { feedStore: FeedStore<FeedMessage> },
|
|
57
|
+
{ feedKey, maxBlocks = 10 }: SubscribeToFeedBlocksRequest
|
|
58
|
+
) =>
|
|
59
|
+
new Stream<SubscribeToFeedBlocksResponse>(({ next }) => {
|
|
60
|
+
if (!feedKey) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const update = async (feed: FeedWrapper<FeedMessage>) => {
|
|
65
|
+
const iterator = new FeedIterator(feed);
|
|
66
|
+
await iterator.open();
|
|
67
|
+
const blocks = [];
|
|
68
|
+
for await (const block of iterator) {
|
|
69
|
+
blocks.push(block);
|
|
70
|
+
if (blocks.length >= feed.properties.length) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
next({
|
|
75
|
+
blocks: blocks.slice(-maxBlocks)
|
|
76
|
+
});
|
|
77
|
+
await iterator.close();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
setImmediate(async () => {
|
|
81
|
+
const feed = await feedStore.getFeed(feedKey);
|
|
82
|
+
if (!feed) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
feed.on('append', () => update(feed)); // TODO(mykola): Unsubscribe.
|
|
86
|
+
feed.on('truncate', () => update(feed)); // TODO(mykola): Unsubscribe.
|
|
87
|
+
await update(feed);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return () => {};
|
|
91
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Stream } from '@dxos/codec-protobuf';
|
|
6
|
+
import { PublicKey } from '@dxos/keys';
|
|
7
|
+
import { CommandTrace } from '@dxos/messaging';
|
|
8
|
+
import { NetworkManager } from '@dxos/network-manager';
|
|
9
|
+
import {
|
|
10
|
+
GetNetworkPeersRequest,
|
|
11
|
+
GetNetworkPeersResponse,
|
|
12
|
+
SubscribeToNetworkTopicsResponse,
|
|
13
|
+
SubscribeToSignalStatusResponse,
|
|
14
|
+
SubscribeToSignalTraceResponse,
|
|
15
|
+
SubscribeToSwarmInfoResponse
|
|
16
|
+
} from '@dxos/protocols/proto/dxos/devtools/host';
|
|
17
|
+
|
|
18
|
+
export const subscribeToNetworkStatus = ({ networkManager }: { networkManager: NetworkManager }) =>
|
|
19
|
+
new Stream<SubscribeToSignalStatusResponse>(({ next, close }) => {
|
|
20
|
+
const update = () => {
|
|
21
|
+
try {
|
|
22
|
+
const status = networkManager.signal.getStatus();
|
|
23
|
+
next({ servers: status });
|
|
24
|
+
} catch (err: any) {
|
|
25
|
+
close(err);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
networkManager.signal.statusChanged.on(update);
|
|
30
|
+
update();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const subscribeToSignalTrace = ({ networkManager }: { networkManager: NetworkManager }) =>
|
|
34
|
+
new Stream<SubscribeToSignalTraceResponse>(({ next }) => {
|
|
35
|
+
next({ events: [] });
|
|
36
|
+
const trace: CommandTrace[] = [];
|
|
37
|
+
networkManager.signal.commandTrace.on((msg) => {
|
|
38
|
+
trace.push(msg);
|
|
39
|
+
next({ events: trace.map((msg) => JSON.stringify(msg)) });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const subscribeToNetworkTopics = ({ networkManager }: { networkManager: NetworkManager }) =>
|
|
44
|
+
new Stream<SubscribeToNetworkTopicsResponse>(({ next, close }) => {
|
|
45
|
+
const update = () => {
|
|
46
|
+
try {
|
|
47
|
+
const topics = networkManager.topics;
|
|
48
|
+
const labeledTopics = topics.map((topic) => ({
|
|
49
|
+
topic,
|
|
50
|
+
label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
|
|
51
|
+
}));
|
|
52
|
+
next({ topics: labeledTopics });
|
|
53
|
+
} catch (err: any) {
|
|
54
|
+
close(err);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
networkManager.topicsUpdated.on(update);
|
|
58
|
+
|
|
59
|
+
update();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const subscribeToSwarmInfo = ({ networkManager }: { networkManager: NetworkManager }) =>
|
|
63
|
+
new Stream<SubscribeToSwarmInfoResponse>(({ next }) => {
|
|
64
|
+
const update = () => {
|
|
65
|
+
const info = networkManager.connectionLog?.swarms;
|
|
66
|
+
if (info) {
|
|
67
|
+
next({ data: info });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
networkManager.connectionLog?.update.on(update);
|
|
71
|
+
update();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const getNetworkPeers = (
|
|
75
|
+
{ networkManager }: { networkManager: NetworkManager },
|
|
76
|
+
request: GetNetworkPeersRequest
|
|
77
|
+
): GetNetworkPeersResponse => {
|
|
78
|
+
if (!request.topic) {
|
|
79
|
+
throw new Error('Expected a network topic');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const map = networkManager.getSwarmMap(PublicKey.from(request.topic));
|
|
83
|
+
return {
|
|
84
|
+
peers: map?.peers.map((peer) => ({
|
|
85
|
+
...peer,
|
|
86
|
+
connections: peer.connections.map((connection) => connection.asUint8Array())
|
|
87
|
+
}))
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Stream } from '@dxos/codec-protobuf';
|
|
6
|
+
import { Space } from '@dxos/echo-db';
|
|
7
|
+
import { SubscribeToPartiesRequest, SubscribeToPartiesResponse } from '@dxos/protocols/proto/dxos/devtools/host';
|
|
8
|
+
import { PartyMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
9
|
+
|
|
10
|
+
import { ServiceContext } from '../services';
|
|
11
|
+
|
|
12
|
+
export const subscribeToSpaces = (context: ServiceContext, { partyKeys = [] }: SubscribeToPartiesRequest) =>
|
|
13
|
+
new Stream<SubscribeToPartiesResponse>(({ next }) => {
|
|
14
|
+
let unsubscribe: () => void;
|
|
15
|
+
|
|
16
|
+
const update = async () => {
|
|
17
|
+
const parties: Space[] = [...context.spaceManager!.spaces.values()];
|
|
18
|
+
const filteredParties = parties.filter(
|
|
19
|
+
(party) => !partyKeys?.length || partyKeys.some((partyKey) => partyKey.equals(party.key))
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
next({
|
|
23
|
+
parties: filteredParties.map((party) => {
|
|
24
|
+
const partyMetadata = context.metadataStore.parties.find((partyMetadata: PartyMetadata) =>
|
|
25
|
+
partyMetadata.key.equals(party.key)
|
|
26
|
+
);
|
|
27
|
+
return {
|
|
28
|
+
key: party.key,
|
|
29
|
+
isOpen: party.isOpen,
|
|
30
|
+
timeframe: partyMetadata!.latestTimeframe!,
|
|
31
|
+
genesisFeed: party.genesisFeedKey,
|
|
32
|
+
controlFeed: party.controlFeedKey,
|
|
33
|
+
dataFeed: party.dataFeedKey
|
|
34
|
+
};
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
setImmediate(async () => {
|
|
40
|
+
await context.initialized.wait();
|
|
41
|
+
unsubscribe = context.spaceManager!.update.on(() => update());
|
|
42
|
+
|
|
43
|
+
// Send initial parties.
|
|
44
|
+
await update();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
unsubscribe?.();
|
|
49
|
+
};
|
|
50
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import assert from 'assert';
|
|
6
|
+
import expect from 'expect';
|
|
7
|
+
|
|
8
|
+
import { createCredentialSignerWithKey } from '@dxos/credentials';
|
|
9
|
+
import { Keyring } from '@dxos/keyring';
|
|
10
|
+
import { PublicKey } from '@dxos/keys';
|
|
11
|
+
import { ComplexSet } from '@dxos/util';
|
|
12
|
+
|
|
13
|
+
import { createHaloAuthProvider, createHaloAuthVerifier } from './authenticator';
|
|
14
|
+
|
|
15
|
+
describe('identity/authenticator', function () {
|
|
16
|
+
it('verifies credentials', async function () {
|
|
17
|
+
if (mochaExecutor.environment !== 'nodejs') {
|
|
18
|
+
this.skip();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const keyring = new Keyring();
|
|
22
|
+
const deviceKey = await keyring.createKey();
|
|
23
|
+
const signer = createCredentialSignerWithKey(keyring, deviceKey);
|
|
24
|
+
const authProvider = createHaloAuthProvider(signer);
|
|
25
|
+
const authVerifier = createHaloAuthVerifier(() => new ComplexSet(PublicKey.hash, [deviceKey]));
|
|
26
|
+
|
|
27
|
+
const nonce = new Uint8Array([2, 1, 3, 7]);
|
|
28
|
+
const credential = await authProvider(nonce);
|
|
29
|
+
assert(credential);
|
|
30
|
+
expect(await authVerifier(nonce, credential)).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { verifyCredential, CredentialSigner } from '@dxos/credentials';
|
|
6
|
+
import { AuthProvider, AuthVerifier } from '@dxos/echo-db';
|
|
7
|
+
import { PublicKey } from '@dxos/keys';
|
|
8
|
+
import { log } from '@dxos/log';
|
|
9
|
+
import { schema } from '@dxos/protocols';
|
|
10
|
+
import { ComplexSet } from '@dxos/util';
|
|
11
|
+
|
|
12
|
+
export const createHaloAuthProvider =
|
|
13
|
+
(signer: CredentialSigner): AuthProvider =>
|
|
14
|
+
async (nonce) => {
|
|
15
|
+
const credential = await signer.createCredential({
|
|
16
|
+
assertion: {
|
|
17
|
+
'@type': 'dxos.halo.credentials.Auth'
|
|
18
|
+
},
|
|
19
|
+
subject: signer.getIssuer(),
|
|
20
|
+
nonce
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return schema.getCodecForType('dxos.halo.credentials.Credential').encode(credential);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const createHaloAuthVerifier =
|
|
27
|
+
(getDeviceSet: () => ComplexSet<PublicKey>): AuthVerifier =>
|
|
28
|
+
async (nonce, auth) => {
|
|
29
|
+
const credential = schema.getCodecForType('dxos.halo.credentials.Credential').decode(auth);
|
|
30
|
+
const deviceSet = getDeviceSet();
|
|
31
|
+
|
|
32
|
+
const result = await verifyCredential(credential);
|
|
33
|
+
if (result.kind === 'fail') {
|
|
34
|
+
log('Invalid credential', { result });
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
|
|
39
|
+
log('Invalid nonce', { nonce, credential });
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!deviceSet.has(credential.issuer)) {
|
|
44
|
+
log('Device not in allowed set');
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return true;
|
|
49
|
+
};
|