trac-msb 0.2.18 → 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 (381) 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 +25 -8
  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 +138 -10
  16. package/src/config/env.js +36 -18
  17. package/src/core/network/Network.js +52 -24
  18. package/src/core/network/protocols/ProtocolInterface.js +5 -5
  19. package/src/core/network/protocols/connectionPolicies.js +86 -0
  20. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
  21. package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
  22. package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
  23. package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
  24. package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
  25. package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
  26. package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
  27. package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
  28. package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
  29. package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
  30. package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
  31. package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
  32. package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
  33. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
  34. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
  35. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
  36. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
  37. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
  38. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
  39. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
  40. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
  41. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
  42. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
  43. package/src/core/network/services/ConnectionManager.js +11 -10
  44. package/src/core/network/services/MessageOrchestrator.js +53 -17
  45. package/src/core/network/services/PendingRequestService.js +22 -19
  46. package/src/core/network/services/TransactionCommitService.js +36 -36
  47. package/src/core/network/services/TransactionPoolService.js +39 -39
  48. package/src/core/network/services/TransactionRateLimiterService.js +8 -4
  49. package/src/core/network/services/ValidatorObserverService.js +397 -110
  50. package/src/core/state/State.js +190 -138
  51. package/src/core/state/utils/address.js +4 -9
  52. package/src/core/state/utils/balance.js +7 -7
  53. package/src/core/state/utils/roles.js +1 -1
  54. package/src/index.js +316 -275
  55. package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
  56. package/src/messages/network/v1/networkMessageFactory.js +1 -1
  57. package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
  58. package/src/messages/state/applyStateMessageFactory.js +1 -1
  59. package/src/utils/buffer.js +1 -1
  60. package/src/utils/check.js +12 -13
  61. package/src/utils/constants.js +7 -0
  62. package/src/utils/errors.js +20 -0
  63. package/src/utils/fileUtils.js +12 -3
  64. package/src/utils/helpers.js +2 -2
  65. package/src/utils/migrationUtils.js +3 -3
  66. package/.dockerignore +0 -16
  67. package/CODE_OF_CONDUCT.md +0 -128
  68. package/docker-compose.yml +0 -17
  69. package/dockerfile +0 -41
  70. package/docs/fee_distribution.md +0 -89
  71. package/docs/trac_network_http_api.openapi.yaml +0 -889
  72. package/migration/.gitkeep +0 -0
  73. package/proto/applyOperations.proto +0 -117
  74. package/proto/network/v1/enums/message_type.proto +0 -16
  75. package/proto/network/v1/enums/result_code.proto +0 -84
  76. package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
  77. package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
  78. package/proto/network/v1/messages/liveness_request.proto +0 -8
  79. package/proto/network/v1/messages/liveness_response.proto +0 -11
  80. package/proto/network/v1/network_message.proto +0 -22
  81. package/rpc/rpc_services.js +0 -181
  82. package/scripts/generate-protobufs.js +0 -67
  83. package/src/core/network/identity/NetworkWalletFactory.js +0 -77
  84. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
  85. package/src/utils/cli.js +0 -130
  86. package/src/utils/cliCommands.js +0 -280
  87. package/tests/acceptance/v1/account/account.test.mjs +0 -129
  88. package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
  89. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
  90. package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
  91. package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
  92. package/tests/acceptance/v1/health/health.test.mjs +0 -33
  93. package/tests/acceptance/v1/rpc.test.mjs +0 -95
  94. package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
  95. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
  96. package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
  97. package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
  98. package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
  99. package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
  100. package/tests/fixtures/apply.fixtures.js +0 -77
  101. package/tests/fixtures/assembleMessage.fixtures.js +0 -41
  102. package/tests/fixtures/check.fixtures.js +0 -428
  103. package/tests/fixtures/networkV1.fixtures.js +0 -59
  104. package/tests/fixtures/protobuf.fixtures.js +0 -388
  105. package/tests/helpers/StateNetworkFactory.js +0 -155
  106. package/tests/helpers/address.js +0 -6
  107. package/tests/helpers/autobaseTestHelpers.js +0 -419
  108. package/tests/helpers/config.js +0 -4
  109. package/tests/helpers/createTestSignature.js +0 -13
  110. package/tests/helpers/regexHelper.js +0 -3
  111. package/tests/helpers/setupApplyTests.js +0 -587
  112. package/tests/helpers/transactionPayloads.mjs +0 -92
  113. package/tests/helpers/wrapper.js +0 -28
  114. package/tests/unit/messages/messages.test.js +0 -12
  115. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
  116. package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
  117. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
  118. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
  119. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
  120. package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
  121. package/tests/unit/network/ProtocolSession.test.js +0 -127
  122. package/tests/unit/network/networkModule.test.js +0 -13
  123. package/tests/unit/network/services/ConnectionManager.test.js +0 -450
  124. package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
  125. package/tests/unit/network/services/PendingRequestService.test.js +0 -431
  126. package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
  127. package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
  128. package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
  129. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
  130. package/tests/unit/network/services/services.test.js +0 -17
  131. package/tests/unit/network/utils/v1TestUtils.js +0 -153
  132. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
  133. package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
  134. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
  135. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
  136. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
  137. package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
  138. package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
  139. package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
  140. package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
  141. package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
  142. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
  143. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
  144. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
  145. package/tests/unit/network/v1/v1.handlers.test.js +0 -15
  146. package/tests/unit/network/v1/v1.test.js +0 -19
  147. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
  148. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
  149. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
  150. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
  151. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
  152. package/tests/unit/state/State.test.js +0 -80
  153. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
  154. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
  155. package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
  156. package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
  157. package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
  158. package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
  159. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
  160. package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
  161. package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
  162. package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
  163. package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
  164. package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
  165. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
  166. package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
  167. package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
  168. package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
  169. package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
  170. package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
  171. package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
  172. package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
  173. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
  174. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
  175. package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
  176. package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
  177. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
  178. package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
  179. package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
  180. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
  181. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
  182. package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
  183. package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
  184. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
  185. package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
  186. package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
  187. package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
  188. package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
  189. package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
  190. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
  191. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
  192. package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
  193. package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
  194. package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
  195. package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
  196. package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
  197. package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
  198. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
  199. package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
  200. package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
  201. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
  202. package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
  203. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
  204. package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
  205. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
  206. package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
  207. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
  208. package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
  209. package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
  210. package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
  211. package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
  212. package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
  213. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
  214. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
  215. package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
  216. package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
  217. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
  218. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
  219. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
  220. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
  221. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
  222. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
  223. package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
  224. package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
  225. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
  226. package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
  227. package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
  228. package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
  229. package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
  230. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
  231. package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
  232. package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
  233. package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
  234. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
  235. package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
  236. package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
  237. package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
  238. package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
  239. package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
  240. package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
  241. package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
  242. package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
  243. package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
  244. package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
  245. package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
  246. package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
  247. package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
  248. package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
  249. package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
  250. package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
  251. package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
  252. package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
  253. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
  254. package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
  255. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
  256. package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
  257. package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
  258. package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
  259. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
  260. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
  261. package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
  262. package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
  263. package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
  264. package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
  265. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
  266. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
  267. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
  268. package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
  269. package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
  270. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
  271. package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
  272. package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
  273. package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
  274. package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
  275. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
  276. package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
  277. package/tests/unit/state/apply/missing-tests.md +0 -18
  278. package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
  279. package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
  280. package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
  281. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
  282. package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
  283. package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
  284. package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
  285. package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
  286. package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
  287. package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
  288. package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
  289. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
  290. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
  291. package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
  292. package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
  293. package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
  294. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
  295. package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
  296. package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
  297. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
  298. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
  299. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
  300. package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
  301. package/tests/unit/state/apply/state.apply.test.js +0 -24
  302. package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
  303. package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
  304. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
  305. package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
  306. package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
  307. package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
  308. package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
  309. package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
  310. package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
  311. package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
  312. package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
  313. package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
  314. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
  315. package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
  316. package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
  317. package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
  318. package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
  319. package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
  320. package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
  321. package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
  322. package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
  323. package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
  324. package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
  325. package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
  326. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
  327. package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
  328. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
  329. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
  330. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
  331. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
  332. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
  333. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
  334. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
  335. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
  336. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
  337. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
  338. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
  339. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
  340. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
  341. package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
  342. package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
  343. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
  344. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
  345. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
  346. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
  347. package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
  348. package/tests/unit/state/stateModule.test.js +0 -23
  349. package/tests/unit/state/stateTestUtils.js +0 -32
  350. package/tests/unit/state/utils/address.test.js +0 -63
  351. package/tests/unit/state/utils/adminEntry.test.js +0 -52
  352. package/tests/unit/state/utils/balance.test.js +0 -320
  353. package/tests/unit/state/utils/lengthEntry.test.js +0 -54
  354. package/tests/unit/state/utils/nodeEntry.test.js +0 -298
  355. package/tests/unit/state/utils/roles.test.js +0 -44
  356. package/tests/unit/unit.test.js +0 -14
  357. package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
  358. package/tests/unit/utils/buffer/buffer.test.js +0 -251
  359. package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
  360. package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
  361. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
  362. package/tests/unit/utils/check/check.test.js +0 -17
  363. package/tests/unit/utils/check/common.test.js +0 -419
  364. package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
  365. package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
  366. package/tests/unit/utils/check/transactionOperation.test.js +0 -107
  367. package/tests/unit/utils/check/transferOperation.test.js +0 -102
  368. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
  369. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
  370. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
  371. package/tests/unit/utils/helpers/helpers.test.js +0 -11
  372. package/tests/unit/utils/helpers/isHexString.test.js +0 -12
  373. package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
  374. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
  375. package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
  376. package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
  377. package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
  378. package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
  379. package/tests/unit/utils/type/type.test.js +0 -25
  380. package/tests/unit/utils/utils.test.js +0 -21
  381. package/whitelist/.gitkeep +0 -0
@@ -1,13 +1,13 @@
1
- import PeerWallet from 'trac-wallet';
1
+ import tracCryptoApi from 'trac-crypto-api';
2
2
  import b4a from 'b4a';
3
3
  import {createMessage, safeWriteUInt32BE, idToBuffer, timestampToBuffer} from "../../../utils/buffer.js";
4
4
  import {NetworkOperationType, ResultCode} from '../../../utils/constants.js';
5
- import {addressToBuffer, isAddressValid} from "../../../core/state/utils/address.js";
5
+ import {isAddressValid} from "../../../core/state/utils/address.js";
6
6
  import {encodeCapabilities} from "../../../utils/buffer.js";
7
7
 
8
8
  /**
9
9
  * Builder for v1 internal network protocol messages.
10
- * @param {PeerWallet} wallet
10
+ * @param {IWallet} wallet
11
11
  * @param {Config} config
12
12
  */
13
13
  class NetworkMessageBuilder {
@@ -16,7 +16,6 @@ class NetworkMessageBuilder {
16
16
  #capabilities;
17
17
  #id;
18
18
  #timestamp;
19
- #issuerAddress;
20
19
  #resultCode;
21
20
  #data;
22
21
  #proof;
@@ -27,7 +26,7 @@ class NetworkMessageBuilder {
27
26
  #config;
28
27
 
29
28
  /**
30
- * @param {PeerWallet} wallet
29
+ * @param {IWallet} wallet
31
30
  * @param {Config} config
32
31
  */
33
32
  constructor(wallet, config) {
@@ -52,14 +51,6 @@ class NetworkMessageBuilder {
52
51
  return this;
53
52
  }
54
53
 
55
- setIssuerAddress(issuerAddress) {
56
- if (!isAddressValid(issuerAddress, this.#config.addressPrefix)) {
57
- throw new Error('Issuer TRAC address must be valid.');
58
- }
59
- this.#issuerAddress = issuerAddress;
60
- return this;
61
- }
62
-
63
54
  setCapabilities(capabilities = []) {
64
55
  if (!Array.isArray(capabilities) || !capabilities.every(capability => typeof capability === 'string')) {
65
56
  throw new Error('Capabilities must be a string array.');
@@ -137,7 +128,7 @@ class NetworkMessageBuilder {
137
128
  }
138
129
 
139
130
  async #buildLivenessRequestPayload() {
140
- const nonce = PeerWallet.generateNonce();
131
+ const nonce = tracCryptoApi.nonce.generate();
141
132
  const tsBuf = timestampToBuffer(this.#timestamp);
142
133
  const idBuf = idToBuffer(this.#id);
143
134
  const message = createMessage(
@@ -147,7 +138,7 @@ class NetworkMessageBuilder {
147
138
  nonce,
148
139
  encodeCapabilities(this.#capabilities),
149
140
  );
150
- const hash = await PeerWallet.blake3(message);
141
+ const hash = await tracCryptoApi.hash.blake3(message);
151
142
  const signature = this.#wallet.sign(hash);
152
143
 
153
144
  this.#payloadKey = 'liveness_request';
@@ -162,7 +153,7 @@ class NetworkMessageBuilder {
162
153
  throw new Error('Result code must be set before building liveness response');
163
154
  }
164
155
 
165
- const nonce = PeerWallet.generateNonce();
156
+ const nonce = tracCryptoApi.nonce.generate();
166
157
  const tsBuf = timestampToBuffer(this.#timestamp);
167
158
  const idBuf = idToBuffer(this.#id);
168
159
  const message = createMessage(
@@ -173,7 +164,7 @@ class NetworkMessageBuilder {
173
164
  safeWriteUInt32BE(this.#resultCode, 0),
174
165
  encodeCapabilities(this.#capabilities),
175
166
  );
176
- const hash = await PeerWallet.blake3(message);
167
+ const hash = await tracCryptoApi.hash.blake3(message);
177
168
  const signature = this.#wallet.sign(hash);
178
169
 
179
170
  this.#payloadKey = 'liveness_response';
@@ -188,7 +179,7 @@ class NetworkMessageBuilder {
188
179
  if (!b4a.isBuffer(this.#data)) {
189
180
  throw new Error('Data must be set before building broadcast transaction request');
190
181
  }
191
- const nonce = PeerWallet.generateNonce();
182
+ const nonce = tracCryptoApi.nonce.generate();
192
183
  const tsBuf = timestampToBuffer(this.#timestamp);
193
184
  const idBuf = idToBuffer(this.#id);
194
185
  const message = createMessage(
@@ -199,7 +190,7 @@ class NetworkMessageBuilder {
199
190
  nonce,
200
191
  encodeCapabilities(this.#capabilities),
201
192
  );
202
- const hash = await PeerWallet.blake3(message);
193
+ const hash = await tracCryptoApi.hash.blake3(message);
203
194
  const signature = this.#wallet.sign(hash);
204
195
 
205
196
  this.#payloadKey = 'broadcast_transaction_request';
@@ -214,7 +205,7 @@ class NetworkMessageBuilder {
214
205
  if (this.#resultCode === null || this.#resultCode === undefined) {
215
206
  throw new Error('Result code must be set before building broadcast transaction response');
216
207
  }
217
- const nonce = PeerWallet.generateNonce();
208
+ const nonce = tracCryptoApi.nonce.generate();
218
209
  const tsBuf = timestampToBuffer(this.#timestamp);
219
210
  const idBuf = idToBuffer(this.#id);
220
211
  const proof = b4a.isBuffer(this.#proof) ? this.#proof : b4a.alloc(0);
@@ -253,7 +244,7 @@ class NetworkMessageBuilder {
253
244
  encodeCapabilities(this.#capabilities),
254
245
  );
255
246
 
256
- const hash = await PeerWallet.blake3(message);
247
+ const hash = await tracCryptoApi.hash.blake3(message);
257
248
  const signature = this.#wallet.sign(hash);
258
249
  this.#payloadKey = 'broadcast_transaction_response';
259
250
  this.#body = {
@@ -3,7 +3,7 @@ import NetworkMessageBuilder from "./NetworkMessageBuilder.js";
3
3
 
4
4
  /**
5
5
  * Factory helper to create a director with a fresh builder instance.
6
- * @param {PeerWallet} wallet
6
+ * @param {IWallet} wallet
7
7
  * @param {object} config
8
8
  * @returns {NetworkMessageDirector}
9
9
  */
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a';
2
- import PeerWallet from 'trac-wallet';
2
+ import tracCryptoApi from 'trac-crypto-api';
3
3
 
4
4
  import { createMessage } from '../../utils/buffer.js';
5
5
  import { OperationType } from '../../utils/constants.js';
@@ -22,7 +22,7 @@ import { isHexString } from '../../utils/helpers.js';
22
22
 
23
23
  /**
24
24
  * Builder for partial/complete ApplyState messages.
25
- * @param {PeerWallet} wallet
25
+ * @param {IWallet} wallet
26
26
  * @param {Config} config
27
27
  */
28
28
  class ApplyStateMessageBuilder {
@@ -257,7 +257,7 @@ class ApplyStateMessageBuilder {
257
257
  throw new Error(`Operation type ${this.#operationType} is not supported for partial build.`);
258
258
  }
259
259
 
260
- const nonce = PeerWallet.generateNonce();
260
+ const nonce = tracCryptoApi.nonce.generate();
261
261
  let msg;
262
262
 
263
263
  switch (this.#operationType) {
@@ -329,7 +329,7 @@ class ApplyStateMessageBuilder {
329
329
  throw new Error(`Unsupported operation type: ${this.#operationType}`);
330
330
  }
331
331
 
332
- const tx = await PeerWallet.blake3(msg);
332
+ const tx = await tracCryptoApi.hash.blake3(msg);
333
333
  const signature = this.#wallet.sign(tx);
334
334
 
335
335
  if (isBootstrapDeployment(this.#operationType)) {
@@ -378,7 +378,7 @@ class ApplyStateMessageBuilder {
378
378
  }
379
379
 
380
380
  async #buildCompleteBody() {
381
- const nonce = PeerWallet.generateNonce();
381
+ const nonce = tracCryptoApi.nonce.generate();
382
382
  let msg;
383
383
 
384
384
  switch (this.#operationType) {
@@ -503,7 +503,7 @@ class ApplyStateMessageBuilder {
503
503
  throw new Error(`Unsupported operation type: ${this.#operationType}`);
504
504
  }
505
505
 
506
- const tx = await PeerWallet.blake3(msg);
506
+ const tx = await tracCryptoApi.hash.blake3(msg);
507
507
  const signature = this.#wallet.sign(tx);
508
508
  const validatorAddress = addressToBuffer(this.#wallet.address, this.#config.addressPrefix);
509
509
 
@@ -3,7 +3,7 @@ import ApplyStateMessageBuilder from "./ApplyStateMessageBuilder.js";
3
3
 
4
4
  /**
5
5
  * Factory helper to create a director with a builder instance.
6
- * @param {PeerWallet} wallet
6
+ * @param {IWallet} wallet
7
7
  * @param {object} config
8
8
  * @returns {ApplyStateMessageDirector}
9
9
  */
@@ -15,7 +15,7 @@ export const safeWriteUInt32BE = (value, offset) => {
15
15
  const buf = b4a.alloc(4);
16
16
  buf.writeUInt32BE(value, offset);
17
17
  return buf;
18
- } catch (error) {
18
+ } catch {
19
19
  return b4a.alloc(4);
20
20
  }
21
21
  }
@@ -41,7 +41,7 @@ class Check {
41
41
  },
42
42
  });
43
43
  const isBuffer = b4a.isBuffer;
44
- this.#validator.add("buffer", function ({ schema, messages }, path, context) {
44
+ this.#validator.add("buffer", function ({ schema, messages }, _path, _context) {
45
45
  return {
46
46
  source:
47
47
  `
@@ -50,11 +50,11 @@ class Check {
50
50
  }
51
51
  if (value.length !== ${schema.length}) {
52
52
  ${this.makeError({
53
- type: "bufferLength",
54
- expected: schema.length,
55
- actual: "value.length",
56
- messages
57
- })}
53
+ type: "bufferLength",
54
+ expected: schema.length,
55
+ actual: "value.length",
56
+ messages
57
+ })}
58
58
  }
59
59
  let isEmpty = true;
60
60
  for (let i = 0; i < value.length; i++) {
@@ -71,7 +71,7 @@ class Check {
71
71
  };
72
72
  });
73
73
 
74
- this.#validator.add("buffer_amount", function ({ schema, messages }, path, context) {
74
+ this.#validator.add("buffer_amount", function ({ schema, messages }, _path, _context) {
75
75
  return {
76
76
  source:
77
77
  `
@@ -80,11 +80,11 @@ class Check {
80
80
  }
81
81
  if (value.length !== ${schema.length}) {
82
82
  ${this.makeError({
83
- type: "bufferLength",
84
- expected: schema.length,
85
- actual: "value.length",
86
- messages
87
- })}
83
+ type: "bufferLength",
84
+ expected: schema.length,
85
+ actual: "value.length",
86
+ messages
87
+ })}
88
88
  }
89
89
  return value;
90
90
  `
@@ -523,4 +523,3 @@ class Check {
523
523
  }
524
524
 
525
525
  export default Check;
526
-
@@ -189,3 +189,10 @@ export const NETWORK_MESSAGE_TYPES = Object.freeze({
189
189
  });
190
190
 
191
191
  export const NETWORK_CAPABILITIES = Object.freeze(["protocols:v1:legacy"]);
192
+
193
+ // Network tryConnect status constants
194
+ export const CONNECTION_STATUS = Object.freeze({
195
+ CONNECTED: 0,
196
+ PENDING: 1,
197
+ IGNORED: 2
198
+ });
@@ -0,0 +1,20 @@
1
+ export class ValidationError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "ValidationError";
5
+ }
6
+ }
7
+
8
+ export class BroadcastError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "BroadcastError";
12
+ }
13
+ }
14
+
15
+ export class NotFoundError extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = "NotFoundError";
19
+ }
20
+ }
@@ -123,18 +123,26 @@ export async function getAllMigrationFiles(migrationDirectory = BALANCE_MIGRATED
123
123
  }
124
124
  }
125
125
 
126
- export async function ensureCoresStoreDir(config) {
126
+ export async function ensureKeyPathDir(config) {
127
127
  try {
128
128
  // const storesDirectoryStats = await fs.promises.stat(config.storesDirectory);
129
129
  // if (!storesDirectoryStats.isDirectory()) {
130
130
  // throw new Error(`Stores directory path is not a directory: ${config.storesDirectory}`);
131
131
  // }
132
- await fs.promises.mkdir(config.storesFullPath, { recursive: true });
132
+ await fs.promises.mkdir(config.keyPairDirectoryPath, { recursive: true });
133
133
  } catch (err) {
134
134
  throw new Error(`Failed to ensure corestore directory: ${err.message}`);
135
135
  }
136
136
  }
137
137
 
138
+ export function verifyWalletPath(config) {
139
+ try {
140
+ return fs.existsSync(config.keyPairPath)
141
+ } catch {
142
+ return false
143
+ }
144
+ }
145
+
138
146
  export async function validateBalanceMigrationData(addresses) {
139
147
  const migrationFiles = await getAllMigrationFiles(BALANCE_MIGRATED_DIR);
140
148
  const addressSet = new Set(addresses.map(a => a.address));
@@ -206,10 +214,11 @@ export async function createWhitelistEntryFile(addresses, migrationNumber, migra
206
214
  }
207
215
 
208
216
  export default {
217
+ verifyWalletPath,
209
218
  readAddressesFromWhitelistFile,
210
219
  readBalanceMigrationFile,
211
220
  getAllMigrationFiles,
212
- ensureCoresStoreDir,
221
+ ensureKeyPathDir,
213
222
  validateBalanceMigrationData,
214
223
  validateWhitelistMigrationData,
215
224
  getNextMigrationNumber,
@@ -1,5 +1,5 @@
1
1
  import b4a from "b4a";
2
- import PeerWallet from "trac-wallet";
2
+ import tracCryptoApi from "trac-crypto-api";
3
3
  import {bufferToAddress} from "../core/state/utils/address.js";
4
4
  import { EntryType } from "./constants.js";
5
5
  import { v7 as uuidv7 } from 'uuid';
@@ -102,5 +102,5 @@ export function generateUUID() {
102
102
  }
103
103
 
104
104
  export function publicKeyToAddress(publicKey, config) {
105
- return PeerWallet.encodeBech32m(config.addressPrefix, b4a.isBuffer(publicKey) ? publicKey : b4a.from(publicKey, typeof publicKey === 'string' ? 'hex' : undefined));
105
+ return tracCryptoApi.address.encode(config.addressPrefix, b4a.isBuffer(publicKey) ? publicKey : b4a.from(publicKey, typeof publicKey === 'string' ? 'hex' : undefined));
106
106
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { isAddressValid } from '../core/state/utils/address.js';
3
- import PeerWallet from 'trac-wallet';
3
+ import tracCryptoApi from 'trac-crypto-api';
4
4
  import b4a from 'b4a';
5
5
  import { ZERO_LICENSE } from '../core/state/utils/nodeEntry.js';
6
6
 
@@ -9,7 +9,7 @@ export async function validateAddressFromIncomingFile(stateInstance, config, add
9
9
  throw new Error(`Invalid address format: '${address}'. Please ensure all addresses are valid.`);
10
10
  }
11
11
 
12
- const publicKey = PeerWallet.decodeBech32m(address);
12
+ const publicKey = tracCryptoApi.address.decode(address);
13
13
 
14
14
  if (!publicKey || publicKey.length !== 32) {
15
15
  throw new Error(`Invalid public key: '${address}'. Please ensure all addresses are valid.`);
@@ -32,4 +32,4 @@ export async function validateAddressFromIncomingFile(stateInstance, config, add
32
32
 
33
33
  export default {
34
34
  validateAddressFromIncomingFile
35
- };
35
+ };
package/.dockerignore DELETED
@@ -1,16 +0,0 @@
1
- node_modules
2
- npm-debug.log*
3
- .git
4
- .gitignore
5
- .github
6
- .idea
7
- .vscode
8
- coverage
9
- docs
10
- migration
11
- dockerfile
12
- proto
13
- stores
14
- tests
15
- whitelist
16
- docker-compose.yml
@@ -1,128 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, religion, or sexual identity
10
- and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the
26
- overall community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or
31
- advances of any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email
35
- address, without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official e-mail address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- info@trac.network.
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series
86
- of actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or
93
- permanent ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within
113
- the community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.0, available at
119
- https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
-
121
- Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
- enforcement ladder](https://github.com/mozilla/diversity).
123
-
124
- [homepage]: https://www.contributor-covenant.org
125
-
126
- For answers to common questions about this code of conduct, see the FAQ at
127
- https://www.contributor-covenant.org/faq. Translations are available at
128
- https://www.contributor-covenant.org/translations.
@@ -1,17 +0,0 @@
1
- services:
2
- msb-rpc:
3
- build:
4
- context: .
5
- dockerfile: dockerfile
6
- container_name: msb-rpc
7
- restart: always
8
- environment:
9
- MSB_STORE: ${MSB_STORE:-rpc-node-store}
10
- MSB_HOST: ${MSB_HOST:-127.0.0.1}
11
- MSB_PORT: ${MSB_PORT:-5000}
12
- NETWORK: ${NETWORK:-mainnet}
13
- volumes:
14
- - ./stores:/msb/stores
15
- ports:
16
- - "${MSB_HOST:-127.0.0.1}:${MSB_PUBLISH_PORT:-5000}:${MSB_PORT:-5000}"
17
- read_only: true
package/dockerfile DELETED
@@ -1,41 +0,0 @@
1
- FROM node:22-bookworm-slim
2
-
3
- RUN apt-get update \
4
- && apt-get install -y --no-install-recommends \
5
- libatomic1 \
6
- libgcc-s1 \
7
- libstdc++6 \
8
- && rm -rf /var/lib/apt/lists/*
9
-
10
- RUN groupadd --system ops \
11
- && useradd --system --gid ops --home /home/ops --shell /usr/sbin/nologin ops \
12
- && mkdir -p /home/ops \
13
- && chown ops:ops /home/ops \
14
- && mkdir -p /msb/stores \
15
- && chown -R node:ops /msb
16
-
17
- WORKDIR /msb
18
-
19
- USER node
20
-
21
- COPY package*.json ./
22
- RUN npm ci --omit=dev
23
- COPY . .
24
-
25
- USER root
26
- RUN chown -R node:ops /msb \
27
- && chmod -R 0555 /msb \
28
- && chown -R node:node /msb/stores \
29
- && chmod 0700 /msb/stores
30
-
31
- USER node
32
-
33
- ENV MSB_STORE=node-store \
34
- MSB_HOST=0.0.0.0 \
35
- MSB_PORT=5000
36
-
37
- VOLUME ["/msb/stores"]
38
- EXPOSE 5000
39
-
40
- ENTRYPOINT ["npm", "run"]
41
- CMD ["env-prod-rpc-docker"]
@@ -1,89 +0,0 @@
1
- # Fee distribution (state.js)
2
-
3
- ## Constants
4
- - `FEE` = 0.03 $TNK base fee.
5
- - Predefined splits: `PERCENT_75`, `PERCENT_50`, `PERCENT_25`.
6
-
7
- ## Operations (excluding TRANSFER and TX)
8
- | Operation | Who pays / amount | When charged | Validator | Remainder |
9
- | --- | --- | --- | --- | --- |
10
- | AddAdmin | Admin, `0` | One-time during initialization | 0% | n/a (free) |
11
- | BalanceInitialization | Admin (sender), `0` | While initialization flag is enabled | 0% | n/a (free) |
12
- | AppendWhitelist | Admin, `FEE` | Only if initialization flag is disabled | 0% | 100% burned (deducted from admin) |
13
- | AddWriter | Writer candidate, `FEE` | Always charged | 75% | 25% burned |
14
- | RemoveWriter | Writer being removed, `FEE` | Always charged | 75% | 25% burned |
15
- | AdminRecovery | Admin, `FEE` | Always charged | 75% | 25% burned |
16
- | AddIndexer | Admin, `FEE` | Always charged | 0% | 100% burned |
17
- | RemoveIndexer | Admin, `FEE` | Always charged | 0% | 100% burned |
18
- | BanValidator | Admin, `FEE` | Always charged | 0% | 100% burned |
19
- | BootstrapDeployment | Deployment initiator, `FEE` | Always charged | 75% | 25% burned |
20
- | Transfer | Requester, `FEE` | Always charged | 75% | 25% burned |
21
- | TX | Requester, `FEE` | Always charged | depends on subnet owner (see TX cases) | depends on subnet owner (see TX cases) |
22
-
23
- ### Operation details
24
- - **AddAdmin**
25
- - Payer: admin (network creator), amount: free.
26
- - Effect: admin receives initial balance `1000 $TNK` and initial staked balance `0.3 $TNK`; admin is set as indexer+validator+whitelisted and admin entry is created. Runs exactly once during bootstrap.
27
- - **AddWriter**
28
- - Payer: writer candidate, amount: `FEE`.
29
- - Split: validator 75%, burned 25%.
30
- - Effect: role set to writer, staking updated, key registered.
31
- - **RemoveWriter**
32
- - Payer: writer being removed, amount: `FEE`.
33
- - Split: validator 75%, burned 25%.
34
- - Effect: role set to whitelisted, stake released, writer key unregistered.
35
- - **AdminRecovery**
36
- - Payer: admin rotating writer key, amount: `FEE`.
37
- - Split: validator 75%, burned 25%.
38
- - Effect: admin writer key swapped, indexer entry updated to the new key.
39
- - **BootstrapDeployment**
40
- - Payer: deployment initiator, amount: `FEE`.
41
- - Split: validator 75%, burned 25%.
42
- - Effect: deployment entry stored for the bootstrap.
43
-
44
- ## Transfer (OperationType.TRANSFER)
45
- - Payer: requester (sender).
46
- - Fee: `FEE` (always charged, in self-transfer only the fee is deducted).
47
- - Basics:
48
- - Amount deducted from sender: `transferAmount + FEE`. In self-transfer only the fee is deducted.
49
- - If the sender lacks full funds for the deduction, the operation is ignored (state unchanged).
50
- - Fee split: validator 75%, burned 25%.
51
- - Transfer amount to recipient:
52
- - Recipient is not a validator: recipient gets `transferAmount` (can be 0). A new recipient is initialized as READER with that balance.
53
- - Recipient is the validator: validator gets `transferAmount` plus its fee share (75% of `FEE`).
54
- - Self-transfer: recipient equals sender. Recipient balance is unchanged. Fee still goes 75% to validator, 25% burned.
55
-
56
- ## Subnetwork TX (OperationType.TX)
57
- - Payer: requester.
58
- - Fee: `FEE`.
59
- - Fee split depends on who deployed the subnet (`bootstrapDeployer`):
60
- 1. `bootstrapDeployer = requester`, validator is different:
61
- - Validator: 50%
62
- - Bootstrap deployer: 0% (no discount for owning the subnet)
63
- - Burned: 50%
64
- 2. `bootstrapDeployer = validator`, requester is different:
65
- - Validator (and deployer): 75% (50% as validator + 25% as deployer)
66
- - Burned: 25%
67
- - Requester: 0%
68
- 3. `bootstrapDeployer` is neither requester nor validator:
69
- - Validator: 50%
70
- - Bootstrap deployer: 25%
71
- - Burned: 25%
72
- - Requester: 0%
73
- - The fee is deducted from the requester before distribution. Others receive only the shares above.
74
-
75
- ## Zero-fee operations
76
- - `ADD_ADMIN` (one-time bootstrap, assigns `1000 $TNK` liquid + `0.3 $TNK` staked to admin).
77
- - `BALANCE_INITIALIZATION` (sender -> recipient top-up) is free while initialization is enabled.
78
- - `DISABLE_INITIALIZATION` is free, can be used exactly once to turn off balance initialization.
79
- - AppendWhitelist before initialization is disabled is free (fee appears only after the flag is turned off).
80
-
81
- ## Validator penalties
82
- - For a batch with invalid operations or an oversized batch: `penalty = FEE * invalidOperations`.
83
- - The penalty is taken from staked balance, not distributed, and the validator is downgraded to whitelisted. Remaining stake after the penalty returns to the normal balance, so part of the penalty is effectively burned.
84
- - Each failed operation in a batch (validation errors, unmet conditions, invalid payload) increases the invalid counter and triggers at least one `FEE` worth of penalty.
85
-
86
- ## Note on the `bs` field in TX
87
- - `bs` identifies the subnet bootstrap, mapped in MSB to the subnet creator address.
88
- - A TX is valid only if `bs` points to a registered bootstrap.
89
- - The subnet owner (address tied to `bs`) receives a share of the TX fee only when they are not the requester. If requester or validator is the creator, the creator’s share is folded into their respective percentage as described above.