mcbe-ipc 3.0.2 → 3.0.3

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.
@@ -50,7 +50,7 @@ export declare namespace DirectIPC {
50
50
  private MAYBE_DECRYPT;
51
51
  get id(): string;
52
52
  constructor(id: string, force_encryption?: boolean);
53
- connect(to: string, encrypted?: boolean, timeout?: number): Promise<Connection>;
53
+ connect(to: string, encrypted?: boolean, timeout?: number, mod?: number, prime?: number): Promise<Connection>;
54
54
  send<S extends PROTO.Serializable<T>, T>(channel: string, serializer: S & PROTO.Serializable<T>, value: T): void;
55
55
  invoke<TS extends PROTO.Serializable<T>, T, RS extends PROTO.Serializable<R>, R>(channel: string, serializer: TS & PROTO.Serializable<T>, value: T, deserializer: RS & PROTO.Serializable<R>): Promise<R>[];
56
56
  on<S extends PROTO.Serializable<T>, T>(channel: string, deserializer: S & PROTO.Serializable<T>, listener: (value: T) => void): () => void;
@@ -42,15 +42,15 @@ var CRYPTO;
42
42
  }
43
43
  return result;
44
44
  }
45
- function make_secret(mod = CRYPTO.MOD) {
45
+ function make_secret(mod) {
46
46
  return Math.floor(Math.random() * (mod - 1)) + 1;
47
47
  }
48
48
  CRYPTO.make_secret = make_secret;
49
- function* make_public(secret, mod = CRYPTO.MOD, prime = CRYPTO.PRIME) {
49
+ function* make_public(secret, mod, prime) {
50
50
  return to_HEX(yield* mod_exp(mod, secret, prime));
51
51
  }
52
52
  CRYPTO.make_public = make_public;
53
- function* make_shared(secret, other, prime = CRYPTO.PRIME) {
53
+ function* make_shared(secret, other, prime) {
54
54
  return to_HEX(yield* mod_exp(to_NUM(other), secret, prime));
55
55
  }
56
56
  CRYPTO.make_shared = make_shared;
@@ -235,7 +235,7 @@ export var DirectIPC;
235
235
  $._enc_map.delete(value);
236
236
  });
237
237
  }
238
- connect(to, encrypted = false, timeout = 20) {
238
+ connect(to, encrypted = false, timeout = 20, mod = CRYPTO.MOD, prime = CRYPTO.PRIME) {
239
239
  const $ = this;
240
240
  return new Promise((resolve, reject) => {
241
241
  const con = this._con_map.get(to);
@@ -244,15 +244,15 @@ export var DirectIPC;
244
244
  resolve(con);
245
245
  }
246
246
  else {
247
- const secret = CRYPTO.make_secret();
247
+ const secret = CRYPTO.make_secret(mod);
248
248
  system.runJob((function* () {
249
- const public_key = yield* CRYPTO.make_public(secret);
249
+ const public_key = yield* CRYPTO.make_public(secret, mod, prime);
250
250
  yield* NET.emit(`ipc:${to}:handshake:synchronize`, HandshakeSynchronizeSerializer, {
251
251
  from: $._id,
252
252
  encryption_enabled: encrypted,
253
253
  encryption_public_key: public_key,
254
- encryption_prime: CRYPTO.PRIME,
255
- encryption_modulus: CRYPTO.MOD
254
+ encryption_prime: prime,
255
+ encryption_modulus: mod
256
256
  });
257
257
  })());
258
258
  function clear() {
@@ -266,7 +266,7 @@ export var DirectIPC;
266
266
  const terminate = NET.listen(`ipc:${this._id}:handshake:acknowledge`, HandshakeAcknowledgeSerializer, function* (data) {
267
267
  if (data.from === to) {
268
268
  const enc = data.encryption_enabled || encrypted
269
- ? yield* CRYPTO.make_shared(secret, data.encryption_public_key)
269
+ ? yield* CRYPTO.make_shared(secret, data.encryption_public_key, prime)
270
270
  : false;
271
271
  const new_con = new Connection($._id, to, enc);
272
272
  $._con_map.set(to, new_con);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "OmniacDev",
4
4
  "description": "IPC system for MCBE Script API projects",
5
5
  "license": "MIT",
6
- "version": "3.0.2",
6
+ "version": "3.0.3",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/OmniacDev/mcbe-ipc.git"