trac-msb 0.2.18 → 0.2.20
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.
- package/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +25 -8
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +138 -10
- package/src/config/env.js +36 -18
- package/src/core/network/Network.js +130 -34
- package/src/core/network/protocols/ProtocolInterface.js +5 -5
- package/src/core/network/protocols/connectionPolicies.js +86 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
- package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
- package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
- package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
- package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
- package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
- package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
- package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
- package/src/core/network/services/ConnectionManager.js +11 -10
- package/src/core/network/services/MessageOrchestrator.js +53 -17
- package/src/core/network/services/PendingRequestService.js +22 -19
- package/src/core/network/services/TransactionCommitService.js +36 -36
- package/src/core/network/services/TransactionPoolService.js +39 -39
- package/src/core/network/services/TransactionRateLimiterService.js +8 -4
- package/src/core/network/services/ValidatorObserverService.js +397 -110
- package/src/core/state/State.js +190 -138
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +316 -275
- package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +7 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +2 -2
- package/src/utils/migrationUtils.js +3 -3
- package/.dockerignore +0 -16
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/rpc/rpc_services.js +0 -181
- package/scripts/generate-protobufs.js +0 -67
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/tests/acceptance/v1/account/account.test.mjs +0 -129
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -59
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/networkModule.test.js +0 -13
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -21
- package/whitelist/.gitkeep +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
3
|
-
import State from '../../../../../state/State.js';
|
|
2
|
+
import tracCryptoApi from 'trac-crypto-api';
|
|
4
3
|
|
|
5
4
|
/*
|
|
6
5
|
BaseResponse class for handling common validation logic for network responses.
|
|
@@ -9,18 +8,16 @@ import State from '../../../../../state/State.js';
|
|
|
9
8
|
class BaseResponse {
|
|
10
9
|
#wallet;
|
|
11
10
|
#state;
|
|
12
|
-
#config
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
*
|
|
16
14
|
* @param {State} state
|
|
17
|
-
* @param {
|
|
15
|
+
* @param {IWallet} wallet
|
|
18
16
|
* @param {Config} config
|
|
19
17
|
*/
|
|
20
|
-
constructor(state, wallet,
|
|
18
|
+
constructor(state, wallet, _config) {
|
|
21
19
|
this.#state = state;
|
|
22
20
|
this.#wallet = wallet;
|
|
23
|
-
this.#config = config;
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
get state() {
|
|
@@ -66,11 +63,11 @@ class BaseResponse {
|
|
|
66
63
|
switch (type) {
|
|
67
64
|
case 'admin':
|
|
68
65
|
const adminEntry = await this.state.getAdminEntry();
|
|
69
|
-
publicKey =
|
|
66
|
+
publicKey = tracCryptoApi.address.decode(adminEntry.address);
|
|
70
67
|
|
|
71
68
|
break;
|
|
72
69
|
default:
|
|
73
|
-
publicKey =
|
|
70
|
+
publicKey = tracCryptoApi.address.decode(message.address);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
if (!publicKey) {
|
|
@@ -80,7 +77,7 @@ class BaseResponse {
|
|
|
80
77
|
const messageWithoutSig = { ...message };
|
|
81
78
|
delete messageWithoutSig.sig;
|
|
82
79
|
const hashInput = b4a.from(JSON.stringify(messageWithoutSig), 'utf8');
|
|
83
|
-
const hash = await
|
|
80
|
+
const hash = await tracCryptoApi.hash.blake3(hashInput);
|
|
84
81
|
const signature = b4a.from(message.sig, 'hex');
|
|
85
82
|
const verified = this.#wallet.verify(signature, hash, publicKey);
|
|
86
83
|
|
|
@@ -91,4 +88,4 @@ class BaseResponse {
|
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
export default BaseResponse;
|
|
91
|
+
export default BaseResponse;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PartialOperationValidator from './PartialOperationValidator.js';
|
|
2
2
|
import {ResultCode} from "../../../../../utils/constants.js";
|
|
3
|
-
import
|
|
3
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
4
4
|
|
|
5
5
|
class PartialBootstrapDeploymentValidator extends PartialOperationValidator {
|
|
6
6
|
constructor(state, selfAddress , config) {
|
|
@@ -28,7 +28,7 @@ class PartialBootstrapDeploymentValidator extends PartialOperationValidator {
|
|
|
28
28
|
async validateBootstrapRegistration(payload) {
|
|
29
29
|
const bootstrapString = payload.bdo.bs.toString('hex');
|
|
30
30
|
if (null !== await this.state.getRegisteredBootstrapEntryUnsigned(bootstrapString)) {
|
|
31
|
-
throw new
|
|
31
|
+
throw new V1ProtocolError(
|
|
32
32
|
ResultCode.BOOTSTRAP_ALREADY_EXISTS,
|
|
33
33
|
`Bootstrap with hash ${bootstrapString} already exists in the state. Bootstrap must be unique.`
|
|
34
34
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
2
|
+
import tracCryptoApi from 'trac-crypto-api';
|
|
3
3
|
import Check from '../../../../../utils/check.js';
|
|
4
4
|
import {bufferToAddress} from "../../../../state/utils/address.js";
|
|
5
5
|
import {createMessage} from "../../../../../utils/buffer.js";
|
|
@@ -7,7 +7,7 @@ import {OperationType, ResultCode} from "../../../../../utils/constants.js";
|
|
|
7
7
|
import {bufferToBigInt} from "../../../../../utils/amountSerialization.js";
|
|
8
8
|
import {FEE} from "../../../../state/utils/transaction.js";
|
|
9
9
|
import * as operationsUtils from '../../../../../utils/applyOperations.js';
|
|
10
|
-
import
|
|
10
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
11
11
|
|
|
12
12
|
const MAX_AMOUNT = BigInt('0xffffffffffffffffffffffffffffffff');
|
|
13
13
|
const FEE_BIGINT = bufferToBigInt(FEE);
|
|
@@ -36,19 +36,19 @@ class PartialOperationValidator {
|
|
|
36
36
|
return this.#check;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async validate(
|
|
40
|
-
throw new
|
|
39
|
+
async validate() {
|
|
40
|
+
throw new V1ProtocolError(ResultCode.UNEXPECTED_ERROR, "Method 'validate()' must be implemented.");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
isPayloadSchemaValid(payload) {
|
|
44
44
|
if (!payload || !payload.type) {
|
|
45
|
-
throw new
|
|
45
|
+
throw new V1ProtocolError(ResultCode.TX_INVALID_PAYLOAD, 'Payload or payload type is missing.');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const selectedValidator = this.#selectCheckSchemaValidator(payload.type);
|
|
49
49
|
const isPayloadValid = selectedValidator(payload);
|
|
50
50
|
if (!isPayloadValid) {
|
|
51
|
-
throw new
|
|
51
|
+
throw new V1ProtocolError(ResultCode.SCHEMA_VALIDATION_FAILED, 'Payload is invalid.');
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -65,7 +65,7 @@ class PartialOperationValidator {
|
|
|
65
65
|
case OperationType.TRANSFER:
|
|
66
66
|
return this.check.validateTransferOperation.bind(this.check);
|
|
67
67
|
default:
|
|
68
|
-
throw new
|
|
68
|
+
throw new V1ProtocolError(
|
|
69
69
|
ResultCode.OPERATION_TYPE_UNKNOWN,
|
|
70
70
|
`Unknown operation type: ${type}`
|
|
71
71
|
);
|
|
@@ -75,14 +75,14 @@ class PartialOperationValidator {
|
|
|
75
75
|
validateRequesterAddress(payload) {
|
|
76
76
|
const incomingAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
77
77
|
if (!incomingAddress) {
|
|
78
|
-
throw new
|
|
78
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_ADDRESS_INVALID, 'Invalid requesting address in payload.');
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const incomingPublicKey =
|
|
81
|
+
const incomingPublicKey = tracCryptoApi.address.decodeSafe(incomingAddress);
|
|
82
82
|
|
|
83
83
|
// TODO: We can add check if public key belongs to the Ed25519 curve. Validate signature already checks that but it would be amazing to catch it earlier.
|
|
84
84
|
if (!incomingPublicKey || incomingPublicKey.length !== PUBLIC_KEY_LENGTH) {
|
|
85
|
-
throw new
|
|
85
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_PUBLIC_KEY_INVALID, 'Invalid requesting public key in payload.');
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -131,7 +131,7 @@ class PartialOperationValidator {
|
|
|
131
131
|
OperationType.TRANSFER
|
|
132
132
|
];
|
|
133
133
|
default:
|
|
134
|
-
throw new
|
|
134
|
+
throw new V1ProtocolError(
|
|
135
135
|
ResultCode.OPERATION_TYPE_UNKNOWN,
|
|
136
136
|
`Unknown operation type: ${payload.type}`
|
|
137
137
|
);
|
|
@@ -142,22 +142,22 @@ class PartialOperationValidator {
|
|
|
142
142
|
const operationKey = operationsUtils.operationToPayload(payload.type);
|
|
143
143
|
const operation = payload[operationKey];
|
|
144
144
|
|
|
145
|
-
const incomingPublicKey =
|
|
145
|
+
const incomingPublicKey = tracCryptoApi.address.decodeSafe(bufferToAddress(payload.address, this.#config.addressPrefix));
|
|
146
146
|
const incomingSignature = operation.is;
|
|
147
147
|
const messageComponents = this.#getMessageComponents(payload);
|
|
148
148
|
|
|
149
149
|
const message = createMessage(...messageComponents);
|
|
150
|
-
const messageHash = await
|
|
150
|
+
const messageHash = await tracCryptoApi.hash.blake3(message);
|
|
151
151
|
const payloadHash = operation.tx;
|
|
152
152
|
if (!b4a.equals(payloadHash, messageHash)) {
|
|
153
|
-
throw new
|
|
153
|
+
throw new V1ProtocolError(
|
|
154
154
|
ResultCode.TX_HASH_MISMATCH,
|
|
155
155
|
'Regenerated transaction does not match incoming transaction in payload.'
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
if (!
|
|
160
|
-
throw new
|
|
159
|
+
if (!tracCryptoApi.signature.verify(incomingSignature, messageHash, incomingPublicKey)) {
|
|
160
|
+
throw new V1ProtocolError(ResultCode.TX_SIGNATURE_INVALID, 'Invalid signature in payload.');
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -168,7 +168,7 @@ class PartialOperationValidator {
|
|
|
168
168
|
const incomingTxv = operation.txv
|
|
169
169
|
|
|
170
170
|
if (!b4a.equals(currentTxv, incomingTxv)) {
|
|
171
|
-
throw new
|
|
171
|
+
throw new V1ProtocolError(ResultCode.TX_EXPIRED, 'Transaction has expired.');
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -179,7 +179,7 @@ class PartialOperationValidator {
|
|
|
179
179
|
const txHex = tx.toString('hex');
|
|
180
180
|
|
|
181
181
|
if (await this.state.get(txHex) !== null) {
|
|
182
|
-
throw new
|
|
182
|
+
throw new V1ProtocolError(
|
|
183
183
|
ResultCode.TX_ALREADY_EXISTS,
|
|
184
184
|
`Transaction with hash ${txHex} already exists in the state.`
|
|
185
185
|
);
|
|
@@ -193,7 +193,7 @@ class PartialOperationValidator {
|
|
|
193
193
|
|
|
194
194
|
const condition = va === undefined && vn === undefined && vs === undefined
|
|
195
195
|
if (!condition) {
|
|
196
|
-
throw new
|
|
196
|
+
throw new V1ProtocolError(
|
|
197
197
|
ResultCode.OPERATION_ALREADY_COMPLETED,
|
|
198
198
|
'Transfer operation must not be completed already (va, vn, vs must be undefined).'
|
|
199
199
|
);
|
|
@@ -210,12 +210,12 @@ class PartialOperationValidator {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
if (!requesterEntry) {
|
|
213
|
-
throw new
|
|
213
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_NOT_FOUND, 'Requester address not found in state');
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
const requesterBalance = bufferToBigInt(requesterEntry.balance);
|
|
217
217
|
if (requesterBalance < FEE_BIGINT) {
|
|
218
|
-
throw new
|
|
218
|
+
throw new V1ProtocolError(ResultCode.INSUFFICIENT_FEE_BALANCE, 'Insufficient balance to cover transaction fee.');
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -225,7 +225,7 @@ class PartialOperationValidator {
|
|
|
225
225
|
const operation = payload[operationKey];
|
|
226
226
|
const bs = operation.bs;
|
|
227
227
|
if (b4a.equals(this.#config.bootstrap, bs)) {
|
|
228
|
-
throw new
|
|
228
|
+
throw new V1ProtocolError(
|
|
229
229
|
ResultCode.EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP,
|
|
230
230
|
`External bootstrap is the same as MSB bootstrap: ${bs.toString('hex')}`
|
|
231
231
|
);
|
|
@@ -242,7 +242,7 @@ class PartialOperationValidator {
|
|
|
242
242
|
|
|
243
243
|
const requesterAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
244
244
|
if (this.#selfAddress === requesterAddress) {
|
|
245
|
-
throw new
|
|
245
|
+
throw new V1ProtocolError(
|
|
246
246
|
ResultCode.SELF_VALIDATION_FORBIDDEN,
|
|
247
247
|
'Requester address cannot be the same as the validator wallet address.'
|
|
248
248
|
);
|
|
@@ -3,7 +3,7 @@ import {OperationType, ResultCode} from "../../../../../utils/constants.js";
|
|
|
3
3
|
import {bufferToAddress} from "../../../../state/utils/address.js";
|
|
4
4
|
import PartialOperationValidator from './PartialOperationValidator.js';
|
|
5
5
|
import {bufferToBigInt} from "../../../../../utils/amountSerialization.js";
|
|
6
|
-
import
|
|
6
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
7
7
|
|
|
8
8
|
class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
9
9
|
#config;
|
|
@@ -43,7 +43,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
43
43
|
const nodeAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
44
44
|
const nodeEntry = await this.state.getNodeEntry(nodeAddress);
|
|
45
45
|
if (!nodeEntry) {
|
|
46
|
-
throw new
|
|
46
|
+
throw new V1ProtocolError(
|
|
47
47
|
ResultCode.ROLE_NODE_ENTRY_NOT_FOUND,
|
|
48
48
|
`Node with address ${nodeAddress} entry does not exist.`
|
|
49
49
|
);
|
|
@@ -51,7 +51,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
51
51
|
|
|
52
52
|
const isNodeAlreadyWriter = nodeEntry.isWriter;
|
|
53
53
|
if (isNodeAlreadyWriter) {
|
|
54
|
-
throw new
|
|
54
|
+
throw new V1ProtocolError(
|
|
55
55
|
ResultCode.ROLE_NODE_ALREADY_WRITER,
|
|
56
56
|
`Node with address ${nodeAddress} is already a writer.`
|
|
57
57
|
);
|
|
@@ -59,7 +59,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
59
59
|
|
|
60
60
|
const isNodeWhitelisted = nodeEntry.isWhitelisted;
|
|
61
61
|
if (!isNodeWhitelisted) {
|
|
62
|
-
throw new
|
|
62
|
+
throw new V1ProtocolError(
|
|
63
63
|
ResultCode.ROLE_NODE_NOT_WHITELISTED,
|
|
64
64
|
`Node with address ${nodeAddress} is not whitelisted.`
|
|
65
65
|
);
|
|
@@ -70,7 +70,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
70
70
|
const nodeAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
71
71
|
const nodeEntry = await this.state.getNodeEntry(nodeAddress);
|
|
72
72
|
if (!nodeEntry) {
|
|
73
|
-
throw new
|
|
73
|
+
throw new V1ProtocolError(
|
|
74
74
|
ResultCode.ROLE_NODE_ENTRY_NOT_FOUND,
|
|
75
75
|
`Node with address ${nodeAddress} entry does not exist.`
|
|
76
76
|
);
|
|
@@ -78,7 +78,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
78
78
|
|
|
79
79
|
const isAlreadyWriter = nodeEntry.isWriter;
|
|
80
80
|
if (!isAlreadyWriter) {
|
|
81
|
-
throw new
|
|
81
|
+
throw new V1ProtocolError(
|
|
82
82
|
ResultCode.ROLE_NODE_NOT_WRITER,
|
|
83
83
|
`Node with address ${nodeAddress} is not a writer.`
|
|
84
84
|
);
|
|
@@ -86,7 +86,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
86
86
|
|
|
87
87
|
const isAlreadyIndexer = nodeEntry.isIndexer;
|
|
88
88
|
if (isAlreadyIndexer) {
|
|
89
|
-
throw new
|
|
89
|
+
throw new V1ProtocolError(
|
|
90
90
|
ResultCode.ROLE_NODE_IS_INDEXER,
|
|
91
91
|
`Node with address ${nodeAddress} is an indexer.`
|
|
92
92
|
);
|
|
@@ -96,7 +96,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
96
96
|
} else if (type === OperationType.ADMIN_RECOVERY) {
|
|
97
97
|
const adminEntry = await this.state.getAdminEntry();
|
|
98
98
|
if (!adminEntry) {
|
|
99
|
-
throw new
|
|
99
|
+
throw new V1ProtocolError(ResultCode.ROLE_ADMIN_ENTRY_MISSING, 'Admin entry does not exist.');
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
const adminAddressBuffer = payload.address;
|
|
@@ -106,7 +106,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
106
106
|
!b4a.equals(payload.rao.iw, adminEntry.wk)
|
|
107
107
|
);
|
|
108
108
|
if (!isRecoveryCase) {
|
|
109
|
-
throw new
|
|
109
|
+
throw new V1ProtocolError(
|
|
110
110
|
ResultCode.ROLE_INVALID_RECOVERY_CASE,
|
|
111
111
|
`Node with address ${adminAddress} is not a valid recovery case.`
|
|
112
112
|
);
|
|
@@ -115,7 +115,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
throw new
|
|
118
|
+
throw new V1ProtocolError(
|
|
119
119
|
ResultCode.ROLE_UNKNOWN_OPERATION,
|
|
120
120
|
`Unknown role access operation type: ${type}`
|
|
121
121
|
);
|
|
@@ -125,7 +125,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
125
125
|
const requesterAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
126
126
|
const nodeEntry = await this.state.getNodeEntry(requesterAddress);
|
|
127
127
|
if (!nodeEntry) {
|
|
128
|
-
throw new
|
|
128
|
+
throw new V1ProtocolError(
|
|
129
129
|
ResultCode.REQUESTER_NOT_FOUND,
|
|
130
130
|
`Node entry not found for address ${requesterAddress}`
|
|
131
131
|
);
|
|
@@ -139,7 +139,7 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
139
139
|
const isOwner = b4a.equals(addressFromRegisteredWritingKey, payload.address);
|
|
140
140
|
|
|
141
141
|
if (!isCurrentWk || !isOwner) {
|
|
142
|
-
throw new
|
|
142
|
+
throw new V1ProtocolError(
|
|
143
143
|
ResultCode.ROLE_INVALID_WRITER_KEY,
|
|
144
144
|
'Invalid writer key: either not owned by requester or different from assigned key'
|
|
145
145
|
);
|
|
@@ -157,13 +157,13 @@ class PartialRoleAccessValidator extends PartialOperationValidator {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
if (!requesterEntry) {
|
|
160
|
-
throw new
|
|
160
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_NOT_FOUND, 'Requester address not found in state');
|
|
161
161
|
}
|
|
162
162
|
const requesterBalance = bufferToBigInt(requesterEntry.balance);
|
|
163
163
|
|
|
164
164
|
const requiredBalance = this.fee * 11n;
|
|
165
165
|
if (requesterBalance < requiredBalance) {
|
|
166
|
-
throw new
|
|
166
|
+
throw new V1ProtocolError(
|
|
167
167
|
ResultCode.ROLE_INSUFFICIENT_FEE_BALANCE,
|
|
168
168
|
'Insufficient requester balance to cover role access operation FEE.'
|
|
169
169
|
);
|
|
@@ -3,7 +3,7 @@ import {safeDecodeApplyOperation} from "../../../../../utils/protobuf/operationH
|
|
|
3
3
|
import deploymentEntryUtils from "../../../../state/utils/deploymentEntry.js";
|
|
4
4
|
import PartialOperationValidator from './PartialOperationValidator.js';
|
|
5
5
|
import {ResultCode} from "../../../../../utils/constants.js";
|
|
6
|
-
import
|
|
6
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
7
7
|
|
|
8
8
|
class PartialTransactionValidator extends PartialOperationValidator {
|
|
9
9
|
#config
|
|
@@ -34,7 +34,7 @@ class PartialTransactionValidator extends PartialOperationValidator {
|
|
|
34
34
|
|
|
35
35
|
validateMsbBootstrap(payload) {
|
|
36
36
|
if (!b4a.equals(this.#config.bootstrap, payload.txo.mbs)) {
|
|
37
|
-
throw new
|
|
37
|
+
throw new V1ProtocolError(
|
|
38
38
|
ResultCode.MSB_BOOTSTRAP_MISMATCH,
|
|
39
39
|
`Declared MSB bootstrap is different than network bootstrap in transaction operation: ${payload.txo.mbs.toString('hex')}`
|
|
40
40
|
);
|
|
@@ -44,7 +44,7 @@ class PartialTransactionValidator extends PartialOperationValidator {
|
|
|
44
44
|
async validateIfExternalBootstrapHasBeenDeployed(payload) {
|
|
45
45
|
const externalBootstrapResult = await this.state.getRegisteredBootstrapEntry(payload.txo.bs.toString('hex'));
|
|
46
46
|
if (externalBootstrapResult === null) {
|
|
47
|
-
throw new
|
|
47
|
+
throw new V1ProtocolError(
|
|
48
48
|
ResultCode.EXTERNAL_BOOTSTRAP_NOT_DEPLOYED,
|
|
49
49
|
`External bootstrap with hash ${payload.txo.bs.toString('hex')} is not registered as deployment entry.`
|
|
50
50
|
);
|
|
@@ -55,7 +55,7 @@ class PartialTransactionValidator extends PartialOperationValidator {
|
|
|
55
55
|
const getBootstrapTransactionTxPayload = await this.state.get(txHash.toString('hex'));
|
|
56
56
|
|
|
57
57
|
if (getBootstrapTransactionTxPayload === null) {
|
|
58
|
-
throw new
|
|
58
|
+
throw new V1ProtocolError(
|
|
59
59
|
ResultCode.EXTERNAL_BOOTSTRAP_TX_MISSING,
|
|
60
60
|
`External bootstrap is not registered as usual tx ${externalBootstrapResult.toString('hex')}: ${payload}`
|
|
61
61
|
);
|
|
@@ -65,7 +65,7 @@ class PartialTransactionValidator extends PartialOperationValidator {
|
|
|
65
65
|
|
|
66
66
|
// edge case
|
|
67
67
|
if (!b4a.equals(decodedBootstrapDeployment.bdo.bs, payload.txo.bs)) {
|
|
68
|
-
throw new
|
|
68
|
+
throw new V1ProtocolError(
|
|
69
69
|
ResultCode.EXTERNAL_BOOTSTRAP_MISMATCH,
|
|
70
70
|
`External bootstrap does not match the one in the transaction payload: ${decodedBootstrapDeployment.bdo.bs.toString('hex')} !== ${payload.txo.bs.toString('hex')}`
|
|
71
71
|
);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import PeerWallet from 'trac-wallet';
|
|
2
|
-
|
|
3
1
|
import {bufferToAddress} from "../../../../state/utils/address.js";
|
|
4
2
|
import {bufferToBigInt} from "../../../../../utils/amountSerialization.js";
|
|
5
3
|
import {ResultCode} from "../../../../../utils/constants.js";
|
|
4
|
+
import { NULL_BUFFER } from '../../../../../utils/buffer.js';
|
|
6
5
|
import PartialOperationValidator from './PartialOperationValidator.js';
|
|
7
|
-
import
|
|
6
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
7
|
+
import tracCryptoApi from "trac-crypto-api";
|
|
8
|
+
import b4a from 'b4a';
|
|
8
9
|
|
|
9
10
|
class PartialTransferValidator extends PartialOperationValidator {
|
|
10
11
|
#config
|
|
@@ -33,15 +34,15 @@ class PartialTransferValidator extends PartialOperationValidator {
|
|
|
33
34
|
#validateRecipientAddress(payload) {
|
|
34
35
|
const incomingAddress = bufferToAddress(payload.tro.to, this.#config.addressPrefix);
|
|
35
36
|
if (!incomingAddress) {
|
|
36
|
-
throw new
|
|
37
|
+
throw new V1ProtocolError(
|
|
37
38
|
ResultCode.TRANSFER_RECIPIENT_ADDRESS_INVALID,
|
|
38
39
|
'Invalid recipient address in transfer payload.'
|
|
39
40
|
);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const incomingPublicKey =
|
|
43
|
-
if (incomingPublicKey
|
|
44
|
-
throw new
|
|
43
|
+
const incomingPublicKey = tracCryptoApi.address.decodeSafe(incomingAddress);
|
|
44
|
+
if (b4a.equals(incomingPublicKey, NULL_BUFFER)) {
|
|
45
|
+
throw new V1ProtocolError(
|
|
45
46
|
ResultCode.TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID,
|
|
46
47
|
'Invalid recipient public key in transfer payload.'
|
|
47
48
|
);
|
|
@@ -55,7 +56,7 @@ class PartialTransferValidator extends PartialOperationValidator {
|
|
|
55
56
|
|
|
56
57
|
const transferAmount = bufferToBigInt(payload.tro.am);
|
|
57
58
|
if (transferAmount > this.max_amount) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new V1ProtocolError(
|
|
59
60
|
ResultCode.TRANSFER_AMOUNT_TOO_LARGE,
|
|
60
61
|
'Transfer amount exceeds maximum allowed value'
|
|
61
62
|
);
|
|
@@ -66,12 +67,12 @@ class PartialTransferValidator extends PartialOperationValidator {
|
|
|
66
67
|
|
|
67
68
|
const senderEntry = await this.state.getNodeEntryUnsigned(senderAddress);
|
|
68
69
|
if (!senderEntry) {
|
|
69
|
-
throw new
|
|
70
|
+
throw new V1ProtocolError(ResultCode.TRANSFER_SENDER_NOT_FOUND, 'Sender account not found');
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
const senderBalance = bufferToBigInt(senderEntry.balance);
|
|
73
74
|
if (!(senderBalance >= totalDeductedAmount)) {
|
|
74
|
-
throw new
|
|
75
|
+
throw new V1ProtocolError(
|
|
75
76
|
ResultCode.TRANSFER_INSUFFICIENT_BALANCE,
|
|
76
77
|
'Insufficient balance for transfer' + (isSelfTransfer ? ' fee' : ' + fee')
|
|
77
78
|
);
|
|
@@ -83,7 +84,7 @@ class PartialTransferValidator extends PartialOperationValidator {
|
|
|
83
84
|
const recipientBalance = bufferToBigInt(recipientEntry.balance);
|
|
84
85
|
const newRecipientBalance = recipientBalance + transferAmount;
|
|
85
86
|
if (newRecipientBalance > this.max_amount) {
|
|
86
|
-
throw new
|
|
87
|
+
throw new V1ProtocolError(
|
|
87
88
|
ResultCode.TRANSFER_RECIPIENT_BALANCE_OVERFLOW,
|
|
88
89
|
'Transfer would cause recipient balance to exceed maximum allowed value'
|
|
89
90
|
);
|
|
@@ -1,91 +1,27 @@
|
|
|
1
1
|
import {ResultCode} from '../../../../utils/constants.js';
|
|
2
2
|
|
|
3
|
-
export function getResultCode(err) {
|
|
4
|
-
return err instanceof V1ProtocolError ? err.resultCode : ResultCode.UNEXPECTED_ERROR;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function shouldEndConnection(err) {
|
|
8
|
-
return err instanceof V1ProtocolError ? Boolean(err.endConnection) : false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
3
|
/**
|
|
12
4
|
* V1 protocol error type.
|
|
13
5
|
*
|
|
14
6
|
* `V1ProtocolError` is the v1 base class used by handlers/validators to attach:
|
|
15
7
|
* - `resultCode`: a stable `ResultCode` enum value for programmatic handling
|
|
16
|
-
* - `endConnection`: a transport hint (close peer connection after responding)
|
|
17
8
|
*/
|
|
18
9
|
export class V1ProtocolError extends Error {
|
|
19
10
|
/**
|
|
20
11
|
* @param {number} resultCode Stable rejection reason (a `ResultCode` enum value).
|
|
21
12
|
* @param {string} message Human-readable error message.
|
|
22
|
-
* @param {boolean} [endConnection=false] Whether the transport should end the connection after responding.
|
|
23
13
|
*/
|
|
24
|
-
constructor(resultCode, message
|
|
14
|
+
constructor(resultCode, message) {
|
|
25
15
|
super(message);
|
|
26
16
|
this.name = this.constructor.name;
|
|
27
17
|
this.resultCode = resultCode;
|
|
28
|
-
this.endConnection = Boolean(endConnection);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class V1InvalidPayloadError extends V1ProtocolError {
|
|
33
|
-
constructor(message = 'Invalid payload', endConnection = false) {
|
|
34
|
-
super(ResultCode.INVALID_PAYLOAD, message, endConnection);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class V1TxInvalidPayloadError extends V1ProtocolError {
|
|
39
|
-
constructor(message = 'Invalid tx payload', endConnection = false) {
|
|
40
|
-
super(ResultCode.TX_INVALID_PAYLOAD, message, endConnection);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export class V1SignatureInvalidError extends V1ProtocolError {
|
|
45
|
-
constructor(message = 'Signature invalid', endConnection = true) {
|
|
46
|
-
super(ResultCode.SIGNATURE_INVALID, message, endConnection);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class V1RateLimitedError extends V1ProtocolError {
|
|
51
|
-
constructor(message = 'Rate limited', endConnection = true) {
|
|
52
|
-
super(ResultCode.RATE_LIMITED, message, endConnection);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class V1UnexpectedError extends V1ProtocolError {
|
|
57
|
-
constructor(message = 'Unexpected error', endConnection = true) {
|
|
58
|
-
super(ResultCode.UNEXPECTED_ERROR, message, endConnection);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export class V1TimeoutError extends V1ProtocolError {
|
|
63
|
-
constructor(message = 'Request timed out', endConnection = false) {
|
|
64
|
-
super(ResultCode.TIMEOUT, message, endConnection);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export class V1NodeHasNoWriteAccess extends V1ProtocolError {
|
|
69
|
-
constructor(message = 'Node has no write access', endConnection = true) {
|
|
70
|
-
super(ResultCode.NODE_HAS_NO_WRITE_ACCESS, message, endConnection);
|
|
71
18
|
}
|
|
72
19
|
}
|
|
73
20
|
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
super(ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE, message, endConnection);
|
|
77
|
-
this.timestamp = Number.isSafeInteger(timestamp) && timestamp > 0 ? timestamp : 0;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export class V1NodeOverloadedError extends V1ProtocolError {
|
|
82
|
-
constructor(message = 'Commit queue is full', endConnection = true) {
|
|
83
|
-
super(ResultCode.NODE_OVERLOADED, message, endConnection);
|
|
84
|
-
}
|
|
21
|
+
export function getResultCode(err) {
|
|
22
|
+
return err instanceof V1ProtocolError ? err.resultCode : ResultCode.UNEXPECTED_ERROR;
|
|
85
23
|
}
|
|
86
24
|
|
|
87
|
-
export
|
|
88
|
-
|
|
89
|
-
super(ResultCode.TX_ALREADY_PENDING, message, endConnection);
|
|
90
|
-
}
|
|
25
|
+
export function shouldEndConnection(err) {
|
|
26
|
+
return err instanceof V1ProtocolError ? Boolean(err.endConnection) : false;
|
|
91
27
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import {ResultCode} from "../../../../../utils/constants.js";
|
|
1
2
|
import {publicKeyToAddress} from "../../../../../utils/helpers.js";
|
|
2
|
-
import {V1ProtocolError
|
|
3
|
+
import {V1ProtocolError} from "../V1ProtocolError.js";
|
|
3
4
|
|
|
4
5
|
class V1BaseOperationHandler {
|
|
5
6
|
#rateLimiterService;
|
|
@@ -58,7 +59,7 @@ class V1BaseOperationHandler {
|
|
|
58
59
|
if (error instanceof V1ProtocolError) {
|
|
59
60
|
return error;
|
|
60
61
|
}
|
|
61
|
-
return new
|
|
62
|
+
return new V1ProtocolError(ResultCode.UNEXPECTED_ERROR, error?.message ?? 'Unexpected error');
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|