trac-msb 0.2.17 → 0.2.19

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 (365) hide show
  1. package/README.md +62 -2
  2. package/SECURITY.md +9 -6
  3. package/cli/commandHandler.js +272 -0
  4. package/cli/handlers.js +210 -0
  5. package/cli/interactive.js +182 -0
  6. package/msb.mjs +7 -8
  7. package/package.json +33 -11
  8. package/rpc/create_server.js +44 -44
  9. package/rpc/handlers.js +43 -56
  10. package/rpc/routes/index.js +8 -8
  11. package/rpc/rpc_server.js +6 -2
  12. package/rpc/utils/helpers.js +46 -66
  13. package/scripts/pear-runner.js +170 -0
  14. package/src/config/args.js +60 -13
  15. package/src/config/config.js +163 -14
  16. package/src/config/env.js +57 -25
  17. package/src/core/network/Network.js +121 -56
  18. package/src/core/network/protocols/LegacyProtocol.js +21 -11
  19. package/src/core/network/protocols/NetworkMessages.js +38 -17
  20. package/src/core/network/protocols/ProtocolInterface.js +15 -3
  21. package/src/core/network/protocols/ProtocolSession.js +144 -17
  22. package/src/core/network/protocols/V1Protocol.js +37 -18
  23. package/src/core/network/protocols/connectionPolicies.js +174 -0
  24. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +26 -20
  25. package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +25 -14
  26. package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +9 -9
  27. package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
  28. package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +19 -12
  29. package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +29 -18
  30. package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +18 -12
  31. package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
  32. package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
  33. package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +53 -31
  34. package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
  35. package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
  36. package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +32 -14
  37. package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
  38. package/src/core/network/protocols/v1/V1ProtocolError.js +27 -0
  39. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +66 -0
  40. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +272 -0
  41. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +88 -0
  42. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
  43. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
  44. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
  45. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +212 -0
  46. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +28 -0
  47. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +260 -0
  48. package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
  49. package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
  50. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
  51. package/src/core/network/services/ConnectionManager.js +149 -96
  52. package/src/core/network/services/MessageOrchestrator.js +197 -37
  53. package/src/core/network/services/PendingRequestService.js +175 -0
  54. package/src/core/network/services/TransactionCommitService.js +149 -0
  55. package/src/core/network/services/TransactionPoolService.js +129 -18
  56. package/src/core/network/services/TransactionRateLimiterService.js +57 -35
  57. package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
  58. package/src/core/network/services/ValidatorObserverService.js +400 -121
  59. package/src/core/state/State.js +259 -156
  60. package/src/core/state/utils/address.js +4 -9
  61. package/src/core/state/utils/balance.js +7 -7
  62. package/src/core/state/utils/roles.js +1 -1
  63. package/src/index.js +320 -278
  64. package/src/messages/network/v1/NetworkMessageBuilder.js +71 -100
  65. package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
  66. package/src/messages/network/v1/networkMessageFactory.js +1 -1
  67. package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
  68. package/src/messages/state/applyStateMessageFactory.js +1 -1
  69. package/src/utils/Scheduler.js +0 -8
  70. package/src/utils/buffer.js +1 -1
  71. package/src/utils/check.js +12 -13
  72. package/src/utils/constants.js +78 -5
  73. package/src/utils/deepEqualApplyPayload.js +40 -0
  74. package/src/utils/errors.js +20 -0
  75. package/src/utils/fileUtils.js +12 -3
  76. package/src/utils/helpers.js +10 -1
  77. package/src/utils/logger.js +25 -0
  78. package/src/utils/migrationUtils.js +3 -3
  79. package/src/utils/normalizers.js +38 -0
  80. package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
  81. package/src/utils/protobuf/operationHelpers.js +24 -3
  82. package/.dockerignore +0 -16
  83. package/.github/workflows/acceptance-tests.yml +0 -38
  84. package/.github/workflows/lint-pr-title.yml +0 -26
  85. package/.github/workflows/publish.yml +0 -33
  86. package/.github/workflows/unit-tests.yml +0 -34
  87. package/CODE_OF_CONDUCT.md +0 -128
  88. package/docker-compose.yml +0 -17
  89. package/dockerfile +0 -41
  90. package/docs/fee_distribution.md +0 -89
  91. package/docs/trac_network_http_api.openapi.yaml +0 -889
  92. package/migration/.gitkeep +0 -0
  93. package/proto/applyOperations.proto +0 -117
  94. package/proto/network.proto +0 -74
  95. package/rpc/rpc_services.js +0 -163
  96. package/scripts/generate-protobufs.js +0 -42
  97. package/src/core/network/identity/NetworkWalletFactory.js +0 -77
  98. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
  99. package/src/utils/cli.js +0 -130
  100. package/src/utils/cliCommands.js +0 -280
  101. package/src/utils/protobuf/network.cjs +0 -840
  102. package/tests/acceptance/v1/account/account.test.mjs +0 -123
  103. package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
  104. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
  105. package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
  106. package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
  107. package/tests/acceptance/v1/health/health.test.mjs +0 -33
  108. package/tests/acceptance/v1/rpc.test.mjs +0 -95
  109. package/tests/acceptance/v1/tx/tx.test.mjs +0 -111
  110. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -213
  111. package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
  112. package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
  113. package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
  114. package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
  115. package/tests/fixtures/apply.fixtures.js +0 -77
  116. package/tests/fixtures/assembleMessage.fixtures.js +0 -41
  117. package/tests/fixtures/check.fixtures.js +0 -428
  118. package/tests/fixtures/networkV1.fixtures.js +0 -85
  119. package/tests/fixtures/protobuf.fixtures.js +0 -388
  120. package/tests/helpers/StateNetworkFactory.js +0 -155
  121. package/tests/helpers/address.js +0 -6
  122. package/tests/helpers/autobaseTestHelpers.js +0 -419
  123. package/tests/helpers/config.js +0 -4
  124. package/tests/helpers/createTestSignature.js +0 -13
  125. package/tests/helpers/regexHelper.js +0 -3
  126. package/tests/helpers/setupApplyTests.js +0 -587
  127. package/tests/helpers/transactionPayloads.mjs +0 -92
  128. package/tests/helpers/wrapper.js +0 -28
  129. package/tests/unit/messages/messages.test.js +0 -12
  130. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -276
  131. package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -201
  132. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
  133. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
  134. package/tests/unit/network/ConnectionManager.test.js +0 -191
  135. package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
  136. package/tests/unit/network/networkModule.test.js +0 -10
  137. package/tests/unit/state/State.test.js +0 -80
  138. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
  139. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
  140. package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
  141. package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
  142. package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
  143. package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
  144. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
  145. package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
  146. package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
  147. package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
  148. package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
  149. package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
  150. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
  151. package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
  152. package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
  153. package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
  154. package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
  155. package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
  156. package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
  157. package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
  158. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
  159. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
  160. package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
  161. package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
  162. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
  163. package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
  164. package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
  165. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
  166. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
  167. package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
  168. package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
  169. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
  170. package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
  171. package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
  172. package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
  173. package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
  174. package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
  175. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
  176. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
  177. package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
  178. package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
  179. package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
  180. package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
  181. package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
  182. package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
  183. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
  184. package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
  185. package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
  186. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
  187. package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
  188. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
  189. package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
  190. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
  191. package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
  192. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
  193. package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
  194. package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
  195. package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
  196. package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
  197. package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
  198. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
  199. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
  200. package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
  201. package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
  202. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
  203. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
  204. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
  205. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
  206. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
  207. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
  208. package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
  209. package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
  210. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
  211. package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
  212. package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
  213. package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
  214. package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
  215. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
  216. package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
  217. package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
  218. package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
  219. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
  220. package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
  221. package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
  222. package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
  223. package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
  224. package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
  225. package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
  226. package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
  227. package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
  228. package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
  229. package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
  230. package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
  231. package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
  232. package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
  233. package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
  234. package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
  235. package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
  236. package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
  237. package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
  238. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
  239. package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
  240. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
  241. package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
  242. package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
  243. package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
  244. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
  245. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
  246. package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
  247. package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
  248. package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
  249. package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
  250. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
  251. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
  252. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
  253. package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
  254. package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
  255. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
  256. package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
  257. package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
  258. package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
  259. package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
  260. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
  261. package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
  262. package/tests/unit/state/apply/missing-tests.md +0 -18
  263. package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
  264. package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
  265. package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
  266. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
  267. package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
  268. package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
  269. package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
  270. package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
  271. package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
  272. package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
  273. package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
  274. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
  275. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
  276. package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
  277. package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
  278. package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
  279. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
  280. package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
  281. package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
  282. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
  283. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
  284. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
  285. package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
  286. package/tests/unit/state/apply/state.apply.test.js +0 -24
  287. package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
  288. package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
  289. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
  290. package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
  291. package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
  292. package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
  293. package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
  294. package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
  295. package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
  296. package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
  297. package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
  298. package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
  299. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
  300. package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
  301. package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
  302. package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
  303. package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
  304. package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
  305. package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
  306. package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
  307. package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
  308. package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
  309. package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
  310. package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
  311. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
  312. package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
  313. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
  314. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
  315. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
  316. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
  317. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
  318. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
  319. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
  320. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
  321. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
  322. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
  323. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
  324. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
  325. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
  326. package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
  327. package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
  328. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
  329. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
  330. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
  331. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
  332. package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
  333. package/tests/unit/state/stateModule.test.js +0 -23
  334. package/tests/unit/state/stateTestUtils.js +0 -32
  335. package/tests/unit/state/utils/address.test.js +0 -63
  336. package/tests/unit/state/utils/adminEntry.test.js +0 -52
  337. package/tests/unit/state/utils/balance.test.js +0 -320
  338. package/tests/unit/state/utils/lengthEntry.test.js +0 -54
  339. package/tests/unit/state/utils/nodeEntry.test.js +0 -298
  340. package/tests/unit/state/utils/roles.test.js +0 -44
  341. package/tests/unit/unit.test.js +0 -14
  342. package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
  343. package/tests/unit/utils/buffer/buffer.test.js +0 -251
  344. package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
  345. package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
  346. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
  347. package/tests/unit/utils/check/check.test.js +0 -17
  348. package/tests/unit/utils/check/common.test.js +0 -419
  349. package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
  350. package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
  351. package/tests/unit/utils/check/transactionOperation.test.js +0 -107
  352. package/tests/unit/utils/check/transferOperation.test.js +0 -102
  353. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
  354. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
  355. package/tests/unit/utils/helpers/helpers.test.js +0 -11
  356. package/tests/unit/utils/helpers/isHexString.test.js +0 -12
  357. package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
  358. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
  359. package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
  360. package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
  361. package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -305
  362. package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
  363. package/tests/unit/utils/type/type.test.js +0 -25
  364. package/tests/unit/utils/utils.test.js +0 -20
  365. package/whitelist/.gitkeep +0 -0
@@ -16,10 +16,10 @@ import {
16
16
  CustomEventType
17
17
  } from '../../utils/constants.js';
18
18
  import { isHexString, sleep, isTransactionRecordPut } from '../../utils/helpers.js';
19
- import PeerWallet from 'trac-wallet';
19
+ import tracCryptoApi from 'trac-crypto-api';
20
20
  import Check from '../../utils/check.js';
21
21
  import { safeDecodeApplyOperation } from '../../utils/protobuf/operationHelpers.js';
22
- import { createMessage, ZERO_WK } from '../../utils/buffer.js';
22
+ import { createMessage, ZERO_WK, NULL_BUFFER } from '../../utils/buffer.js';
23
23
  import addressUtils from './utils/address.js';
24
24
  import adminEntryUtils from './utils/adminEntry.js';
25
25
  import nodeEntryUtils, { setWritingKey, NODE_ENTRY_SIZE } from './utils/nodeEntry.js';
@@ -40,32 +40,34 @@ import { safeWriteUInt32BE } from '../../utils/buffer.js';
40
40
  import deploymentEntryUtils from './utils/deploymentEntry.js';
41
41
  import { deepCopyBuffer } from '../../utils/buffer.js';
42
42
  import { Status } from './utils/transaction.js';
43
- import Corestore from 'corestore';
43
+ import remote from 'hypercore/lib/fully-remote-proof.js'
44
+ import PQueue from 'p-queue';
44
45
 
45
46
  const OVERSIZED_BATCH_PENALTY_MULTIPLIER = BATCH_SIZE;
46
47
 
47
48
  // TODO: #addWriter, #removeWriter, #transfer, #transferFeeTxOperation need to be refactored to get in arguments actor's nodeEntries in buffer format.
48
49
 
49
50
  class State extends ReadyResource {
51
+ #writeQueue = new PQueue({ concurrency: 1 });
50
52
  #base;
51
53
  #bee;
52
54
  #store;
53
- #wallet;
54
55
  #writingKey;
55
56
  #config
57
+ #wallet
58
+ #activeWriterCountCache = new Map();
56
59
 
57
60
  /**
58
61
  * @param {Corestore} store
59
- * @param {PeerWallet} wallet
62
+ * @param {IWallet} wallet
60
63
  * @param {Config} config
61
64
  **/
62
65
  constructor(store, wallet, config) {
63
66
  super();
64
67
 
65
68
  this.#config = config
66
-
69
+ this.#wallet = wallet
67
70
  this.#store = store;
68
- this.#wallet = wallet;
69
71
 
70
72
  this.check = new Check(config);
71
73
  this.#base = new Autobase(this.#store, this.#config.bootstrap, {
@@ -136,6 +138,17 @@ class State extends ReadyResource {
136
138
  return result.value;
137
139
  }
138
140
 
141
+ async waitForUnsigned(txHash, timeout, interval = 200) {
142
+ const start = Date.now();
143
+ while (Date.now() - start < timeout) {
144
+ await sleep(interval);
145
+ const entry = await this.get(txHash);
146
+ if (entry) return true;
147
+ }
148
+
149
+ return false;
150
+ }
151
+
139
152
  async getSigned(key) {
140
153
  const view_session = this.#base.view.checkout(this.#base.view.core.signedLength);
141
154
  try {
@@ -173,11 +186,19 @@ class State extends ReadyResource {
173
186
 
174
187
  return !!(localWritable && !localIndexer) && (unsignedIsWriter && !unsignedIsIndexer)
175
188
  }
189
+
190
+ async isAdmin() {
191
+ const adminEntry = await this.getAdminEntry();
192
+ return !!adminEntry && this.#wallet?.address === adminEntry?.address && b4a.equals(adminEntry?.wk, this.writingKey)
193
+ }
176
194
 
177
195
  async isAdminAllowedToValidate() {
196
+ if (!this.writingKey) return false;
197
+
178
198
  const isAdmin = this.writingKey.toString('hex') === this.#config.bootstrap.toString('hex');
179
199
  const isIndexer = this.isIndexer();
180
- const lengthCondition = await this.getWriterLength() <= this.#config.maxWritersForAdminIndexerConnection;
200
+ const activeWriters = await this.getActiveWriterCount(true);
201
+ const lengthCondition = activeWriters < this.#config.maxWritersForAdminIndexerConnection;
181
202
  return !!(isAdmin && isIndexer && lengthCondition);
182
203
  }
183
204
 
@@ -187,20 +208,41 @@ class State extends ReadyResource {
187
208
  return !!nodeEntry.isWhitelisted;
188
209
  }
189
210
 
190
- async isAddressWriter(address) {
191
- const nodeEntry = await this.getNodeEntry(address);
192
- if (nodeEntry === null) return false;
193
- return !!nodeEntry.isWriter;
211
+ async getIndexersEntry() {
212
+ return Object.values(this.#base.system.indexers);
194
213
  }
195
214
 
196
- async isAddressIndexer(address) {
197
- const nodeEntry = await this.getNodeEntry(address);
198
- if (nodeEntry === null) return false;
199
- return !!nodeEntry.isIndexer;
200
- }
215
+ async getActiveWriterCount(excludeAdmin = false) {
216
+ const cached = this.#activeWriterCountCache.get(excludeAdmin);
217
+ const systemLength = this.#base.system?.core?.length ?? -1;
201
218
 
202
- async getIndexersEntry() {
203
- return Object.values(this.#base.system.indexers);
219
+ if (cached && cached.systemLength === systemLength) {
220
+ return cached.value;
221
+ }
222
+
223
+ const activeAddresses = new Set();
224
+ const adminAddress = (await this.getAdminEntry())?.address ?? null;
225
+
226
+ for await (const { key, value } of this.#base.system.list()) {
227
+ if (!key || !value || value.isRemoved) continue;
228
+
229
+ const writerKeyHex = key.toString('hex');
230
+ const addressBuffer = await this.getRegisteredWriterKey(writerKeyHex);
231
+ if (!addressBuffer) continue;
232
+
233
+ const address = addressUtils.bufferToAddress(addressBuffer, this.#config.addressPrefix);
234
+ if (!address) continue;
235
+
236
+ // Non-admin indexers do not participate in validator capacity decisions.
237
+ if (value.isIndexer && address !== adminAddress) continue;
238
+ if (excludeAdmin && address === adminAddress) continue;
239
+
240
+ activeAddresses.add(address);
241
+ }
242
+
243
+ const count = activeAddresses.size;
244
+ this.#activeWriterCountCache.set(excludeAdmin, { systemLength, value: count });
245
+ return count;
204
246
  }
205
247
 
206
248
  async isWkInIndexersEntry(wk) {
@@ -243,7 +285,67 @@ class State extends ReadyResource {
243
285
  }
244
286
 
245
287
  async append(payload) {
246
- await this.#base.append(payload);
288
+ return this.#writeQueue.add(() => this.#base.append(payload));
289
+ }
290
+
291
+ async appendWithProofOfPublication(batch, batchTxHashes) {
292
+ return this.#writeQueue.add(async () => {
293
+
294
+ const core = this.#base.local;
295
+ const end = await this.#base.append(batch);
296
+ const start = end - batch.length;
297
+ const timestamp = new Date();
298
+ const snapshot = core.snapshot(); // consistent view while generating proofs.
299
+ await snapshot.ready();
300
+ // TODO: check state if specific tx has been appened THEN generate a proof.
301
+ try {
302
+ const receipts = [];
303
+ let failedProofs = 0;
304
+ for (let i = 0; i < batch.length; i++) {
305
+ const blockNumber = start + i;
306
+ const completeTx = batch[i];
307
+ const txHash = batchTxHashes[i];
308
+
309
+ let proof = null;
310
+ let proofError = null;
311
+
312
+ // wait:false makes get fail fast (null) instead of waiting for missing data/replication.
313
+ const rawBlock = await snapshot.get(blockNumber, { raw: true, wait: false });
314
+ if (!rawBlock) {
315
+ proofError = `Missing raw block after append (block=${blockNumber}, start=${start}, end=${end})`;
316
+ failedProofs++;
317
+ } else {
318
+ try {
319
+ proof = await remote.proof(snapshot, { index: blockNumber, block: rawBlock });
320
+ } catch (error) {
321
+ proofError = `Proof generation failed (block=${blockNumber}, start=${start}, end=${end}): ${error?.message ?? 'unknown error'}`;
322
+ failedProofs++;
323
+ }
324
+ }
325
+ receipts.push({
326
+ txHash,
327
+ completeTx,
328
+ proof,
329
+ proofError,
330
+ timestamp,
331
+ blockNumber
332
+ });
333
+ }
334
+ if (failedProofs > 0) {
335
+ console.error(`appendWithProof completed with ${failedProofs} proof failures (batch=${batch.length})`);
336
+ }
337
+ return receipts;
338
+ } finally {
339
+ await snapshot.close();
340
+ }
341
+ });
342
+ }
343
+
344
+ async verifyProofOfPublication(proof) {
345
+ // Valid concern. We currently rely on Hypercore’s internal fully-remote-proof helper, which requires low-level storage access
346
+ const out = await remote.verify(this.#store.storage, proof);
347
+ if (!out) throw new Error('Proof of publication verification failed');
348
+ return out;
247
349
  }
248
350
 
249
351
  async getIndexerSequenceState() {
@@ -251,7 +353,7 @@ class State extends ReadyResource {
251
353
  for (const indexer of Object.values(this.#base.system.indexers)) {
252
354
  buf.push(indexer.key);
253
355
  }
254
- return await PeerWallet.blake3(b4a.concat(buf));
356
+ return await tracCryptoApi.hash.blake3(b4a.concat(buf));
255
357
  }
256
358
 
257
359
  async isInitalizationDisabled() {
@@ -264,6 +366,7 @@ class State extends ReadyResource {
264
366
  return b4a.equals(initialization, safeWriteUInt32BE(0, 0))
265
367
  }
266
368
  }
369
+
267
370
  async getTransactionConfirmedLength(hash) {
268
371
  if (!isHexString(hash) || hash.length !== 64) {
269
372
  throw new Error("Invalid hash format");
@@ -437,8 +540,8 @@ class State extends ReadyResource {
437
540
  }
438
541
 
439
542
  // Verify requester admin public key
440
- const requesterAdminPublicKey = PeerWallet.decodeBech32mSafe(adminAddressString);
441
- if (requesterAdminPublicKey === null) {
543
+ const requesterAdminPublicKey = tracCryptoApi.address.decodeSafe(adminAddressString);
544
+ if (b4a.equals(requesterAdminPublicKey, NULL_BUFFER)) {
442
545
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Error while decoding requester public key.", node.from.key)
443
546
  return Status.FAILURE;
444
547
  };
@@ -452,8 +555,8 @@ class State extends ReadyResource {
452
555
  };
453
556
 
454
557
  // Validate recipient public key
455
- const recipientPublicKey = PeerWallet.decodeBech32mSafe(recipientAddressString);
456
- if (recipientPublicKey === null) {
558
+ const recipientPublicKey = tracCryptoApi.address.decodeSafe(recipientAddressString);
559
+ if (b4a.equals(recipientPublicKey, NULL_BUFFER)) {
457
560
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Failed to decode recipient public key.", node.from.key)
458
561
  return Status.FAILURE;
459
562
  };
@@ -485,8 +588,8 @@ class State extends ReadyResource {
485
588
  return Status.FAILURE;
486
589
  };
487
590
 
488
- const adminPublicKey = PeerWallet.decodeBech32mSafe(decodedAdminEntry.address);
489
- if (adminPublicKey === null) {
591
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(decodedAdminEntry.address);
592
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
490
593
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Failed to decode admin public key.", node.from.key)
491
594
  return Status.FAILURE;
492
595
  };
@@ -511,7 +614,7 @@ class State extends ReadyResource {
511
614
  return Status.FAILURE;
512
615
  };
513
616
 
514
- const hash = await PeerWallet.blake3Safe(message);
617
+ const hash = await tracCryptoApi.hash.blake3Safe(message);
515
618
  const txHashHexString = op.bio.tx.toString('hex');
516
619
  if (!b4a.equals(hash, op.bio.tx)) {
517
620
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Message hash does not match the tx_hash.", node.from.key)
@@ -519,7 +622,7 @@ class State extends ReadyResource {
519
622
  };
520
623
 
521
624
  // Verify signature
522
- const isMessageVerifed = this.#wallet.verify(op.bio.is, hash, adminPublicKey);
625
+ const isMessageVerifed = tracCryptoApi.signature.verify(op.bio.is, hash, adminPublicKey);
523
626
  if (!isMessageVerifed) {
524
627
  this.#safeLogApply(OperationType.BALANCE_INITIALIZATION, "Failed to verify message signature.", node.from.key)
525
628
  return Status.FAILURE;
@@ -588,8 +691,8 @@ class State extends ReadyResource {
588
691
  };
589
692
 
590
693
  // Validate requester admin public key
591
- const requesterAdminPublicKey = PeerWallet.decodeBech32mSafe(adminAddressString);
592
- if (requesterAdminPublicKey === null) {
694
+ const requesterAdminPublicKey = tracCryptoApi.address.decodeSafe(adminAddressString);
695
+ if (b4a.equals(requesterAdminPublicKey, NULL_BUFFER)) {
593
696
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Failed to decode requester public key.", node.from.key)
594
697
  return Status.FAILURE;
595
698
  };
@@ -608,8 +711,8 @@ class State extends ReadyResource {
608
711
  return Status.FAILURE;
609
712
  };
610
713
 
611
- const adminPublicKey = PeerWallet.decodeBech32mSafe(decodedAdminEntry.address);
612
- if (adminPublicKey === null) {
714
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(decodedAdminEntry.address);
715
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
613
716
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Failed to decode admin public key.", node.from.key)
614
717
  return Status.FAILURE;
615
718
  };
@@ -633,7 +736,7 @@ class State extends ReadyResource {
633
736
  return Status.FAILURE;
634
737
  };
635
738
 
636
- const hash = await PeerWallet.blake3Safe(message);
739
+ const hash = await tracCryptoApi.hash.blake3Safe(message);
637
740
  const txHashHexString = op.cao.tx.toString('hex');
638
741
  if (!b4a.equals(hash, op.cao.tx)) {
639
742
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Message hash does not match the tx_hash.", node.from.key)
@@ -641,7 +744,7 @@ class State extends ReadyResource {
641
744
  };
642
745
 
643
746
  // Verify signature
644
- const isMessageVerifed = this.#wallet.verify(op.cao.is, hash, adminPublicKey);
747
+ const isMessageVerifed = tracCryptoApi.signature.verify(op.cao.is, hash, adminPublicKey);
645
748
  if (!isMessageVerifed) {
646
749
  this.#safeLogApply(OperationType.DISABLE_INITIALIZATION, "Failed to verify message signature.", node.from.key)
647
750
  return Status.FAILURE;
@@ -693,8 +796,8 @@ class State extends ReadyResource {
693
796
  };
694
797
 
695
798
  // Validate requester admin public key (admin)
696
- const adminPublicKey = PeerWallet.decodeBech32mSafe(adminAddressString);
697
- if (adminPublicKey === null) {
799
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(adminAddressString);
800
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
698
801
  this.#safeLogApply(OperationType.ADD_ADMIN, "Error while decoding requester public key.", node.from.key)
699
802
  return Status.FAILURE;
700
803
  };
@@ -719,14 +822,14 @@ class State extends ReadyResource {
719
822
  return Status.FAILURE;
720
823
  };
721
824
 
722
- const hash = await PeerWallet.blake3Safe(requesterMessage);
825
+ const hash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
723
826
  if (!b4a.equals(hash, op.cao.tx)) {
724
827
  this.#safeLogApply(OperationType.ADD_ADMIN, "Message hash does not match the tx_hash.", node.from.key)
725
828
  return Status.FAILURE;
726
829
  };
727
830
 
728
831
  // verify signature
729
- const isMessageVerifed = this.#wallet.verify(op.cao.is, op.cao.tx, adminPublicKey)
832
+ const isMessageVerifed = tracCryptoApi.signature.verify(op.cao.is, op.cao.tx, adminPublicKey)
730
833
  const txHashHexString = op.cao.tx.toString('hex');
731
834
  if (!isMessageVerifed) {
732
835
  this.#safeLogApply(OperationType.ADD_ADMIN, "Failed to verify message signature.", node.from.key)
@@ -853,8 +956,8 @@ class State extends ReadyResource {
853
956
  return Status.FAILURE;
854
957
  };
855
958
 
856
- const requesterAdminPublicKey = PeerWallet.decodeBech32mSafe(requesterAdminAddressString);
857
- if (requesterAdminPublicKey === null) {
959
+ const requesterAdminPublicKey = tracCryptoApi.address.decodeSafe(requesterAdminAddressString);
960
+ if (b4a.equals(requesterAdminPublicKey, NULL_BUFFER)) {
858
961
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Error while decoding requester public key.", node.from.key)
859
962
  return Status.FAILURE;
860
963
  };
@@ -873,14 +976,14 @@ class State extends ReadyResource {
873
976
  return Status.FAILURE;
874
977
  };
875
978
 
876
- const hash = await PeerWallet.blake3Safe(requesterMessage);
979
+ const hash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
877
980
  if (!b4a.equals(hash, op.rao.tx)) {
878
981
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Message hash does not match the tx_hash.", node.from.key)
879
982
  return Status.FAILURE;
880
983
  };
881
984
 
882
985
  // verify requester signature
883
- const isRequesterMessageVerifed = this.#wallet.verify(op.rao.is, op.rao.tx, requesterAdminPublicKey);
986
+ const isRequesterMessageVerifed = tracCryptoApi.signature.verify(op.rao.is, op.rao.tx, requesterAdminPublicKey);
884
987
  const txHashHexString = op.rao.tx.toString('hex');
885
988
  if (!isRequesterMessageVerifed) {
886
989
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to verify requester message signature.", node.from.key)
@@ -895,8 +998,8 @@ class State extends ReadyResource {
895
998
  return Status.FAILURE;
896
999
  };
897
1000
 
898
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
899
- if (validatorPublicKey === null) {
1001
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
1002
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
900
1003
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to decode validator public key.", node.from.key)
901
1004
  return Status.FAILURE;
902
1005
  };
@@ -915,8 +1018,8 @@ class State extends ReadyResource {
915
1018
  };
916
1019
 
917
1020
  // verify validator signature
918
- const validatorHash = await PeerWallet.blake3Safe(validatorMessage);
919
- const isValidatorMessageVerifed = this.#wallet.verify(op.rao.vs, validatorHash, validatorPublicKey);
1021
+ const validatorHash = await tracCryptoApi.hash.blake3Safe(validatorMessage);
1022
+ const isValidatorMessageVerifed = tracCryptoApi.signature.verify(op.rao.vs, validatorHash, validatorPublicKey);
920
1023
  if (!isValidatorMessageVerifed) {
921
1024
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to verify message signature.", node.from.key)
922
1025
  return Status.FAILURE;
@@ -958,7 +1061,7 @@ class State extends ReadyResource {
958
1061
  return Status.FAILURE;
959
1062
  };
960
1063
 
961
- const publicKeyAdminEntry = PeerWallet.decodeBech32mSafe(decodedAdminEntry.address);
1064
+ const publicKeyAdminEntry = tracCryptoApi.address.decodeSafe(decodedAdminEntry.address);
962
1065
  if (!b4a.equals(requesterAdminPublicKey, publicKeyAdminEntry)) {
963
1066
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Admin public key does not match the node public key.", node.from.key)
964
1067
  return Status.FAILURE;
@@ -996,7 +1099,7 @@ class State extends ReadyResource {
996
1099
  }; // New admin wk is already in indexers entry
997
1100
 
998
1101
  // charging fee from the requester (admin)
999
- const decodedAdminNodeEntry = nodeEntryUtils.decode(newAdminNodeEntry, this.#config.addressPrefix)
1102
+ const decodedAdminNodeEntry = nodeEntryUtils.decode(newAdminNodeEntry)
1000
1103
  if (decodedAdminNodeEntry === null) {
1001
1104
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Failed to decode node entry.", node.from.key)
1002
1105
  return Status.FAILURE;
@@ -1021,7 +1124,7 @@ class State extends ReadyResource {
1021
1124
  const chargedAdminEntry = updatedFee.update(newAdminNodeEntry)
1022
1125
 
1023
1126
  // Reward logic
1024
- const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
1127
+ const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer);
1025
1128
  if (validatorNodeEntry === null) {
1026
1129
  this.#safeLogApply(OperationType.ADMIN_RECOVERY, "Invalid validator node entry.", node.from.key)
1027
1130
  return Status.FAILURE;
@@ -1080,8 +1183,8 @@ class State extends ReadyResource {
1080
1183
  return Status.FAILURE;
1081
1184
  };
1082
1185
  // Validate recipient public key
1083
- const requesterAdminPublicKey = PeerWallet.decodeBech32mSafe(adminAddressString);
1084
- if (requesterAdminPublicKey === null) {
1186
+ const requesterAdminPublicKey = tracCryptoApi.address.decodeSafe(adminAddressString);
1187
+ if (b4a.equals(requesterAdminPublicKey, NULL_BUFFER)) {
1085
1188
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to decode recipient public key.", node.from.key)
1086
1189
  return Status.FAILURE;
1087
1190
  };
@@ -1106,8 +1209,8 @@ class State extends ReadyResource {
1106
1209
 
1107
1210
  // Extract admin entry
1108
1211
  const adminAddress = decodedAdminEntry.address;
1109
- const adminPublicKey = PeerWallet.decodeBech32mSafe(adminAddress);
1110
- if (adminPublicKey === null) {
1212
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(adminAddress);
1213
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
1111
1214
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to decode admin public key.", node.from.key)
1112
1215
  return Status.FAILURE;
1113
1216
  };
@@ -1126,8 +1229,8 @@ class State extends ReadyResource {
1126
1229
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to verify node address.", node.from.key)
1127
1230
  return Status.FAILURE;
1128
1231
  };
1129
- const nodePublicKey = PeerWallet.decodeBech32mSafe(nodeAddressString);
1130
- if (nodePublicKey === null) {
1232
+ const nodePublicKey = tracCryptoApi.address.decodeSafe(nodeAddressString);
1233
+ if (b4a.equals(nodePublicKey, NULL_BUFFER)) {
1131
1234
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to decode node public key.", node.from.key)
1132
1235
  return Status.FAILURE;
1133
1236
  };
@@ -1146,13 +1249,13 @@ class State extends ReadyResource {
1146
1249
  };
1147
1250
 
1148
1251
  // verify signature
1149
- const hash = await PeerWallet.blake3Safe(message);
1252
+ const hash = await tracCryptoApi.hash.blake3Safe(message);
1150
1253
  if (!b4a.equals(hash, op.aco.tx)) {
1151
1254
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Message hash does not match the tx_hash.", node.from.key)
1152
1255
  return Status.FAILURE;
1153
1256
  };
1154
1257
 
1155
- const isMessageVerified = this.#wallet.verify(op.aco.is, op.aco.tx, adminPublicKey);
1258
+ const isMessageVerified = tracCryptoApi.signature.verify(op.aco.is, op.aco.tx, adminPublicKey);
1156
1259
  if (!isMessageVerified) {
1157
1260
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to verify message signature.", node.from.key)
1158
1261
  return Status.FAILURE;
@@ -1194,7 +1297,7 @@ class State extends ReadyResource {
1194
1297
  return Status.FAILURE;
1195
1298
  };
1196
1299
 
1197
- const decodedNodeEntry = nodeEntryUtils.decode(adminNodeEntry, this.#config.addressPrefix)
1300
+ const decodedNodeEntry = nodeEntryUtils.decode(adminNodeEntry)
1198
1301
  if (decodedNodeEntry === null) {
1199
1302
  this.#safeLogApply(OperationType.APPEND_WHITELIST, "Failed to decode admin entry.", node.from.key)
1200
1303
  return Status.FAILURE;
@@ -1353,8 +1456,8 @@ class State extends ReadyResource {
1353
1456
  return Status.FAILURE;
1354
1457
  };
1355
1458
 
1356
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
1357
- if (requesterPublicKey === null) {
1459
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
1460
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
1358
1461
  this.#safeLogApply(OperationType.ADD_WRITER, "Error while decoding requester public key.", node.from.key)
1359
1462
  return Status.FAILURE;
1360
1463
  };
@@ -1379,13 +1482,13 @@ class State extends ReadyResource {
1379
1482
  return Status.FAILURE;
1380
1483
  };
1381
1484
 
1382
- const hash = await PeerWallet.blake3Safe(requesterMessage);
1485
+ const hash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
1383
1486
  if (!b4a.equals(hash, op.rao.tx)) {
1384
1487
  this.#safeLogApply(OperationType.ADD_WRITER, "Message hash does not match the tx_hash.", node.from.key)
1385
1488
  return Status.FAILURE;
1386
1489
  };
1387
1490
 
1388
- const isRequesterMessageVerifed = this.#wallet.verify(op.rao.is, op.rao.tx, requesterPublicKey);
1491
+ const isRequesterMessageVerifed = tracCryptoApi.signature.verify(op.rao.is, op.rao.tx, requesterPublicKey);
1389
1492
  const txHashHexString = op.rao.tx.toString('hex');
1390
1493
  if (!isRequesterMessageVerifed) {
1391
1494
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to verify message signature.", node.from.key)
@@ -1401,8 +1504,8 @@ class State extends ReadyResource {
1401
1504
  };
1402
1505
 
1403
1506
  // validate validator public key
1404
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
1405
- if (validatorPublicKey === null) {
1507
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
1508
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
1406
1509
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to decode validator public key.", node.from.key)
1407
1510
  return Status.FAILURE;
1408
1511
  };
@@ -1420,8 +1523,8 @@ class State extends ReadyResource {
1420
1523
  return Status.FAILURE;
1421
1524
  };
1422
1525
 
1423
- const validatorHash = await PeerWallet.blake3Safe(validatorMessage);
1424
- const isValidatorMessageVerifed = this.#wallet.verify(op.rao.vs, validatorHash, validatorPublicKey);
1526
+ const validatorHash = await tracCryptoApi.hash.blake3Safe(validatorMessage);
1527
+ const isValidatorMessageVerifed = tracCryptoApi.signature.verify(op.rao.vs, validatorHash, validatorPublicKey);
1425
1528
  if (!isValidatorMessageVerifed) {
1426
1529
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to verify validator message signature.", node.from.key)
1427
1530
  return Status.FAILURE;
@@ -1476,7 +1579,7 @@ class State extends ReadyResource {
1476
1579
  return null;
1477
1580
  };
1478
1581
 
1479
- const decodedRequesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntry, this.#config.addressPrefix)
1582
+ const decodedRequesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntry)
1480
1583
  if (decodedRequesterNodeEntry === null) {
1481
1584
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to decode node entry.", node.from.key)
1482
1585
  return null;
@@ -1561,7 +1664,7 @@ class State extends ReadyResource {
1561
1664
 
1562
1665
  // reward the validator
1563
1666
 
1564
- const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix)
1667
+ const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer)
1565
1668
  if (decodedValidatorEntry === null) {
1566
1669
  this.#safeLogApply(OperationType.ADD_WRITER, "Failed to decode validator entry.", node.from.key)
1567
1670
  return null;
@@ -1658,8 +1761,8 @@ class State extends ReadyResource {
1658
1761
  };
1659
1762
 
1660
1763
  // Validate requester public key
1661
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
1662
- if (requesterPublicKey === null) {
1764
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
1765
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
1663
1766
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Error while decoding requester public key.", node.from.key)
1664
1767
  return Status.FAILURE;
1665
1768
  };
@@ -1678,13 +1781,13 @@ class State extends ReadyResource {
1678
1781
  };
1679
1782
 
1680
1783
  // compare hashes
1681
- const hash = await PeerWallet.blake3Safe(requesterMessage);
1784
+ const hash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
1682
1785
  if (!b4a.equals(hash, op.rao.tx)) {
1683
1786
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Message hash does not match the tx_hash.", node.from.key)
1684
1787
  return Status.FAILURE;
1685
1788
  };
1686
1789
 
1687
- const isRequesterMessageVerifed = this.#wallet.verify(op.rao.is, op.rao.tx, requesterPublicKey);
1790
+ const isRequesterMessageVerifed = tracCryptoApi.signature.verify(op.rao.is, op.rao.tx, requesterPublicKey);
1688
1791
  const txHashHexString = op.rao.tx.toString('hex');
1689
1792
  if (!isRequesterMessageVerifed) {
1690
1793
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to verify message signature.", node.from.key)
@@ -1700,8 +1803,8 @@ class State extends ReadyResource {
1700
1803
  };
1701
1804
 
1702
1805
  // validate validator public key
1703
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
1704
- if (validatorPublicKey === null) {
1806
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
1807
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
1705
1808
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to decode validator public key.", node.from.key)
1706
1809
  return Status.FAILURE;
1707
1810
  };
@@ -1718,8 +1821,8 @@ class State extends ReadyResource {
1718
1821
  return Status.FAILURE;
1719
1822
  };
1720
1823
 
1721
- const validatorHash = await PeerWallet.blake3Safe(validatorMessage);
1722
- const isValidatorMessageVerifed = this.#wallet.verify(op.rao.vs, validatorHash, validatorPublicKey);
1824
+ const validatorHash = await tracCryptoApi.hash.blake3Safe(validatorMessage);
1825
+ const isValidatorMessageVerifed = tracCryptoApi.signature.verify(op.rao.vs, validatorHash, validatorPublicKey);
1723
1826
  if (!isValidatorMessageVerifed) {
1724
1827
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to verify validator message signature.", node.from.key)
1725
1828
  return Status.FAILURE;
@@ -1777,7 +1880,7 @@ class State extends ReadyResource {
1777
1880
  return null;
1778
1881
  };
1779
1882
 
1780
- const decodedNodeEntry = nodeEntryUtils.decode(requesterNodeEntry, this.#config.addressPrefix);
1883
+ const decodedNodeEntry = nodeEntryUtils.decode(requesterNodeEntry);
1781
1884
  if (decodedNodeEntry === null) {
1782
1885
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to decode requester node entry.", node.from.key)
1783
1886
  return null;
@@ -1793,9 +1896,9 @@ class State extends ReadyResource {
1793
1896
  };
1794
1897
 
1795
1898
  /**
1796
- * Ensure that:
1797
- * 1) writer key exists in registry (we can not unregister something that was not registered),
1798
- * 2) matches the one in node entry ,
1899
+ * Ensure that:
1900
+ * 1) writer key exists in registry (we can not unregister something that was not registered),
1901
+ * 2) matches the one in node entry ,
1799
1902
  * 3) belongs to the requester - this prevents unauthorized key removal
1800
1903
  */
1801
1904
  const writerKeyHasBeenRegistered = await this.#getRegisteredWriterKeyApply(batch, op.rao.iw.toString('hex'))
@@ -1838,7 +1941,7 @@ class State extends ReadyResource {
1838
1941
  };
1839
1942
 
1840
1943
  // Validator reward logic
1841
- const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
1944
+ const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer);
1842
1945
  if (decodedValidatorEntry === null) {
1843
1946
  this.#safeLogApply(OperationType.REMOVE_WRITER, "Failed to decode validator node entry.", node.from.key)
1844
1947
  return null;
@@ -1880,7 +1983,7 @@ class State extends ReadyResource {
1880
1983
  console.info(`Writer removed: addr:wk:tx - ${requesterAddressString}:${op.rao.iw.toString('hex')}:${txHashHexString}`);
1881
1984
  }
1882
1985
 
1883
- this.#emitEvent(CustomEventType.UNWRITABLE, PeerWallet.decodeBech32mSafe(requesterAddressString))
1986
+ this.#emitEvent(CustomEventType.UNWRITABLE, tracCryptoApi.address.decodeSafe(requesterAddressString))
1884
1987
  }
1885
1988
 
1886
1989
  async #handleApplyAddIndexerOperation(op, view, base, node, batch) {
@@ -1898,8 +2001,8 @@ class State extends ReadyResource {
1898
2001
  };
1899
2002
 
1900
2003
  // Validate requester public key
1901
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
1902
- if (requesterPublicKey === null) {
2004
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
2005
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
1903
2006
  this.#safeLogApply(OperationType.ADD_INDEXER, "Error while decoding requester public key.", node.from.key)
1904
2007
  return Status.FAILURE;
1905
2008
  };
@@ -1913,8 +2016,8 @@ class State extends ReadyResource {
1913
2016
  };
1914
2017
 
1915
2018
  // Validate pretending indexer public key
1916
- const pretentingPublicKey = PeerWallet.decodeBech32mSafe(pretendingAddressString);
1917
- if (pretentingPublicKey === null) {
2019
+ const pretentingPublicKey = tracCryptoApi.address.decodeSafe(pretendingAddressString);
2020
+ if (b4a.equals(pretentingPublicKey, NULL_BUFFER)) {
1918
2021
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode pretending indexer public key.", node.from.key)
1919
2022
  return Status.FAILURE;
1920
2023
  };
@@ -1938,8 +2041,8 @@ class State extends ReadyResource {
1938
2041
  };
1939
2042
 
1940
2043
  // Extract admin public key
1941
- const adminPublicKey = PeerWallet.decodeBech32mSafe(decodedAdminEntry.address);
1942
- if (adminPublicKey === null) {
2044
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(decodedAdminEntry.address);
2045
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
1943
2046
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode admin public key.", node.from.key)
1944
2047
  return Status.FAILURE;
1945
2048
  };
@@ -1964,13 +2067,13 @@ class State extends ReadyResource {
1964
2067
  return Status.FAILURE;
1965
2068
  };
1966
2069
 
1967
- const hash = await PeerWallet.blake3Safe(message);
2070
+ const hash = await tracCryptoApi.hash.blake3Safe(message);
1968
2071
  if (!b4a.equals(hash, op.aco.tx)) {
1969
2072
  this.#safeLogApply(OperationType.ADD_INDEXER, "Message hash does not match the tx_hash.", node.from.key)
1970
2073
  return Status.FAILURE;
1971
2074
  };
1972
2075
 
1973
- const isMessageVerifed = this.#wallet.verify(op.aco.is, hash, adminPublicKey);
2076
+ const isMessageVerifed = tracCryptoApi.signature.verify(op.aco.is, hash, adminPublicKey);
1974
2077
  const txHashHexString = hash.toString('hex');
1975
2078
  if (!isMessageVerifed) {
1976
2079
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to verify message signature.", node.from.key)
@@ -2012,7 +2115,7 @@ class State extends ReadyResource {
2012
2115
  return null;
2013
2116
  };
2014
2117
 
2015
- const decodedPretenderNodeEntry = nodeEntryUtils.decode(pretenderNodeEntry, this.#config.addressPrefix);
2118
+ const decodedPretenderNodeEntry = nodeEntryUtils.decode(pretenderNodeEntry);
2016
2119
  if (decodedPretenderNodeEntry === null) {
2017
2120
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode pretender indexer node entry.", node.from.key)
2018
2121
  return null;
@@ -2053,7 +2156,7 @@ class State extends ReadyResource {
2053
2156
  return null;
2054
2157
  };
2055
2158
 
2056
- const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer, this.#config.addressPrefix);
2159
+ const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer);
2057
2160
  if (adminNodeEntry === null) {
2058
2161
  this.#safeLogApply(OperationType.ADD_INDEXER, "Failed to decode requester node entry.", node.from.key)
2059
2162
  return null;
@@ -2098,7 +2201,7 @@ class State extends ReadyResource {
2098
2201
  console.info(`Indexer added addr:wk:tx - ${pretendingAddressString}:${decodedPretenderNodeEntry.wk.toString('hex')}:${txHashHexString}`);
2099
2202
  }
2100
2203
 
2101
- this.#emitEvent(CustomEventType.IS_INDEXER, PeerWallet.decodeBech32mSafe(pretendingAddressString))
2204
+ this.#emitEvent(CustomEventType.IS_INDEXER, tracCryptoApi.address.decodeSafe(pretendingAddressString))
2102
2205
  }
2103
2206
 
2104
2207
  async #handleApplyRemoveIndexerOperation(op, view, base, node, batch) {
@@ -2116,8 +2219,8 @@ class State extends ReadyResource {
2116
2219
  };
2117
2220
 
2118
2221
  // Validate requester public key (admin)
2119
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
2120
- if (requesterPublicKey === null) {
2222
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
2223
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
2121
2224
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Error while decoding requester public key.", node.from.key)
2122
2225
  return Status.FAILURE;
2123
2226
  };
@@ -2130,8 +2233,8 @@ class State extends ReadyResource {
2130
2233
  return Status.FAILURE;
2131
2234
  };
2132
2235
 
2133
- const toRemoveAddressPublicKey = PeerWallet.decodeBech32mSafe(toRemoveAddressString);
2134
- if (toRemoveAddressPublicKey === null) {
2236
+ const toRemoveAddressPublicKey = tracCryptoApi.address.decodeSafe(toRemoveAddressString);
2237
+ if (b4a.equals(toRemoveAddressPublicKey, NULL_BUFFER)) {
2135
2238
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode target indexer public key.", node.from.key)
2136
2239
  return Status.FAILURE;
2137
2240
  };
@@ -2154,8 +2257,8 @@ class State extends ReadyResource {
2154
2257
  return Status.FAILURE;
2155
2258
  };
2156
2259
 
2157
- const adminPublicKey = PeerWallet.decodeBech32mSafe(decodedAdminEntry.address);
2158
- if (adminPublicKey === null) {
2260
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(decodedAdminEntry.address);
2261
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
2159
2262
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode admin public key.", node.from.key)
2160
2263
  return Status.FAILURE;
2161
2264
  };
@@ -2179,13 +2282,13 @@ class State extends ReadyResource {
2179
2282
  return Status.FAILURE;
2180
2283
  };
2181
2284
  // compare hashes
2182
- const hash = await PeerWallet.blake3Safe(message);
2285
+ const hash = await tracCryptoApi.hash.blake3Safe(message);
2183
2286
  if (!b4a.equals(hash, op.aco.tx)) {
2184
2287
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Message hash does not match the tx_hash.", node.from.key)
2185
2288
  return Status.FAILURE;
2186
2289
  };
2187
2290
 
2188
- const isMessageVerifed = this.#wallet.verify(op.aco.is, hash, adminPublicKey);
2291
+ const isMessageVerifed = tracCryptoApi.signature.verify(op.aco.is, hash, adminPublicKey);
2189
2292
  const txHashHexString = hash.toString('hex');
2190
2293
  if (!isMessageVerifed) {
2191
2294
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to verify message signature.", node.from.key)
@@ -2225,7 +2328,7 @@ class State extends ReadyResource {
2225
2328
  return null;
2226
2329
  };
2227
2330
 
2228
- const decodedNodeEntry = nodeEntryUtils.decode(toRemoveNodeEntry, this.#config.addressPrefix);
2331
+ const decodedNodeEntry = nodeEntryUtils.decode(toRemoveNodeEntry);
2229
2332
  if (decodedNodeEntry === null) {
2230
2333
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode target indexer node entry.", node.from.key)
2231
2334
  return null;
@@ -2259,7 +2362,7 @@ class State extends ReadyResource {
2259
2362
  return null;
2260
2363
  };
2261
2364
 
2262
- const decodedAdminNodeEntry = nodeEntryUtils.decode(adminNodeEntry, this.#config.addressPrefix)
2365
+ const decodedAdminNodeEntry = nodeEntryUtils.decode(adminNodeEntry)
2263
2366
  if (decodedAdminNodeEntry === null) {
2264
2367
  this.#safeLogApply(OperationType.REMOVE_INDEXER, "Failed to decode requester node entry.", node.from.key)
2265
2368
  return null;
@@ -2332,8 +2435,8 @@ class State extends ReadyResource {
2332
2435
  };
2333
2436
 
2334
2437
  // Validate requester public key
2335
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
2336
- if (requesterPublicKey === null) {
2438
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
2439
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
2337
2440
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Error while decoding requester public key.", node.from.key)
2338
2441
  return Status.FAILURE;
2339
2442
  };
@@ -2351,8 +2454,8 @@ class State extends ReadyResource {
2351
2454
  return Status.FAILURE;
2352
2455
  };
2353
2456
 
2354
- const adminPublicKey = PeerWallet.decodeBech32mSafe(decodedAdminEntry.address);
2355
- if (adminPublicKey === null) {
2457
+ const adminPublicKey = tracCryptoApi.address.decodeSafe(decodedAdminEntry.address);
2458
+ if (b4a.equals(adminPublicKey, NULL_BUFFER)) {
2356
2459
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to decode admin public key.", node.from.key)
2357
2460
  return Status.FAILURE;
2358
2461
  };
@@ -2382,13 +2485,13 @@ class State extends ReadyResource {
2382
2485
  };
2383
2486
 
2384
2487
  // compare hashes
2385
- const regeneratedHash = await PeerWallet.blake3Safe(message);
2488
+ const regeneratedHash = await tracCryptoApi.hash.blake3Safe(message);
2386
2489
  if (!b4a.equals(regeneratedHash, op.aco.tx)) {
2387
2490
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Message hash does not match the tx_hash.", node.from.key)
2388
2491
  return Status.FAILURE;
2389
2492
  };
2390
2493
 
2391
- const isMessageVerifed = this.#wallet.verify(op.aco.is, regeneratedHash, adminPublicKey);
2494
+ const isMessageVerifed = tracCryptoApi.signature.verify(op.aco.is, regeneratedHash, adminPublicKey);
2392
2495
  const txHashHexString = regeneratedHash.toString('hex');
2393
2496
  if (!isMessageVerifed) {
2394
2497
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to verify message signature.", node.from.key)
@@ -2445,7 +2548,7 @@ class State extends ReadyResource {
2445
2548
  return Status.FAILURE;
2446
2549
  };
2447
2550
 
2448
- const decodedToBanNodeEntry = nodeEntryUtils.decode(updatedToBanNodeEntry, this.#config.addressPrefix);
2551
+ const decodedToBanNodeEntry = nodeEntryUtils.decode(updatedToBanNodeEntry);
2449
2552
  if (decodedToBanNodeEntry === null) {
2450
2553
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to decode target node entry.", node.from.key)
2451
2554
  return Status.FAILURE;
@@ -2464,7 +2567,7 @@ class State extends ReadyResource {
2464
2567
  return Status.FAILURE;
2465
2568
  };
2466
2569
 
2467
- const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer, this.#config.addressPrefix);
2570
+ const adminNodeEntry = nodeEntryUtils.decode(adminNodeEntryBuffer);
2468
2571
  if (adminNodeEntry === null) {
2469
2572
  this.#safeLogApply(OperationType.BAN_VALIDATOR, "Failed to verify admin node entry.", node.from.key)
2470
2573
  return Status.FAILURE;
@@ -2514,7 +2617,7 @@ class State extends ReadyResource {
2514
2617
  console.info(`Node has been banned: addr:wk:tx - ${nodeToBeBannedAddressString}:${decodedToBanNodeEntry.wk.toString('hex')}:${txHashHexString}`);
2515
2618
  }
2516
2619
 
2517
- this.#emitEvent(CustomEventType.UNWRITABLE, PeerWallet.decodeBech32mSafe(nodeToBeBannedAddressString))
2620
+ this.#emitEvent(CustomEventType.UNWRITABLE, tracCryptoApi.address.decodeSafe(nodeToBeBannedAddressString))
2518
2621
 
2519
2622
  return Status.SUCCESS;
2520
2623
  }
@@ -2560,8 +2663,8 @@ class State extends ReadyResource {
2560
2663
  };
2561
2664
 
2562
2665
  // validate requester public key
2563
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
2564
- if (requesterPublicKey === null) {
2666
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
2667
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
2565
2668
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Failed to decode requester public key.", node.from.key)
2566
2669
  return Status.FAILURE;
2567
2670
  };
@@ -2582,13 +2685,13 @@ class State extends ReadyResource {
2582
2685
  };
2583
2686
 
2584
2687
  // ensure that tx is valid
2585
- const regeneratedTxHash = await PeerWallet.blake3Safe(requesterMessage);
2688
+ const regeneratedTxHash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
2586
2689
  if (!b4a.equals(regeneratedTxHash, op.bdo.tx)) {
2587
2690
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Message hash does not match the tx_hash.", node.from.key)
2588
2691
  return Status.FAILURE;
2589
2692
  };
2590
2693
 
2591
- const isRequesterSignatureValid = this.#wallet.verify(op.bdo.is, regeneratedTxHash, requesterPublicKey);
2694
+ const isRequesterSignatureValid = tracCryptoApi.signature.verify(op.bdo.is, regeneratedTxHash, requesterPublicKey);
2592
2695
  if (!isRequesterSignatureValid) {
2593
2696
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Failed to verify message signature.", node.from.key)
2594
2697
  return Status.FAILURE;
@@ -2605,8 +2708,8 @@ class State extends ReadyResource {
2605
2708
  };
2606
2709
 
2607
2710
  // validate validator public key
2608
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
2609
- if (validatorPublicKey === null) {
2711
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
2712
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
2610
2713
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Failed to decode validator public key.", node.from.key)
2611
2714
  return Status.FAILURE;
2612
2715
  };
@@ -2624,9 +2727,9 @@ class State extends ReadyResource {
2624
2727
  return Status.FAILURE;
2625
2728
  };
2626
2729
 
2627
- const validatorMessageHash = await PeerWallet.blake3Safe(validatorMessage);
2730
+ const validatorMessageHash = await tracCryptoApi.hash.blake3Safe(validatorMessage);
2628
2731
 
2629
- const isValidatorSignatureValid = this.#wallet.verify(op.bdo.vs, validatorMessageHash, validatorPublicKey);
2732
+ const isValidatorSignatureValid = tracCryptoApi.signature.verify(op.bdo.vs, validatorMessageHash, validatorPublicKey);
2630
2733
  if (!isValidatorSignatureValid) {
2631
2734
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Failed to verify validator message signature.", node.from.key)
2632
2735
  return Status.FAILURE;
@@ -2687,7 +2790,7 @@ class State extends ReadyResource {
2687
2790
  return Status.FAILURE;
2688
2791
  };
2689
2792
 
2690
- const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer, this.#config.addressPrefix);
2793
+ const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer);
2691
2794
  if (requesterNodeEntry === null) {
2692
2795
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Invalid requester node entry.", node.from.key)
2693
2796
  return Status.FAILURE;
@@ -2717,7 +2820,7 @@ class State extends ReadyResource {
2717
2820
  };
2718
2821
 
2719
2822
  // reward validator for processing this transaction.
2720
- const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
2823
+ const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer);
2721
2824
  if (validatorNodeEntry === null) {
2722
2825
  this.#safeLogApply(OperationType.BOOTSTRAP_DEPLOYMENT, "Invalid validator node entry.", node.from.key)
2723
2826
  return Status.FAILURE;
@@ -2797,8 +2900,8 @@ class State extends ReadyResource {
2797
2900
  return Status.FAILURE;
2798
2901
  };
2799
2902
 
2800
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
2801
- if (requesterPublicKey === null) {
2903
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
2904
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
2802
2905
  this.#safeLogApply(OperationType.TX, "Failed to decode requester public key.", node.from.key)
2803
2906
  return Status.FAILURE;
2804
2907
  };
@@ -2818,13 +2921,13 @@ class State extends ReadyResource {
2818
2921
  return Status.FAILURE;
2819
2922
  };
2820
2923
 
2821
- const regeneratedTxHash = await PeerWallet.blake3Safe(requesterMessage);
2924
+ const regeneratedTxHash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
2822
2925
  if (!b4a.equals(regeneratedTxHash, op.txo.tx)) {
2823
2926
  this.#safeLogApply(OperationType.TX, "Message hash does not match the tx_hash.", node.from.key)
2824
2927
  return Status.FAILURE;
2825
2928
  };
2826
2929
 
2827
- const isRequesterSignatureValid = this.#wallet.verify(op.txo.is, op.txo.tx, requesterPublicKey); // tx contains already a nonce.
2930
+ const isRequesterSignatureValid = tracCryptoApi.signature.verify(op.txo.is, op.txo.tx, requesterPublicKey); // tx contains already a nonce.
2828
2931
  if (!isRequesterSignatureValid) {
2829
2932
  this.#safeLogApply(OperationType.TX, "Failed to verify message signature.", node.from.key)
2830
2933
  return Status.FAILURE;
@@ -2838,8 +2941,8 @@ class State extends ReadyResource {
2838
2941
  return Status.FAILURE;
2839
2942
  };
2840
2943
 
2841
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
2842
- if (validatorPublicKey === null) {
2944
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
2945
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
2843
2946
  this.#safeLogApply(OperationType.TX, "Failed to decode validator public key.", node.from.key)
2844
2947
  return Status.FAILURE;
2845
2948
  };
@@ -2857,8 +2960,8 @@ class State extends ReadyResource {
2857
2960
  return Status.FAILURE;
2858
2961
  };
2859
2962
 
2860
- const validatorMessageHash = await PeerWallet.blake3Safe(validatorMessage);
2861
- const isValidatorSignatureValid = this.#wallet.verify(op.txo.vs, validatorMessageHash, validatorPublicKey);
2963
+ const validatorMessageHash = await tracCryptoApi.hash.blake3Safe(validatorMessage);
2964
+ const isValidatorSignatureValid = tracCryptoApi.signature.verify(op.txo.vs, validatorMessageHash, validatorPublicKey);
2862
2965
  if (!isValidatorSignatureValid) {
2863
2966
  this.#safeLogApply(OperationType.TX, "Failed to verify validator message signature.", node.from.key)
2864
2967
  return Status.FAILURE;
@@ -2930,7 +3033,7 @@ class State extends ReadyResource {
2930
3033
  batch,
2931
3034
  node
2932
3035
  );
2933
-
3036
+
2934
3037
  // TODO: cover next 4 guards below with tests
2935
3038
  if (transferFeeTxOperationResult === null) {
2936
3039
  this.#safeLogApply(OperationType.TX, "Fee transfer operation failed completely.", node.from.key);
@@ -3001,8 +3104,8 @@ class State extends ReadyResource {
3001
3104
  return Status.FAILURE;
3002
3105
  };
3003
3106
 
3004
- const requesterPublicKey = PeerWallet.decodeBech32mSafe(requesterAddressString);
3005
- if (requesterPublicKey === null) {
3107
+ const requesterPublicKey = tracCryptoApi.address.decodeSafe(requesterAddressString);
3108
+ if (b4a.equals(requesterPublicKey, NULL_BUFFER)) {
3006
3109
  this.#safeLogApply(OperationType.TRANSFER, "Error while decoding requester public key.", node.from.key)
3007
3110
  return Status.FAILURE;
3008
3111
  };
@@ -3023,13 +3126,13 @@ class State extends ReadyResource {
3023
3126
  };
3024
3127
 
3025
3128
  // ensure that tx is valid
3026
- const regeneratedTxHash = await PeerWallet.blake3Safe(requesterMessage);
3129
+ const regeneratedTxHash = await tracCryptoApi.hash.blake3Safe(requesterMessage);
3027
3130
  if (!b4a.equals(regeneratedTxHash, op.tro.tx)) {
3028
3131
  this.#safeLogApply(OperationType.TRANSFER, "Message hash does not match the tx_hash.", node.from.key)
3029
3132
  return Status.FAILURE;
3030
3133
  };
3031
3134
 
3032
- const isRequesterSignatureValid = this.#wallet.verify(op.tro.is, regeneratedTxHash, requesterPublicKey);
3135
+ const isRequesterSignatureValid = tracCryptoApi.signature.verify(op.tro.is, regeneratedTxHash, requesterPublicKey);
3033
3136
  if (!isRequesterSignatureValid) {
3034
3137
  this.#safeLogApply(OperationType.TRANSFER, "Failed to verify message signature.", node.from.key)
3035
3138
  return Status.FAILURE;
@@ -3043,8 +3146,8 @@ class State extends ReadyResource {
3043
3146
  return Status.FAILURE;
3044
3147
  };
3045
3148
 
3046
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
3047
- if (validatorPublicKey === null) {
3149
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
3150
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
3048
3151
  this.#safeLogApply(OperationType.TRANSFER, "Failed to decode validator public key.", node.from.key)
3049
3152
  return Status.FAILURE;
3050
3153
  };
@@ -3061,8 +3164,8 @@ class State extends ReadyResource {
3061
3164
  return Status.FAILURE;
3062
3165
  };
3063
3166
 
3064
- const validatorMessageHash = await PeerWallet.blake3Safe(validatorMessage);
3065
- const isValidatorSignatureValid = this.#wallet.verify(op.tro.vs, validatorMessageHash, validatorPublicKey);
3167
+ const validatorMessageHash = await tracCryptoApi.hash.blake3Safe(validatorMessage);
3168
+ const isValidatorSignatureValid = tracCryptoApi.signature.verify(op.tro.vs, validatorMessageHash, validatorPublicKey);
3066
3169
  if (!isValidatorSignatureValid) {
3067
3170
  this.#safeLogApply(OperationType.TRANSFER, "Failed to verify message signature.", node.from.key)
3068
3171
  return Status.FAILURE;
@@ -3105,8 +3208,8 @@ class State extends ReadyResource {
3105
3208
  return Status.FAILURE;
3106
3209
  };
3107
3210
 
3108
- const recipientPublicKey = PeerWallet.decodeBech32mSafe(recipientAddressString);
3109
- if (recipientPublicKey === null) {
3211
+ const recipientPublicKey = tracCryptoApi.address.decodeSafe(recipientAddressString);
3212
+ if (b4a.equals(recipientPublicKey, NULL_BUFFER)) {
3110
3213
  this.#safeLogApply(OperationType.TRANSFER, "Failed to decode recipient public key.", node.from.key)
3111
3214
  return Status.FAILURE;
3112
3215
  };
@@ -3206,7 +3309,7 @@ class State extends ReadyResource {
3206
3309
  return null;
3207
3310
  }
3208
3311
 
3209
- const senderEntry = nodeEntryUtils.decode(senderEntryBuffer, this.#config.addressPrefix);
3312
+ const senderEntry = nodeEntryUtils.decode(senderEntryBuffer);
3210
3313
  if (senderEntry === null) {
3211
3314
  this.#safeLogApply(OperationType.TRANSFER, "Invalid sender node entry.", node.from.key)
3212
3315
  return null;
@@ -3259,7 +3362,7 @@ class State extends ReadyResource {
3259
3362
  };
3260
3363
  result.recipientEntry = newRecipientEntry;
3261
3364
  } else {
3262
- const recipientEntry = nodeEntryUtils.decode(recipientEntryBuffer, this.#config.addressPrefix);
3365
+ const recipientEntry = nodeEntryUtils.decode(recipientEntryBuffer);
3263
3366
  if (recipientEntry === null) {
3264
3367
  this.#safeLogApply(OperationType.TRANSFER, "Invalid recipient entry.", node.from.key)
3265
3368
  return null;
@@ -3286,7 +3389,7 @@ class State extends ReadyResource {
3286
3389
  }
3287
3390
  }
3288
3391
 
3289
- const validatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
3392
+ const validatorEntry = nodeEntryUtils.decode(validatorEntryBuffer);
3290
3393
  if (validatorEntry === null) {
3291
3394
  this.#safeLogApply(OperationType.TRANSFER, "Invalid validator entry.", node.from.key)
3292
3395
  return null;
@@ -3343,7 +3446,7 @@ class State extends ReadyResource {
3343
3446
  for (const indexer of Object.values(base.system.indexers)) {
3344
3447
  buf.push(indexer.key);
3345
3448
  }
3346
- return await PeerWallet.blake3Safe(b4a.concat(buf));
3449
+ return await tracCryptoApi.hash.blake3Safe(b4a.concat(buf));
3347
3450
  } catch (error) {
3348
3451
  console.error(error);
3349
3452
  return null;
@@ -3365,7 +3468,7 @@ class State extends ReadyResource {
3365
3468
  return false;
3366
3469
  };
3367
3470
 
3368
- const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
3471
+ const decodedValidatorEntry = nodeEntryUtils.decode(validatorEntryBuffer);
3369
3472
  if (decodedValidatorEntry === null) {
3370
3473
  this.#safeLogApply(op.type, "Failed to decode validator entry.", node.from.key)
3371
3474
  return false;
@@ -3388,7 +3491,7 @@ class State extends ReadyResource {
3388
3491
 
3389
3492
  /**
3390
3493
  * Retrieves the address assigned to a given writing key from the registry.
3391
- *
3494
+ *
3392
3495
  * @param {Object} batch - The current Hyperbee batch instance used for reading state.
3393
3496
  * @param {string} writingKey - The writing key in hex string format.
3394
3497
  * @returns {Buffer|null} The address buffer assigned to the writing key, or null if not registered.
@@ -3443,7 +3546,7 @@ class State extends ReadyResource {
3443
3546
  return null;
3444
3547
  }
3445
3548
 
3446
- const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer, this.#config.addressPrefix);
3549
+ const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer);
3447
3550
  if (decodedNodeEntry === null) {
3448
3551
  this.#safeLogApply("StakeBalance", "Failed to decode node entry", node.from.key);
3449
3552
  return null;
@@ -3487,7 +3590,7 @@ class State extends ReadyResource {
3487
3590
  return null;
3488
3591
  }
3489
3592
 
3490
- const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer, this.#config.addressPrefix);
3593
+ const decodedNodeEntry = nodeEntryUtils.decode(nodeEntryBuffer);
3491
3594
  if (decodedNodeEntry === null) {
3492
3595
  this.#safeLogApply("withdrawStakedBalanceApply", "Failed to decode node entry", node.from.key);
3493
3596
  return null;
@@ -3564,8 +3667,8 @@ class State extends ReadyResource {
3564
3667
  return;
3565
3668
  }
3566
3669
 
3567
- const validatorPublicKey = PeerWallet.decodeBech32mSafe(validatorAddressString);
3568
- if (validatorPublicKey === null) {
3670
+ const validatorPublicKey = tracCryptoApi.address.decodeSafe(validatorAddressString);
3671
+ if (b4a.equals(validatorPublicKey, NULL_BUFFER)) {
3569
3672
  this.#safeLogApply("ValidatorPenalty", `Failed to decode validator public key: ${validatorAddressString}`, writingKeyBuffer);
3570
3673
  return;
3571
3674
  }
@@ -3576,7 +3679,7 @@ class State extends ReadyResource {
3576
3679
  return;
3577
3680
  }
3578
3681
 
3579
- const decodedValidatorNodeEntry = nodeEntryUtils.decode(validatorNodeEntryBuffer, this.#config.addressPrefix);
3682
+ const decodedValidatorNodeEntry = nodeEntryUtils.decode(validatorNodeEntryBuffer);
3580
3683
  if (decodedValidatorNodeEntry === null) {
3581
3684
  this.#safeLogApply("ValidatorPenalty", `Failed to decode validator node entry for address: ${validatorAddressString}`, writingKeyBuffer);
3582
3685
  return;
@@ -3710,7 +3813,7 @@ class State extends ReadyResource {
3710
3813
  return null;
3711
3814
  }
3712
3815
 
3713
- const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer, this.#config.addressPrefix);
3816
+ const requesterNodeEntry = nodeEntryUtils.decode(requesterNodeEntryBuffer);
3714
3817
  if (requesterNodeEntry === null) {
3715
3818
  this.#safeLogApply("transferFeeTxOperation", "Invalid requester node entry, can not to decode.", node.from.key)
3716
3819
  return null;
@@ -3741,7 +3844,7 @@ class State extends ReadyResource {
3741
3844
 
3742
3845
  // Validator always gets 50% of the fee by the base
3743
3846
 
3744
- const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer, this.#config.addressPrefix);
3847
+ const validatorNodeEntry = nodeEntryUtils.decode(validatorEntryBuffer);
3745
3848
  if (validatorNodeEntry === null) {
3746
3849
  this.#safeLogApply("transferFeeTxOperation", "Invalid validator node entry, can not to decode.", node.from.key)
3747
3850
  return null;
@@ -3811,7 +3914,7 @@ class State extends ReadyResource {
3811
3914
  return null;
3812
3915
  }
3813
3916
 
3814
- const subnetworkCreatorNodeEntry = nodeEntryUtils.decode(subnetworkCreatorNodeEntryBuffer, this.#config.addressPrefix);
3917
+ const subnetworkCreatorNodeEntry = nodeEntryUtils.decode(subnetworkCreatorNodeEntryBuffer);
3815
3918
  if (subnetworkCreatorNodeEntry === null) {
3816
3919
  this.#safeLogApply("transferFeeTxOperation", "Invalid subnetwork creator node entry, can not to decode.", node.from.key)
3817
3920
  return null;