trac-msb 0.2.7 → 0.2.9

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