@hive-p2p/server 1.0.60 → 1.0.61
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/core/arbiter.mjs +3 -3
- package/core/crypto-codex.mjs +2 -2
- package/core/node-services.mjs +2 -2
- package/core/topologist.mjs +2 -2
- package/package.json +1 -1
package/core/arbiter.mjs
CHANGED
|
@@ -99,7 +99,7 @@ export class Arbiter {
|
|
|
99
99
|
/** Call from HiveP2P module only! @param {string} from @param {any} message @param {Uint8Array} serialized @param {number} [powCheckFactor] default: 0.01 (1%) */
|
|
100
100
|
async digestMessage(from, message, serialized, powCheckFactor = .01) {
|
|
101
101
|
const { senderId, pubkey, topic, expectedEnd } = message; // avoid powControl() on banished peers
|
|
102
|
-
if (!this.#signatureControl(from, message, serialized)) return;
|
|
102
|
+
if (!await this.#signatureControl(from, message, serialized)) return;
|
|
103
103
|
if (!this.#lengthControl(from, topic ? 'gossip' : 'unicast', serialized, expectedEnd)) return;
|
|
104
104
|
|
|
105
105
|
const routeOrHopsOk = topic ? this.#hopsControl(from, message) : this.#routeLengthControl(from, message);
|
|
@@ -111,11 +111,11 @@ export class Arbiter {
|
|
|
111
111
|
return true;
|
|
112
112
|
}
|
|
113
113
|
/** @param {string} from @param {import('./gossip.mjs').GossipMessage} message @param {Uint8Array} serialized */
|
|
114
|
-
#signatureControl(from, message, serialized) {
|
|
114
|
+
async #signatureControl(from, message, serialized) {
|
|
115
115
|
try {
|
|
116
116
|
const { pubkey, signature, signatureStart } = message;
|
|
117
117
|
const signedData = serialized.subarray(0, signatureStart);
|
|
118
|
-
const signatureValid = this.cryptoCodex.verifySignature(pubkey, signature, signedData);
|
|
118
|
+
const signatureValid = await this.cryptoCodex.verifySignature(pubkey, signature, signedData);
|
|
119
119
|
if (!signatureValid) throw new Error('Gossip signature invalid');
|
|
120
120
|
this.adjustTrust(from, TRUST_VALUES.VALID_SIGNATURE, 'Gossip signature valid');
|
|
121
121
|
return true;
|
package/core/crypto-codex.mjs
CHANGED
|
@@ -168,9 +168,9 @@ export class CryptoCodex {
|
|
|
168
168
|
|
|
169
169
|
// MESSSAGE READING (DESERIALIZATION AND SIGNATURE VERIFICATION INCLUDED)
|
|
170
170
|
/** @param {Uint8Array} publicKey @param {Uint8Array} dataToVerify @param {Uint8Array} signature */
|
|
171
|
-
verifySignature(publicKey, dataToVerify, signature) {
|
|
171
|
+
async verifySignature(publicKey, dataToVerify, signature) {
|
|
172
172
|
if (this.AVOID_CRYPTO) return true;
|
|
173
|
-
return ed25519.
|
|
173
|
+
return ed25519.verifyAsync(dataToVerify, signature, publicKey);
|
|
174
174
|
}
|
|
175
175
|
/** @param {Uint8Array} bufferView */
|
|
176
176
|
readBufferHeader(bufferView, readAssociatedId = true) {
|
package/core/node-services.mjs
CHANGED
|
@@ -56,7 +56,7 @@ export class NodeServices {
|
|
|
56
56
|
ws.on('error', (error) => console.error(`WebSocket error on Node #${this.id} with peer ${remoteId}:`, error.stack));
|
|
57
57
|
|
|
58
58
|
let remoteId;
|
|
59
|
-
ws.on('message', (data) => { // When peer proves his id, we can handle data normally
|
|
59
|
+
ws.on('message', async (data) => { // When peer proves his id, we can handle data normally
|
|
60
60
|
if (remoteId) for (const cb of this.peerStore.callbacks.data) cb(remoteId, data);
|
|
61
61
|
else { // FIRST MESSAGE SHOULD BE HANDSHAKE WITH ID
|
|
62
62
|
const d = new Uint8Array(data); if (d[0] > 127) return; // not unicast, ignore
|
|
@@ -68,7 +68,7 @@ export class NodeServices {
|
|
|
68
68
|
|
|
69
69
|
const { signatureStart, pubkey, signature } = message;
|
|
70
70
|
const signedData = d.subarray(0, signatureStart);
|
|
71
|
-
if (!this.cryptoCodex.verifySignature(pubkey, signature, signedData)) return;
|
|
71
|
+
if (!await this.cryptoCodex.verifySignature(pubkey, signature, signedData)) return;
|
|
72
72
|
|
|
73
73
|
remoteId = route[0];
|
|
74
74
|
this.peerStore.digestPeerNeighbors(remoteId, neighborsList); // Update known store
|
package/core/topologist.mjs
CHANGED
|
@@ -175,7 +175,7 @@ export class Topologist {
|
|
|
175
175
|
this.bootstrapsConnectionState.set(publicUrl, false);
|
|
176
176
|
for (const cb of this.peerStore.callbacks.disconnect) cb(remoteId, 'out');
|
|
177
177
|
}
|
|
178
|
-
ws.onmessage = (data) => {
|
|
178
|
+
ws.onmessage = async (data) => {
|
|
179
179
|
if (remoteId) for (const cb of this.peerStore.callbacks.data) cb(remoteId, data.data);
|
|
180
180
|
else { // FIRST MESSAGE SHOULD BE HANDSHAKE WITH ID
|
|
181
181
|
const d = new Uint8Array(data.data); if (d[0] > 127) return; // not unicast, ignore
|
|
@@ -187,7 +187,7 @@ export class Topologist {
|
|
|
187
187
|
|
|
188
188
|
const { signatureStart, pubkey, signature } = message;
|
|
189
189
|
const signedData = d.subarray(0, signatureStart);
|
|
190
|
-
if (!this.cryptoCodex.verifySignature(pubkey, signature, signedData)) return;
|
|
190
|
+
if (!await this.cryptoCodex.verifySignature(pubkey, signature, signedData)) return;
|
|
191
191
|
|
|
192
192
|
remoteId = route[0];
|
|
193
193
|
this.peerStore.digestPeerNeighbors(remoteId, neighborsList); // Update known store
|