@dxos/client 2.24.1-dev.656a99d5 → 2.25.1-dev.bf49bd36

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.
Files changed (35) hide show
  1. package/dist/src/api/halo-proxy.d.ts +4 -1
  2. package/dist/src/api/halo-proxy.d.ts.map +1 -1
  3. package/dist/src/api/halo-proxy.js +7 -1
  4. package/dist/src/api/halo-proxy.js.map +1 -1
  5. package/dist/src/client/service-host/services/halo.d.ts +14 -0
  6. package/dist/src/client/service-host/services/halo.d.ts.map +1 -0
  7. package/dist/src/client/service-host/services/halo.js +69 -0
  8. package/dist/src/client/service-host/services/halo.js.map +1 -0
  9. package/dist/src/client/service-host/services/profile.d.ts +1 -2
  10. package/dist/src/client/service-host/services/profile.d.ts.map +1 -1
  11. package/dist/src/client/service-host/services/profile.js +0 -19
  12. package/dist/src/client/service-host/services/profile.js.map +1 -1
  13. package/dist/src/client/service-host/services/services.d.ts.map +1 -1
  14. package/dist/src/client/service-host/services/services.js +2 -0
  15. package/dist/src/client/service-host/services/services.js.map +1 -1
  16. package/dist/src/interfaces/client-service-provider.d.ts +2 -1
  17. package/dist/src/interfaces/client-service-provider.d.ts.map +1 -1
  18. package/dist/src/interfaces/client-service-provider.js +1 -0
  19. package/dist/src/interfaces/client-service-provider.js.map +1 -1
  20. package/dist/src/proto/gen/dxos/client.d.ts +33 -15
  21. package/dist/src/proto/gen/dxos/client.d.ts.map +1 -1
  22. package/dist/src/proto/gen/dxos/client.js.map +1 -1
  23. package/dist/src/proto/gen/index.d.ts +4 -0
  24. package/dist/src/proto/gen/index.d.ts.map +1 -1
  25. package/dist/src/proto/gen/index.js +1 -1
  26. package/dist/src/proto/gen/index.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +22 -19
  29. package/src/api/halo-proxy.ts +11 -2
  30. package/src/client/service-host/services/halo.ts +75 -0
  31. package/src/client/service-host/services/profile.ts +1 -32
  32. package/src/client/service-host/services/services.ts +2 -0
  33. package/src/interfaces/client-service-provider.ts +3 -1
  34. package/src/proto/gen/dxos/client.ts +32 -15
  35. package/src/proto/gen/index.ts +5 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/client",
3
- "version": "2.24.1-dev.656a99d5",
3
+ "version": "2.25.1-dev.bf49bd36",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "DXOS.org",
6
6
  "main": "dist/src/index.js",
@@ -10,21 +10,24 @@
10
10
  "src"
11
11
  ],
12
12
  "dependencies": {
13
- "@dxos/async": "2.24.1-dev.656a99d5",
14
- "@dxos/codec-protobuf": "2.24.1-dev.656a99d5",
15
- "@dxos/config": "2.24.1-dev.656a99d5",
16
- "@dxos/credentials": "2.24.1-dev.656a99d5",
17
- "@dxos/crypto": "2.24.1-dev.656a99d5",
18
- "@dxos/debug": "2.24.1-dev.656a99d5",
19
- "@dxos/echo-db": "2.24.1-dev.656a99d5",
20
- "@dxos/echo-protocol": "2.24.1-dev.656a99d5",
21
- "@dxos/feed-store": "2.24.1-dev.656a99d5",
22
- "@dxos/model-factory": "2.24.1-dev.656a99d5",
23
- "@dxos/network-manager": "2.24.1-dev.656a99d5",
24
- "@dxos/object-model": "2.24.1-dev.656a99d5",
25
- "@dxos/proto": "2.24.1-dev.656a99d5",
26
- "@dxos/rpc": "2.24.1-dev.656a99d5",
27
- "@dxos/util": "2.24.1-dev.656a99d5",
13
+ "@dxos/async": "2.25.1-dev.bf49bd36",
14
+ "@dxos/codec-protobuf": "2.25.1-dev.bf49bd36",
15
+ "@dxos/config": "2.25.1-dev.bf49bd36",
16
+ "@dxos/credentials": "2.25.1-dev.bf49bd36",
17
+ "@dxos/crypto": "2.25.1-dev.bf49bd36",
18
+ "@dxos/debug": "2.25.1-dev.bf49bd36",
19
+ "@dxos/echo-db": "2.25.1-dev.bf49bd36",
20
+ "@dxos/echo-protocol": "2.25.1-dev.bf49bd36",
21
+ "@dxos/feed-store": "2.25.1-dev.bf49bd36",
22
+ "@dxos/model-factory": "2.25.1-dev.bf49bd36",
23
+ "@dxos/network-manager": "2.25.1-dev.bf49bd36",
24
+ "@dxos/object-model": "2.25.1-dev.bf49bd36",
25
+ "@dxos/proto": "2.25.1-dev.bf49bd36",
26
+ "@dxos/rpc": "2.25.1-dev.bf49bd36",
27
+ "@dxos/util": "2.25.1-dev.bf49bd36",
28
+ "@polkadot/keyring": "6.11.1",
29
+ "@polkadot/util": "6.11.1",
30
+ "@polkadot/util-crypto": "6.11.1",
28
31
  "@wirelineio/registry-client": "~1.1.0-beta.3",
29
32
  "abstract-leveldown": "~7.0.0",
30
33
  "assert": "^2.0.0",
@@ -38,9 +41,9 @@
38
41
  "uuid": "^8.3.2"
39
42
  },
40
43
  "devDependencies": {
41
- "@dxos/random-access-multi-storage": "2.24.1-dev.656a99d5",
42
- "@dxos/testutils": "2.24.0",
43
- "@dxos/toolchain-node-library": "2.24.0",
44
+ "@dxos/random-access-multi-storage": "2.25.1-dev.bf49bd36",
45
+ "@dxos/testutils": "2.25.0",
46
+ "@dxos/toolchain-node-library": "2.25.0",
44
47
  "@types/debug": "^4.1.7",
45
48
  "@types/expect": "~24.3.0",
46
49
  "@types/jest": "^26.0.7",
@@ -3,11 +3,12 @@
3
3
  //
4
4
 
5
5
  import { Event } from '@dxos/async';
6
+ import { KeyRecord } from '@dxos/credentials';
6
7
  import { Contact, CreateProfileOptions, InvitationDescriptor, InvitationOptions, PartyMember, ResultSet } from '@dxos/echo-db';
7
8
  import { SubscriptionGroup } from '@dxos/util';
8
9
 
9
10
  import { ClientServiceProvider } from '../interfaces';
10
- import { Profile } from '../proto/gen/dxos/client';
11
+ import { Profile, SignRequest } from '../proto/gen/dxos/client';
11
12
  import { Invitation, InvitationProxy, InvitationRequest } from './invitations';
12
13
 
13
14
  export interface CreateInvitationOptions extends InvitationOptions {
@@ -119,6 +120,14 @@ export class HaloProxy extends InvitationProxy {
119
120
  );
120
121
  }
121
122
 
123
+ async addKeyRecord (keyRecord: KeyRecord) {
124
+ await this._serviceProvider.services.HaloService.AddKeyRecord({ keyRecord });
125
+ }
126
+
127
+ async sign (request: SignRequest) {
128
+ return await this._serviceProvider.services.HaloService.Sign(request);
129
+ }
130
+
122
131
  /**
123
132
  * Allocate resources and set-up internal subscriptions.
124
133
  *
@@ -132,7 +141,7 @@ export class HaloProxy extends InvitationProxy {
132
141
  }, () => {});
133
142
  this._subscriptions.push(() => profileStream.close());
134
143
 
135
- const contactsStream = this._serviceProvider.services.ProfileService.SubscribeContacts();
144
+ const contactsStream = this._serviceProvider.services.HaloService.SubscribeContacts();
136
145
  contactsStream.subscribe(data => {
137
146
  this._contacts = data.contacts as PartyMember[];
138
147
  this._contactsChanged.emit();
@@ -0,0 +1,75 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import PolkadotKeyring from '@polkadot/keyring';
6
+ import { hexToU8a, u8aToHex } from '@polkadot/util';
7
+ import { cryptoWaitReady } from '@polkadot/util-crypto';
8
+ import assert from 'assert';
9
+
10
+ import { Stream } from '@dxos/codec-protobuf';
11
+ import { KeyRecord, KeyType } from '@dxos/credentials';
12
+ import { ECHO } from '@dxos/echo-db';
13
+ import { SubscriptionGroup } from '@dxos/util';
14
+
15
+ import { AddKeyRecordRequest, Contacts, HaloService as IHaloService, SignRequest, SignResponse } from '../../../proto/gen/dxos/client';
16
+ import { resultSetToStream } from '../../../util';
17
+ import { CreateServicesOpts } from './interfaces';
18
+
19
+ export class HaloService implements IHaloService {
20
+ constructor (private echo: ECHO) {}
21
+
22
+ SubscribeContacts (): Stream<Contacts> {
23
+ if (this.echo.halo.isInitialized) {
24
+ return resultSetToStream(this.echo.halo.queryContacts(), (contacts): Contacts => ({ contacts }));
25
+ } else {
26
+ return new Stream(({ next }) => {
27
+ const subGroup = new SubscriptionGroup();
28
+
29
+ setImmediate(async () => {
30
+ await this.echo.halo.identityReady.waitForCondition(() => this.echo.halo.isInitialized);
31
+
32
+ const resultSet = this.echo.halo.queryContacts();
33
+ next({ contacts: resultSet.value });
34
+ subGroup.push(resultSet.update.on(() => next({ contacts: resultSet.value })));
35
+ });
36
+
37
+ return () => subGroup.unsubscribe();
38
+ });
39
+ }
40
+ }
41
+
42
+ async AddKeyRecord (request: AddKeyRecordRequest): Promise<void> {
43
+ assert(request.keyRecord && request.keyRecord.publicKey, 'Missing key record.');
44
+ await this.echo.halo.keyring.addKeyRecord(request.keyRecord);
45
+ assert(await this.echo.halo.keyring.getKey(request.keyRecord.publicKey), 'Key not inserted correctly.');
46
+ }
47
+
48
+ private async polkadotSign (key: KeyRecord, payload: SignRequest['payload']): Promise<SignResponse> {
49
+ await cryptoWaitReady();
50
+
51
+ assert(key.secretKey, 'Secret key is missing.');
52
+
53
+ const keyring = new PolkadotKeyring({ type: 'sr25519' });
54
+ const keypair = keyring.addFromUri(key.secretKey.toString());
55
+
56
+ const signature = u8aToHex(keypair.sign(hexToU8a(payload), { withType: true }));
57
+ return {
58
+ signed: signature
59
+ };
60
+ }
61
+
62
+ async Sign (request: SignRequest): Promise<SignResponse> {
63
+ assert(request.publicKey, 'Provide a publicKey of the key that should be used for signing.');
64
+ const key = await this.echo.halo.keyring.getFullKey(request.publicKey);
65
+ assert(key, 'Key not found.');
66
+ if (key.type === KeyType.DXNS) {
67
+ return this.polkadotSign(key, request.payload);
68
+ }
69
+ throw new Error('Only DXNS key signing is supported.');
70
+ }
71
+ }
72
+
73
+ export const createHaloService = ({ echo }: CreateServicesOpts): HaloService => {
74
+ return new HaloService(echo);
75
+ };
@@ -9,22 +9,11 @@ import { latch } from '@dxos/async';
9
9
  import { Stream } from '@dxos/codec-protobuf';
10
10
  import { defaultSecretValidator, generatePasscode, SecretProvider } from '@dxos/credentials';
11
11
  import { ECHO, InvitationDescriptor } from '@dxos/echo-db';
12
- import { SubscriptionGroup } from '@dxos/util';
13
12
 
14
13
  import {
15
- InvitationState,
16
- ProfileService as IProfileService,
17
- AuthenticateInvitationRequest,
18
- SubscribeProfileResponse,
19
- InvitationRequest,
20
- CreateProfileRequest,
21
- Contacts,
22
- RedeemedInvitation,
23
- Profile
24
- , RecoverProfileRequest
14
+ AuthenticateInvitationRequest, CreateProfileRequest, InvitationRequest, InvitationState, Profile, ProfileService as IProfileService, RecoverProfileRequest, RedeemedInvitation, SubscribeProfileResponse
25
15
  } from '../../../proto/gen/dxos/client';
26
16
  import { InvitationDescriptor as InvitationDescriptorProto } from '../../../proto/gen/dxos/echo/invitation';
27
- import { resultSetToStream } from '../../../util';
28
17
  import { CreateServicesOpts, InviteeInvitation, InviteeInvitations } from './interfaces';
29
18
 
30
19
  export class ProfileService implements IProfileService {
@@ -122,26 +111,6 @@ export class ProfileService implements IProfileService {
122
111
  invitation.secret = request.secret;
123
112
  invitation.secretTrigger?.();
124
113
  }
125
-
126
- SubscribeContacts (): Stream<Contacts> {
127
- if (this.echo.halo.isInitialized) {
128
- return resultSetToStream(this.echo.halo.queryContacts(), (contacts): Contacts => ({ contacts }));
129
- } else {
130
- return new Stream(({ next }) => {
131
- const subGroup = new SubscriptionGroup();
132
-
133
- setImmediate(async () => {
134
- await this.echo.halo.identityReady.waitForCondition(() => this.echo.halo.isInitialized);
135
-
136
- const resultSet = this.echo.halo.queryContacts();
137
- next({ contacts: resultSet.value });
138
- subGroup.push(resultSet.update.on(() => next({ contacts: resultSet.value })));
139
- });
140
-
141
- return () => subGroup.unsubscribe();
142
- });
143
- }
144
- }
145
114
  }
146
115
 
147
116
  export const createProfileService = ({ echo }: CreateServicesOpts): ProfileService => {
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { ClientServices } from '../../../interfaces';
6
+ import { createHaloService } from './halo';
6
7
  import { CreateServicesOpts } from './interfaces';
7
8
  import { createPartyService } from './party';
8
9
  import { createProfileService } from './profile';
@@ -12,6 +13,7 @@ export const createServices = (opts: CreateServicesOpts): Omit<ClientServices, '
12
13
  return {
13
14
  SystemService: createSystemService(opts),
14
15
  ProfileService: createProfileService(opts),
16
+ HaloService: createHaloService(opts),
15
17
  PartyService: createPartyService(opts),
16
18
  DataService: opts.echo.dataService,
17
19
  TracingService: {
@@ -7,13 +7,14 @@ import { DataService, schema as schemaProtocol } from '@dxos/echo-protocol';
7
7
  import { createServiceBundle } from '@dxos/rpc';
8
8
 
9
9
  import { schema } from '../proto/gen';
10
- import { PartyService, ProfileService, SystemService } from '../proto/gen/dxos/client';
10
+ import { PartyService, ProfileService, SystemService, HaloService } from '../proto/gen/dxos/client';
11
11
  import { DevtoolsHost, TracingService } from '../proto/gen/dxos/devtools';
12
12
 
13
13
  // TODO(burdon): Is there a way to mark TS (generics) so cast isn't required for result of stream?
14
14
  export interface ClientServices {
15
15
  SystemService: SystemService;
16
16
  ProfileService: ProfileService;
17
+ HaloService: HaloService;
17
18
  PartyService: PartyService;
18
19
  DataService: DataService;
19
20
  DevtoolsHost: DevtoolsHost;
@@ -24,6 +25,7 @@ export const clientServiceBundle = createServiceBundle<ClientServices>({
24
25
  SystemService: schema.getService('dxos.client.SystemService'),
25
26
  ProfileService: schema.getService('dxos.client.ProfileService'),
26
27
  PartyService: schema.getService('dxos.client.PartyService'),
28
+ HaloService: schema.getService('dxos.client.HaloService'),
27
29
  // DataService is provided and implemented internally in ECHO so we import it from there.
28
30
  DataService: schemaProtocol.getService('dxos.echo.service.DataService'),
29
31
  DevtoolsHost: schema.getService('dxos.devtools.DevtoolsHost'),
@@ -14,21 +14,6 @@ export interface SystemService {
14
14
  GetConfig: (request: void) => Promise<dxos_config.Config>;
15
15
  Reset: (request: void) => Promise<void>;
16
16
  }
17
- export interface Profile {
18
- publicKey: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
19
- username?: string;
20
- }
21
- export interface SubscribeProfileResponse {
22
- profile?: Profile;
23
- }
24
- export interface CreateProfileRequest {
25
- username?: string;
26
- publicKey?: Uint8Array;
27
- secretKey?: Uint8Array;
28
- }
29
- export interface RecoverProfileRequest {
30
- seedPhrase?: string;
31
- }
32
17
  export enum InvitationState {
33
18
  WAITING_FOR_CONNECTION = 1,
34
19
  CONNECTED = 2,
@@ -68,6 +53,21 @@ export interface AuthenticateInvitationRequest {
68
53
  processId?: string;
69
54
  secret?: Uint8Array;
70
55
  }
56
+ export interface Profile {
57
+ publicKey: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
58
+ username?: string;
59
+ }
60
+ export interface SubscribeProfileResponse {
61
+ profile?: Profile;
62
+ }
63
+ export interface CreateProfileRequest {
64
+ username?: string;
65
+ publicKey?: Uint8Array;
66
+ secretKey?: Uint8Array;
67
+ }
68
+ export interface RecoverProfileRequest {
69
+ seedPhrase?: string;
70
+ }
71
71
  export interface Contact {
72
72
  publicKey?: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
73
73
  displayName?: string;
@@ -82,7 +82,24 @@ export interface ProfileService {
82
82
  CreateInvitation: (request: void) => Stream<InvitationRequest>;
83
83
  AcceptInvitation: (request: dxos_echo_invitation.InvitationDescriptor) => Stream<RedeemedInvitation>;
84
84
  AuthenticateInvitation: (request: AuthenticateInvitationRequest) => Promise<void>;
85
+ }
86
+ export interface AddKeyRecordRequest {
87
+ keyRecord?: dxos_halo_keys.KeyRecord;
88
+ }
89
+ export interface SignRequest {
90
+ /**
91
+ * - The public key of the key that is supposed to be used for signing.
92
+ */
93
+ publicKey?: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
94
+ payload?: ReturnType<typeof substitutions["google.protobuf.Any"]["decode"]>;
95
+ }
96
+ export interface SignResponse {
97
+ signed?: ReturnType<typeof substitutions["google.protobuf.Any"]["decode"]>;
98
+ }
99
+ export interface HaloService {
85
100
  SubscribeContacts: (request: void) => Stream<Contacts>;
101
+ AddKeyRecord: (request: AddKeyRecordRequest) => Promise<void>;
102
+ Sign: (request: SignRequest) => Promise<SignResponse>;
86
103
  }
87
104
  export interface Party {
88
105
  publicKey: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;