trac-msb 0.2.7 → 0.2.8

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.
Files changed (146) hide show
  1. package/.github/workflows/publish.yml +8 -16
  2. package/docs/networking-dualstack-plan.md +75 -0
  3. package/docs/networking-layer-redesign.md +155 -0
  4. package/msb.mjs +11 -23
  5. package/package.json +2 -3
  6. package/rpc/{create_server.mjs → create_server.js} +2 -2
  7. package/rpc/{handlers.mjs → handlers.js} +5 -5
  8. package/rpc/routes/{index.mjs → index.js} +1 -1
  9. package/rpc/routes/{v1.mjs → v1.js} +1 -1
  10. package/rpc/{rpc_server.mjs → rpc_server.js} +1 -1
  11. package/rpc/rpc_services.js +4 -4
  12. package/src/config/config.js +137 -0
  13. package/src/config/env.js +61 -0
  14. package/src/core/network/Network.js +119 -73
  15. package/src/core/network/identity/NetworkWalletFactory.js +3 -4
  16. package/src/core/network/messaging/NetworkMessages.js +12 -11
  17. package/src/core/network/messaging/handlers/GetRequestHandler.js +5 -4
  18. package/src/core/network/messaging/handlers/ResponseHandler.js +4 -5
  19. package/src/core/network/messaging/handlers/RoleOperationHandler.js +17 -19
  20. package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +44 -38
  21. package/src/core/network/messaging/handlers/TransferOperationHandler.js +29 -25
  22. package/src/core/network/messaging/handlers/base/BaseOperationHandler.js +20 -21
  23. package/src/core/network/messaging/routes/NetworkMessageRouter.js +24 -20
  24. package/src/core/network/messaging/validators/AdminResponse.js +2 -2
  25. package/src/core/network/messaging/validators/CustomNodeResponse.js +2 -2
  26. package/src/core/network/messaging/validators/PartialBootstrapDeployment.js +3 -3
  27. package/src/core/network/messaging/validators/PartialRoleAccess.js +15 -12
  28. package/src/core/network/messaging/validators/PartialTransaction.js +9 -10
  29. package/src/core/network/messaging/validators/PartialTransfer.js +10 -7
  30. package/src/core/network/messaging/validators/ValidatorResponse.js +2 -2
  31. package/src/core/network/messaging/validators/base/BaseResponse.js +13 -5
  32. package/src/core/network/messaging/validators/base/PartialOperation.js +37 -21
  33. package/src/core/network/services/ConnectionManager.js +9 -15
  34. package/src/core/network/services/MessageOrchestrator.js +10 -22
  35. package/src/core/network/services/TransactionPoolService.js +9 -8
  36. package/src/core/network/services/ValidatorObserverService.js +46 -21
  37. package/src/core/state/State.js +136 -139
  38. package/src/core/state/utils/address.js +18 -16
  39. package/src/core/state/utils/adminEntry.js +17 -16
  40. package/src/core/state/utils/deploymentEntry.js +15 -15
  41. package/src/core/state/utils/transaction.js +3 -95
  42. package/src/index.js +153 -201
  43. package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +36 -32
  44. package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +39 -42
  45. package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +20 -20
  46. package/src/messages/partialStateMessages/PartialStateMessageOperations.js +29 -22
  47. package/src/utils/check.js +21 -17
  48. package/src/utils/cliCommands.js +11 -11
  49. package/src/utils/constants.js +2 -10
  50. package/src/utils/fileUtils.js +1 -4
  51. package/src/utils/helpers.js +9 -20
  52. package/src/utils/migrationUtils.js +2 -2
  53. package/src/utils/normalizers.js +10 -9
  54. package/tests/acceptance/v1/account/account.test.mjs +2 -2
  55. package/tests/acceptance/v1/balance/balance.test.mjs +1 -1
  56. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +11 -2
  57. package/tests/acceptance/v1/rpc.test.mjs +9 -9
  58. package/tests/acceptance/v1/tx/tx.test.mjs +4 -2
  59. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +7 -3
  60. package/tests/fixtures/check.fixtures.js +42 -42
  61. package/tests/fixtures/protobuf.fixtures.js +27 -26
  62. package/tests/helpers/StateNetworkFactory.js +3 -5
  63. package/tests/helpers/autobaseTestHelpers.js +1 -2
  64. package/tests/helpers/config.js +3 -0
  65. package/tests/helpers/setupApplyTests.js +89 -82
  66. package/tests/helpers/transactionPayloads.mjs +26 -12
  67. package/tests/integration/apply/addAdmin/addAdminBasic.test.js +10 -9
  68. package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +20 -19
  69. package/tests/integration/apply/addIndexer.test.js +23 -21
  70. package/tests/integration/apply/addWhitelist.test.js +9 -9
  71. package/tests/integration/apply/addWriter.test.js +33 -32
  72. package/tests/integration/apply/banValidator.test.js +16 -9
  73. package/tests/integration/apply/postTx/invalidSubValues.test.js +4 -4
  74. package/tests/integration/apply/postTx/postTx.test.js +7 -33
  75. package/tests/integration/apply/removeIndexer.test.js +11 -7
  76. package/tests/integration/apply/removeWriter.test.js +20 -19
  77. package/tests/integration/apply/transfer.test.js +18 -16
  78. package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +2 -2
  79. package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +2 -1
  80. package/tests/unit/messageOperations/assembleAdminMessage.test.js +9 -10
  81. package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +3 -2
  82. package/tests/unit/messageOperations/assemblePostTransaction.test.js +25 -43
  83. package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +2 -2
  84. package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +2 -2
  85. package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +5 -4
  86. package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +4 -3
  87. package/tests/unit/network/ConnectionManager.test.js +4 -2
  88. package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
  89. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +6 -6
  90. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +8 -8
  91. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +6 -5
  92. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +24 -23
  93. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +10 -16
  94. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
  95. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +45 -41
  96. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
  97. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +17 -16
  98. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +3 -4
  99. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +2 -1
  100. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +2 -1
  101. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +23 -25
  102. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
  103. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +19 -18
  104. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +5 -4
  105. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +4 -3
  106. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +2 -1
  107. package/tests/unit/state/apply/common/commonScenarioHelper.js +3 -4
  108. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +2 -2
  109. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +2 -2
  110. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +2 -1
  111. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +2 -1
  112. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +2 -1
  113. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +2 -1
  114. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +11 -10
  115. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
  116. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +6 -7
  117. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +35 -34
  118. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +44 -43
  119. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +26 -25
  120. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +2 -1
  121. package/tests/unit/state/stateModule.test.js +0 -1
  122. package/tests/unit/state/stateTestUtils.js +7 -3
  123. package/tests/unit/state/utils/address.test.js +3 -3
  124. package/tests/unit/state/utils/adminEntry.test.js +10 -9
  125. package/tests/unit/utils/check/adminControlOperation.test.js +3 -3
  126. package/tests/unit/utils/check/balanceInitializationOperation.test.js +2 -2
  127. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +2 -3
  128. package/tests/unit/utils/check/common.test.js +7 -6
  129. package/tests/unit/utils/check/coreAdminOperation.test.js +3 -3
  130. package/tests/unit/utils/check/roleAccessOperation.test.js +3 -2
  131. package/tests/unit/utils/check/transactionOperation.test.js +3 -3
  132. package/tests/unit/utils/check/transferOperation.test.js +3 -3
  133. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -1
  134. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -1
  135. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +7 -0
  136. package/tests/unit/utils/utils.test.js +0 -1
  137. package/src/core/state/utils/indexerEntry.js +0 -105
  138. package/src/utils/crypto.js +0 -11
  139. package/tests/unit/state/utils/indexerEntry.test.js +0 -83
  140. package/tests/unit/state/utils/transaction.test.js +0 -97
  141. package/tests/unit/utils/crypto/createHash.test.js +0 -15
  142. /package/rpc/{constants.mjs → constants.js} +0 -0
  143. /package/rpc/{cors.mjs → cors.js} +0 -0
  144. /package/rpc/utils/{confirmedParameter.mjs → confirmedParameter.js} +0 -0
  145. /package/rpc/utils/{helpers.mjs → helpers.js} +0 -0
  146. /package/rpc/utils/{url.mjs → url.js} +0 -0
@@ -13,7 +13,6 @@ import {
13
13
  BATCH_SIZE,
14
14
  ADMIN_INITIAL_STAKED_BALANCE,
15
15
  MAX_WRITERS_FOR_ADMIN_INDEXER_CONNECTION,
16
- NETWORK_ID,
17
16
  TRAC_NAMESPACE,
18
17
  CustomEventType
19
18
  } from '../../utils/constants.js';
@@ -24,11 +23,10 @@ import { safeDecodeApplyOperation } from '../../utils/protobuf/operationHelpers.
24
23
  import { createMessage, ZERO_WK } from '../../utils/buffer.js';
25
24
  import addressUtils from './utils/address.js';
26
25
  import adminEntryUtils from './utils/adminEntry.js';
27
- import nodeEntryUtils, { setWritingKey, ZERO_BALANCE, NODE_ENTRY_SIZE } from './utils/nodeEntry.js';
26
+ import nodeEntryUtils, { setWritingKey, NODE_ENTRY_SIZE } from './utils/nodeEntry.js';
28
27
  import nodeRoleUtils from './utils/roles.js';
29
28
  import lengthEntryUtils from './utils/lengthEntry.js';
30
29
  import transactionUtils from './utils/transaction.js';
31
- import { blake3Hash } from '../../utils/crypto.js';
32
30
  import {
33
31
  BALANCE_FEE,
34
32
  toBalance,
@@ -43,6 +41,7 @@ import { safeWriteUInt32BE } from '../../utils/buffer.js';
43
41
  import deploymentEntryUtils from './utils/deploymentEntry.js';
44
42
  import { deepCopyBuffer } from '../../utils/buffer.js';
45
43
  import { Status } from './utils/transaction.js';
44
+ import Corestore from 'corestore';
46
45
 
47
46
  const OVERSIZED_BATCH_PENALTY_MULTIPLIER = BATCH_SIZE;
48
47
 
@@ -51,24 +50,26 @@ const OVERSIZED_BATCH_PENALTY_MULTIPLIER = BATCH_SIZE;
51
50
  class State extends ReadyResource {
52
51
  #base;
53
52
  #bee;
54
- #bootstrap;
55
53
  #store;
56
54
  #wallet;
57
- #enable_tx_apply_logs;
58
- #enable_error_apply_logs;
59
55
  #writingKey;
56
+ #config
60
57
 
61
- constructor(store, bootstrap, wallet, options = {}) {
58
+ /**
59
+ * @param {Corestore} store
60
+ * @param {PeerWallet} wallet
61
+ * @param {object} config
62
+ **/
63
+ constructor(store, wallet, config) {
62
64
  super();
63
65
 
66
+ this.#config = config
67
+
64
68
  this.#store = store;
65
- this.#bootstrap = bootstrap;
66
69
  this.#wallet = wallet;
67
- this.#enable_tx_apply_logs = options.enable_tx_apply_logs !== undefined ? options.enable_tx_apply_logs : true;
68
- this.#enable_error_apply_logs = options.enable_error_apply_logs !== undefined ? options.enable_error_apply_logs : true;
69
70
 
70
- this.check = new Check();
71
- this.#base = new Autobase(this.#store, this.#bootstrap, {
71
+ this.check = new Check(config);
72
+ this.#base = new Autobase(this.#store, this.#config.bootstrap, {
72
73
  ackInterval: ACK_INTERVAL,
73
74
  valueEncoding: AUTOBASE_VALUE_ENCODING,
74
75
  bigBatches: false,
@@ -86,10 +87,6 @@ class State extends ReadyResource {
86
87
  return this.#writingKey;
87
88
  }
88
89
 
89
- get bootstrap() {
90
- return this.#bootstrap;
91
- }
92
-
93
90
  get applyHandler() {
94
91
  return this.#apply.bind(this);
95
92
  }
@@ -152,7 +149,7 @@ class State extends ReadyResource {
152
149
 
153
150
  async getAdminEntry() {
154
151
  const adminEntry = await this.getSigned(EntryType.ADMIN);
155
- return adminEntry ? adminEntryUtils.decode(adminEntry) : null;
152
+ return adminEntry ? adminEntryUtils.decode(adminEntry, this.#config.addressPrefix) : null;
156
153
  }
157
154
 
158
155
  async getNodeEntry(address) {
@@ -179,7 +176,7 @@ class State extends ReadyResource {
179
176
  }
180
177
 
181
178
  async isAdminAllowedToValidate() {
182
- const isAdmin = this.writingKey.toString('hex') === this.bootstrap.toString('hex');
179
+ const isAdmin = this.writingKey.toString('hex') === this.#config.bootstrap.toString('hex');
183
180
  const isIndexer = this.isIndexer();
184
181
  const lengthCondition = await this.getWriterLength() <= MAX_WRITERS_FOR_ADMIN_INDEXER_CONNECTION;
185
182
  return !!(isAdmin && isIndexer && lengthCondition);
@@ -228,7 +225,7 @@ class State extends ReadyResource {
228
225
 
229
226
  async getAddressByLicenseId(licenseId) {
230
227
  const address = await this.getSigned(EntryType.LICENSE_INDEX + licenseId);
231
- return address ? addressUtils.bufferToAddress(address) : null;
228
+ return address ? addressUtils.bufferToAddress(address, this.#config.addressPrefix) : null;
232
229
  }
233
230
 
234
231
  async getWriterIndex(index) {
@@ -256,7 +253,7 @@ class State extends ReadyResource {
256
253
  for (const indexer of Object.values(this.#base.system.indexers)) {
257
254
  buf.push(indexer.key);
258
255
  }
259
- return await blake3Hash(b4a.concat(buf));
256
+ return await PeerWallet.blake3(b4a.concat(buf));
260
257
  }
261
258
 
262
259
  async isInitalizationDisabled() {
@@ -337,7 +334,7 @@ class State extends ReadyResource {
337
334
 
338
335
  async getRegisteredWriterKey(writingKey) {
339
336
  const entry = await this.get(EntryType.WRITER_ADDRESS + writingKey);
340
- return entry ? addressUtils.addressToBuffer(entry) : null;
337
+ return entry ? addressUtils.addressToBuffer(entry, this.#config.addressPrefix) : null;
341
338
  }
342
339
 
343
340
  #setupHyperbee(store) {
@@ -435,7 +432,7 @@ class State extends ReadyResource {
435
432
 
436
433
  // Extract and validate the requester network address
437
434
  const adminAddressBuffer = op.address;
438
- const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer);
435
+ const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer, this.#config.addressPrefix);
439
436
  if (adminAddressString === null) {
440
437
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Requester address is invalid.", node.from.key)
441
438
  return Status.FAILURE;
@@ -450,7 +447,7 @@ class State extends ReadyResource {
450
447
 
451
448
  // Validate recipient address
452
449
  const recipientAddress = op.bio.ia;
453
- const recipientAddressString = addressUtils.bufferToAddress(recipientAddress);
450
+ const recipientAddressString = addressUtils.bufferToAddress(recipientAddress, this.#config.addressPrefix);
454
451
  if (recipientAddressString === null) {
455
452
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Recipient address is invalid.", node.from.key)
456
453
  return Status.FAILURE;
@@ -478,7 +475,7 @@ class State extends ReadyResource {
478
475
 
479
476
  // Ensure that an admin invoked this operation
480
477
  const adminEntry = await this.#getEntryApply(EntryType.ADMIN, batch);
481
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
478
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
482
479
 
483
480
  if (decodedAdminEntry === null) {
484
481
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Failed to decode admin entry.", node.from.key)
@@ -504,7 +501,7 @@ class State extends ReadyResource {
504
501
 
505
502
  // Recreate requester message
506
503
  const message = createMessage(
507
- NETWORK_ID,
504
+ this.#config.networkId,
508
505
  op.bio.txv,
509
506
  op.bio.ia,
510
507
  amount.value,
@@ -516,7 +513,7 @@ class State extends ReadyResource {
516
513
  return Status.FAILURE;
517
514
  };
518
515
 
519
- const hash = await blake3Hash(message);
516
+ const hash = await PeerWallet.blake3Safe(message);
520
517
  const txHashHexString = op.bio.tx.toString('hex');
521
518
  if (!b4a.equals(hash, op.bio.tx)) {
522
519
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Message hash does not match the tx_hash.", node.from.key)
@@ -586,7 +583,7 @@ class State extends ReadyResource {
586
583
 
587
584
  // Extract and validate the network address
588
585
  const adminAddressBuffer = op.address;
589
- const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer);
586
+ const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer, this.#config.addressPrefix);
590
587
  if (adminAddressString === null) {
591
588
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Failed to validate requester address.", node.from.key)
592
589
  return Status.FAILURE;
@@ -601,7 +598,7 @@ class State extends ReadyResource {
601
598
 
602
599
  // Ensure that an admin invoked this operation
603
600
  const adminEntry = await this.#getEntryApply(EntryType.ADMIN, batch);
604
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
601
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
605
602
 
606
603
  if (decodedAdminEntry === null) {
607
604
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Failed to decode admin entry.", node.from.key)
@@ -627,7 +624,7 @@ class State extends ReadyResource {
627
624
 
628
625
  // Recreate requester message
629
626
  const message = createMessage(
630
- NETWORK_ID,
627
+ this.#config.networkId,
631
628
  op.cao.txv,
632
629
  op.cao.iw,
633
630
  op.cao.in,
@@ -638,7 +635,7 @@ class State extends ReadyResource {
638
635
  return Status.FAILURE;
639
636
  };
640
637
 
641
- const hash = await blake3Hash(message);
638
+ const hash = await PeerWallet.blake3Safe(message);
642
639
  const txHashHexString = op.cao.tx.toString('hex');
643
640
  if (!b4a.equals(hash, op.cao.tx)) {
644
641
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Message hash does not match the tx_hash.", node.from.key)
@@ -691,7 +688,7 @@ class State extends ReadyResource {
691
688
 
692
689
  // Extract and validate the requester address (admin)
693
690
  const adminAddressBuffer = op.address;
694
- const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer);
691
+ const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer, this.#config.addressPrefix);
695
692
  if (adminAddressString === null) {
696
693
  this.#safeLogApply(OperationType.ADD_ADMIN, "Requester address is invalid.", node.from.key)
697
694
  return Status.FAILURE;
@@ -705,14 +702,14 @@ class State extends ReadyResource {
705
702
  };
706
703
 
707
704
  // Check if the operation is being performed by the bootstrap node - the original deployer of the Trac Network
708
- if (!b4a.equals(node.from.key, this.bootstrap) || !b4a.equals(op.cao.iw, this.bootstrap)) {
705
+ if (!b4a.equals(node.from.key, this.#config.bootstrap) || !b4a.equals(op.cao.iw, this.#config.bootstrap)) {
709
706
  this.#safeLogApply(OperationType.ADD_ADMIN, "Node is not a bootstrap node.", node.from.key)
710
707
  return Status.FAILURE;
711
708
  };
712
709
 
713
710
  // recreate requester message
714
711
  const requesterMessage = createMessage(
715
- NETWORK_ID,
712
+ this.#config.networkId,
716
713
  op.cao.txv,
717
714
  op.cao.iw,
718
715
  op.cao.in,
@@ -724,7 +721,7 @@ class State extends ReadyResource {
724
721
  return Status.FAILURE;
725
722
  };
726
723
 
727
- const hash = await blake3Hash(requesterMessage);
724
+ const hash = await PeerWallet.blake3Safe(requesterMessage);
728
725
  if (!b4a.equals(hash, op.cao.tx)) {
729
726
  this.#safeLogApply(OperationType.ADD_ADMIN, "Message hash does not match the tx_hash.", node.from.key)
730
727
  return Status.FAILURE;
@@ -788,7 +785,7 @@ class State extends ReadyResource {
788
785
  }
789
786
 
790
787
  // Create a new admin entry
791
- const newAdminEntry = adminEntryUtils.encode(adminAddressBuffer, op.cao.iw);
788
+ const newAdminEntry = adminEntryUtils.encode(adminAddressBuffer, op.cao.iw, this.#config.addressPrefix);
792
789
  if (newAdminEntry.length === 0) {
793
790
  this.#safeLogApply(OperationType.ADD_ADMIN, "Failed to verify message signature.", node.from.key)
794
791
  return Status.FAILURE;
@@ -813,7 +810,7 @@ class State extends ReadyResource {
813
810
  await batch.put(EntryType.INITIALIZATION, safeWriteUInt32BE(1, 0));
814
811
  await batch.put(txHashHexString, node.value);
815
812
 
816
- if (this.#enable_tx_apply_logs) {
813
+ if (this.#config.enableTxApplyLogs) {
817
814
  console.info(`Admin added addr:wk:tx - ${adminAddressString}:${op.cao.iw.toString('hex')}:${txHashHexString}`);
818
815
  }
819
816
 
@@ -852,7 +849,7 @@ class State extends ReadyResource {
852
849
 
853
850
  // Extract and validate the requester address and pubkey
854
851
  const requesterAdminAddressBuffer = op.address;
855
- const requesterAdminAddressString = addressUtils.bufferToAddress(requesterAdminAddressBuffer);
852
+ const requesterAdminAddressString = addressUtils.bufferToAddress(requesterAdminAddressBuffer, this.#config.addressPrefix);
856
853
  if (requesterAdminAddressString === null) {
857
854
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Requester address is invalid.", node.from.key)
858
855
  return Status.FAILURE;
@@ -866,7 +863,7 @@ class State extends ReadyResource {
866
863
 
867
864
  // recreate requester message
868
865
  const requesterMessage = createMessage(
869
- NETWORK_ID,
866
+ this.#config.networkId,
870
867
  op.rao.txv,
871
868
  op.rao.iw,
872
869
  op.rao.in,
@@ -878,7 +875,7 @@ class State extends ReadyResource {
878
875
  return Status.FAILURE;
879
876
  };
880
877
 
881
- const hash = await blake3Hash(requesterMessage);
878
+ const hash = await PeerWallet.blake3Safe(requesterMessage);
882
879
  if (!b4a.equals(hash, op.rao.tx)) {
883
880
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Message hash does not match the tx_hash.", node.from.key)
884
881
  return Status.FAILURE;
@@ -894,7 +891,7 @@ class State extends ReadyResource {
894
891
 
895
892
  // Extract and validate the validator address and pubkey
896
893
  const validatorAddress = op.rao.va;
897
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddress);
894
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddress, this.#config.addressPrefix);
898
895
  if (validatorAddressString === null) {
899
896
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to validate validator address.", node.from.key)
900
897
  return Status.FAILURE;
@@ -908,7 +905,7 @@ class State extends ReadyResource {
908
905
 
909
906
  // recreate validator message
910
907
  const validatorMessage = createMessage(
911
- NETWORK_ID,
908
+ this.#config.networkId,
912
909
  op.rao.tx,
913
910
  op.rao.vn,
914
911
  OperationType.ADMIN_RECOVERY
@@ -920,7 +917,7 @@ class State extends ReadyResource {
920
917
  };
921
918
 
922
919
  // verify validator signature
923
- const validatorHash = await blake3Hash(validatorMessage);
920
+ const validatorHash = await PeerWallet.blake3Safe(validatorMessage);
924
921
  const isValidatorMessageVerifed = this.#wallet.verify(op.rao.vs, validatorHash, validatorPublicKey);
925
922
  if (!isValidatorMessageVerifed) {
926
923
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to verify message signature.", node.from.key)
@@ -956,7 +953,7 @@ class State extends ReadyResource {
956
953
  }
957
954
 
958
955
  const adminEntry = await this.#getEntryApply(EntryType.ADMIN, batch);
959
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
956
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
960
957
 
961
958
  if (decodedAdminEntry === null) {
962
959
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to decode admin entry.", node.from.key)
@@ -984,7 +981,7 @@ class State extends ReadyResource {
984
981
  }; // Old admin wk is not in indexers entry
985
982
 
986
983
  // Update admin entry with new writing key
987
- const newAdminEntry = adminEntryUtils.encode(requesterAdminAddressBuffer, op.rao.iw);
984
+ const newAdminEntry = adminEntryUtils.encode(requesterAdminAddressBuffer, op.rao.iw, this.#config.addressPrefix);
988
985
  if (newAdminEntry.length === 0) {
989
986
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Invalid admin entry.", node.from.key)
990
987
  return Status.FAILURE;
@@ -1001,7 +998,7 @@ class State extends ReadyResource {
1001
998
  }; // New admin wk is already in indexers entry
1002
999
 
1003
1000
  // charging fee from the requester (admin)
1004
- const decodedAdminNodeEntry = nodeEntryUtils.decode(newAdminNodeEntry)
1001
+ const decodedAdminNodeEntry = nodeEntryUtils.decode(newAdminNodeEntry, this.#config.addressPrefix)
1005
1002
  if (decodedAdminNodeEntry === null) {
1006
1003
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to decode node entry.", node.from.key)
1007
1004
  return Status.FAILURE;
@@ -1026,7 +1023,7 @@ class State extends ReadyResource {
1026
1023
  const chargedAdminEntry = updatedFee.update(newAdminNodeEntry)
1027
1024
 
1028
1025
  // Reward logic
1029
- const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer);
1026
+ const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
1030
1027
  if (validatorNodeEntry === null) {
1031
1028
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Invalid validator node entry.", node.from.key)
1032
1029
  return Status.FAILURE;
@@ -1064,7 +1061,7 @@ class State extends ReadyResource {
1064
1061
  await batch.put(validatorAddressString, updatedValidatorNodeEntry);
1065
1062
  await batch.put(txHashHexString, node.value);
1066
1063
 
1067
- if (this.#enable_tx_apply_logs) {
1064
+ if (this.#config.enableTxApplyLogs) {
1068
1065
  console.info(`Admin has been recovered addr:wk:tx - ${requesterAdminAddressString}:${op.rao.iw.toString('hex')}:${txHashHexString}`);
1069
1066
  }
1070
1067
 
@@ -1079,7 +1076,7 @@ class State extends ReadyResource {
1079
1076
 
1080
1077
  // Validate the recipient address
1081
1078
  const adminAddressBuffer = op.address;
1082
- const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer);
1079
+ const adminAddressString = addressUtils.bufferToAddress(adminAddressBuffer, this.#config.addressPrefix);
1083
1080
  if (adminAddressString === null) {
1084
1081
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Recipient address is invalid.", node.from.key)
1085
1082
  return Status.FAILURE;
@@ -1098,7 +1095,7 @@ class State extends ReadyResource {
1098
1095
  return Status.FAILURE;
1099
1096
  };
1100
1097
 
1101
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
1098
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
1102
1099
  if (decodedAdminEntry === null) {
1103
1100
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to decode admin entry.", node.from.key)
1104
1101
  return Status.FAILURE;
@@ -1126,7 +1123,7 @@ class State extends ReadyResource {
1126
1123
  // Extract and validate the network prefix from the node's address
1127
1124
  const nodeAddressBuffer = op.aco.ia;
1128
1125
 
1129
- const nodeAddressString = addressUtils.bufferToAddress(nodeAddressBuffer);
1126
+ const nodeAddressString = addressUtils.bufferToAddress(nodeAddressBuffer, this.#config.addressPrefix);
1130
1127
  if (nodeAddressString === null) {
1131
1128
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to verify node address.", node.from.key)
1132
1129
  return Status.FAILURE;
@@ -1139,7 +1136,7 @@ class State extends ReadyResource {
1139
1136
 
1140
1137
  // verify signature
1141
1138
  const message = createMessage(
1142
- NETWORK_ID,
1139
+ this.#config.networkId,
1143
1140
  op.aco.txv,
1144
1141
  op.aco.ia,
1145
1142
  op.aco.in,
@@ -1151,7 +1148,7 @@ class State extends ReadyResource {
1151
1148
  };
1152
1149
 
1153
1150
  // verify signature
1154
- const hash = await blake3Hash(message);
1151
+ const hash = await PeerWallet.blake3Safe(message);
1155
1152
  if (!b4a.equals(hash, op.aco.tx)) {
1156
1153
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Message hash does not match the tx_hash.", node.from.key)
1157
1154
  return Status.FAILURE;
@@ -1199,7 +1196,7 @@ class State extends ReadyResource {
1199
1196
  return Status.FAILURE;
1200
1197
  };
1201
1198
 
1202
- const decodedNodeEntry = nodeEntryUtils.decode(adminNodeEntry)
1199
+ const decodedNodeEntry = nodeEntryUtils.decode(adminNodeEntry, this.#config.addressPrefix)
1203
1200
  if (decodedNodeEntry === null) {
1204
1201
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to decode admin entry.", node.from.key)
1205
1202
  return Status.FAILURE;
@@ -1352,7 +1349,7 @@ class State extends ReadyResource {
1352
1349
 
1353
1350
  // Extract and validate the requester address
1354
1351
  const requesterAddressBuffer = op.address;
1355
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
1352
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
1356
1353
  if (requesterAddressString === null) {
1357
1354
  this.#safeLogApply(OperationType.ADD_WRITER, "Requester address is invalid.", node.from.key)
1358
1355
  return Status.FAILURE;
@@ -1372,7 +1369,7 @@ class State extends ReadyResource {
1372
1369
 
1373
1370
  // verify requester signature
1374
1371
  const requesterMessage = createMessage(
1375
- NETWORK_ID,
1372
+ this.#config.networkId,
1376
1373
  op.rao.txv,
1377
1374
  op.rao.iw,
1378
1375
  op.rao.in,
@@ -1384,7 +1381,7 @@ class State extends ReadyResource {
1384
1381
  return Status.FAILURE;
1385
1382
  };
1386
1383
 
1387
- const hash = await blake3Hash(requesterMessage);
1384
+ const hash = await PeerWallet.blake3Safe(requesterMessage);
1388
1385
  if (!b4a.equals(hash, op.rao.tx)) {
1389
1386
  this.#safeLogApply(OperationType.ADD_WRITER, "Message hash does not match the tx_hash.", node.from.key)
1390
1387
  return Status.FAILURE;
@@ -1399,7 +1396,7 @@ class State extends ReadyResource {
1399
1396
 
1400
1397
  // verify validator signature
1401
1398
  const validatorAddress = op.rao.va;
1402
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddress);
1399
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddress, this.#config.addressPrefix);
1403
1400
  if (validatorAddressString === null) {
1404
1401
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to validate validator address.", node.from.key)
1405
1402
  return Status.FAILURE;
@@ -1414,7 +1411,7 @@ class State extends ReadyResource {
1414
1411
 
1415
1412
  // recreate validator message
1416
1413
  const validatorMessage = createMessage(
1417
- NETWORK_ID,
1414
+ this.#config.networkId,
1418
1415
  op.rao.tx,
1419
1416
  op.rao.vn,
1420
1417
  OperationType.ADD_WRITER
@@ -1425,7 +1422,7 @@ class State extends ReadyResource {
1425
1422
  return Status.FAILURE;
1426
1423
  };
1427
1424
 
1428
- const validatorHash = await blake3Hash(validatorMessage);
1425
+ const validatorHash = await PeerWallet.blake3Safe(validatorMessage);
1429
1426
  const isValidatorMessageVerifed = this.#wallet.verify(op.rao.vs, validatorHash, validatorPublicKey);
1430
1427
  if (!isValidatorMessageVerifed) {
1431
1428
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to verify validator message signature.", node.from.key)
@@ -1481,7 +1478,7 @@ class State extends ReadyResource {
1481
1478
  return null;
1482
1479
  };
1483
1480
 
1484
- const decodedRequesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntry)
1481
+ const decodedRequesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntry, this.#config.addressPrefix)
1485
1482
  if (decodedRequesterNodeEntry === null) {
1486
1483
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to decode node entry.", node.from.key)
1487
1484
  return null;
@@ -1566,7 +1563,7 @@ class State extends ReadyResource {
1566
1563
 
1567
1564
  // reward the validator
1568
1565
 
1569
- const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer)
1566
+ const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix)
1570
1567
  if (decodedValidatorEntry === null) {
1571
1568
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to decode validator entry.", node.from.key)
1572
1569
  return null;
@@ -1619,7 +1616,7 @@ class State extends ReadyResource {
1619
1616
  await batch.put(validatorAddressString, updatedValidatorEntry);
1620
1617
  await batch.put(txHashHexString, node.value);
1621
1618
 
1622
- if (this.#enable_tx_apply_logs) {
1619
+ if (this.#config.enableTxApplyLogs) {
1623
1620
  console.info(`Writer has been added addr:wk:tx - ${requesterAddressString}:${op.rao.iw.toString('hex')}:${txHashHexString}`);
1624
1621
  }
1625
1622
  }
@@ -1656,7 +1653,7 @@ class State extends ReadyResource {
1656
1653
 
1657
1654
  // Extract and validate the network address
1658
1655
  const requesterAddress = op.address;
1659
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddress);
1656
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddress, this.#config.addressPrefix);
1660
1657
  if (requesterAddressString === null) {
1661
1658
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Requester address is invalid.", node.from.key)
1662
1659
  return Status.FAILURE;
@@ -1671,7 +1668,7 @@ class State extends ReadyResource {
1671
1668
 
1672
1669
  // verify requester signature
1673
1670
  const requesterMessage = createMessage(
1674
- NETWORK_ID,
1671
+ this.#config.networkId,
1675
1672
  op.rao.txv,
1676
1673
  op.rao.iw,
1677
1674
  op.rao.in,
@@ -1683,7 +1680,7 @@ class State extends ReadyResource {
1683
1680
  };
1684
1681
 
1685
1682
  // compare hashes
1686
- const hash = await blake3Hash(requesterMessage);
1683
+ const hash = await PeerWallet.blake3Safe(requesterMessage);
1687
1684
  if (!b4a.equals(hash, op.rao.tx)) {
1688
1685
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Message hash does not match the tx_hash.", node.from.key)
1689
1686
  return Status.FAILURE;
@@ -1698,7 +1695,7 @@ class State extends ReadyResource {
1698
1695
 
1699
1696
  // verify validator signature
1700
1697
  const validatorAddress = op.rao.va;
1701
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddress);
1698
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddress, this.#config.addressPrefix);
1702
1699
  if (validatorAddressString === null) {
1703
1700
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to verify validator address.", node.from.key)
1704
1701
  return Status.FAILURE;
@@ -1713,7 +1710,7 @@ class State extends ReadyResource {
1713
1710
 
1714
1711
  // recreate validator message
1715
1712
  const validatorMessage = createMessage(
1716
- NETWORK_ID,
1713
+ this.#config.networkId,
1717
1714
  op.rao.tx,
1718
1715
  op.rao.vn,
1719
1716
  OperationType.REMOVE_WRITER
@@ -1723,7 +1720,7 @@ class State extends ReadyResource {
1723
1720
  return Status.FAILURE;
1724
1721
  };
1725
1722
 
1726
- const validatorHash = await blake3Hash(validatorMessage);
1723
+ const validatorHash = await PeerWallet.blake3Safe(validatorMessage);
1727
1724
  const isValidatorMessageVerifed = this.#wallet.verify(op.rao.vs, validatorHash, validatorPublicKey);
1728
1725
  if (!isValidatorMessageVerifed) {
1729
1726
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to verify validator message signature.", node.from.key)
@@ -1782,7 +1779,7 @@ class State extends ReadyResource {
1782
1779
  return null;
1783
1780
  };
1784
1781
 
1785
- const decodedNodeEntry = nodeEntryUtils.decode(requesterNodeEntry);
1782
+ const decodedNodeEntry = nodeEntryUtils.decode(requesterNodeEntry, this.#config.addressPrefix);
1786
1783
  if (decodedNodeEntry === null) {
1787
1784
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to decode requester node entry.", node.from.key)
1788
1785
  return null;
@@ -1843,7 +1840,7 @@ class State extends ReadyResource {
1843
1840
  };
1844
1841
 
1845
1842
  // Validator reward logic
1846
- const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer);
1843
+ const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
1847
1844
  if (decodedValidatorEntry === null) {
1848
1845
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to decode validator node entry.", node.from.key)
1849
1846
  return null;
@@ -1881,7 +1878,7 @@ class State extends ReadyResource {
1881
1878
  await batch.put(validatorAddressString, updateValidatorEntry);
1882
1879
  await batch.put(txHashHexString, node.value);
1883
1880
 
1884
- if (this.#enable_tx_apply_logs) {
1881
+ if (this.#config.enableTxApplyLogs) {
1885
1882
  console.info(`Writer removed: addr:wk:tx - ${requesterAddressString}:${op.rao.iw.toString('hex')}:${txHashHexString}`);
1886
1883
  }
1887
1884
 
@@ -1896,7 +1893,7 @@ class State extends ReadyResource {
1896
1893
 
1897
1894
  // Extract and validate the requester address (admin)
1898
1895
  const requesterAddressBuffer = op.address;
1899
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
1896
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
1900
1897
  if (requesterAddressString === null) {
1901
1898
  this.#safeLogApply(OperationType.ADD_INDEXER, "Requester address is invalid.", node.from.key)
1902
1899
  return Status.FAILURE;
@@ -1911,7 +1908,7 @@ class State extends ReadyResource {
1911
1908
 
1912
1909
  // Extract and validate pretending indexer address
1913
1910
  const pretendingAddressBuffer = op.aco.ia;
1914
- const pretendingAddressString = addressUtils.bufferToAddress(pretendingAddressBuffer);
1911
+ const pretendingAddressString = addressUtils.bufferToAddress(pretendingAddressBuffer, this.#config.addressPrefix);
1915
1912
  if (pretendingAddressString === null) {
1916
1913
  this.#safeLogApply(OperationType.ADD_INDEXER, "Pretending indexer address is invalid.", node.from.key)
1917
1914
  return Status.FAILURE;
@@ -1931,7 +1928,7 @@ class State extends ReadyResource {
1931
1928
  return Status.FAILURE;
1932
1929
  };
1933
1930
 
1934
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
1931
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
1935
1932
  if (decodedAdminEntry === null) {
1936
1933
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode admin entry.", node.from.key)
1937
1934
  return Status.FAILURE;
@@ -1957,7 +1954,7 @@ class State extends ReadyResource {
1957
1954
 
1958
1955
  // verify requester signature
1959
1956
  const message = createMessage(
1960
- NETWORK_ID,
1957
+ this.#config.networkId,
1961
1958
  op.aco.txv,
1962
1959
  op.aco.ia,
1963
1960
  op.aco.in,
@@ -1969,7 +1966,7 @@ class State extends ReadyResource {
1969
1966
  return Status.FAILURE;
1970
1967
  };
1971
1968
 
1972
- const hash = await blake3Hash(message);
1969
+ const hash = await PeerWallet.blake3Safe(message);
1973
1970
  if (!b4a.equals(hash, op.aco.tx)) {
1974
1971
  this.#safeLogApply(OperationType.ADD_INDEXER, "Message hash does not match the tx_hash.", node.from.key)
1975
1972
  return Status.FAILURE;
@@ -2017,7 +2014,7 @@ class State extends ReadyResource {
2017
2014
  return null;
2018
2015
  };
2019
2016
 
2020
- const decodedPretenderNodeEntry = nodeEntryUtils.decode(pretenderNodeEntry);
2017
+ const decodedPretenderNodeEntry = nodeEntryUtils.decode(pretenderNodeEntry, this.#config.addressPrefix);
2021
2018
  if (decodedPretenderNodeEntry === null) {
2022
2019
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode pretender indexer node entry.", node.from.key)
2023
2020
  return null;
@@ -2058,7 +2055,7 @@ class State extends ReadyResource {
2058
2055
  return null;
2059
2056
  };
2060
2057
 
2061
- const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer);
2058
+ const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer, this.#config.addressPrefix);
2062
2059
  if (adminNodeEntry === null) {
2063
2060
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode requester node entry.", node.from.key)
2064
2061
  return null;
@@ -2099,7 +2096,7 @@ class State extends ReadyResource {
2099
2096
  // store operation hash to avoid replay attack.
2100
2097
  await batch.put(txHashHexString, node.value);
2101
2098
 
2102
- if (this.#enable_tx_apply_logs) {
2099
+ if (this.#config.enableTxApplyLogs) {
2103
2100
  console.info(`Indexer added addr:wk:tx - ${pretendingAddressString}:${decodedPretenderNodeEntry.wk.toString('hex')}:${txHashHexString}`);
2104
2101
  }
2105
2102
 
@@ -2114,7 +2111,7 @@ class State extends ReadyResource {
2114
2111
 
2115
2112
  // Extract and validate the requester address (admin)
2116
2113
  const requesterAddressBuffer = op.address;
2117
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
2114
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
2118
2115
  if (requesterAddressString === null) {
2119
2116
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Requester address is invalid.", node.from.key)
2120
2117
  return Status.FAILURE;
@@ -2129,7 +2126,7 @@ class State extends ReadyResource {
2129
2126
 
2130
2127
  // Extract and validate pretending indexer address
2131
2128
  const toRemoveAddressBuffer = op.aco.ia;
2132
- const toRemoveAddressString = addressUtils.bufferToAddress(toRemoveAddressBuffer);
2129
+ const toRemoveAddressString = addressUtils.bufferToAddress(toRemoveAddressBuffer, this.#config.addressPrefix);
2133
2130
  if (toRemoveAddressString === null) {
2134
2131
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Target indexer address is invalid.", node.from.key)
2135
2132
  return Status.FAILURE;
@@ -2148,7 +2145,7 @@ class State extends ReadyResource {
2148
2145
  return Status.FAILURE;
2149
2146
  };
2150
2147
 
2151
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
2148
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
2152
2149
  if (decodedAdminEntry === null) {
2153
2150
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode admin entry.", node.from.key)
2154
2151
  return Status.FAILURE;
@@ -2172,7 +2169,7 @@ class State extends ReadyResource {
2172
2169
 
2173
2170
  // verify requester signature
2174
2171
  const message = createMessage(
2175
- NETWORK_ID,
2172
+ this.#config.networkId,
2176
2173
  op.aco.txv,
2177
2174
  op.aco.ia,
2178
2175
  op.aco.in,
@@ -2184,7 +2181,7 @@ class State extends ReadyResource {
2184
2181
  return Status.FAILURE;
2185
2182
  };
2186
2183
  // compare hashes
2187
- const hash = await blake3Hash(message);
2184
+ const hash = await PeerWallet.blake3Safe(message);
2188
2185
  if (!b4a.equals(hash, op.aco.tx)) {
2189
2186
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Message hash does not match the tx_hash.", node.from.key)
2190
2187
  return Status.FAILURE;
@@ -2230,7 +2227,7 @@ class State extends ReadyResource {
2230
2227
  return null;
2231
2228
  };
2232
2229
 
2233
- const decodedNodeEntry = nodeEntryUtils.decode(toRemoveNodeEntry);
2230
+ const decodedNodeEntry = nodeEntryUtils.decode(toRemoveNodeEntry, this.#config.addressPrefix);
2234
2231
  if (decodedNodeEntry === null) {
2235
2232
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode target indexer node entry.", node.from.key)
2236
2233
  return null;
@@ -2264,7 +2261,7 @@ class State extends ReadyResource {
2264
2261
  return null;
2265
2262
  };
2266
2263
 
2267
- const decodedAdminNodeEntry = nodeEntryUtils.decode(adminNodeEntry)
2264
+ const decodedAdminNodeEntry = nodeEntryUtils.decode(adminNodeEntry, this.#config.addressPrefix)
2268
2265
  if (decodedAdminNodeEntry === null) {
2269
2266
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode requester node entry.", node.from.key)
2270
2267
  return null;
@@ -2318,7 +2315,7 @@ class State extends ReadyResource {
2318
2315
 
2319
2316
  // store operation hash to avoid replay attack.
2320
2317
  await batch.put(txHashHexString, node.value);
2321
- if (this.#enable_tx_apply_logs) {
2318
+ if (this.#config.enableTxApplyLogs) {
2322
2319
  console.info(`Indexer has been removed addr:wk:tx - ${toRemoveAddressString}:${decodedNodeEntry.wk.toString('hex')}:${txHashHexString}`);
2323
2320
  }
2324
2321
  }
@@ -2330,7 +2327,7 @@ class State extends ReadyResource {
2330
2327
  };
2331
2328
  // Extract and validate the network prefix from the node's address
2332
2329
  const requesterAddressBuffer = op.address;
2333
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
2330
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
2334
2331
  if (requesterAddressString === null) {
2335
2332
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Requester address is invalid.", node.from.key)
2336
2333
  return Status.FAILURE;
@@ -2350,7 +2347,7 @@ class State extends ReadyResource {
2350
2347
  return Status.FAILURE;
2351
2348
  };
2352
2349
 
2353
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry);
2350
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry, this.#config.addressPrefix);
2354
2351
  if (decodedAdminEntry === null) {
2355
2352
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to decode admin node entry.", node.from.key)
2356
2353
  return Status.FAILURE;
@@ -2375,7 +2372,7 @@ class State extends ReadyResource {
2375
2372
 
2376
2373
  // recreate requester message
2377
2374
  const message = createMessage(
2378
- NETWORK_ID,
2375
+ this.#config.networkId,
2379
2376
  op.aco.txv,
2380
2377
  op.aco.ia,
2381
2378
  op.aco.in,
@@ -2387,7 +2384,7 @@ class State extends ReadyResource {
2387
2384
  };
2388
2385
 
2389
2386
  // compare hashes
2390
- const regeneratedHash = await blake3Hash(message);
2387
+ const regeneratedHash = await PeerWallet.blake3Safe(message);
2391
2388
  if (!b4a.equals(regeneratedHash, op.aco.tx)) {
2392
2389
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Message hash does not match the tx_hash.", node.from.key)
2393
2390
  return Status.FAILURE;
@@ -2421,7 +2418,7 @@ class State extends ReadyResource {
2421
2418
 
2422
2419
  // Extract and validate the node address to be banned
2423
2420
  const nodeToBeBannedAddressBuffer = op.aco.ia;
2424
- const nodeToBeBannedAddressString = addressUtils.bufferToAddress(nodeToBeBannedAddressBuffer);
2421
+ const nodeToBeBannedAddressString = addressUtils.bufferToAddress(nodeToBeBannedAddressBuffer, this.#config.addressPrefix);
2425
2422
  if (nodeToBeBannedAddressString === null) {
2426
2423
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to verify target node address.", node.from.key)
2427
2424
  return Status.FAILURE;
@@ -2450,7 +2447,7 @@ class State extends ReadyResource {
2450
2447
  return Status.FAILURE;
2451
2448
  };
2452
2449
 
2453
- const decodedToBanNodeEntry = nodeEntryUtils.decode(updatedToBanNodeEntry);
2450
+ const decodedToBanNodeEntry = nodeEntryUtils.decode(updatedToBanNodeEntry, this.#config.addressPrefix);
2454
2451
  if (decodedToBanNodeEntry === null) {
2455
2452
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to decode target node entry.", node.from.key)
2456
2453
  return Status.FAILURE;
@@ -2469,7 +2466,7 @@ class State extends ReadyResource {
2469
2466
  return Status.FAILURE;
2470
2467
  };
2471
2468
 
2472
- const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer);
2469
+ const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer, this.#config.addressPrefix);
2473
2470
  if (adminNodeEntry === null) {
2474
2471
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to verify admin node entry.", node.from.key)
2475
2472
  return Status.FAILURE;
@@ -2515,7 +2512,7 @@ class State extends ReadyResource {
2515
2512
 
2516
2513
  await batch.put(requesterAddressString, updatedAdminNodeEntry);
2517
2514
  await batch.put(txHashHexString, node.value);
2518
- if (this.#enable_tx_apply_logs) {
2515
+ if (this.#config.enableTxApplyLogs) {
2519
2516
  console.info(`Node has been banned: addr:wk:tx - ${nodeToBeBannedAddressString}:${decodedToBanNodeEntry.wk.toString('hex')}:${txHashHexString}`);
2520
2517
  }
2521
2518
 
@@ -2535,7 +2532,7 @@ class State extends ReadyResource {
2535
2532
  return Status.FAILURE;
2536
2533
  };
2537
2534
  // do not allow to deploy bootstrap deployment on the same bootstrap.
2538
- if (b4a.equals(op.bdo.bs, this.bootstrap)) {
2535
+ if (b4a.equals(op.bdo.bs, this.#config.bootstrap)) {
2539
2536
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Cannot deploy bootstrap on existing same bootstrap.", node.from.key)
2540
2537
  return Status.FAILURE;
2541
2538
  };
@@ -2558,7 +2555,7 @@ class State extends ReadyResource {
2558
2555
 
2559
2556
  // validate requester signature
2560
2557
  const requesterAddressBuffer = op.address;
2561
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
2558
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
2562
2559
  if (requesterAddressString === null) {
2563
2560
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Requester address is invalid.", node.from.key)
2564
2561
  return Status.FAILURE;
@@ -2573,7 +2570,7 @@ class State extends ReadyResource {
2573
2570
 
2574
2571
  // recreate requester message
2575
2572
  const requesterMessage = createMessage(
2576
- NETWORK_ID,
2573
+ this.#config.networkId,
2577
2574
  op.bdo.txv,
2578
2575
  op.bdo.bs,
2579
2576
  op.bdo.ic,
@@ -2587,7 +2584,7 @@ class State extends ReadyResource {
2587
2584
  };
2588
2585
 
2589
2586
  // ensure that tx is valid
2590
- const regeneratedTxHash = await blake3Hash(requesterMessage);
2587
+ const regeneratedTxHash = await PeerWallet.blake3Safe(requesterMessage);
2591
2588
  if (!b4a.equals(regeneratedTxHash, op.bdo.tx)) {
2592
2589
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Message hash does not match the tx_hash.", node.from.key)
2593
2590
  return Status.FAILURE;
@@ -2603,7 +2600,7 @@ class State extends ReadyResource {
2603
2600
 
2604
2601
  //validation of validator signature
2605
2602
  const validatorAddressBuffer = op.bdo.va;
2606
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer);
2603
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer, this.#config.addressPrefix);
2607
2604
  if (validatorAddressString === null) {
2608
2605
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Invalid validator address.", node.from.key)
2609
2606
  return Status.FAILURE;
@@ -2618,7 +2615,7 @@ class State extends ReadyResource {
2618
2615
 
2619
2616
  // recreate validator message
2620
2617
  const validatorMessage = createMessage(
2621
- NETWORK_ID,
2618
+ this.#config.networkId,
2622
2619
  op.bdo.tx,
2623
2620
  op.bdo.vn,
2624
2621
  OperationType.BOOTSTRAP_DEPLOYMENT
@@ -2629,7 +2626,7 @@ class State extends ReadyResource {
2629
2626
  return Status.FAILURE;
2630
2627
  };
2631
2628
 
2632
- const validatorMessageHash = await blake3Hash(validatorMessage);
2629
+ const validatorMessageHash = await PeerWallet.blake3Safe(validatorMessage);
2633
2630
 
2634
2631
  const isValidatorSignatureValid = this.#wallet.verify(op.bdo.vs, validatorMessageHash, validatorPublicKey);
2635
2632
  if (!isValidatorSignatureValid) {
@@ -2673,7 +2670,7 @@ class State extends ReadyResource {
2673
2670
  return Status.IGNORE;
2674
2671
  };
2675
2672
 
2676
- const deploymentEntry = deploymentEntryUtils.encode(op.bdo.tx, requesterAddressBuffer);
2673
+ const deploymentEntry = deploymentEntryUtils.encode(op.bdo.tx, requesterAddressBuffer, this.#config.addressPrefix);
2677
2674
  if (deploymentEntry.length === 0) {
2678
2675
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Invalid deployment entry.", node.from.key)
2679
2676
  return Status.FAILURE;
@@ -2692,7 +2689,7 @@ class State extends ReadyResource {
2692
2689
  return Status.FAILURE;
2693
2690
  };
2694
2691
 
2695
- const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer);
2692
+ const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer, this.#config.addressPrefix);
2696
2693
  if (requesterNodeEntry === null) {
2697
2694
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Invalid requester node entry.", node.from.key)
2698
2695
  return Status.FAILURE;
@@ -2722,7 +2719,7 @@ class State extends ReadyResource {
2722
2719
  };
2723
2720
 
2724
2721
  // reward validator for processing this transaction.
2725
- const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer);
2722
+ const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
2726
2723
  if (validatorNodeEntry === null) {
2727
2724
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Invalid validator node entry.", node.from.key)
2728
2725
  return Status.FAILURE;
@@ -2751,7 +2748,7 @@ class State extends ReadyResource {
2751
2748
  await batch.put(validatorAddressString, updatedValidatorNodeEntry);
2752
2749
  await batch.put(hashHexString, node.value);
2753
2750
 
2754
- if (this.#enable_tx_apply_logs) {
2751
+ if (this.#config.enableTxApplyLogs) {
2755
2752
  console.info(`Deployment operation: ${hashHexString} and deployment/${bootstrapDeploymentHexString} have been appended.`);
2756
2753
  }
2757
2754
  return Status.SUCCESS;
@@ -2789,14 +2786,14 @@ class State extends ReadyResource {
2789
2786
  return Status.FAILURE;
2790
2787
  };
2791
2788
 
2792
- if (!b4a.equals(op.txo.mbs, this.bootstrap)) {
2789
+ if (!b4a.equals(op.txo.mbs, this.#config.bootstrap)) {
2793
2790
  this.#safeLogApply(OperationType.TX, "Declared MSB bootstrap is different than real MSB bootstrap.", node.from.key)
2794
2791
  return Status.FAILURE;
2795
2792
  };
2796
2793
 
2797
2794
  // validate invoker signature
2798
2795
  const requesterAddressBuffer = op.address;
2799
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
2796
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
2800
2797
  if (requesterAddressString === null) {
2801
2798
  this.#safeLogApply(OperationType.TX, "Invalid requester address.", node.from.key)
2802
2799
  return Status.FAILURE;
@@ -2809,12 +2806,12 @@ class State extends ReadyResource {
2809
2806
  };
2810
2807
 
2811
2808
  const requesterMessage = createMessage(
2812
- NETWORK_ID,
2809
+ this.#config.networkId,
2813
2810
  op.txo.txv,
2814
2811
  op.txo.iw,
2815
2812
  op.txo.ch,
2816
2813
  op.txo.bs,
2817
- this.bootstrap,
2814
+ this.#config.bootstrap,
2818
2815
  op.txo.in,
2819
2816
  OperationType.TX
2820
2817
  );
@@ -2823,7 +2820,7 @@ class State extends ReadyResource {
2823
2820
  return Status.FAILURE;
2824
2821
  };
2825
2822
 
2826
- const regeneratedTxHash = await blake3Hash(requesterMessage);
2823
+ const regeneratedTxHash = await PeerWallet.blake3Safe(requesterMessage);
2827
2824
  if (!b4a.equals(regeneratedTxHash, op.txo.tx)) {
2828
2825
  this.#safeLogApply(OperationType.TX, "Message hash does not match the tx_hash.", node.from.key)
2829
2826
  return Status.FAILURE;
@@ -2837,7 +2834,7 @@ class State extends ReadyResource {
2837
2834
 
2838
2835
  //second signature
2839
2836
  const validatorAddressBuffer = op.txo.va;
2840
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer);
2837
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer, this.#config.addressPrefix);
2841
2838
  if (validatorAddressString === null) {
2842
2839
  this.#safeLogApply(OperationType.TX, "Invalid validator address.", node.from.key)
2843
2840
  return Status.FAILURE;
@@ -2851,7 +2848,7 @@ class State extends ReadyResource {
2851
2848
 
2852
2849
  // recreate validator message
2853
2850
  const validatorMessage = createMessage(
2854
- NETWORK_ID,
2851
+ this.#config.networkId,
2855
2852
  op.txo.tx,
2856
2853
  op.txo.vn,
2857
2854
  OperationType.TX
@@ -2862,7 +2859,7 @@ class State extends ReadyResource {
2862
2859
  return Status.FAILURE;
2863
2860
  };
2864
2861
 
2865
- const validatorMessageHash = await blake3Hash(validatorMessage);
2862
+ const validatorMessageHash = await PeerWallet.blake3Safe(validatorMessage);
2866
2863
  const isValidatorSignatureValid = this.#wallet.verify(op.txo.vs, validatorMessageHash, validatorPublicKey);
2867
2864
  if (!isValidatorSignatureValid) {
2868
2865
  this.#safeLogApply(OperationType.TX, "Failed to verify validator message signature.", node.from.key)
@@ -2908,13 +2905,13 @@ class State extends ReadyResource {
2908
2905
  };
2909
2906
 
2910
2907
  // check the subnetwork creator address
2911
- const deploymentEntry = deploymentEntryUtils.decode(bootstrapHasBeenRegistered);
2908
+ const deploymentEntry = deploymentEntryUtils.decode(bootstrapHasBeenRegistered, this.#config.addressLength);
2912
2909
  if (deploymentEntry === null) {
2913
2910
  this.#safeLogApply(OperationType.TX, "Invalid deployment entry.", node.from.key)
2914
2911
  return Status.FAILURE;
2915
2912
  };
2916
2913
 
2917
- const subnetworkCreatorAddressString = addressUtils.bufferToAddress(deploymentEntry.address);
2914
+ const subnetworkCreatorAddressString = addressUtils.bufferToAddress(deploymentEntry.address, this.#config.addressPrefix);
2918
2915
  if (subnetworkCreatorAddressString === null) {
2919
2916
  this.#safeLogApply(OperationType.TX, "Invalid subnet creator address.", node.from.key)
2920
2917
  return Status.FAILURE;
@@ -2966,7 +2963,7 @@ class State extends ReadyResource {
2966
2963
  }
2967
2964
  await batch.put(hashHexString, node.value);
2968
2965
 
2969
- if (this.#enable_tx_apply_logs) {
2966
+ if (this.#config.enableTxApplyLogs) {
2970
2967
  console.info(`Subnetwork TX operation: ${hashHexString} has been appended.`);
2971
2968
  }
2972
2969
  return Status.SUCCESS;
@@ -3000,7 +2997,7 @@ class State extends ReadyResource {
3000
2997
 
3001
2998
  // validate requester signature
3002
2999
  const requesterAddressBuffer = op.address;
3003
- const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer);
3000
+ const requesterAddressString = addressUtils.bufferToAddress(requesterAddressBuffer, this.#config.addressPrefix);
3004
3001
  if (requesterAddressString === null) {
3005
3002
  this.#safeLogApply(OperationType.TRANSFER, "Requester address is invalid.", node.from.key)
3006
3003
  return Status.FAILURE;
@@ -3014,7 +3011,7 @@ class State extends ReadyResource {
3014
3011
 
3015
3012
  // recreate requester message
3016
3013
  const requesterMessage = createMessage(
3017
- NETWORK_ID,
3014
+ this.#config.networkId,
3018
3015
  op.tro.txv,
3019
3016
  op.tro.to,
3020
3017
  op.tro.am,
@@ -3028,7 +3025,7 @@ class State extends ReadyResource {
3028
3025
  };
3029
3026
 
3030
3027
  // ensure that tx is valid
3031
- const regeneratedTxHash = await blake3Hash(requesterMessage);
3028
+ const regeneratedTxHash = await PeerWallet.blake3Safe(requesterMessage);
3032
3029
  if (!b4a.equals(regeneratedTxHash, op.tro.tx)) {
3033
3030
  this.#safeLogApply(OperationType.TRANSFER, "Message hash does not match the tx_hash.", node.from.key)
3034
3031
  return Status.FAILURE;
@@ -3042,7 +3039,7 @@ class State extends ReadyResource {
3042
3039
 
3043
3040
  // signature of the validator
3044
3041
  const validatorAddressBuffer = op.tro.va;
3045
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer);
3042
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer, this.#config.addressPrefix);
3046
3043
  if (validatorAddressString === null) {
3047
3044
  this.#safeLogApply(OperationType.TRANSFER, "Validator address is invalid.", node.from.key)
3048
3045
  return Status.FAILURE;
@@ -3055,7 +3052,7 @@ class State extends ReadyResource {
3055
3052
  };
3056
3053
 
3057
3054
  const validatorMessage = createMessage(
3058
- NETWORK_ID,
3055
+ this.#config.networkId,
3059
3056
  op.tro.tx,
3060
3057
  op.tro.vn,
3061
3058
  OperationType.TRANSFER
@@ -3066,7 +3063,7 @@ class State extends ReadyResource {
3066
3063
  return Status.FAILURE;
3067
3064
  };
3068
3065
 
3069
- const validatorMessageHash = await blake3Hash(validatorMessage);
3066
+ const validatorMessageHash = await PeerWallet.blake3Safe(validatorMessage);
3070
3067
  const isValidatorSignatureValid = this.#wallet.verify(op.tro.vs, validatorMessageHash, validatorPublicKey);
3071
3068
  if (!isValidatorSignatureValid) {
3072
3069
  this.#safeLogApply(OperationType.TRANSFER, "Failed to verify message signature.", node.from.key)
@@ -3104,7 +3101,7 @@ class State extends ReadyResource {
3104
3101
 
3105
3102
  // Check if recipient address is valid.
3106
3103
  const recipientAddressBuffer = op.tro.to;
3107
- const recipientAddressString = addressUtils.bufferToAddress(recipientAddressBuffer);
3104
+ const recipientAddressString = addressUtils.bufferToAddress(recipientAddressBuffer, this.#config.addressPrefix);
3108
3105
  if (recipientAddressString === null) {
3109
3106
  this.#safeLogApply(OperationType.TRANSFER, "Invalid recipient address.", node.from.key)
3110
3107
  return Status.FAILURE;
@@ -3170,7 +3167,7 @@ class State extends ReadyResource {
3170
3167
 
3171
3168
  await batch.put(hashHexString, node.value);
3172
3169
 
3173
- if (this.#enable_tx_apply_logs) {
3170
+ if (this.#config.enableTxApplyLogs) {
3174
3171
  console.info(`Transfer operation: ${hashHexString} has been appended.`);
3175
3172
  }
3176
3173
  return Status.SUCCESS;
@@ -3211,7 +3208,7 @@ class State extends ReadyResource {
3211
3208
  return null;
3212
3209
  }
3213
3210
 
3214
- const senderEntry = nodeEntryUtils.decode(senderEntryBuffer);
3211
+ const senderEntry = nodeEntryUtils.decode(senderEntryBuffer, this.#config.addressPrefix);
3215
3212
  if (senderEntry === null) {
3216
3213
  this.#safeLogApply(OperationType.TRANSFER, "Invalid sender node entry.", node.from.key)
3217
3214
  return null;
@@ -3264,7 +3261,7 @@ class State extends ReadyResource {
3264
3261
  };
3265
3262
  result.recipientEntry = newRecipientEntry;
3266
3263
  } else {
3267
- const recipientEntry = nodeEntryUtils.decode(recipientEntryBuffer);
3264
+ const recipientEntry = nodeEntryUtils.decode(recipientEntryBuffer, this.#config.addressPrefix);
3268
3265
  if (recipientEntry === null) {
3269
3266
  this.#safeLogApply(OperationType.TRANSFER, "Invalid recipient entry.", node.from.key)
3270
3267
  return null;
@@ -3291,7 +3288,7 @@ class State extends ReadyResource {
3291
3288
  }
3292
3289
  }
3293
3290
 
3294
- const validatorEntry = nodeEntryUtils.decode(validatorEntryBuffer);
3291
+ const validatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
3295
3292
  if (validatorEntry === null) {
3296
3293
  this.#safeLogApply(OperationType.TRANSFER, "Invalid validator entry.", node.from.key)
3297
3294
  return null;
@@ -3348,7 +3345,7 @@ class State extends ReadyResource {
3348
3345
  for (const indexer of Object.values(base.system.indexers)) {
3349
3346
  buf.push(indexer.key);
3350
3347
  }
3351
- return await blake3Hash(b4a.concat(buf));
3348
+ return await PeerWallet.blake3Safe(b4a.concat(buf));
3352
3349
  } catch (error) {
3353
3350
  console.error(error);
3354
3351
  return null;
@@ -3370,7 +3367,7 @@ class State extends ReadyResource {
3370
3367
  return false;
3371
3368
  };
3372
3369
 
3373
- const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer);
3370
+ const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
3374
3371
  if (decodedValidatorEntry === null) {
3375
3372
  this.#safeLogApply(op.type, "Failed to decode validator entry.", node.from.key)
3376
3373
  return false;
@@ -3432,7 +3429,7 @@ class State extends ReadyResource {
3432
3429
  }
3433
3430
 
3434
3431
  #safeLogApply(operationType = "Common", errorMessage, writingKey = null) {
3435
- if (!this.#enable_error_apply_logs) return;
3432
+ if (!this.#config.enableErrorApplyLogs) return;
3436
3433
  try {
3437
3434
  const date = new Date().toISOString();
3438
3435
  const wk = writingKey ? writingKey.toString('hex') : 'N/A';
@@ -3448,7 +3445,7 @@ class State extends ReadyResource {
3448
3445
  return null;
3449
3446
  }
3450
3447
 
3451
- const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer);
3448
+ const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer, this.#config.addressPrefix);
3452
3449
  if (decodedNodeEntry === null) {
3453
3450
  this.#safeLogApply("StakeBalance", "Failed to decode node entry", node.from.key);
3454
3451
  return null;
@@ -3492,7 +3489,7 @@ class State extends ReadyResource {
3492
3489
  return null;
3493
3490
  }
3494
3491
 
3495
- const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer);
3492
+ const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer, this.#config.addressPrefix);
3496
3493
  if (decodedNodeEntry === null) {
3497
3494
  this.#safeLogApply("withdrawStakedBalanceApply", "Failed to decode node entry", node.from.key);
3498
3495
  return null;
@@ -3543,7 +3540,7 @@ class State extends ReadyResource {
3543
3540
  this.#safeLogApply("ValidatorPenalty", "Admin entry not found", writingKeyBuffer);
3544
3541
  return;
3545
3542
  }
3546
- const adminEntry = adminEntryUtils.decode(adminEntryBuffer);
3543
+ const adminEntry = adminEntryUtils.decode(adminEntryBuffer, this.#config.addressPrefix);
3547
3544
  if (adminEntry === null) {
3548
3545
  this.#safeLogApply("ValidatorPenalty", "Failed to decode admin entry", writingKeyBuffer);
3549
3546
  return;
@@ -3563,7 +3560,7 @@ class State extends ReadyResource {
3563
3560
  return;
3564
3561
  }
3565
3562
 
3566
- const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer);
3563
+ const validatorAddressString = addressUtils.bufferToAddress(validatorAddressBuffer, this.#config.addressPrefix);
3567
3564
  if (validatorAddressString === null) {
3568
3565
  this.#safeLogApply("ValidatorPenalty", `Invalid validator address: ${validatorAddressString}`, writingKeyBuffer);
3569
3566
  return;
@@ -3581,7 +3578,7 @@ class State extends ReadyResource {
3581
3578
  return;
3582
3579
  }
3583
3580
 
3584
- const decodedValidatorNodeEntry = nodeEntryUtils.decode(validatorNodeEntryBuffer);
3581
+ const decodedValidatorNodeEntry = nodeEntryUtils.decode(validatorNodeEntryBuffer, this.#config.addressPrefix);
3585
3582
  if (decodedValidatorNodeEntry === null) {
3586
3583
  this.#safeLogApply("ValidatorPenalty", `Failed to decode validator node entry for address: ${validatorAddressString}`, writingKeyBuffer);
3587
3584
  return;
@@ -3715,7 +3712,7 @@ class State extends ReadyResource {
3715
3712
  return null;
3716
3713
  }
3717
3714
 
3718
- const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer);
3715
+ const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer, this.#config.addressPrefix);
3719
3716
  if (requesterNodeEntry === null) {
3720
3717
  this.#safeLogApply("transferFeeTxOperation", "Invalid requester node entry, can not to decode.", node.from.key)
3721
3718
  return null;
@@ -3746,7 +3743,7 @@ class State extends ReadyResource {
3746
3743
 
3747
3744
  // Validator always gets 50% of the fee by the base
3748
3745
 
3749
- const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer);
3746
+ const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
3750
3747
  if (validatorNodeEntry === null) {
3751
3748
  this.#safeLogApply("transferFeeTxOperation", "Invalid validator node entry, can not to decode.", node.from.key)
3752
3749
  return null;
@@ -3816,7 +3813,7 @@ class State extends ReadyResource {
3816
3813
  return null;
3817
3814
  }
3818
3815
 
3819
- const subnetworkCreatorNodeEntry = nodeEntryUtils.decode(subnetworkCreatorNodeEntryBuffer);
3816
+ const subnetworkCreatorNodeEntry = nodeEntryUtils.decode(subnetworkCreatorNodeEntryBuffer, this.#config.addressPrefix);
3820
3817
  if (subnetworkCreatorNodeEntry === null) {
3821
3818
  this.#safeLogApply("transferFeeTxOperation", "Invalid subnetwork creator node entry, can not to decode.", node.from.key)
3822
3819
  return null;