mcbe-ipc 3.0.2 → 3.0.4

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;
@@ -124,7 +124,7 @@ export var DirectIPC;
124
124
  const stream = new PROTO.ByteQueue();
125
125
  yield* serializer.serialize(value, stream);
126
126
  const bytes = yield* $.MAYBE_ENCRYPT(stream.to_uint8array());
127
- yield* NET.emit(`ipc:${$._to}:${channel}:send`, ConnectionSerializer, {
127
+ yield* NET.emit(`ipc:${$._to}:manager:${channel}:send`, ConnectionSerializer, {
128
128
  from: $._from,
129
129
  bytes
130
130
  });
@@ -136,13 +136,13 @@ export var DirectIPC;
136
136
  const stream = new PROTO.ByteQueue();
137
137
  yield* serializer.serialize(value, stream);
138
138
  const bytes = yield* $.MAYBE_ENCRYPT(stream.to_uint8array());
139
- yield* NET.emit(`ipc:${$._to}:${channel}:invoke`, ConnectionSerializer, {
139
+ yield* NET.emit(`ipc:${$._to}:manager:${channel}:invoke`, ConnectionSerializer, {
140
140
  from: $._from,
141
141
  bytes
142
142
  });
143
143
  })());
144
144
  return new Promise(resolve => {
145
- const terminate = NET.listen(`ipc:${$._from}:${channel}:handle`, ConnectionSerializer, function* (data) {
145
+ const terminate = NET.listen(`ipc:${$._from}:connection:${channel}:handle`, ConnectionSerializer, function* (data) {
146
146
  if (data.from === $._to) {
147
147
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes);
148
148
  const stream = PROTO.ByteQueue.from_uint8array(bytes);
@@ -155,7 +155,7 @@ export var DirectIPC;
155
155
  }
156
156
  on(channel, deserializer, listener) {
157
157
  const $ = this;
158
- const terminate = NET.listen(`ipc:${$._from}:${channel}:send`, ConnectionSerializer, function* (data) {
158
+ const terminate = NET.listen(`ipc:${$._from}:connection:${channel}:send`, ConnectionSerializer, function* (data) {
159
159
  if (data.from === $._to) {
160
160
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes);
161
161
  const stream = PROTO.ByteQueue.from_uint8array(bytes);
@@ -168,7 +168,7 @@ export var DirectIPC;
168
168
  }
169
169
  once(channel, deserializer, listener) {
170
170
  const $ = this;
171
- const terminate = NET.listen(`ipc:${$._from}:${channel}:send`, ConnectionSerializer, function* (data) {
171
+ const terminate = NET.listen(`ipc:${$._from}:connection:${channel}:send`, ConnectionSerializer, function* (data) {
172
172
  if (data.from === $._to) {
173
173
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes);
174
174
  const stream = PROTO.ByteQueue.from_uint8array(bytes);
@@ -182,7 +182,7 @@ export var DirectIPC;
182
182
  }
183
183
  handle(channel, deserializer, serializer, listener) {
184
184
  const $ = this;
185
- const terminate = NET.listen(`ipc:${$._from}:${channel}:invoke`, ConnectionSerializer, function* (data) {
185
+ const terminate = NET.listen(`ipc:${$._from}:connection:${channel}:invoke`, ConnectionSerializer, function* (data) {
186
186
  if (data.from === $._to) {
187
187
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes);
188
188
  const stream = PROTO.ByteQueue.from_uint8array(bytes);
@@ -191,7 +191,7 @@ export var DirectIPC;
191
191
  const return_stream = new PROTO.ByteQueue();
192
192
  yield* serializer.serialize(result, return_stream);
193
193
  const return_bytes = yield* $.MAYBE_ENCRYPT(return_stream.to_uint8array());
194
- yield* NET.emit(`ipc:${$._to}:${channel}:handle`, ConnectionSerializer, {
194
+ yield* NET.emit(`ipc:${$._to}:manager:${channel}:handle`, ConnectionSerializer, {
195
195
  from: $._from,
196
196
  bytes: return_bytes
197
197
  });
@@ -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);
@@ -284,7 +284,7 @@ export var DirectIPC;
284
284
  const stream = new PROTO.ByteQueue();
285
285
  yield* serializer.serialize(value, stream);
286
286
  const bytes = yield* $.MAYBE_ENCRYPT(stream.to_uint8array(), enc);
287
- yield* NET.emit(`ipc:${key}:${channel}:send`, ConnectionSerializer, {
287
+ yield* NET.emit(`ipc:${key}:connection:${channel}:send`, ConnectionSerializer, {
288
288
  from: $._id,
289
289
  bytes
290
290
  });
@@ -299,13 +299,13 @@ export var DirectIPC;
299
299
  const stream = new PROTO.ByteQueue();
300
300
  yield* serializer.serialize(value, stream);
301
301
  const bytes = yield* $.MAYBE_ENCRYPT(stream.to_uint8array(), enc);
302
- yield* NET.emit(`ipc:${key}:${channel}:invoke`, ConnectionSerializer, {
302
+ yield* NET.emit(`ipc:${key}:connection:${channel}:invoke`, ConnectionSerializer, {
303
303
  from: $._id,
304
304
  bytes
305
305
  });
306
306
  })());
307
307
  promises.push(new Promise(resolve => {
308
- const terminate = NET.listen(`ipc:${$._id}:${channel}:handle`, ConnectionSerializer, function* (data) {
308
+ const terminate = NET.listen(`ipc:${$._id}:manager:${channel}:handle`, ConnectionSerializer, function* (data) {
309
309
  if (data.from === key) {
310
310
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes, enc);
311
311
  const stream = PROTO.ByteQueue.from_uint8array(bytes);
@@ -320,7 +320,7 @@ export var DirectIPC;
320
320
  }
321
321
  on(channel, deserializer, listener) {
322
322
  const $ = this;
323
- return NET.listen(`ipc:${$._id}:${channel}:send`, ConnectionSerializer, function* (data) {
323
+ return NET.listen(`ipc:${$._id}:manager:${channel}:send`, ConnectionSerializer, function* (data) {
324
324
  const enc = $._enc_map.get(data.from);
325
325
  if (enc !== undefined) {
326
326
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes, enc);
@@ -332,7 +332,7 @@ export var DirectIPC;
332
332
  }
333
333
  once(channel, deserializer, listener) {
334
334
  const $ = this;
335
- const terminate = NET.listen(`ipc:${$._id}:${channel}:send`, ConnectionSerializer, function* (data) {
335
+ const terminate = NET.listen(`ipc:${$._id}:manager:${channel}:send`, ConnectionSerializer, function* (data) {
336
336
  const enc = $._enc_map.get(data.from);
337
337
  if (enc !== undefined) {
338
338
  const bytes = yield* $.MAYBE_DECRYPT(data.bytes, enc);
@@ -346,7 +346,7 @@ export var DirectIPC;
346
346
  }
347
347
  handle(channel, deserializer, serializer, listener) {
348
348
  const $ = this;
349
- return NET.listen(`ipc:${$._id}:${channel}:invoke`, ConnectionSerializer, function* (data) {
349
+ return NET.listen(`ipc:${$._id}:manager:${channel}:invoke`, ConnectionSerializer, function* (data) {
350
350
  const enc = $._enc_map.get(data.from);
351
351
  if (enc !== undefined) {
352
352
  const input_bytes = yield* $.MAYBE_DECRYPT(data.bytes, enc);
@@ -356,7 +356,7 @@ export var DirectIPC;
356
356
  const output_stream = new PROTO.ByteQueue();
357
357
  yield* serializer.serialize(result, output_stream);
358
358
  const output_bytes = yield* $.MAYBE_ENCRYPT(output_stream.to_uint8array(), enc);
359
- yield* NET.emit(`ipc:${data.from}:${channel}:handle`, ConnectionSerializer, {
359
+ yield* NET.emit(`ipc:${data.from}:connection:${channel}:handle`, ConnectionSerializer, {
360
360
  from: $._id,
361
361
  bytes: output_bytes
362
362
  });
package/dist/ipc.js CHANGED
@@ -342,7 +342,7 @@ export var PROTO;
342
342
  function Optional(value) {
343
343
  return {
344
344
  *serialize(optional, stream) {
345
- yield* PROTO.Boolean.serialize(value !== undefined, stream);
345
+ yield* PROTO.Boolean.serialize(optional !== undefined, stream);
346
346
  if (optional !== undefined) {
347
347
  yield* value.serialize(optional, stream);
348
348
  }
@@ -420,7 +420,7 @@ export var NET;
420
420
  for (let i = 0; i < uint8array.length; i++) {
421
421
  const char_code = uint8array[i] | (uint8array[++i] << 8);
422
422
  const utf16_size = char_code <= 0x7f ? 1 : char_code <= 0x7ff ? 2 : char_code <= 0xffff ? 3 : 4;
423
- const char_size = char_code > 0xff ? utf16_size : 3;
423
+ const char_size = char_code > 0xff ? utf16_size : 2;
424
424
  if (acc_size + char_size > max_size) {
425
425
  result.push(acc_str);
426
426
  acc_str = '';
package/dist/proto.js CHANGED
@@ -341,7 +341,7 @@ export var PROTO;
341
341
  function Optional(value) {
342
342
  return {
343
343
  *serialize(optional, stream) {
344
- yield* PROTO.Boolean.serialize(value !== undefined, stream);
344
+ yield* PROTO.Boolean.serialize(optional !== undefined, stream);
345
345
  if (optional !== undefined) {
346
346
  yield* value.serialize(optional, stream);
347
347
  }
package/package.json CHANGED
@@ -3,10 +3,10 @@
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.4",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/OmniacDev/mcbe-ipc.git"
9
+ "url": "git+https://github.com/OmniacDev/mcbe-ipc.git"
10
10
  },
11
11
  "bugs": {
12
12
  "url": "https://github.com/OmniacDev/mcbe-ipc/issues"