@dxos/client 2.27.9 → 2.27.10-dev.557f45a1
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/src/api/halo-proxy.d.ts +4 -0
- package/dist/src/api/halo-proxy.d.ts.map +1 -1
- package/dist/src/api/halo-proxy.js +12 -0
- package/dist/src/api/halo-proxy.js.map +1 -1
- package/dist/src/client/client.test.js +16 -0
- package/dist/src/client/client.test.js.map +1 -1
- package/dist/src/client/service-host/services/halo.d.ts +5 -1
- package/dist/src/client/service-host/services/halo.d.ts.map +1 -1
- package/dist/src/client/service-host/services/halo.js +38 -9
- package/dist/src/client/service-host/services/halo.js.map +1 -1
- package/dist/src/proto/gen/dxos/client.d.ts +16 -2
- package/dist/src/proto/gen/dxos/client.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/config.d.ts +5 -1
- package/dist/src/proto/gen/dxos/config.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/config.js.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.d.ts +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.js +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.js.map +1 -1
- package/dist/src/proto/gen/index.d.ts +3 -0
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/api/halo-proxy.ts +16 -0
- package/src/client/client.test.ts +21 -0
- package/src/client/service-host/services/halo.ts +47 -7
- package/src/proto/gen/dxos/client.ts +16 -2
- package/src/proto/gen/dxos/config.ts +5 -1
- package/src/proto/gen/dxos/halo/keys.ts +1 -1
- package/src/proto/gen/index.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/client",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.10-dev.557f45a1",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "DXOS.org",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
"src"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dxos/async": "2.27.
|
|
14
|
-
"@dxos/codec-protobuf": "2.27.
|
|
15
|
-
"@dxos/config": "2.27.
|
|
16
|
-
"@dxos/credentials": "2.27.
|
|
17
|
-
"@dxos/crypto": "2.27.
|
|
18
|
-
"@dxos/debug": "2.27.
|
|
19
|
-
"@dxos/echo-db": "2.27.
|
|
20
|
-
"@dxos/echo-protocol": "2.27.
|
|
21
|
-
"@dxos/feed-store": "2.27.
|
|
22
|
-
"@dxos/model-factory": "2.27.
|
|
23
|
-
"@dxos/network-manager": "2.27.
|
|
24
|
-
"@dxos/object-model": "2.27.
|
|
25
|
-
"@dxos/protocol": "2.27.
|
|
26
|
-
"@dxos/rpc": "2.27.
|
|
27
|
-
"@dxos/util": "2.27.
|
|
13
|
+
"@dxos/async": "2.27.10-dev.557f45a1",
|
|
14
|
+
"@dxos/codec-protobuf": "2.27.10-dev.557f45a1",
|
|
15
|
+
"@dxos/config": "2.27.10-dev.557f45a1",
|
|
16
|
+
"@dxos/credentials": "2.27.10-dev.557f45a1",
|
|
17
|
+
"@dxos/crypto": "2.27.10-dev.557f45a1",
|
|
18
|
+
"@dxos/debug": "2.27.10-dev.557f45a1",
|
|
19
|
+
"@dxos/echo-db": "2.27.10-dev.557f45a1",
|
|
20
|
+
"@dxos/echo-protocol": "2.27.10-dev.557f45a1",
|
|
21
|
+
"@dxos/feed-store": "2.27.10-dev.557f45a1",
|
|
22
|
+
"@dxos/model-factory": "2.27.10-dev.557f45a1",
|
|
23
|
+
"@dxos/network-manager": "2.27.10-dev.557f45a1",
|
|
24
|
+
"@dxos/object-model": "2.27.10-dev.557f45a1",
|
|
25
|
+
"@dxos/protocol": "2.27.10-dev.557f45a1",
|
|
26
|
+
"@dxos/rpc": "2.27.10-dev.557f45a1",
|
|
27
|
+
"@dxos/util": "2.27.10-dev.557f45a1",
|
|
28
28
|
"@polkadot/keyring": "6.11.1",
|
|
29
29
|
"@polkadot/util": "6.11.1",
|
|
30
30
|
"@polkadot/util-crypto": "6.11.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"uuid": "^8.3.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@dxos/random-access-multi-storage": "2.27.
|
|
44
|
+
"@dxos/random-access-multi-storage": "2.27.10-dev.557f45a1",
|
|
45
45
|
"@dxos/testutils": "2.27.9",
|
|
46
46
|
"@dxos/toolchain-node-library": "2.27.9",
|
|
47
47
|
"@types/debug": "^4.1.7",
|
package/src/api/halo-proxy.ts
CHANGED
|
@@ -128,6 +128,22 @@ export class HaloProxy extends InvitationProxy {
|
|
|
128
128
|
return await this._serviceProvider.services.HaloService.sign(request);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
async setGlobalPreference (key: string, value: string): Promise<void> {
|
|
132
|
+
await this._serviceProvider.services.HaloService.setGlobalPreference({ key, value });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async getGlobalPreference (key: string): Promise<string | undefined> {
|
|
136
|
+
return (await this._serviceProvider.services.HaloService.getGlobalPreference({ key })).value;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async setDevicePreference (key: string, value: string): Promise<void> {
|
|
140
|
+
await this._serviceProvider.services.HaloService.setDevicePreference({ key, value });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async getDevicePreference (key: string): Promise<string | undefined> {
|
|
144
|
+
return (await this._serviceProvider.services.HaloService.getDevicePreference({ key })).value;
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
/**
|
|
132
148
|
* Allocate resources and set-up internal subscriptions.
|
|
133
149
|
*
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
import expect from 'expect';
|
|
7
7
|
import { it as test } from 'mocha';
|
|
8
|
+
import waitForExpect from 'wait-for-expect';
|
|
8
9
|
|
|
9
10
|
import { sleep, waitForCondition } from '@dxos/async';
|
|
10
11
|
import { ConfigObject } from '@dxos/config';
|
|
@@ -201,6 +202,26 @@ describe('Client', () => {
|
|
|
201
202
|
|
|
202
203
|
expect(invitee.halo.profile).not.toBeUndefined();
|
|
203
204
|
}).timeout(5000);
|
|
205
|
+
|
|
206
|
+
test('DXNS Account is synced between devices', async () => {
|
|
207
|
+
const { inviter, invitee } = await prepareInvitations();
|
|
208
|
+
|
|
209
|
+
const DXNSAccount = 'd3abd23e3f36a61a9e5d58e4b6286f89649594eedbd096b3a6e256ca1fe4c147';
|
|
210
|
+
await inviter.halo.setGlobalPreference('DXNSAccount', DXNSAccount);
|
|
211
|
+
|
|
212
|
+
const invitation = await inviter.halo.createInvitation();
|
|
213
|
+
await invitee.halo.acceptInvitation(invitation.descriptor).wait();
|
|
214
|
+
|
|
215
|
+
await waitForExpect(async () => {
|
|
216
|
+
expect(await invitee.halo.getGlobalPreference('DXNSAccount')).toEqual(DXNSAccount);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// The preference can be changed and synced back.
|
|
220
|
+
await invitee.halo.setGlobalPreference('DXNSAccount', '123');
|
|
221
|
+
await waitForExpect(async () => {
|
|
222
|
+
expect(await inviter.halo.getGlobalPreference('DXNSAccount')).toEqual('123');
|
|
223
|
+
}, 10_000, 100);
|
|
224
|
+
}).timeout(10_000);
|
|
204
225
|
});
|
|
205
226
|
|
|
206
227
|
describe('data', () => {
|
|
@@ -3,16 +3,26 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import PolkadotKeyring from '@polkadot/keyring';
|
|
6
|
-
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
7
6
|
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
|
8
7
|
import assert from 'assert';
|
|
9
8
|
|
|
10
9
|
import { Stream } from '@dxos/codec-protobuf';
|
|
11
10
|
import { KeyRecord, KeyType } from '@dxos/credentials';
|
|
12
11
|
import { ECHO } from '@dxos/echo-db';
|
|
12
|
+
import { ObjectModel } from '@dxos/object-model';
|
|
13
13
|
import { SubscriptionGroup } from '@dxos/util';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
AddKeyRecordRequest,
|
|
17
|
+
Contacts,
|
|
18
|
+
HaloService as IHaloService,
|
|
19
|
+
SignRequest,
|
|
20
|
+
SignResponse,
|
|
21
|
+
SetPreferenceRequest,
|
|
22
|
+
GetPreferenceRequest,
|
|
23
|
+
GetPreferenceResponse
|
|
24
|
+
|
|
25
|
+
} from '../../../proto/gen/dxos/client';
|
|
16
26
|
import { resultSetToStream } from '../../../util';
|
|
17
27
|
import { CreateServicesOpts } from './interfaces';
|
|
18
28
|
|
|
@@ -50,7 +60,7 @@ export class HaloService implements IHaloService {
|
|
|
50
60
|
assert(await this.echo.halo.keyring.getKey(request.keyRecord.publicKey), 'Key not inserted correctly.');
|
|
51
61
|
}
|
|
52
62
|
|
|
53
|
-
private async polkadotSign (key: KeyRecord, payload:
|
|
63
|
+
private async polkadotSign (key: KeyRecord, payload: Uint8Array): Promise<SignResponse> {
|
|
54
64
|
await cryptoWaitReady();
|
|
55
65
|
|
|
56
66
|
assert(key.secretKey, 'Secret key is missing.');
|
|
@@ -58,9 +68,8 @@ export class HaloService implements IHaloService {
|
|
|
58
68
|
const keyring = new PolkadotKeyring({ type: 'sr25519' });
|
|
59
69
|
const keypair = keyring.addFromUri(key.secretKey.toString());
|
|
60
70
|
|
|
61
|
-
const signature = u8aToHex(keypair.sign(hexToU8a(payload), { withType: true }));
|
|
62
71
|
return {
|
|
63
|
-
signed:
|
|
72
|
+
signed: keypair.sign(payload, { withType: true })
|
|
64
73
|
};
|
|
65
74
|
}
|
|
66
75
|
|
|
@@ -68,10 +77,41 @@ export class HaloService implements IHaloService {
|
|
|
68
77
|
assert(request.publicKey, 'Provide a publicKey of the key that should be used for signing.');
|
|
69
78
|
const key = await this.echo.halo.keyring.getFullKey(request.publicKey);
|
|
70
79
|
assert(key, 'Key not found.');
|
|
71
|
-
if (key.type === KeyType.
|
|
80
|
+
if (key.type === KeyType.DXNS_ADDRESS) {
|
|
81
|
+
assert(request.payload, 'No payload to sign.');
|
|
72
82
|
return this.polkadotSign(key, request.payload);
|
|
73
83
|
}
|
|
74
|
-
throw new Error('Only DXNS key signing is supported.');
|
|
84
|
+
throw new Error('Only DXNS Address key signing is supported.');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async setGlobalPreference (request: SetPreferenceRequest): Promise<void> {
|
|
88
|
+
assert(request.key, 'Missing key of property.');
|
|
89
|
+
const preferences: ObjectModel | undefined = this.echo.halo.identity.preferences?.getGlobalPreferences()?.model;
|
|
90
|
+
assert(preferences, 'Preferences failed to load.');
|
|
91
|
+
await preferences.setProperty(request.key, request.value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async getGlobalPreference (request: GetPreferenceRequest): Promise<GetPreferenceResponse> {
|
|
95
|
+
assert(request.key, 'Missing key of property.');
|
|
96
|
+
const preferences: ObjectModel | undefined = this.echo.halo.identity.preferences?.getGlobalPreferences()?.model;
|
|
97
|
+
return {
|
|
98
|
+
value: preferences?.getProperty(request.key)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async setDevicePreference (request: SetPreferenceRequest): Promise<void> {
|
|
103
|
+
assert(request.key, 'Missing key of property.');
|
|
104
|
+
const preferences: ObjectModel | undefined = this.echo.halo.identity.preferences?.getDevicePreferences()?.model;
|
|
105
|
+
assert(preferences, 'Preferences failed to load.');
|
|
106
|
+
await preferences.setProperty(request.key, request.value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async getDevicePreference (request: GetPreferenceRequest): Promise<GetPreferenceResponse> {
|
|
110
|
+
assert(request.key, 'Missing key of property.');
|
|
111
|
+
const preferences: ObjectModel | undefined = this.echo.halo.identity.preferences?.getDevicePreferences()?.model;
|
|
112
|
+
return {
|
|
113
|
+
value: preferences?.getProperty(request.key)
|
|
114
|
+
};
|
|
75
115
|
}
|
|
76
116
|
}
|
|
77
117
|
|
|
@@ -91,15 +91,29 @@ export interface SignRequest {
|
|
|
91
91
|
* - The public key of the key that is supposed to be used for signing.
|
|
92
92
|
*/
|
|
93
93
|
publicKey?: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
|
|
94
|
-
payload?:
|
|
94
|
+
payload?: Uint8Array;
|
|
95
95
|
}
|
|
96
96
|
export interface SignResponse {
|
|
97
|
-
signed?:
|
|
97
|
+
signed?: Uint8Array;
|
|
98
|
+
}
|
|
99
|
+
export interface SetPreferenceRequest {
|
|
100
|
+
key?: string;
|
|
101
|
+
value?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface GetPreferenceRequest {
|
|
104
|
+
key?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface GetPreferenceResponse {
|
|
107
|
+
value?: string;
|
|
98
108
|
}
|
|
99
109
|
export interface HaloService {
|
|
100
110
|
subscribeContacts: (request: void) => Stream<Contacts>;
|
|
101
111
|
addKeyRecord: (request: AddKeyRecordRequest) => Promise<void>;
|
|
102
112
|
sign: (request: SignRequest) => Promise<SignResponse>;
|
|
113
|
+
setGlobalPreference: (request: SetPreferenceRequest) => Promise<void>;
|
|
114
|
+
getGlobalPreference: (request: GetPreferenceRequest) => Promise<GetPreferenceResponse>;
|
|
115
|
+
setDevicePreference: (request: SetPreferenceRequest) => Promise<void>;
|
|
116
|
+
getDevicePreference: (request: GetPreferenceRequest) => Promise<GetPreferenceResponse>;
|
|
103
117
|
}
|
|
104
118
|
export interface Party {
|
|
105
119
|
publicKey: ReturnType<typeof substitutions["dxos.halo.keys.PubKey"]["decode"]>;
|
|
@@ -183,7 +183,11 @@ export namespace Runtime {
|
|
|
183
183
|
*/
|
|
184
184
|
accountUri?: string;
|
|
185
185
|
/**
|
|
186
|
-
* Public
|
|
186
|
+
* Public Polkadot Address.
|
|
187
|
+
*/
|
|
188
|
+
address?: string;
|
|
189
|
+
/**
|
|
190
|
+
* Public address of a DXNS Account.
|
|
187
191
|
*/
|
|
188
192
|
account?: string;
|
|
189
193
|
faucet?: string;
|