trac-msb 0.0.91 → 0.0.93

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.
@@ -1,3 +1,13 @@
1
1
  3e84de76f23d1f8f47aa5f133cb928ead44f91429df0b3f9761205049f2beeec
2
2
  bd3c9c5844187407baf418c3aa6329c364297b895f961a1f88a91bfe666f72c2
3
- 17e1856a71e2aef8be3dcb6776316cf90d339f8cab9bcbb3c356be2da86fd2e7
3
+ 17e1856a71e2aef8be3dcb6776316cf90d339f8cab9bcbb3c356be2da86fd2e7
4
+ ea866411e7d377efeae2eb1d243956e6a122330e697ff33d8312d1db48976658
5
+ 30149ac3be7ab7c35c047f64cfa76c59ad7a3373fdc2ac568a05c3ed4169bb4f
6
+ 49fd8429f26e61c7ae9382c763585c8085ac4d0c47649b3cb4b435f4b04f3a59
7
+ 0e3831a32bd8b955be4050d7bcdacb38ec3b33cefd8e4f3c9921c98e1989f179
8
+ eb3f93f89694374f5caabebb7499a218631e67e857197531e8422a70b038e992
9
+ b675e900dce3d2d191a847230750ed98f86253888bc3ddd05c15de4f64c00881
10
+ 714c6a9c4af41bfcf2c42a5f79ef85655ce398c4bbd070a03629d0a03d97dca5
11
+ 35f12e13e447038d07e9ee2a1750084ca006368fced4e8e0c55d354e99b9571a
12
+ 0fd54a89ea654011b800ed9f006deefdbdb68ddf1f0a392478cf7956f362adfe
13
+ 1961a27b204d9bf8f1d0483103b3b510ed401d502e0b6b41dce399894f6924f1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.91",
4
+ "version": "0.0.93",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/index.js CHANGED
@@ -208,10 +208,13 @@ export class MainSettlementBus extends ReadyResource {
208
208
 
209
209
  async #handleApplyAppendWhitelistOperation(op, view, base, node, batch) {
210
210
  const adminEntry = await batch.get(EntryType.ADMIN);
211
- if (null === adminEntry || !this.check.sanitizeIndexerOrWhitelistOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
211
+ if (null === adminEntry || !this.check.sanitizeIndexerOrWhitelistOperations(op) /* TODO: This cannot work, needs to be signed, not checked against wallet!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
212
+ // TODO: is the below an admin signature?
212
213
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, adminEntry.value.tracPublicKey, MsgUtils.createMessage(op.key, op.value.nonce, op.type));
214
+ console.log('isMessageVerifed', isMessageVerifed);
213
215
  if (!isMessageVerifed) return;
214
- const isWhitelisted = await this.#isWhitelisted(op.key);
216
+ const isWhitelisted = await this.#isWhitelisted2(op.key, batch);
217
+ console.log('iswhitelisted', isWhitelisted);
215
218
  if (isWhitelisted) return;
216
219
  await this.#createWhitelistEntry(batch, op.key);
217
220
  }
@@ -223,10 +226,11 @@ export class MainSettlementBus extends ReadyResource {
223
226
 
224
227
  async #handleApplyAddWriterOperation(op, view, base, node, batch) {
225
228
  const adminEntry = await batch.get(EntryType.ADMIN);
226
- if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
229
+ if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) /*TODO: this cannot work, needs to be signed, not checked against wallet!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
227
230
 
228
- const isWhitelisted = await this.#isWhitelisted(op.key);
231
+ const isWhitelisted = await this.#isWhitelisted2(op.key, batch);
229
232
  if (!isWhitelisted || op.key !== op.value.pub) return;
233
+ // TODO: if the below is not a message signed by admin BUT this handler is supposed to be executed by the admin, then use admin signatures in apply!
230
234
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.wk, op.value.nonce, op.type));
231
235
  if (isMessageVerifed) {
232
236
  await this.#addWriter(op, batch, base);
@@ -257,7 +261,8 @@ export class MainSettlementBus extends ReadyResource {
257
261
 
258
262
  async #handleApplyRemoveWriterOperation(op, view, base, node, batch) {
259
263
  const adminEntry = await batch.get(EntryType.ADMIN);
260
- if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
264
+ if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) /*TODO: this cannot work, needs to be signed, not checked against wallet!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
265
+ // TODO: if the below is not a message signed by admin BUT this handler is supposed to be executed by the admin, then use admin signatures in apply!
261
266
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.wk, op.value.nonce, op.type));
262
267
  if (isMessageVerifed) {
263
268
  await this.#removeWriter(op, batch, base);
@@ -293,15 +298,16 @@ export class MainSettlementBus extends ReadyResource {
293
298
  }
294
299
 
295
300
  const adminEntry = await batch.get(EntryType.ADMIN);
296
- if (null === adminEntry || !this.#isAdmin(adminEntry.value, node)) return;
301
+ if (null === adminEntry /* TODO: this cannot work!!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
297
302
 
298
- if (!this.#isWhitelisted(op.key)) return;
303
+ if (!this.#isWhitelisted2(op.key, batch)) return;
299
304
 
300
305
  const indexersEntry = await batch.get(EntryType.INDEXERS);
301
306
  if (null === indexersEntry || Array.from(indexersEntry.value).includes(op.key) ||
302
307
  Array.from(indexersEntry.value).length >= MAX_INDEXERS) {
303
308
  return;
304
309
  }
310
+ // TODO: is the below an admin signature?
305
311
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, adminEntry.value.tracPublicKey, MsgUtils.createMessage(op.key, op.value.nonce, op.type))
306
312
  if (isMessageVerifed) {
307
313
  await this.#addIndexer(indexersEntry.value, op, batch, base);
@@ -327,7 +333,8 @@ export class MainSettlementBus extends ReadyResource {
327
333
  if (!this.check.sanitizeIndexerOrWhitelistOperations(op)) return;
328
334
  const adminEntry = await batch.get(EntryType.ADMIN);
329
335
  let indexersEntry = await batch.get(EntryType.INDEXERS);
330
- if (null === adminEntry || !this.#isAdmin(adminEntry.value, node) || null === indexersEntry || !Array.from(indexersEntry.value).includes(op.key) || Array.from(indexersEntry.value).length <= 1) return;
336
+ if (null === adminEntry /* TODO: this cannot work!!! || !this.#isAdmin(adminEntry.value, node) */ || null === indexersEntry || !Array.from(indexersEntry.value).includes(op.key) || Array.from(indexersEntry.value).length <= 1) return;
337
+ // TODO: is the below an admin signature?
331
338
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, adminEntry.value.tracPublicKey, MsgUtils.createMessage(op.key, op.value.nonce, op.type))
332
339
  if (isMessageVerifed) {
333
340
  let nodeEntry = await batch.get(op.key);
@@ -466,6 +473,11 @@ export class MainSettlementBus extends ReadyResource {
466
473
  return !!whitelistEntry;
467
474
  }
468
475
 
476
+ async #isWhitelisted2(key, batch) {
477
+ const whitelistEntry = await this.getWhitelistEntry2(key, batch)
478
+ return !!whitelistEntry;
479
+ }
480
+
469
481
  async updater() {
470
482
  while (true) {
471
483
  if (this.#base.writable) {
@@ -493,6 +505,11 @@ export class MainSettlementBus extends ReadyResource {
493
505
  return entry
494
506
  }
495
507
 
508
+ async getWhitelistEntry2(key, batch) {
509
+ const entry = await batch.get(WHITELIST_PREFIX + key);
510
+ return entry !== null ? entry.value : null
511
+ }
512
+
496
513
  async #handleIncomingEvent(data) {
497
514
  try {
498
515
  const bufferData = data.toString();