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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {OperationType, ResultCode} from "../../../../../../utils/constants.js";
|
|
2
|
+
import {V1ProtocolError} from "../../V1ProtocolError.js";
|
|
3
|
+
|
|
4
|
+
function createOperationStrategy(payloadKey, validator, buildCompleteOperation) {
|
|
5
|
+
return {
|
|
6
|
+
payloadKey,
|
|
7
|
+
async build(decodedTransaction) {
|
|
8
|
+
await validator.validate(decodedTransaction);
|
|
9
|
+
return buildCompleteOperation(decodedTransaction);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createBroadcastTransactionOperationStrategies({
|
|
15
|
+
partialRoleAccessValidator,
|
|
16
|
+
partialBootstrapDeploymentValidator,
|
|
17
|
+
partialTransactionValidator,
|
|
18
|
+
partialTransferValidator,
|
|
19
|
+
createApplyStateMessageFactory
|
|
20
|
+
}) {
|
|
21
|
+
return new Map([
|
|
22
|
+
[
|
|
23
|
+
OperationType.ADD_WRITER,
|
|
24
|
+
createOperationStrategy(
|
|
25
|
+
'rao',
|
|
26
|
+
partialRoleAccessValidator,
|
|
27
|
+
decodedTransaction => createApplyStateMessageFactory().buildCompleteAddWriterMessage(
|
|
28
|
+
decodedTransaction.address,
|
|
29
|
+
decodedTransaction.rao.tx,
|
|
30
|
+
decodedTransaction.rao.txv,
|
|
31
|
+
decodedTransaction.rao.iw,
|
|
32
|
+
decodedTransaction.rao.in,
|
|
33
|
+
decodedTransaction.rao.is
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
OperationType.REMOVE_WRITER,
|
|
39
|
+
createOperationStrategy(
|
|
40
|
+
'rao',
|
|
41
|
+
partialRoleAccessValidator,
|
|
42
|
+
decodedTransaction => createApplyStateMessageFactory().buildCompleteRemoveWriterMessage(
|
|
43
|
+
decodedTransaction.address,
|
|
44
|
+
decodedTransaction.rao.tx,
|
|
45
|
+
decodedTransaction.rao.txv,
|
|
46
|
+
decodedTransaction.rao.iw,
|
|
47
|
+
decodedTransaction.rao.in,
|
|
48
|
+
decodedTransaction.rao.is
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
OperationType.ADMIN_RECOVERY,
|
|
54
|
+
createOperationStrategy(
|
|
55
|
+
'rao',
|
|
56
|
+
partialRoleAccessValidator,
|
|
57
|
+
decodedTransaction => createApplyStateMessageFactory().buildCompleteAdminRecoveryMessage(
|
|
58
|
+
decodedTransaction.address,
|
|
59
|
+
decodedTransaction.rao.tx,
|
|
60
|
+
decodedTransaction.rao.txv,
|
|
61
|
+
decodedTransaction.rao.iw,
|
|
62
|
+
decodedTransaction.rao.in,
|
|
63
|
+
decodedTransaction.rao.is
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
OperationType.TX,
|
|
69
|
+
createOperationStrategy(
|
|
70
|
+
'txo',
|
|
71
|
+
partialTransactionValidator,
|
|
72
|
+
decodedTransaction => createApplyStateMessageFactory().buildCompleteTransactionOperationMessage(
|
|
73
|
+
decodedTransaction.address,
|
|
74
|
+
decodedTransaction.txo.tx,
|
|
75
|
+
decodedTransaction.txo.txv,
|
|
76
|
+
decodedTransaction.txo.iw,
|
|
77
|
+
decodedTransaction.txo.in,
|
|
78
|
+
decodedTransaction.txo.ch,
|
|
79
|
+
decodedTransaction.txo.is,
|
|
80
|
+
decodedTransaction.txo.bs,
|
|
81
|
+
decodedTransaction.txo.mbs
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
87
|
+
createOperationStrategy(
|
|
88
|
+
'bdo',
|
|
89
|
+
partialBootstrapDeploymentValidator,
|
|
90
|
+
decodedTransaction => createApplyStateMessageFactory().buildCompleteBootstrapDeploymentMessage(
|
|
91
|
+
decodedTransaction.address,
|
|
92
|
+
decodedTransaction.bdo.tx,
|
|
93
|
+
decodedTransaction.bdo.txv,
|
|
94
|
+
decodedTransaction.bdo.bs,
|
|
95
|
+
decodedTransaction.bdo.ic,
|
|
96
|
+
decodedTransaction.bdo.in,
|
|
97
|
+
decodedTransaction.bdo.is
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
OperationType.TRANSFER,
|
|
103
|
+
createOperationStrategy(
|
|
104
|
+
'tro',
|
|
105
|
+
partialTransferValidator,
|
|
106
|
+
decodedTransaction => createApplyStateMessageFactory().buildCompleteTransferOperationMessage(
|
|
107
|
+
decodedTransaction.address,
|
|
108
|
+
decodedTransaction.tro.tx,
|
|
109
|
+
decodedTransaction.tro.txv,
|
|
110
|
+
decodedTransaction.tro.in,
|
|
111
|
+
decodedTransaction.tro.to,
|
|
112
|
+
decodedTransaction.tro.am,
|
|
113
|
+
decodedTransaction.tro.is
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
]
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function resolveBroadcastTransactionOperationStrategy(type, operationStrategies) {
|
|
121
|
+
const operationStrategy = operationStrategies.get(type);
|
|
122
|
+
|
|
123
|
+
if (!operationStrategy) {
|
|
124
|
+
throw new V1ProtocolError(ResultCode.TX_INVALID_PAYLOAD, `Unsupported transaction type: ${type}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return operationStrategy;
|
|
128
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import b4a from "b4a";
|
|
2
|
+
|
|
3
|
+
import { operationToPayload } from "../../../../../../utils/applyOperations.js";
|
|
4
|
+
|
|
5
|
+
const COMPLETION_FIELDS = ['va', 'vn', 'vs'];
|
|
6
|
+
|
|
7
|
+
export function sanitizeDecodedPartialTransaction(decodedTransaction) {
|
|
8
|
+
const operationKey = operationToPayload(decodedTransaction?.type);
|
|
9
|
+
const operation = decodedTransaction?.[operationKey];
|
|
10
|
+
|
|
11
|
+
if (!operation || typeof operation !== 'object') {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const completionField of COMPLETION_FIELDS) {
|
|
16
|
+
// Protobuf decode sets optional completion fields as null, but partial validators expect those fields to be absent.
|
|
17
|
+
// Otherwise, the presence of null fields causes validation to fail with "Expected type X but got null" errors.
|
|
18
|
+
if (operation[completionField] === null) {
|
|
19
|
+
delete operation[completionField];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getTxHashFromDecodedTransaction(decodedTransaction, payloadKey = operationToPayload(decodedTransaction?.type)) {
|
|
25
|
+
return b4a.toString(decodedTransaction[payloadKey].tx, 'hex');
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import V1ValidationSchema from "./V1ValidationSchema.js";
|
|
2
2
|
import {NetworkOperationType, ResultCode} from "../../../../../utils/constants.js";
|
|
3
|
-
import
|
|
3
|
+
import tracCryptoApi from "trac-crypto-api";
|
|
4
4
|
import b4a from "b4a";
|
|
5
5
|
import {
|
|
6
6
|
createMessage,
|
|
@@ -10,34 +10,30 @@ import {
|
|
|
10
10
|
timestampToBuffer
|
|
11
11
|
} from "../../../../../utils/buffer.js";
|
|
12
12
|
import {
|
|
13
|
-
V1InvalidPayloadError,
|
|
14
13
|
V1ProtocolError,
|
|
15
|
-
V1SignatureInvalidError,
|
|
16
|
-
V1UnexpectedError,
|
|
17
14
|
} from "../V1ProtocolError.js";
|
|
18
15
|
import _ from 'lodash';
|
|
16
|
+
|
|
19
17
|
class V1BaseOperation {
|
|
20
18
|
#v1ValidationSchema
|
|
21
|
-
#config
|
|
22
19
|
|
|
23
|
-
constructor(
|
|
24
|
-
this.#config = config;
|
|
20
|
+
constructor(_config) {
|
|
25
21
|
this.#v1ValidationSchema = new V1ValidationSchema();
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
async validate(
|
|
24
|
+
async validate(_payload, _connection, _pendingRequestServiceEntry) {
|
|
29
25
|
throw new Error("Method 'validate()' must be implemented.");
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
isPayloadSchemaValid(payload) {
|
|
33
29
|
if (_.isNil(payload?.type)) {
|
|
34
|
-
throw new
|
|
30
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD,'Payload or payload type is missing.');
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
const selectedValidator = this.#selectCheckSchemaValidator(payload.type);
|
|
38
34
|
const isPayloadValid = selectedValidator(payload);
|
|
39
35
|
if (!isPayloadValid) {
|
|
40
|
-
throw new
|
|
36
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Payload is invalid.');
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
|
|
@@ -52,33 +48,33 @@ class V1BaseOperation {
|
|
|
52
48
|
if (error instanceof V1ProtocolError) {
|
|
53
49
|
throw error;
|
|
54
50
|
}
|
|
55
|
-
throw new
|
|
51
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, `Failed to build signature message: ${error.message}`);
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
let hash;
|
|
59
55
|
try {
|
|
60
|
-
hash = await
|
|
61
|
-
} catch
|
|
62
|
-
throw new
|
|
56
|
+
hash = await tracCryptoApi.hash.blake3(message);
|
|
57
|
+
} catch {
|
|
58
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Failed to hash signature message.');
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
let verified = false;
|
|
66
62
|
try {
|
|
67
|
-
verified =
|
|
68
|
-
} catch
|
|
63
|
+
verified = tracCryptoApi.signature.verify(signature, hash, remotePublicKey);
|
|
64
|
+
} catch {
|
|
69
65
|
verified = false;
|
|
70
66
|
}
|
|
71
67
|
if (!verified) {
|
|
72
|
-
throw new
|
|
68
|
+
throw new V1ProtocolError(ResultCode.SIGNATURE_INVALID, 'signature verification failed.');
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
#buildSignatureMessage(payload) {
|
|
77
73
|
if (!Number.isInteger(payload.type)) {
|
|
78
|
-
throw new
|
|
74
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Operation type must be an integer.');
|
|
79
75
|
}
|
|
80
76
|
if (payload.type === 0) {
|
|
81
|
-
throw new
|
|
77
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Operation type is unspecified.');
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
const idBuf = idToBuffer(payload.id);
|
|
@@ -119,21 +115,21 @@ class V1BaseOperation {
|
|
|
119
115
|
|
|
120
116
|
if (result === ResultCode.OK) {
|
|
121
117
|
if (!hasProof || !hasTimestamp) {
|
|
122
|
-
throw new
|
|
118
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Result code OK requires non-empty proof and timestamp > 0.');
|
|
123
119
|
}
|
|
124
120
|
} else if (result === ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE) {
|
|
125
121
|
if (hasProof) {
|
|
126
|
-
throw new
|
|
122
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Result code TX_ACCEPTED_PROOF_UNAVAILABLE requires empty proof.');
|
|
127
123
|
}
|
|
128
124
|
if (!hasTimestamp) {
|
|
129
|
-
throw new
|
|
125
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Result code TX_ACCEPTED_PROOF_UNAVAILABLE requires timestamp > 0.');
|
|
130
126
|
}
|
|
131
127
|
} else {
|
|
132
128
|
if (hasProof) {
|
|
133
|
-
throw new
|
|
129
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Non-OK result code requires empty proof.');
|
|
134
130
|
}
|
|
135
131
|
if (timestamp !== 0) {
|
|
136
|
-
throw new
|
|
132
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Non-OK result code requires timestamp to be 0, except TX_ACCEPTED_PROOF_UNAVAILABLE.');
|
|
137
133
|
}
|
|
138
134
|
}
|
|
139
135
|
|
|
@@ -151,16 +147,16 @@ class V1BaseOperation {
|
|
|
151
147
|
return {signature, message};
|
|
152
148
|
}
|
|
153
149
|
default:
|
|
154
|
-
throw new
|
|
150
|
+
throw new V1ProtocolError(ResultCode.UNEXPECTED_ERROR, `Unknown operation type: ${payload.type}`);
|
|
155
151
|
}
|
|
156
152
|
}
|
|
157
153
|
|
|
158
154
|
#selectCheckSchemaValidator(type) {
|
|
159
155
|
if (!Number.isInteger(type)) {
|
|
160
|
-
throw new
|
|
156
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Operation type must be an integer.');
|
|
161
157
|
}
|
|
162
158
|
if (type === 0) {
|
|
163
|
-
throw new
|
|
159
|
+
throw new V1ProtocolError(ResultCode.INVALID_PAYLOAD, 'Operation type is unspecified.');
|
|
164
160
|
}
|
|
165
161
|
|
|
166
162
|
switch (type) {
|
|
@@ -173,14 +169,15 @@ class V1BaseOperation {
|
|
|
173
169
|
case NetworkOperationType.BROADCAST_TRANSACTION_RESPONSE:
|
|
174
170
|
return this.#v1ValidationSchema.validateV1BroadcastTransactionResponse.bind(this.#v1ValidationSchema);
|
|
175
171
|
default:
|
|
176
|
-
throw new
|
|
172
|
+
throw new V1ProtocolError(ResultCode.UNEXPECTED_ERROR, `Unknown operation type: ${type}`);
|
|
177
173
|
}
|
|
178
174
|
}
|
|
179
175
|
|
|
180
176
|
validatePeerCorrectness(remotePublicKey, pendingRequestServiceEntry) {
|
|
181
177
|
const senderPublicKeyHex = b4a.toString(remotePublicKey, 'hex');
|
|
182
178
|
if (senderPublicKeyHex !== pendingRequestServiceEntry.requestedTo) {
|
|
183
|
-
throw new
|
|
179
|
+
throw new V1ProtocolError(
|
|
180
|
+
ResultCode.INVALID_PAYLOAD,
|
|
184
181
|
`Response sender mismatch. Expected ${pendingRequestServiceEntry.requestedTo}, got ${senderPublicKeyHex}.`
|
|
185
182
|
);
|
|
186
183
|
}
|
|
@@ -196,11 +193,15 @@ class V1BaseOperation {
|
|
|
196
193
|
expectedResponseType = NetworkOperationType.BROADCAST_TRANSACTION_RESPONSE;
|
|
197
194
|
break;
|
|
198
195
|
default:
|
|
199
|
-
throw new
|
|
196
|
+
throw new V1ProtocolError(
|
|
197
|
+
ResultCode.UNEXPECTED_ERROR,
|
|
198
|
+
`Unsupported pending request type: ${pendingRequestServiceEntry.requestType}.`
|
|
199
|
+
);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
if (payload.type !== expectedResponseType) {
|
|
203
|
-
throw new
|
|
203
|
+
throw new V1ProtocolError(
|
|
204
|
+
ResultCode.INVALID_PAYLOAD,
|
|
204
205
|
`Response type mismatch for id ${pendingRequestServiceEntry.id}. Expected ${expectedResponseType}, got ${payload.type}.`
|
|
205
206
|
);
|
|
206
207
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import V1BaseOperation from "./V1BaseOperation.js";
|
|
2
2
|
import b4a from "b4a";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE, ResultCode} from '../../../../../utils/constants.js';
|
|
4
|
+
import {V1ProtocolError} from "../V1ProtocolError.js";
|
|
5
5
|
|
|
6
6
|
class V1BroadcastTransactionRequest extends V1BaseOperation {
|
|
7
7
|
constructor(config) {
|
|
@@ -17,7 +17,9 @@ class V1BroadcastTransactionRequest extends V1BaseOperation {
|
|
|
17
17
|
|
|
18
18
|
isDataPropertySizeValid(payload) {
|
|
19
19
|
if (b4a.byteLength(payload.broadcast_transaction_request.data) > MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new V1ProtocolError(
|
|
21
|
+
ResultCode.INVALID_PAYLOAD,
|
|
22
|
+
`The 'data' field exceeds the maximum allowed byte size of ${MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE}. Actual size: ${b4a.byteLength(payload.broadcast_transaction_request.data)}`);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -12,6 +12,24 @@ import {V1ProtocolError} from "../V1ProtocolError.js";
|
|
|
12
12
|
|
|
13
13
|
const VALIDATOR_METADATA_FIELDS = new Set(["va", "vn", "vs"]);
|
|
14
14
|
|
|
15
|
+
const stripValidatorMetadata = (value) => {
|
|
16
|
+
|
|
17
|
+
if (value === null || value === undefined) return value;
|
|
18
|
+
if (b4a.isBuffer(value)) return value;
|
|
19
|
+
if (Array.isArray(value)) return value.map(stripValidatorMetadata);
|
|
20
|
+
if (typeof value !== "object") return value;
|
|
21
|
+
|
|
22
|
+
const result = {};
|
|
23
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
24
|
+
if (VALIDATOR_METADATA_FIELDS.has(key)) {
|
|
25
|
+
result[key] = null;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
result[key] = stripValidatorMetadata(nestedValue);
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
15
33
|
class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
16
34
|
#config;
|
|
17
35
|
#check;
|
|
@@ -59,16 +77,14 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
59
77
|
if (!Number.isInteger(type)) {
|
|
60
78
|
throw new V1ProtocolError(
|
|
61
79
|
ResultCode.VALIDATOR_RESPONSE_TX_TYPE_INVALID,
|
|
62
|
-
'Decoded validator transaction type is missing or invalid.'
|
|
63
|
-
false
|
|
80
|
+
'Decoded validator transaction type is missing or invalid.'
|
|
64
81
|
);
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
if (!Object.values(OperationType).includes(type)) {
|
|
68
85
|
throw new V1ProtocolError(
|
|
69
86
|
ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN,
|
|
70
|
-
`Decoded validator transaction type ${type} is not defined in OperationType constants
|
|
71
|
-
false
|
|
87
|
+
`Decoded validator transaction type ${type} is not defined in OperationType constants.`
|
|
72
88
|
);
|
|
73
89
|
}
|
|
74
90
|
|
|
@@ -91,16 +107,14 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
91
107
|
default:
|
|
92
108
|
throw new V1ProtocolError(
|
|
93
109
|
ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED,
|
|
94
|
-
`Unsupported decoded validator transaction type: ${type}
|
|
95
|
-
false
|
|
110
|
+
`Unsupported decoded validator transaction type: ${type}`
|
|
96
111
|
);
|
|
97
112
|
}
|
|
98
113
|
|
|
99
114
|
if (!isValid) {
|
|
100
115
|
throw new V1ProtocolError(
|
|
101
116
|
ResultCode.VALIDATOR_RESPONSE_SCHEMA_INVALID,
|
|
102
|
-
`Decoded validator transaction schema validation failed for type ${type}
|
|
103
|
-
false
|
|
117
|
+
`Decoded validator transaction schema validation failed for type ${type}.`
|
|
104
118
|
);
|
|
105
119
|
}
|
|
106
120
|
}
|
|
@@ -115,8 +129,7 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
115
129
|
if (!b4a.isBuffer(stateTxEncodedFromRequest) || stateTxEncodedFromRequest.length === 0) {
|
|
116
130
|
throw new V1ProtocolError(
|
|
117
131
|
ResultCode.PENDING_REQUEST_MISSING_TX_DATA,
|
|
118
|
-
'Missing transaction data in pending request entry.'
|
|
119
|
-
false
|
|
132
|
+
'Missing transaction data in pending request entry.'
|
|
120
133
|
);
|
|
121
134
|
}
|
|
122
135
|
const provenBlock = proofResult.proof.block.value;
|
|
@@ -130,8 +143,7 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
130
143
|
if (!isDeepEqualApplyPayload(stateTxDecodedFromRequest, strippedValidatorPayload)) {
|
|
131
144
|
throw new V1ProtocolError(
|
|
132
145
|
ResultCode.PROOF_PAYLOAD_MISMATCH,
|
|
133
|
-
'Decoded transaction payload mismatch after removing validator metadata fields.'
|
|
134
|
-
false
|
|
146
|
+
'Decoded transaction payload mismatch after removing validator metadata fields.'
|
|
135
147
|
);
|
|
136
148
|
}
|
|
137
149
|
return {validatorDecodedTx: stateTxDecodedFromResponse, manifest};
|
|
@@ -145,8 +157,7 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
145
157
|
if (!b4a.isBuffer(validatorAddressBuffer) || validatorAddressBuffer.length === 0) {
|
|
146
158
|
throw new V1ProtocolError(
|
|
147
159
|
ResultCode.VALIDATOR_WRITER_KEY_NOT_REGISTERED,
|
|
148
|
-
`Validator with writer key ${writerKeyFromManifestHex} is not registered
|
|
149
|
-
false
|
|
160
|
+
`Validator with writer key ${writerKeyFromManifestHex} is not registered.`
|
|
150
161
|
);
|
|
151
162
|
}
|
|
152
163
|
|
|
@@ -166,24 +177,21 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
166
177
|
if (!b4a.equals(validatorAddressFromTx, validatorAddressFromConnectionPublicKey)) {
|
|
167
178
|
throw new V1ProtocolError(
|
|
168
179
|
ResultCode.VALIDATOR_ADDRESS_MISMATCH,
|
|
169
|
-
`Validator address from transaction (${bufferToAddress(validatorAddressFromTx, this.#config.addressPrefix)}) does not match address derived from connection public key (${bufferToAddress(validatorAddressFromConnectionPublicKey, this.#config.addressPrefix)})
|
|
170
|
-
false
|
|
180
|
+
`Validator address from transaction (${bufferToAddress(validatorAddressFromTx, this.#config.addressPrefix)}) does not match address derived from connection public key (${bufferToAddress(validatorAddressFromConnectionPublicKey, this.#config.addressPrefix)}).`
|
|
171
181
|
);
|
|
172
182
|
}
|
|
173
183
|
|
|
174
184
|
if (!b4a.equals(validatorAddressFromTx, validatorAddressCorrelatedWithManifest)) {
|
|
175
185
|
throw new V1ProtocolError(
|
|
176
186
|
ResultCode.VALIDATOR_ADDRESS_MISMATCH,
|
|
177
|
-
`Validator address from transaction (${bufferToAddress(validatorAddressFromTx, this.#config.addressPrefix)}) does not match address correlated with manifest writer key (${bufferToAddress(validatorAddressCorrelatedWithManifest, this.#config.addressPrefix)})
|
|
178
|
-
false
|
|
187
|
+
`Validator address from transaction (${bufferToAddress(validatorAddressFromTx, this.#config.addressPrefix)}) does not match address correlated with manifest writer key (${bufferToAddress(validatorAddressCorrelatedWithManifest, this.#config.addressPrefix)}).`
|
|
179
188
|
);
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
if (!b4a.equals(validatorAddressCorrelatedWithManifest, validatorAddressFromConnectionPublicKey)) {
|
|
183
192
|
throw new V1ProtocolError(
|
|
184
193
|
ResultCode.VALIDATOR_ADDRESS_MISMATCH,
|
|
185
|
-
`Validator address correlated with manifest writer key (${bufferToAddress(validatorAddressCorrelatedWithManifest, this.#config.addressPrefix)}) does not match address derived from connection public key (${bufferToAddress(validatorAddressFromConnectionPublicKey, this.#config.addressPrefix)})
|
|
186
|
-
false
|
|
194
|
+
`Validator address correlated with manifest writer key (${bufferToAddress(validatorAddressCorrelatedWithManifest, this.#config.addressPrefix)}) does not match address derived from connection public key (${bufferToAddress(validatorAddressFromConnectionPublicKey, this.#config.addressPrefix)}).`
|
|
187
195
|
);
|
|
188
196
|
}
|
|
189
197
|
|
|
@@ -193,24 +201,21 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
193
201
|
if (!account) {
|
|
194
202
|
throw new V1ProtocolError(
|
|
195
203
|
ResultCode.VALIDATOR_NODE_ENTRY_NOT_FOUND,
|
|
196
|
-
`No node entry found in state for validator address derived from connection public key (${validatorAddressFromConnection})
|
|
197
|
-
false
|
|
204
|
+
`No node entry found in state for validator address derived from connection public key (${validatorAddressFromConnection}).`
|
|
198
205
|
);
|
|
199
206
|
}
|
|
200
207
|
|
|
201
208
|
if (!account.isWriter) {
|
|
202
209
|
throw new V1ProtocolError(
|
|
203
210
|
ResultCode.VALIDATOR_NODE_NOT_WRITER,
|
|
204
|
-
`Node entry found for validator address derived from connection public key (${validatorAddressFromConnection}), but it is not registered as a writer
|
|
205
|
-
false
|
|
211
|
+
`Node entry found for validator address derived from connection public key (${validatorAddressFromConnection}), but it is not registered as a writer.`
|
|
206
212
|
);
|
|
207
213
|
}
|
|
208
214
|
|
|
209
215
|
if (!b4a.isBuffer(account.wk) || !b4a.equals(account.wk, writerKeyFromManifest)) {
|
|
210
216
|
throw new V1ProtocolError(
|
|
211
217
|
ResultCode.VALIDATOR_WRITER_KEY_MISMATCH,
|
|
212
|
-
`Writer key from manifest (${b4a.toString(writerKeyFromManifest, "hex")}) does not match writer key in state for validator address derived from connection public key (${validatorAddressFromConnection})
|
|
213
|
-
false
|
|
218
|
+
`Writer key from manifest (${b4a.toString(writerKeyFromManifest, "hex")}) does not match writer key in state for validator address derived from connection public key (${validatorAddressFromConnection}).`
|
|
214
219
|
);
|
|
215
220
|
}
|
|
216
221
|
}
|
|
@@ -219,37 +224,17 @@ class V1BroadcastTransactionResponse extends V1BaseOperation {
|
|
|
219
224
|
if (resultCode === ResultCode.TX_COMMITTED_RECEIPT_MISSING) {
|
|
220
225
|
throw new V1ProtocolError(
|
|
221
226
|
resultCode,
|
|
222
|
-
`Validator response indicates an error with result code ${resultCode}, which is an internal error code
|
|
223
|
-
true
|
|
227
|
+
`Validator response indicates an error with result code ${resultCode}, which is an internal error code.`
|
|
224
228
|
)
|
|
225
229
|
}
|
|
226
230
|
}
|
|
227
231
|
}
|
|
228
232
|
|
|
229
|
-
const stripValidatorMetadata = (value) => {
|
|
230
|
-
|
|
231
|
-
if (value === null || value === undefined) return value;
|
|
232
|
-
if (b4a.isBuffer(value)) return value;
|
|
233
|
-
if (Array.isArray(value)) return value.map(stripValidatorMetadata);
|
|
234
|
-
if (typeof value !== "object") return value;
|
|
235
|
-
|
|
236
|
-
const result = {};
|
|
237
|
-
for (const [key, nestedValue] of Object.entries(value)) {
|
|
238
|
-
if (VALIDATOR_METADATA_FIELDS.has(key)) {
|
|
239
|
-
result[key] = null;
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
result[key] = stripValidatorMetadata(nestedValue);
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
233
|
export function extractRequiredVaFromDecodedTx(validatorDecodedTx) {
|
|
248
234
|
if (!validatorDecodedTx || typeof validatorDecodedTx !== 'object') {
|
|
249
235
|
throw new V1ProtocolError(
|
|
250
236
|
ResultCode.VALIDATOR_TX_OBJECT_INVALID,
|
|
251
|
-
'Invalid decoded transaction: expected object'
|
|
252
|
-
false
|
|
237
|
+
'Invalid decoded transaction: expected object'
|
|
253
238
|
);
|
|
254
239
|
}
|
|
255
240
|
|
|
@@ -266,8 +251,7 @@ export function extractRequiredVaFromDecodedTx(validatorDecodedTx) {
|
|
|
266
251
|
if (!b4a.isBuffer(va)) {
|
|
267
252
|
throw new V1ProtocolError(
|
|
268
253
|
ResultCode.VALIDATOR_VA_MISSING,
|
|
269
|
-
'Missing validator address (va) in decoded transaction'
|
|
270
|
-
false
|
|
254
|
+
'Missing validator address (va) in decoded transaction'
|
|
271
255
|
);
|
|
272
256
|
}
|
|
273
257
|
return va;
|
|
@@ -30,7 +30,7 @@ class V1ValidationSchema {
|
|
|
30
30
|
},
|
|
31
31
|
});
|
|
32
32
|
const isBuffer = b4a.isBuffer;
|
|
33
|
-
this.#validator.add("buffer", function ({schema, messages},
|
|
33
|
+
this.#validator.add("buffer", function ({schema, messages}, _path, _context) {
|
|
34
34
|
const allowZero = schema.allowZero === true;
|
|
35
35
|
const allowEmpty = schema.allowEmpty === true;
|
|
36
36
|
const exactLength = Number.isInteger(schema.length) ? schema.length : null;
|
|
@@ -6,6 +6,13 @@ import {Logger} from "../../../utils/logger.js";
|
|
|
6
6
|
* @typedef {import('hyperswarm').Connection} Connection
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
export class ConnectionManagerError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
class ConnectionManager {
|
|
10
17
|
#validators
|
|
11
18
|
#maxValidators
|
|
@@ -180,15 +187,16 @@ class ConnectionManager {
|
|
|
180
187
|
/**
|
|
181
188
|
* Removes a validator from the pool.
|
|
182
189
|
* @param {String | Buffer} publicKey - The public key hex string of the validator to remove
|
|
190
|
+
* @param {object} [options]
|
|
191
|
+
* @param {boolean} [options.endConnection=true] - Whether to close the underlying socket.
|
|
183
192
|
*/
|
|
184
|
-
remove(publicKey) {
|
|
193
|
+
remove(publicKey, { endConnection = true } = {}) {
|
|
185
194
|
this.#logger.debug(`remove: removing validator ${publicKeyToAddress(publicKey, this.#config)}`);
|
|
186
195
|
const publicKeyHex = this.#toHexString(publicKey);
|
|
187
196
|
this.#stopHealthCheck(publicKeyHex);
|
|
188
197
|
if (this.exists(publicKeyHex)) {
|
|
189
|
-
// Close the connection socket
|
|
190
198
|
const entry = this.#validators.get(publicKeyHex);
|
|
191
|
-
if (entry && entry.connection && typeof entry.connection.end === 'function') {
|
|
199
|
+
if (endConnection && entry && entry.connection && typeof entry.connection.end === 'function') {
|
|
192
200
|
try {
|
|
193
201
|
entry.connection.end();
|
|
194
202
|
} catch (e) {
|
|
@@ -349,11 +357,4 @@ class ConnectionManager {
|
|
|
349
357
|
}
|
|
350
358
|
}
|
|
351
359
|
|
|
352
|
-
export class ConnectionManagerError extends Error {
|
|
353
|
-
constructor(message) {
|
|
354
|
-
super(message);
|
|
355
|
-
this.name = this.constructor.name;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
360
|
export default ConnectionManager;
|