@peers-app/peers-sdk 0.14.0 → 0.15.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/dist/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- package/package.json +14 -8
package/dist/device/device.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Device = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
4
|
const keys_1 = require("../keys");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
6
|
class Device {
|
|
7
7
|
userId;
|
|
8
8
|
deviceId;
|
|
@@ -45,11 +45,17 @@ class Device {
|
|
|
45
45
|
if (!response) {
|
|
46
46
|
return response;
|
|
47
47
|
}
|
|
48
|
-
if (typeof response ===
|
|
48
|
+
if (typeof response === "object" &&
|
|
49
|
+
"contents" in response &&
|
|
50
|
+
"nonce" in response &&
|
|
51
|
+
"fromPublicKey" in response) {
|
|
49
52
|
const signedResponse = this.openBoxWithSecretKey(response);
|
|
50
53
|
return this.unwrapResponse(signedResponse);
|
|
51
54
|
}
|
|
52
|
-
if (typeof response ===
|
|
55
|
+
if (typeof response === "object" &&
|
|
56
|
+
"contents" in response &&
|
|
57
|
+
"signature" in response &&
|
|
58
|
+
"publicKey" in response) {
|
|
53
59
|
const signedResponse = response;
|
|
54
60
|
return (0, keys_1.openSignedObject)(signedResponse);
|
|
55
61
|
}
|
|
@@ -81,7 +87,7 @@ class Device {
|
|
|
81
87
|
try {
|
|
82
88
|
const deviceInfo = (0, keys_1.openSignedObject)(remoteHandshake);
|
|
83
89
|
if (remoteHandshake.publicKey !== deviceInfo.publicKey) {
|
|
84
|
-
throw new Error(
|
|
90
|
+
throw new Error("Handshake signing key does not match claimed identity key");
|
|
85
91
|
}
|
|
86
92
|
if (deviceInfo.connectionId !== connectionId) {
|
|
87
93
|
throw new Error(`Invalid connectionId ${deviceInfo.connectionId}, expected ${connectionId}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("../utils");
|
|
4
3
|
const keys_1 = require("../keys");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
5
|
const device_1 = require("./device");
|
|
6
6
|
describe(device_1.Device, () => {
|
|
7
7
|
it("should create a new device with valid keys", async () => {
|
|
@@ -44,7 +44,7 @@ describe(device_1.Device, () => {
|
|
|
44
44
|
describe("getHandshake", () => {
|
|
45
45
|
it("should return a valid and correct handshake object", async () => {
|
|
46
46
|
const connectionId = (0, utils_1.newid)();
|
|
47
|
-
const handshake = client.getHandshake(connectionId,
|
|
47
|
+
const handshake = client.getHandshake(connectionId, "localhost");
|
|
48
48
|
expect(handshake.publicKey).toBe(client.publicKey);
|
|
49
49
|
expect(handshake.contents.userId).toBe(userId1);
|
|
50
50
|
expect(handshake.contents.publicKey).toBe(client.publicKey);
|
|
@@ -55,8 +55,8 @@ describe(device_1.Device, () => {
|
|
|
55
55
|
describe("handshakeResponse", () => {
|
|
56
56
|
it("should return a valid and correct handshake response object", async () => {
|
|
57
57
|
const connectionId = (0, utils_1.newid)();
|
|
58
|
-
const handshake = client.getHandshake(connectionId,
|
|
59
|
-
const handshakeResponse = server.handshakeResponse(handshake, connectionId,
|
|
58
|
+
const handshake = client.getHandshake(connectionId, "localhost");
|
|
59
|
+
const handshakeResponse = server.handshakeResponse(handshake, connectionId, "localhost");
|
|
60
60
|
expect(handshakeResponse.userId).toBe(userId2);
|
|
61
61
|
expect(handshakeResponse.deviceId).toBe(server.deviceId);
|
|
62
62
|
expect(handshakeResponse.publicKey).toBe(server.publicKey);
|
|
@@ -70,8 +70,8 @@ describe(device_1.Device, () => {
|
|
|
70
70
|
const c2 = {
|
|
71
71
|
connectionId: (0, utils_1.newid)(),
|
|
72
72
|
};
|
|
73
|
-
const handshake = client.getHandshake(c1.connectionId,
|
|
74
|
-
expect(() => server.handshakeResponse(handshake, c2.connectionId,
|
|
73
|
+
const handshake = client.getHandshake(c1.connectionId, "localhost");
|
|
74
|
+
expect(() => server.handshakeResponse(handshake, c2.connectionId, "localhost")).toThrow(/Invalid connectionId/);
|
|
75
75
|
});
|
|
76
76
|
it("should reject a handshake signed by a different key than the one claimed in the payload (key confusion)", async () => {
|
|
77
77
|
const connectionId = (0, utils_1.newid)();
|
|
@@ -80,36 +80,35 @@ describe(device_1.Device, () => {
|
|
|
80
80
|
const clientImposter = new device_1.Device(userId1, client.deviceId, {
|
|
81
81
|
secretKey: (0, keys_1.newKeys)().secretKey,
|
|
82
82
|
publicKey: client.publicKey,
|
|
83
|
-
publicBoxKey: client.publicBoxKey
|
|
83
|
+
publicBoxKey: client.publicBoxKey,
|
|
84
84
|
});
|
|
85
|
-
const handshake = clientImposter.getHandshake(connectionId,
|
|
86
|
-
expect(() => server.handshakeResponse(handshake, connectionId,
|
|
87
|
-
.toThrow(/signing key does not match claimed identity key/i);
|
|
85
|
+
const handshake = clientImposter.getHandshake(connectionId, "localhost");
|
|
86
|
+
expect(() => server.handshakeResponse(handshake, connectionId, "localhost")).toThrow(/signing key does not match claimed identity key/i);
|
|
88
87
|
});
|
|
89
88
|
it("should detect when requests and responses are being forwarded through a different address", async () => {
|
|
90
89
|
const connToServer = {
|
|
91
90
|
connectionId: (0, utils_1.newid)(),
|
|
92
91
|
};
|
|
93
|
-
const
|
|
92
|
+
const _connToClient = {
|
|
94
93
|
connectionId: connToServer.connectionId,
|
|
95
94
|
};
|
|
96
|
-
const
|
|
95
|
+
const _manInTheMiddle = new device_1.Device(userId2);
|
|
97
96
|
// const mitmAddress = manInTheMiddle.publicAddress || manInTheMiddle.localAddress;
|
|
98
97
|
// const connToManInTheMiddle = {
|
|
99
98
|
// connectionId: connToServer.connectionId,
|
|
100
99
|
// remoteAddress: mitmAddress
|
|
101
100
|
// };
|
|
102
|
-
// // client is being intercepted
|
|
101
|
+
// // client is being intercepted
|
|
103
102
|
// {
|
|
104
103
|
// expect(() => {
|
|
105
104
|
// doHandshake(client, connToManInTheMiddle, server, connToClient);
|
|
106
|
-
// }).toThrow(/Invalid client address/);
|
|
105
|
+
// }).toThrow(/Invalid client address/);
|
|
107
106
|
// }
|
|
108
|
-
// // server is being intercepted
|
|
107
|
+
// // server is being intercepted
|
|
109
108
|
// {
|
|
110
109
|
// expect(() => {
|
|
111
110
|
// doHandshake(client, connToServer, server, connToManInTheMiddle);
|
|
112
|
-
// }).toThrow(/Invalid server address/);
|
|
111
|
+
// }).toThrow(/Invalid server address/);
|
|
113
112
|
// }
|
|
114
113
|
});
|
|
115
114
|
});
|
|
@@ -197,4 +196,4 @@ describe(ServerDevice, () => {
|
|
|
197
196
|
});
|
|
198
197
|
});
|
|
199
198
|
})
|
|
200
|
-
*/
|
|
199
|
+
*/
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IDeviceInfo } from "../data";
|
|
1
|
+
import { type IDeviceInfo } from "../data";
|
|
2
2
|
import { TrustLevel } from "./socket.type";
|
|
3
|
-
export declare function getTrustLevelFn(me: Pick<IDeviceInfo,
|
|
3
|
+
export declare function getTrustLevelFn(me: Pick<IDeviceInfo, "userId" | "publicKey" | "publicBoxKey">, serverUrl?: string): (deviceInfo: IDeviceInfo, _registerNew?: boolean) => Promise<TrustLevel>;
|
|
@@ -5,11 +5,13 @@ const context_1 = require("../context");
|
|
|
5
5
|
const data_1 = require("../data");
|
|
6
6
|
const socket_type_1 = require("./socket.type");
|
|
7
7
|
function getTrustLevelFn(me, serverUrl) {
|
|
8
|
-
return async function getTrustLevel(deviceInfo,
|
|
8
|
+
return async function getTrustLevel(deviceInfo, _registerNew) {
|
|
9
9
|
const userContext = await (0, context_1.getUserContext)();
|
|
10
10
|
const userDataContext = userContext.userDataContext;
|
|
11
11
|
// if this is my own device it is trusted
|
|
12
|
-
if (deviceInfo.userId === me.userId &&
|
|
12
|
+
if (deviceInfo.userId === me.userId &&
|
|
13
|
+
deviceInfo.publicKey === me.publicKey &&
|
|
14
|
+
deviceInfo.publicBoxKey === me.publicBoxKey) {
|
|
13
15
|
// if (deviceInfo.deviceId === thisDeviceId()) {
|
|
14
16
|
// return TrustLevel.Untrusted;
|
|
15
17
|
// }
|
|
@@ -56,24 +58,33 @@ function getTrustLevelFn(me, serverUrl) {
|
|
|
56
58
|
groupUser = groupUser ?? found; // all groups sync the same signed record
|
|
57
59
|
const gtl = await (0, data_1.UserTrustLevels)(groupContext).get(deviceInfo.userId);
|
|
58
60
|
if (gtl?.trustLevel !== undefined) {
|
|
59
|
-
groupTrustLevel =
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
groupTrustLevel =
|
|
62
|
+
groupTrustLevel === undefined
|
|
63
|
+
? gtl.trustLevel
|
|
64
|
+
: Math.min(groupTrustLevel, gtl.trustLevel);
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
const effectiveUser = user ?? groupUser;
|
|
66
|
-
if (effectiveUser &&
|
|
69
|
+
if (effectiveUser &&
|
|
70
|
+
device &&
|
|
71
|
+
!(deviceInfo.userId === device.userId &&
|
|
72
|
+
deviceInfo.userId === effectiveUser.userId &&
|
|
73
|
+
deviceInfo.publicKey === effectiveUser.publicKey &&
|
|
74
|
+
deviceInfo.publicBoxKey === effectiveUser.publicBoxKey)) {
|
|
67
75
|
// deviceInfo does not align with local info about user and device, return Untrusted
|
|
68
76
|
// TODO check if user has changed their public keys
|
|
69
77
|
return socket_type_1.TrustLevel.Untrusted;
|
|
70
78
|
}
|
|
71
|
-
if (userTrustLevel?.trustLevel &&
|
|
79
|
+
if (userTrustLevel?.trustLevel &&
|
|
80
|
+
userTrustLevel.trustLevel >= socket_type_1.TrustLevel.Trusted &&
|
|
81
|
+
device?.trustLevel &&
|
|
82
|
+
device.trustLevel >= socket_type_1.TrustLevel.Trusted) {
|
|
72
83
|
device.lastSeen = new Date();
|
|
73
84
|
await (0, data_1.Devices)(userDataContext).save(device, { restoreIfDeleted: true });
|
|
74
85
|
return socket_type_1.TrustLevel.Trusted;
|
|
75
86
|
}
|
|
76
|
-
let
|
|
87
|
+
let _trustLevel = device?.trustLevel ?? socket_type_1.TrustLevel.Unknown;
|
|
77
88
|
const lastSeen = new Date();
|
|
78
89
|
if (!device) {
|
|
79
90
|
device = {
|
|
@@ -97,7 +108,7 @@ function getTrustLevelFn(me, serverUrl) {
|
|
|
97
108
|
device.trustLevel = socket_type_1.TrustLevel.Known;
|
|
98
109
|
}
|
|
99
110
|
}
|
|
100
|
-
|
|
111
|
+
_trustLevel = device.trustLevel;
|
|
101
112
|
let newUser = false;
|
|
102
113
|
if (!user && !groupUser) {
|
|
103
114
|
// Truly unknown user — create an unsigned stub in the personal DB so
|
|
@@ -109,7 +120,7 @@ function getTrustLevelFn(me, serverUrl) {
|
|
|
109
120
|
publicBoxKey: deviceInfo.publicBoxKey,
|
|
110
121
|
name: serverUrl || `Unnamed_${deviceInfo.userId.substring(20)}`,
|
|
111
122
|
};
|
|
112
|
-
|
|
123
|
+
_trustLevel = socket_type_1.TrustLevel.NewUser;
|
|
113
124
|
newUser = true;
|
|
114
125
|
}
|
|
115
126
|
// TODO - reimplement this, checks with peers to see if this is an untrusted device
|
|
@@ -139,7 +150,7 @@ function getTrustLevelFn(me, serverUrl) {
|
|
|
139
150
|
// trustLevel: remoteTrustLevel,
|
|
140
151
|
// assignedAt: new Date(),
|
|
141
152
|
// }, { restoreIfDeleted: true });
|
|
142
|
-
// }
|
|
153
|
+
// }
|
|
143
154
|
if (newUser) {
|
|
144
155
|
// TODO: I'm not sure we immediately want to save this user to the my personal db...
|
|
145
156
|
await (0, data_1.Users)(userDataContext).save(user, {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
3
4
|
const get_trust_level_fn_1 = require("./get-trust-level-fn");
|
|
4
5
|
const socket_type_1 = require("./socket.type");
|
|
5
|
-
|
|
6
|
-
jest.mock('../context', () => ({
|
|
6
|
+
jest.mock("../context", () => ({
|
|
7
7
|
getUserContext: jest.fn(),
|
|
8
8
|
}));
|
|
9
|
-
jest.mock(
|
|
9
|
+
jest.mock("../data", () => ({
|
|
10
10
|
Devices: jest.fn(),
|
|
11
11
|
Users: jest.fn(),
|
|
12
12
|
UserTrustLevels: jest.fn(),
|
|
@@ -56,13 +56,13 @@ function setupMocks(deviceRecord = null, userRecord = null, trustRecord = null)
|
|
|
56
56
|
mockUserTrustLevels.mockReturnValue(trustTable);
|
|
57
57
|
return { devTable, usersTable, trustTable };
|
|
58
58
|
}
|
|
59
|
-
describe(
|
|
59
|
+
describe("getTrustLevelFn", () => {
|
|
60
60
|
beforeEach(() => {
|
|
61
61
|
jest.clearAllMocks();
|
|
62
62
|
});
|
|
63
63
|
// ─── Own-device fast path ───────────────────────────────────────────────────
|
|
64
|
-
describe(
|
|
65
|
-
it(
|
|
64
|
+
describe("own device (userId + publicKey + publicBoxKey all match)", () => {
|
|
65
|
+
it("returns NewDevice when device is newly seen (< 2 days old)", async () => {
|
|
66
66
|
const me = makeTestIdentity();
|
|
67
67
|
const deviceInfo = { ...me };
|
|
68
68
|
const recentDate = new Date(Date.now() - 1000 * 60 * 60 * 24); // 1 day ago
|
|
@@ -79,7 +79,7 @@ describe('getTrustLevelFn', () => {
|
|
|
79
79
|
expect(result).toBe(socket_type_1.TrustLevel.NewDevice);
|
|
80
80
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({ trustLevel: socket_type_1.TrustLevel.NewDevice }), expect.objectContaining({ restoreIfDeleted: true, weakInsert: true }));
|
|
81
81
|
});
|
|
82
|
-
it(
|
|
82
|
+
it("returns Trusted when own device has been seen for more than 2 days", async () => {
|
|
83
83
|
const me = makeTestIdentity();
|
|
84
84
|
const deviceInfo = { ...me };
|
|
85
85
|
const oldDate = new Date(Date.now() - 1000 * 60 * 60 * 24 * 3); // 3 days ago
|
|
@@ -95,21 +95,21 @@ describe('getTrustLevelFn', () => {
|
|
|
95
95
|
const result = await getTrustLevel(deviceInfo);
|
|
96
96
|
expect(result).toBe(socket_type_1.TrustLevel.Trusted);
|
|
97
97
|
});
|
|
98
|
-
it(
|
|
98
|
+
it("creates a new device record if own device has not been seen before", async () => {
|
|
99
99
|
const me = makeTestIdentity();
|
|
100
100
|
const deviceInfo = { ...me };
|
|
101
101
|
const { devTable } = setupMocks(null); // no existing device
|
|
102
|
-
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me,
|
|
102
|
+
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me, "https://myserver.example.com");
|
|
103
103
|
const result = await getTrustLevel(deviceInfo);
|
|
104
104
|
expect(result).toBe(socket_type_1.TrustLevel.NewDevice);
|
|
105
105
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({
|
|
106
106
|
deviceId: me.deviceId,
|
|
107
107
|
userId: me.userId,
|
|
108
|
-
serverUrl:
|
|
108
|
+
serverUrl: "https://myserver.example.com",
|
|
109
109
|
trustLevel: socket_type_1.TrustLevel.NewDevice,
|
|
110
110
|
}), expect.objectContaining({ restoreIfDeleted: true, weakInsert: true }));
|
|
111
111
|
});
|
|
112
|
-
it(
|
|
112
|
+
it("does not look up Users or UserTrustLevels for own device", async () => {
|
|
113
113
|
const me = makeTestIdentity();
|
|
114
114
|
const deviceInfo = { ...me };
|
|
115
115
|
setupMocks(null);
|
|
@@ -118,7 +118,7 @@ describe('getTrustLevelFn', () => {
|
|
|
118
118
|
expect(mockUsers).not.toHaveBeenCalled();
|
|
119
119
|
expect(mockUserTrustLevels).not.toHaveBeenCalled();
|
|
120
120
|
});
|
|
121
|
-
it(
|
|
121
|
+
it("updates lastSeen on every call for own device", async () => {
|
|
122
122
|
const me = makeTestIdentity();
|
|
123
123
|
const deviceInfo = { ...me };
|
|
124
124
|
const pastDate = new Date(Date.now() - 1000 * 60 * 5); // 5 minutes ago
|
|
@@ -139,8 +139,8 @@ describe('getTrustLevelFn', () => {
|
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
// ─── Blocked device early exit ──────────────────────────────────────────────
|
|
142
|
-
describe(
|
|
143
|
-
it(
|
|
142
|
+
describe("explicitly blocked device (trustLevel < Unknown)", () => {
|
|
143
|
+
it("returns Untrusted immediately without saving any records", async () => {
|
|
144
144
|
const me = makeTestIdentity();
|
|
145
145
|
const other = makeTestIdentity();
|
|
146
146
|
const blockedDevice = {
|
|
@@ -158,7 +158,7 @@ describe('getTrustLevelFn', () => {
|
|
|
158
158
|
// Should not save anything — returns early before any writes
|
|
159
159
|
expect(devTable.save).not.toHaveBeenCalled();
|
|
160
160
|
});
|
|
161
|
-
it(
|
|
161
|
+
it("returns Malicious immediately for malicious-flagged devices", async () => {
|
|
162
162
|
const me = makeTestIdentity();
|
|
163
163
|
const other = makeTestIdentity();
|
|
164
164
|
const maliciousDevice = {
|
|
@@ -175,15 +175,15 @@ describe('getTrustLevelFn', () => {
|
|
|
175
175
|
});
|
|
176
176
|
});
|
|
177
177
|
// ─── Key-mismatch guard ─────────────────────────────────────────────────────
|
|
178
|
-
describe(
|
|
179
|
-
it(
|
|
178
|
+
describe("key-mismatch guard (user AND device both exist)", () => {
|
|
179
|
+
it("returns Untrusted when publicKey does not match stored user record", async () => {
|
|
180
180
|
const me = makeTestIdentity();
|
|
181
181
|
const other = makeTestIdentity();
|
|
182
182
|
const existingUser = {
|
|
183
183
|
userId: other.userId,
|
|
184
184
|
publicKey: `different_pk_${(0, utils_1.newid)()}`,
|
|
185
185
|
publicBoxKey: other.publicBoxKey,
|
|
186
|
-
name:
|
|
186
|
+
name: "Alice",
|
|
187
187
|
};
|
|
188
188
|
const existingDevice = {
|
|
189
189
|
deviceId: other.deviceId,
|
|
@@ -197,14 +197,14 @@ describe('getTrustLevelFn', () => {
|
|
|
197
197
|
const result = await getTrustLevel(other);
|
|
198
198
|
expect(result).toBe(socket_type_1.TrustLevel.Untrusted);
|
|
199
199
|
});
|
|
200
|
-
it(
|
|
200
|
+
it("returns Untrusted when publicBoxKey does not match stored user record", async () => {
|
|
201
201
|
const me = makeTestIdentity();
|
|
202
202
|
const other = makeTestIdentity();
|
|
203
203
|
const existingUser = {
|
|
204
204
|
userId: other.userId,
|
|
205
205
|
publicKey: other.publicKey,
|
|
206
206
|
publicBoxKey: `different_pbk_${(0, utils_1.newid)()}`,
|
|
207
|
-
name:
|
|
207
|
+
name: "Alice",
|
|
208
208
|
};
|
|
209
209
|
const existingDevice = {
|
|
210
210
|
deviceId: other.deviceId,
|
|
@@ -218,14 +218,14 @@ describe('getTrustLevelFn', () => {
|
|
|
218
218
|
const result = await getTrustLevel(other);
|
|
219
219
|
expect(result).toBe(socket_type_1.TrustLevel.Untrusted);
|
|
220
220
|
});
|
|
221
|
-
it(
|
|
221
|
+
it("returns Untrusted when device.userId does not match deviceInfo.userId", async () => {
|
|
222
222
|
const me = makeTestIdentity();
|
|
223
223
|
const other = makeTestIdentity();
|
|
224
224
|
const existingUser = {
|
|
225
225
|
userId: other.userId,
|
|
226
226
|
publicKey: other.publicKey,
|
|
227
227
|
publicBoxKey: other.publicBoxKey,
|
|
228
|
-
name:
|
|
228
|
+
name: "Alice",
|
|
229
229
|
};
|
|
230
230
|
const existingDevice = {
|
|
231
231
|
deviceId: other.deviceId,
|
|
@@ -239,7 +239,7 @@ describe('getTrustLevelFn', () => {
|
|
|
239
239
|
const result = await getTrustLevel(other);
|
|
240
240
|
expect(result).toBe(socket_type_1.TrustLevel.Untrusted);
|
|
241
241
|
});
|
|
242
|
-
it(
|
|
242
|
+
it("does NOT return Untrusted when only device exists (no user record yet)", async () => {
|
|
243
243
|
const me = makeTestIdentity();
|
|
244
244
|
const other = makeTestIdentity();
|
|
245
245
|
const existingDevice = {
|
|
@@ -255,14 +255,14 @@ describe('getTrustLevelFn', () => {
|
|
|
255
255
|
const result = await getTrustLevel(other);
|
|
256
256
|
expect(result).not.toBe(socket_type_1.TrustLevel.Untrusted);
|
|
257
257
|
});
|
|
258
|
-
it(
|
|
258
|
+
it("does NOT return Untrusted when only user exists (no device record yet)", async () => {
|
|
259
259
|
const me = makeTestIdentity();
|
|
260
260
|
const other = makeTestIdentity();
|
|
261
261
|
const existingUser = {
|
|
262
262
|
userId: other.userId,
|
|
263
263
|
publicKey: `different_pk_${(0, utils_1.newid)()}`, // key mismatch present but device is missing
|
|
264
264
|
publicBoxKey: other.publicBoxKey,
|
|
265
|
-
name:
|
|
265
|
+
name: "Alice",
|
|
266
266
|
};
|
|
267
267
|
// device record is null — mismatch check is skipped
|
|
268
268
|
setupMocks(null, existingUser);
|
|
@@ -272,15 +272,15 @@ describe('getTrustLevelFn', () => {
|
|
|
272
272
|
});
|
|
273
273
|
});
|
|
274
274
|
// ─── Trusted fast path ──────────────────────────────────────────────────────
|
|
275
|
-
describe(
|
|
276
|
-
it(
|
|
275
|
+
describe("trusted fast path", () => {
|
|
276
|
+
it("returns Trusted immediately when device and userTrustLevel are both >= Trusted", async () => {
|
|
277
277
|
const me = makeTestIdentity();
|
|
278
278
|
const other = makeTestIdentity();
|
|
279
279
|
const existingUser = {
|
|
280
280
|
userId: other.userId,
|
|
281
281
|
publicKey: other.publicKey,
|
|
282
282
|
publicBoxKey: other.publicBoxKey,
|
|
283
|
-
name:
|
|
283
|
+
name: "Alice",
|
|
284
284
|
};
|
|
285
285
|
const existingDevice = {
|
|
286
286
|
deviceId: other.deviceId,
|
|
@@ -299,14 +299,14 @@ describe('getTrustLevelFn', () => {
|
|
|
299
299
|
expect(result).toBe(socket_type_1.TrustLevel.Trusted);
|
|
300
300
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({ trustLevel: socket_type_1.TrustLevel.Trusted }), expect.objectContaining({ restoreIfDeleted: true }));
|
|
301
301
|
});
|
|
302
|
-
it(
|
|
302
|
+
it("does NOT trigger fast path when device is Trusted but userTrustLevel is not", async () => {
|
|
303
303
|
const me = makeTestIdentity();
|
|
304
304
|
const other = makeTestIdentity();
|
|
305
305
|
const existingUser = {
|
|
306
306
|
userId: other.userId,
|
|
307
307
|
publicKey: other.publicKey,
|
|
308
308
|
publicBoxKey: other.publicBoxKey,
|
|
309
|
-
name:
|
|
309
|
+
name: "Alice",
|
|
310
310
|
};
|
|
311
311
|
const existingDevice = {
|
|
312
312
|
deviceId: other.deviceId,
|
|
@@ -325,14 +325,14 @@ describe('getTrustLevelFn', () => {
|
|
|
325
325
|
// save was called via the normal path (weakInsert), not the fast path
|
|
326
326
|
expect(devTable.save).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ weakInsert: true }));
|
|
327
327
|
});
|
|
328
|
-
it(
|
|
328
|
+
it("does NOT trigger fast path when userTrustLevel is Trusted but device is not", async () => {
|
|
329
329
|
const me = makeTestIdentity();
|
|
330
330
|
const other = makeTestIdentity();
|
|
331
331
|
const existingUser = {
|
|
332
332
|
userId: other.userId,
|
|
333
333
|
publicKey: other.publicKey,
|
|
334
334
|
publicBoxKey: other.publicBoxKey,
|
|
335
|
-
name:
|
|
335
|
+
name: "Alice",
|
|
336
336
|
};
|
|
337
337
|
const existingDevice = {
|
|
338
338
|
deviceId: other.deviceId,
|
|
@@ -352,12 +352,12 @@ describe('getTrustLevelFn', () => {
|
|
|
352
352
|
});
|
|
353
353
|
});
|
|
354
354
|
// ─── New user / new device resolution ───────────────────────────────────────
|
|
355
|
-
describe(
|
|
356
|
-
it(
|
|
355
|
+
describe("new user and new device", () => {
|
|
356
|
+
it("returns NewDevice and saves a user stub when both user and device are unseen", async () => {
|
|
357
357
|
const me = makeTestIdentity();
|
|
358
358
|
const other = makeTestIdentity();
|
|
359
359
|
const { devTable, usersTable } = setupMocks(null, null, null);
|
|
360
|
-
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me,
|
|
360
|
+
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me, "https://server.example.com");
|
|
361
361
|
const result = await getTrustLevel(other);
|
|
362
362
|
// The local `trustLevel` variable is set to NewUser (10), but the function returns
|
|
363
363
|
// `device.trustLevel` which remains NewDevice (20). The NewUser assignment was
|
|
@@ -367,16 +367,16 @@ describe('getTrustLevelFn', () => {
|
|
|
367
367
|
userId: other.userId,
|
|
368
368
|
publicKey: other.publicKey,
|
|
369
369
|
publicBoxKey: other.publicBoxKey,
|
|
370
|
-
name:
|
|
370
|
+
name: "https://server.example.com",
|
|
371
371
|
}), expect.objectContaining({ restoreIfDeleted: true, weakInsert: true }));
|
|
372
372
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({
|
|
373
373
|
deviceId: other.deviceId,
|
|
374
374
|
userId: other.userId,
|
|
375
|
-
serverUrl:
|
|
375
|
+
serverUrl: "https://server.example.com",
|
|
376
376
|
trustLevel: socket_type_1.TrustLevel.NewDevice,
|
|
377
377
|
}), expect.objectContaining({ restoreIfDeleted: true, weakInsert: true }));
|
|
378
378
|
});
|
|
379
|
-
it(
|
|
379
|
+
it("uses a fallback name from userId suffix when serverUrl is not provided", async () => {
|
|
380
380
|
const me = makeTestIdentity();
|
|
381
381
|
const other = makeTestIdentity();
|
|
382
382
|
const { usersTable } = setupMocks(null, null, null);
|
|
@@ -385,14 +385,14 @@ describe('getTrustLevelFn', () => {
|
|
|
385
385
|
const savedUser = usersTable.save.mock.calls[0][0];
|
|
386
386
|
expect(savedUser.name).toBe(`Unnamed_${other.userId.substring(20)}`);
|
|
387
387
|
});
|
|
388
|
-
it(
|
|
388
|
+
it("does not save a user stub when user already exists", async () => {
|
|
389
389
|
const me = makeTestIdentity();
|
|
390
390
|
const other = makeTestIdentity();
|
|
391
391
|
const existingUser = {
|
|
392
392
|
userId: other.userId,
|
|
393
393
|
publicKey: other.publicKey,
|
|
394
394
|
publicBoxKey: other.publicBoxKey,
|
|
395
|
-
name:
|
|
395
|
+
name: "Alice",
|
|
396
396
|
};
|
|
397
397
|
const { usersTable } = setupMocks(null, existingUser, null);
|
|
398
398
|
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me);
|
|
@@ -401,15 +401,15 @@ describe('getTrustLevelFn', () => {
|
|
|
401
401
|
});
|
|
402
402
|
});
|
|
403
403
|
// ─── Device aging ────────────────────────────────────────────────────────────
|
|
404
|
-
describe(
|
|
405
|
-
it(
|
|
404
|
+
describe("device aging", () => {
|
|
405
|
+
it("returns NewDevice for a device first seen < 7 days ago", async () => {
|
|
406
406
|
const me = makeTestIdentity();
|
|
407
407
|
const other = makeTestIdentity();
|
|
408
408
|
const existingUser = {
|
|
409
409
|
userId: other.userId,
|
|
410
410
|
publicKey: other.publicKey,
|
|
411
411
|
publicBoxKey: other.publicBoxKey,
|
|
412
|
-
name:
|
|
412
|
+
name: "Alice",
|
|
413
413
|
};
|
|
414
414
|
const existingDevice = {
|
|
415
415
|
deviceId: other.deviceId,
|
|
@@ -423,14 +423,14 @@ describe('getTrustLevelFn', () => {
|
|
|
423
423
|
const result = await getTrustLevel(other);
|
|
424
424
|
expect(result).toBe(socket_type_1.TrustLevel.NewDevice);
|
|
425
425
|
});
|
|
426
|
-
it(
|
|
426
|
+
it("promotes device to Known when first seen > 7 days ago", async () => {
|
|
427
427
|
const me = makeTestIdentity();
|
|
428
428
|
const other = makeTestIdentity();
|
|
429
429
|
const existingUser = {
|
|
430
430
|
userId: other.userId,
|
|
431
431
|
publicKey: other.publicKey,
|
|
432
432
|
publicBoxKey: other.publicBoxKey,
|
|
433
|
-
name:
|
|
433
|
+
name: "Alice",
|
|
434
434
|
};
|
|
435
435
|
const existingDevice = {
|
|
436
436
|
deviceId: other.deviceId,
|
|
@@ -445,14 +445,14 @@ describe('getTrustLevelFn', () => {
|
|
|
445
445
|
expect(result).toBe(socket_type_1.TrustLevel.Known);
|
|
446
446
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({ trustLevel: socket_type_1.TrustLevel.Known }), expect.anything());
|
|
447
447
|
});
|
|
448
|
-
it(
|
|
448
|
+
it("bumps existing device with Unknown trust level up to NewDevice", async () => {
|
|
449
449
|
const me = makeTestIdentity();
|
|
450
450
|
const other = makeTestIdentity();
|
|
451
451
|
const existingUser = {
|
|
452
452
|
userId: other.userId,
|
|
453
453
|
publicKey: other.publicKey,
|
|
454
454
|
publicBoxKey: other.publicBoxKey,
|
|
455
|
-
name:
|
|
455
|
+
name: "Alice",
|
|
456
456
|
};
|
|
457
457
|
const existingDevice = {
|
|
458
458
|
deviceId: other.deviceId,
|
|
@@ -467,14 +467,14 @@ describe('getTrustLevelFn', () => {
|
|
|
467
467
|
expect(result).toBe(socket_type_1.TrustLevel.NewDevice);
|
|
468
468
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({ trustLevel: socket_type_1.TrustLevel.NewDevice }), expect.anything());
|
|
469
469
|
});
|
|
470
|
-
it(
|
|
470
|
+
it("does not downgrade a device already at Known when re-evaluated before 7 days", async () => {
|
|
471
471
|
const me = makeTestIdentity();
|
|
472
472
|
const other = makeTestIdentity();
|
|
473
473
|
const existingUser = {
|
|
474
474
|
userId: other.userId,
|
|
475
475
|
publicKey: other.publicKey,
|
|
476
476
|
publicBoxKey: other.publicBoxKey,
|
|
477
|
-
name:
|
|
477
|
+
name: "Alice",
|
|
478
478
|
};
|
|
479
479
|
const existingDevice = {
|
|
480
480
|
deviceId: other.deviceId,
|
|
@@ -488,14 +488,14 @@ describe('getTrustLevelFn', () => {
|
|
|
488
488
|
const result = await getTrustLevel(other);
|
|
489
489
|
expect(result).toBe(socket_type_1.TrustLevel.Known);
|
|
490
490
|
});
|
|
491
|
-
it(
|
|
491
|
+
it("updates lastSeen on the device record each time", async () => {
|
|
492
492
|
const me = makeTestIdentity();
|
|
493
493
|
const other = makeTestIdentity();
|
|
494
494
|
const existingUser = {
|
|
495
495
|
userId: other.userId,
|
|
496
496
|
publicKey: other.publicKey,
|
|
497
497
|
publicBoxKey: other.publicBoxKey,
|
|
498
|
-
name:
|
|
498
|
+
name: "Alice",
|
|
499
499
|
};
|
|
500
500
|
const pastDate = new Date(Date.now() - 1000 * 60 * 60); // 1 hour ago
|
|
501
501
|
const existingDevice = {
|
|
@@ -515,31 +515,31 @@ describe('getTrustLevelFn', () => {
|
|
|
515
515
|
});
|
|
516
516
|
});
|
|
517
517
|
// ─── Existing user, no device ────────────────────────────────────────────────
|
|
518
|
-
describe(
|
|
519
|
-
it(
|
|
518
|
+
describe("existing user but no device record", () => {
|
|
519
|
+
it("creates a new device record with NewDevice trust level", async () => {
|
|
520
520
|
const me = makeTestIdentity();
|
|
521
521
|
const other = makeTestIdentity();
|
|
522
522
|
const existingUser = {
|
|
523
523
|
userId: other.userId,
|
|
524
524
|
publicKey: other.publicKey,
|
|
525
525
|
publicBoxKey: other.publicBoxKey,
|
|
526
|
-
name:
|
|
526
|
+
name: "Alice",
|
|
527
527
|
};
|
|
528
528
|
const { devTable } = setupMocks(null, existingUser, null);
|
|
529
|
-
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me,
|
|
529
|
+
const getTrustLevel = (0, get_trust_level_fn_1.getTrustLevelFn)(me, "https://relay.example.com");
|
|
530
530
|
const result = await getTrustLevel(other);
|
|
531
531
|
expect(result).toBe(socket_type_1.TrustLevel.NewDevice);
|
|
532
532
|
expect(devTable.save).toHaveBeenCalledWith(expect.objectContaining({
|
|
533
533
|
deviceId: other.deviceId,
|
|
534
534
|
userId: other.userId,
|
|
535
|
-
serverUrl:
|
|
535
|
+
serverUrl: "https://relay.example.com",
|
|
536
536
|
trustLevel: socket_type_1.TrustLevel.NewDevice,
|
|
537
537
|
}), expect.anything());
|
|
538
538
|
});
|
|
539
539
|
});
|
|
540
540
|
// ─── Parallel DB lookups ────────────────────────────────────────────────────
|
|
541
|
-
describe(
|
|
542
|
-
it(
|
|
541
|
+
describe("parallel DB lookups for non-self devices", () => {
|
|
542
|
+
it("queries Users, Devices and UserTrustLevels in parallel", async () => {
|
|
543
543
|
const me = makeTestIdentity();
|
|
544
544
|
const other = makeTestIdentity();
|
|
545
545
|
setupMocks(null, null, null);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Uses a single binary event '_bin' for all data transfer, achieving
|
|
8
8
|
* ~130 MB/s throughput with proper backpressure handling.
|
|
9
9
|
*/
|
|
10
|
-
import { IBinaryPeer } from
|
|
10
|
+
import type { IBinaryPeer } from "./binary-peer-connection-v2";
|
|
11
11
|
/**
|
|
12
12
|
* Minimal socket.io interface - works with both client and server sockets
|
|
13
13
|
*/
|