@fairfox/polly 0.49.0 → 0.50.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/src/mesh.js +25 -14
- package/dist/src/mesh.js.map +4 -4
- package/dist/src/peer.js +16 -10
- package/dist/src/peer.js.map +4 -4
- package/dist/src/shared/lib/mesh-client.d.ts +31 -9
- package/dist/src/shared/lib/mesh-network-adapter.d.ts +22 -5
- package/dist/tools/quality/src/cli.js +3 -3
- package/dist/tools/quality/src/cli.js.map +4 -4
- package/dist/tools/quality/src/index.js +3 -3
- package/dist/tools/quality/src/index.js.map +4 -4
- package/package.json +1 -1
package/dist/src/mesh.js
CHANGED
|
@@ -1019,12 +1019,15 @@ var DEFAULT_MESH_KEY_ID = "polly-mesh-default";
|
|
|
1019
1019
|
|
|
1020
1020
|
class MeshNetworkAdapter extends NetworkAdapter {
|
|
1021
1021
|
base;
|
|
1022
|
-
|
|
1022
|
+
keyringSource;
|
|
1023
1023
|
encryptionEnabled;
|
|
1024
|
+
get keyring() {
|
|
1025
|
+
return this.keyringSource();
|
|
1026
|
+
}
|
|
1024
1027
|
constructor(options) {
|
|
1025
1028
|
super();
|
|
1026
1029
|
this.base = options.base;
|
|
1027
|
-
this.
|
|
1030
|
+
this.keyringSource = options.keyringSource;
|
|
1028
1031
|
this.encryptionEnabled = options.encryptionEnabled ?? true;
|
|
1029
1032
|
this.base.on("close", () => this.emit("close"));
|
|
1030
1033
|
this.base.on("peer-candidate", (payload) => this.emit("peer-candidate", payload));
|
|
@@ -1057,10 +1060,11 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
1057
1060
|
this.base.send(wrapped);
|
|
1058
1061
|
}
|
|
1059
1062
|
wrap(message) {
|
|
1063
|
+
const keyring = this.keyringSource();
|
|
1060
1064
|
const serialised = serialiseMessage(message);
|
|
1061
1065
|
let payloadToSign;
|
|
1062
1066
|
if (this.encryptionEnabled) {
|
|
1063
|
-
const docKey =
|
|
1067
|
+
const docKey = keyring.documentKeys.get(DEFAULT_MESH_KEY_ID);
|
|
1064
1068
|
if (!docKey) {
|
|
1065
1069
|
throw new Error(`MeshNetworkAdapter: missing document encryption key under id "${DEFAULT_MESH_KEY_ID}". Provision the key in the keyring before sending.`);
|
|
1066
1070
|
}
|
|
@@ -1069,7 +1073,7 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
1069
1073
|
} else {
|
|
1070
1074
|
payloadToSign = serialised;
|
|
1071
1075
|
}
|
|
1072
|
-
const signed = signEnvelope(payloadToSign, message.senderId,
|
|
1076
|
+
const signed = signEnvelope(payloadToSign, message.senderId, keyring.identity.secretKey);
|
|
1073
1077
|
const signedBytes = encodeSignedEnvelope(signed);
|
|
1074
1078
|
return {
|
|
1075
1079
|
type: message.type,
|
|
@@ -1087,10 +1091,11 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
1087
1091
|
} catch {
|
|
1088
1092
|
return;
|
|
1089
1093
|
}
|
|
1090
|
-
|
|
1094
|
+
const keyring = this.keyringSource();
|
|
1095
|
+
if (keyring.revokedPeers.has(signed.senderId)) {
|
|
1091
1096
|
return;
|
|
1092
1097
|
}
|
|
1093
|
-
const senderKey =
|
|
1098
|
+
const senderKey = keyring.knownPeers.get(signed.senderId);
|
|
1094
1099
|
if (!senderKey) {
|
|
1095
1100
|
return;
|
|
1096
1101
|
}
|
|
@@ -1109,7 +1114,7 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
1109
1114
|
} catch {
|
|
1110
1115
|
return;
|
|
1111
1116
|
}
|
|
1112
|
-
const docKey =
|
|
1117
|
+
const docKey = keyring.documentKeys.get(encrypted.documentId);
|
|
1113
1118
|
if (!docKey) {
|
|
1114
1119
|
return;
|
|
1115
1120
|
}
|
|
@@ -2165,7 +2170,8 @@ async function resolveIceServers(rtc) {
|
|
|
2165
2170
|
return rtc?.iceServers;
|
|
2166
2171
|
}
|
|
2167
2172
|
async function createMeshClient(options) {
|
|
2168
|
-
const
|
|
2173
|
+
const keyringSource = await resolveKeyringSource(options.keyring);
|
|
2174
|
+
const keyring = keyringSource();
|
|
2169
2175
|
const encryptionEnabled = options.encryptionEnabled ?? true;
|
|
2170
2176
|
if (encryptionEnabled && !keyring.documentKeys.has(DEFAULT_MESH_KEY_ID)) {
|
|
2171
2177
|
throw new Error(`createMeshClient: encryption is enabled but the keyring has no document key for "${DEFAULT_MESH_KEY_ID}". Bootstrap or apply a pairing token that carries the document key before connecting.`);
|
|
@@ -2210,7 +2216,7 @@ async function createMeshClient(options) {
|
|
|
2210
2216
|
webrtcAdapter = new MeshWebRTCAdapter(webrtcAdapterOptions);
|
|
2211
2217
|
const networkAdapter = new MeshNetworkAdapter({
|
|
2212
2218
|
base: webrtcAdapter,
|
|
2213
|
-
|
|
2219
|
+
keyringSource,
|
|
2214
2220
|
encryptionEnabled
|
|
2215
2221
|
});
|
|
2216
2222
|
const repo = new Repo({
|
|
@@ -2222,7 +2228,9 @@ async function createMeshClient(options) {
|
|
|
2222
2228
|
await signaling.connect();
|
|
2223
2229
|
return {
|
|
2224
2230
|
repo,
|
|
2225
|
-
keyring
|
|
2231
|
+
get keyring() {
|
|
2232
|
+
return keyringSource();
|
|
2233
|
+
},
|
|
2226
2234
|
signaling,
|
|
2227
2235
|
networkAdapter,
|
|
2228
2236
|
webrtcAdapter,
|
|
@@ -2233,15 +2241,18 @@ async function createMeshClient(options) {
|
|
|
2233
2241
|
}
|
|
2234
2242
|
};
|
|
2235
2243
|
}
|
|
2236
|
-
async function
|
|
2244
|
+
async function resolveKeyringSource(source) {
|
|
2245
|
+
if (typeof source === "object" && source !== null && "source" in source) {
|
|
2246
|
+
return source.source;
|
|
2247
|
+
}
|
|
2237
2248
|
if ("storage" in source) {
|
|
2238
2249
|
const loaded = await source.storage.load();
|
|
2239
2250
|
if (loaded === null) {
|
|
2240
2251
|
throw new Error("createMeshClient: keyring storage returned null (no saved keyring). In a Node CLI, bootstrap with `bootstrapCliKeyring` from `@fairfox/polly/mesh/node`; in a browser, run your pairing flow first and save the keyring through the storage adapter before constructing the client.");
|
|
2241
2252
|
}
|
|
2242
|
-
return loaded;
|
|
2253
|
+
return () => loaded;
|
|
2243
2254
|
}
|
|
2244
|
-
return source;
|
|
2255
|
+
return () => source;
|
|
2245
2256
|
}
|
|
2246
2257
|
// src/shared/lib/pairing.ts
|
|
2247
2258
|
init_encryption();
|
|
@@ -2637,4 +2648,4 @@ export {
|
|
|
2637
2648
|
$meshCounter
|
|
2638
2649
|
};
|
|
2639
2650
|
|
|
2640
|
-
//# debugId=
|
|
2651
|
+
//# debugId=B2B892016D246AC464756E2164756E21
|