trac-msb 0.2.17 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +33 -11
- 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 +163 -14
- package/src/config/env.js +57 -25
- package/src/core/network/Network.js +121 -56
- package/src/core/network/protocols/LegacyProtocol.js +21 -11
- package/src/core/network/protocols/NetworkMessages.js +38 -17
- package/src/core/network/protocols/ProtocolInterface.js +15 -3
- package/src/core/network/protocols/ProtocolSession.js +144 -17
- package/src/core/network/protocols/V1Protocol.js +37 -18
- package/src/core/network/protocols/connectionPolicies.js +174 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +26 -20
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +25 -14
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +9 -9
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +19 -12
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +29 -18
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +18 -12
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
- package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +53 -31
- package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
- package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
- package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +32 -14
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +27 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +66 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +272 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +88 -0
- 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 +212 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +28 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +260 -0
- package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
- package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
- package/src/core/network/services/ConnectionManager.js +149 -96
- package/src/core/network/services/MessageOrchestrator.js +197 -37
- package/src/core/network/services/PendingRequestService.js +175 -0
- package/src/core/network/services/TransactionCommitService.js +149 -0
- package/src/core/network/services/TransactionPoolService.js +129 -18
- package/src/core/network/services/TransactionRateLimiterService.js +57 -35
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +400 -121
- package/src/core/state/State.js +259 -156
- 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 +320 -278
- package/src/messages/network/v1/NetworkMessageBuilder.js +71 -100
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- 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/Scheduler.js +0 -8
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +78 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- package/src/utils/migrationUtils.js +3 -3
- package/src/utils/normalizers.js +38 -0
- package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
- package/src/utils/protobuf/operationHelpers.js +24 -3
- package/.dockerignore +0 -16
- package/.github/workflows/acceptance-tests.yml +0 -38
- package/.github/workflows/lint-pr-title.yml +0 -26
- package/.github/workflows/publish.yml +0 -33
- package/.github/workflows/unit-tests.yml +0 -34
- 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.proto +0 -74
- package/rpc/rpc_services.js +0 -163
- package/scripts/generate-protobufs.js +0 -42
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/acceptance/v1/account/account.test.mjs +0 -123
- 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 -111
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -213
- 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 -85
- 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 -276
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -201
- 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/ConnectionManager.test.js +0 -191
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/networkModule.test.js +0 -10
- 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/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 -305
- 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 -20
- package/whitelist/.gitkeep +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NETWORK_MESSAGE_TYPES } from '../../../../../utils/constants.js';
|
|
2
|
-
import
|
|
2
|
+
import tracCryptoApi from 'trac-crypto-api';
|
|
3
3
|
import b4a from 'b4a';
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class LegacyGetRequestHandler {
|
|
6
6
|
#wallet;
|
|
7
7
|
#state;
|
|
8
8
|
|
|
@@ -15,18 +15,18 @@ class GetRequestHandler {
|
|
|
15
15
|
return this.#state;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async handle(message,
|
|
18
|
+
async handle(message, connection, channelString) {
|
|
19
19
|
switch (message) {
|
|
20
20
|
case NETWORK_MESSAGE_TYPES.GET.VALIDATOR:
|
|
21
|
-
await this.handleGetValidatorResponse(
|
|
21
|
+
await this.handleGetValidatorResponse(connection, channelString);
|
|
22
22
|
break;
|
|
23
23
|
default:
|
|
24
24
|
throw new Error(`Unhandled GET type: ${message}`);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async handleGetValidatorResponse(
|
|
29
|
-
const nonce =
|
|
28
|
+
async handleGetValidatorResponse(connection, channelString) {
|
|
29
|
+
const nonce = b4a.toString(tracCryptoApi.nonce.generate(), 'hex');
|
|
30
30
|
const payload = {
|
|
31
31
|
op: 'validatorResponse',
|
|
32
32
|
wk: this.state.writingKey.toString('hex'),
|
|
@@ -39,15 +39,15 @@ class GetRequestHandler {
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
const hashInput = b4a.from(JSON.stringify(payload), 'utf8');
|
|
42
|
-
const hash = await
|
|
42
|
+
const hash = await tracCryptoApi.hash.blake3(hashInput);
|
|
43
43
|
const sig = this.#wallet.sign(hash);
|
|
44
44
|
|
|
45
45
|
const responseMessage = {
|
|
46
46
|
...payload,
|
|
47
47
|
sig: sig.toString('hex'),
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
connection.protocolSession.sendAndForget(responseMessage)
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export default
|
|
53
|
+
export default LegacyGetRequestHandler;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ValidatorResponse from '../validators/ValidatorResponse.js';
|
|
2
|
+
|
|
3
|
+
class LegacyResponseHandler {
|
|
4
|
+
#responseValidator;
|
|
5
|
+
|
|
6
|
+
constructor(state, wallet, config) {
|
|
7
|
+
this.#responseValidator = new ValidatorResponse(state, wallet, config);
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async handle(message, channelString) {
|
|
12
|
+
await this.#handleValidatorResponse(message, channelString);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async #handleValidatorResponse(message, channelString) {
|
|
16
|
+
const isValid = await this.#responseValidator.validate(message, channelString);
|
|
17
|
+
if (!isValid) {
|
|
18
|
+
throw new Error("Validator response verification failed");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default LegacyResponseHandler;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {OperationType} from '../../../../../utils/constants.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import PartialRoleAccessValidator from "../../shared/validators/PartialRoleAccessValidator.js";
|
|
3
|
+
import BaseStateOperationHandler from './BaseStateOperationHandler.js';
|
|
4
4
|
import {applyStateMessageFactory} from "../../../../../messages/state/applyStateMessageFactory.js";
|
|
5
5
|
import {safeEncodeApplyOperation} from "../../../../../utils/protobuf/operationHelpers.js";
|
|
6
6
|
import {normalizeRoleAccessOperation} from "../../../../../utils/normalizers.js";
|
|
7
|
+
import { publicKeyToAddress } from "../../../../../utils/helpers.js"
|
|
8
|
+
import b4a from "b4a";
|
|
7
9
|
|
|
8
|
-
class
|
|
10
|
+
class LegacyRoleOperationHandler extends BaseStateOperationHandler {
|
|
9
11
|
#partialRoleAccessValidator;
|
|
10
12
|
#wallet;
|
|
11
13
|
#config;
|
|
12
|
-
#txPoolService;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @param {State} state
|
|
16
|
-
* @param {
|
|
17
|
+
* @param {IWallet} wallet
|
|
17
18
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
18
19
|
* @param {TransactionPoolService} txPoolService
|
|
19
20
|
* @param {Config} config
|
|
@@ -22,8 +23,7 @@ class RoleOperationHandler extends BaseOperationHandler {
|
|
|
22
23
|
super(state, wallet, rateLimiter, txPoolService, config);
|
|
23
24
|
this.#wallet = wallet;
|
|
24
25
|
this.#config = config;
|
|
25
|
-
this.#partialRoleAccessValidator = new
|
|
26
|
-
this.#txPoolService = txPoolService;
|
|
26
|
+
this.#partialRoleAccessValidator = new PartialRoleAccessValidator(state, this.#wallet.address ,this.#config)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
get partialRoleAccessValidator() {
|
|
@@ -35,7 +35,8 @@ class RoleOperationHandler extends BaseOperationHandler {
|
|
|
35
35
|
const isValid = await this.partialRoleAccessValidator.validate(normalizedPartialRoleAccessPayload)
|
|
36
36
|
let completePayload = null
|
|
37
37
|
if (!isValid) {
|
|
38
|
-
throw new Error(
|
|
38
|
+
throw new Error(
|
|
39
|
+
`OperationHandler: partial role access payload validation failed. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
switch (normalizedPartialRoleAccessPayload.type) {
|
|
@@ -74,15 +75,21 @@ class RoleOperationHandler extends BaseOperationHandler {
|
|
|
74
75
|
)
|
|
75
76
|
break;
|
|
76
77
|
default:
|
|
77
|
-
throw new Error(
|
|
78
|
+
throw new Error(
|
|
79
|
+
`OperationHandler: Assembling complete role access operation failed due to unsupported operation type. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
|
|
80
|
+
);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
if (!completePayload) {
|
|
81
|
-
throw new Error(
|
|
84
|
+
throw new Error(
|
|
85
|
+
`OperationHandler: Assembling complete role access operation failed. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
|
|
86
|
+
);
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
|
|
89
|
+
const encodedOperation = safeEncodeApplyOperation(completePayload);
|
|
90
|
+
const txHash = b4a.toString(completePayload.rao.tx, 'hex');
|
|
91
|
+
this.enqueueTransaction(txHash, encodedOperation);
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
export default
|
|
95
|
+
export default LegacyRoleOperationHandler;
|
|
@@ -1,47 +1,49 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseStateOperationHandler from './BaseStateOperationHandler.js';
|
|
2
2
|
import {
|
|
3
3
|
OperationType
|
|
4
4
|
} from '../../../../../utils/constants.js';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import PartialBootstrapDeploymentValidator from "../../shared/validators/PartialBootstrapDeploymentValidator.js";
|
|
6
|
+
import PartialTransactionValidator from "../../shared/validators/PartialTransactionValidator.js";
|
|
7
7
|
import {applyStateMessageFactory} from "../../../../../messages/state/applyStateMessageFactory.js";
|
|
8
8
|
import {safeEncodeApplyOperation} from "../../../../../utils/protobuf/operationHelpers.js";
|
|
9
9
|
import {
|
|
10
10
|
normalizeBootstrapDeploymentOperation,
|
|
11
11
|
normalizeTransactionOperation
|
|
12
12
|
} from "../../../../../utils/normalizers.js";
|
|
13
|
+
import b4a from "b4a";
|
|
14
|
+
import {publicKeyToAddress} from "../../../../../utils/helpers.js";
|
|
13
15
|
|
|
14
16
|
|
|
15
|
-
class
|
|
17
|
+
class LegacySubnetworkOperationHandler extends BaseStateOperationHandler {
|
|
16
18
|
#partialBootstrapDeploymentValidator;
|
|
17
19
|
#partialTransactionValidator;
|
|
18
20
|
#config;
|
|
19
21
|
#wallet;
|
|
20
|
-
#txPoolService;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @param {State} state
|
|
24
|
-
* @param {
|
|
25
|
+
* @param {IWallet} wallet
|
|
25
26
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
26
27
|
* @param {TransactionPoolService} txPoolService
|
|
27
28
|
* @param {Config} config
|
|
28
29
|
**/
|
|
29
|
-
constructor(
|
|
30
|
+
constructor(state, wallet, rateLimiter, txPoolService, config) {
|
|
30
31
|
super(state, wallet, rateLimiter, txPoolService, config);
|
|
31
32
|
this.#config = config;
|
|
32
33
|
this.#wallet = wallet
|
|
33
|
-
this.#partialBootstrapDeploymentValidator = new
|
|
34
|
-
this.#partialTransactionValidator = new
|
|
35
|
-
this.#txPoolService = txPoolService;
|
|
34
|
+
this.#partialBootstrapDeploymentValidator = new PartialBootstrapDeploymentValidator(state, this.#wallet.address, config);
|
|
35
|
+
this.#partialTransactionValidator = new PartialTransactionValidator(state, this.#wallet.address, config);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async handleOperation(payload, connection)
|
|
38
|
+
async handleOperation(payload, connection) {
|
|
39
39
|
if (payload.type === OperationType.TX) {
|
|
40
40
|
await this.#partialTransactionSubHandler(payload, connection);
|
|
41
41
|
} else if (payload.type === OperationType.BOOTSTRAP_DEPLOYMENT) {
|
|
42
42
|
await this.#partialBootstrapDeploymentSubHandler(payload, connection);
|
|
43
43
|
} else {
|
|
44
|
-
throw new Error(
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Unsupported operation type for LegacySubnetworkOperationHandler. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)} `
|
|
46
|
+
);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -49,10 +51,12 @@ class SubnetworkOperationHandler extends BaseOperationHandler {
|
|
|
49
51
|
const normalizedPayload = normalizeTransactionOperation(payload, this.#config);
|
|
50
52
|
const isValid = await this.#partialTransactionValidator.validate(normalizedPayload);
|
|
51
53
|
if (!isValid) {
|
|
52
|
-
throw new Error(
|
|
54
|
+
throw new Error(`
|
|
55
|
+
SubnetworkHandler: Transaction validation failed. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
|
|
56
|
+
);
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
const completeTransactionOperation = await applyStateMessageFactory(this.#wallet,this.#config)
|
|
59
|
+
const completeTransactionOperation = await applyStateMessageFactory(this.#wallet, this.#config)
|
|
56
60
|
.buildCompleteTransactionOperationMessage(
|
|
57
61
|
normalizedPayload.address,
|
|
58
62
|
normalizedPayload.txo.tx,
|
|
@@ -64,14 +68,19 @@ class SubnetworkOperationHandler extends BaseOperationHandler {
|
|
|
64
68
|
normalizedPayload.txo.bs,
|
|
65
69
|
normalizedPayload.txo.mbs
|
|
66
70
|
)
|
|
67
|
-
|
|
71
|
+
const encodedOperation = safeEncodeApplyOperation(completeTransactionOperation);
|
|
72
|
+
const txHash = b4a.toString(normalizedPayload.txo.tx, 'hex');
|
|
73
|
+
this.enqueueTransaction(txHash, encodedOperation);
|
|
74
|
+
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
async #partialBootstrapDeploymentSubHandler(payload, connection) {
|
|
71
78
|
const normalizedPayload = normalizeBootstrapDeploymentOperation(payload, this.#config);
|
|
72
79
|
const isValid = await this.#partialBootstrapDeploymentValidator.validate(normalizedPayload);
|
|
73
80
|
if (!isValid) {
|
|
74
|
-
throw new Error(
|
|
81
|
+
throw new Error(
|
|
82
|
+
`SubnetworkHandler: Bootstrap deployment validation failed. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
|
|
83
|
+
);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
|
|
@@ -85,9 +94,11 @@ class SubnetworkOperationHandler extends BaseOperationHandler {
|
|
|
85
94
|
normalizedPayload.bdo.in,
|
|
86
95
|
normalizedPayload.bdo.is
|
|
87
96
|
)
|
|
88
|
-
|
|
97
|
+
const encodedOperation = safeEncodeApplyOperation(completeBootstrapDeploymentOperation);
|
|
98
|
+
const txHash = b4a.toString(normalizedPayload.bdo.tx, 'hex');
|
|
99
|
+
this.enqueueTransaction(txHash, encodedOperation);
|
|
89
100
|
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
|
|
93
|
-
export default
|
|
104
|
+
export default LegacySubnetworkOperationHandler;
|
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseStateOperationHandler from './BaseStateOperationHandler.js';
|
|
2
2
|
import {OperationType} from '../../../../../utils/constants.js';
|
|
3
|
-
import
|
|
3
|
+
import PartialTransferValidator from "../../shared/validators/PartialTransferValidator.js";
|
|
4
4
|
import {normalizeTransferOperation} from "../../../../../utils/normalizers.js"
|
|
5
5
|
import {applyStateMessageFactory} from "../../../../../messages/state/applyStateMessageFactory.js";
|
|
6
6
|
import {safeEncodeApplyOperation} from "../../../../../utils/protobuf/operationHelpers.js";
|
|
7
|
+
import b4a from "b4a";
|
|
8
|
+
import {publicKeyToAddress} from "../../../../../utils/helpers.js";
|
|
7
9
|
|
|
8
|
-
class
|
|
10
|
+
class LegacyTransferOperationHandler extends BaseStateOperationHandler {
|
|
9
11
|
#partialTransferValidator;
|
|
10
12
|
#config;
|
|
11
13
|
#wallet;
|
|
12
|
-
#txPoolService;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @param {State} state
|
|
16
|
-
* @param {
|
|
17
|
+
* @param {IWallet} wallet
|
|
17
18
|
* @param {TransactionRateLimiterService} rateLimiter
|
|
19
|
+
* @param {TransactionPoolService} txPoolService
|
|
18
20
|
* @param {Config} config
|
|
19
21
|
**/
|
|
20
22
|
constructor(state, wallet, rateLimiter, txPoolService, config) {
|
|
21
23
|
super(state, wallet, rateLimiter, txPoolService, config);
|
|
22
24
|
this.#config = config;
|
|
23
25
|
this.#wallet = wallet;
|
|
24
|
-
this.#partialTransferValidator = new
|
|
25
|
-
this.#txPoolService = txPoolService;
|
|
26
|
+
this.#partialTransferValidator = new PartialTransferValidator(state, this.#wallet.address, this.#config);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
async handleOperation(payload, connection) {
|
|
29
30
|
if (payload.type !== OperationType.TRANSFER) {
|
|
30
|
-
throw new Error(
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Unsupported operation type for LegacyTransferOperationHandler. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
|
|
33
|
+
);
|
|
31
34
|
}
|
|
32
35
|
await this.#handleTransfer(payload, connection);
|
|
33
36
|
}
|
|
@@ -36,7 +39,9 @@ class TransferOperationHandler extends BaseOperationHandler {
|
|
|
36
39
|
const normalizedPayload = normalizeTransferOperation(payload, this.#config);
|
|
37
40
|
const isValid = await this.#partialTransferValidator.validate(normalizedPayload);
|
|
38
41
|
if (!isValid) {
|
|
39
|
-
throw new Error(
|
|
42
|
+
throw new Error(
|
|
43
|
+
`TransferHandler: Transfer validation failed. Requested by ${publicKeyToAddress(connection.remotePublicKey, this.#config)}`
|
|
44
|
+
);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
const completeTransferOperation = await applyStateMessageFactory(this.#wallet, this.#config)
|
|
@@ -49,9 +54,10 @@ class TransferOperationHandler extends BaseOperationHandler {
|
|
|
49
54
|
normalizedPayload.tro.am,
|
|
50
55
|
normalizedPayload.tro.is
|
|
51
56
|
)
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
const encodedOperation = safeEncodeApplyOperation(completeTransferOperation);
|
|
58
|
+
const txHash = b4a.toString(normalizedPayload.tro.tx, 'hex');
|
|
59
|
+
this.enqueueTransaction(txHash, encodedOperation);
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
export default
|
|
63
|
+
export default LegacyTransferOperationHandler;
|
|
@@ -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,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PartialOperationValidator from './PartialOperationValidator.js';
|
|
2
|
+
import {ResultCode} from "../../../../../utils/constants.js";
|
|
3
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
2
4
|
|
|
3
|
-
class
|
|
5
|
+
class PartialBootstrapDeploymentValidator extends PartialOperationValidator {
|
|
4
6
|
constructor(state, selfAddress , config) {
|
|
5
7
|
super(state, selfAddress , config);
|
|
6
8
|
}
|
|
@@ -26,9 +28,12 @@ class PartialBootstrapDeployment extends PartialOperation {
|
|
|
26
28
|
async validateBootstrapRegistration(payload) {
|
|
27
29
|
const bootstrapString = payload.bdo.bs.toString('hex');
|
|
28
30
|
if (null !== await this.state.getRegisteredBootstrapEntryUnsigned(bootstrapString)) {
|
|
29
|
-
throw new
|
|
31
|
+
throw new V1ProtocolError(
|
|
32
|
+
ResultCode.BOOTSTRAP_ALREADY_EXISTS,
|
|
33
|
+
`Bootstrap with hash ${bootstrapString} already exists in the state. Bootstrap must be unique.`
|
|
34
|
+
);
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
export default
|
|
39
|
+
export default PartialBootstrapDeploymentValidator;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import
|
|
3
|
-
import Check from '
|
|
4
|
-
import {bufferToAddress} from "
|
|
5
|
-
import {createMessage} from "
|
|
6
|
-
import {OperationType} from "
|
|
7
|
-
import {bufferToBigInt} from "
|
|
8
|
-
import {FEE} from "
|
|
9
|
-
import * as operationsUtils from '
|
|
2
|
+
import tracCryptoApi from 'trac-crypto-api';
|
|
3
|
+
import Check from '../../../../../utils/check.js';
|
|
4
|
+
import {bufferToAddress} from "../../../../state/utils/address.js";
|
|
5
|
+
import {createMessage} from "../../../../../utils/buffer.js";
|
|
6
|
+
import {OperationType, ResultCode} from "../../../../../utils/constants.js";
|
|
7
|
+
import {bufferToBigInt} from "../../../../../utils/amountSerialization.js";
|
|
8
|
+
import {FEE} from "../../../../state/utils/transaction.js";
|
|
9
|
+
import * as operationsUtils from '../../../../../utils/applyOperations.js';
|
|
10
|
+
import {V1ProtocolError} from '../../v1/V1ProtocolError.js';
|
|
10
11
|
|
|
11
12
|
const MAX_AMOUNT = BigInt('0xffffffffffffffffffffffffffffffff');
|
|
12
13
|
const FEE_BIGINT = bufferToBigInt(FEE);
|
|
13
14
|
const PUBLIC_KEY_LENGTH = 32;
|
|
14
15
|
|
|
15
|
-
class
|
|
16
|
+
class PartialOperationValidator {
|
|
16
17
|
#state;
|
|
17
18
|
#check;
|
|
18
19
|
#config
|
|
@@ -35,19 +36,19 @@ class PartialOperation {
|
|
|
35
36
|
return this.#check;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
async validate(
|
|
39
|
-
throw new
|
|
39
|
+
async validate() {
|
|
40
|
+
throw new V1ProtocolError(ResultCode.UNEXPECTED_ERROR, "Method 'validate()' must be implemented.");
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
isPayloadSchemaValid(payload) {
|
|
43
44
|
if (!payload || !payload.type) {
|
|
44
|
-
throw new
|
|
45
|
+
throw new V1ProtocolError(ResultCode.TX_INVALID_PAYLOAD, 'Payload or payload type is missing.');
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
const selectedValidator = this.#selectCheckSchemaValidator(payload.type);
|
|
48
49
|
const isPayloadValid = selectedValidator(payload);
|
|
49
50
|
if (!isPayloadValid) {
|
|
50
|
-
throw new
|
|
51
|
+
throw new V1ProtocolError(ResultCode.SCHEMA_VALIDATION_FAILED, 'Payload is invalid.');
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -64,21 +65,24 @@ class PartialOperation {
|
|
|
64
65
|
case OperationType.TRANSFER:
|
|
65
66
|
return this.check.validateTransferOperation.bind(this.check);
|
|
66
67
|
default:
|
|
67
|
-
throw new
|
|
68
|
+
throw new V1ProtocolError(
|
|
69
|
+
ResultCode.OPERATION_TYPE_UNKNOWN,
|
|
70
|
+
`Unknown operation type: ${type}`
|
|
71
|
+
);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
validateRequesterAddress(payload) {
|
|
72
76
|
const incomingAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
73
77
|
if (!incomingAddress) {
|
|
74
|
-
throw new
|
|
78
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_ADDRESS_INVALID, 'Invalid requesting address in payload.');
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
const incomingPublicKey =
|
|
81
|
+
const incomingPublicKey = tracCryptoApi.address.decodeSafe(incomingAddress);
|
|
78
82
|
|
|
79
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.
|
|
80
84
|
if (!incomingPublicKey || incomingPublicKey.length !== PUBLIC_KEY_LENGTH) {
|
|
81
|
-
throw new
|
|
85
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_PUBLIC_KEY_INVALID, 'Invalid requesting public key in payload.');
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
88
|
|
|
@@ -127,7 +131,10 @@ class PartialOperation {
|
|
|
127
131
|
OperationType.TRANSFER
|
|
128
132
|
];
|
|
129
133
|
default:
|
|
130
|
-
throw new
|
|
134
|
+
throw new V1ProtocolError(
|
|
135
|
+
ResultCode.OPERATION_TYPE_UNKNOWN,
|
|
136
|
+
`Unknown operation type: ${payload.type}`
|
|
137
|
+
);
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
|
|
@@ -135,19 +142,22 @@ class PartialOperation {
|
|
|
135
142
|
const operationKey = operationsUtils.operationToPayload(payload.type);
|
|
136
143
|
const operation = payload[operationKey];
|
|
137
144
|
|
|
138
|
-
const incomingPublicKey =
|
|
145
|
+
const incomingPublicKey = tracCryptoApi.address.decodeSafe(bufferToAddress(payload.address, this.#config.addressPrefix));
|
|
139
146
|
const incomingSignature = operation.is;
|
|
140
147
|
const messageComponents = this.#getMessageComponents(payload);
|
|
141
148
|
|
|
142
149
|
const message = createMessage(...messageComponents);
|
|
143
|
-
const messageHash = await
|
|
150
|
+
const messageHash = await tracCryptoApi.hash.blake3(message);
|
|
144
151
|
const payloadHash = operation.tx;
|
|
145
152
|
if (!b4a.equals(payloadHash, messageHash)) {
|
|
146
|
-
throw new
|
|
153
|
+
throw new V1ProtocolError(
|
|
154
|
+
ResultCode.TX_HASH_MISMATCH,
|
|
155
|
+
'Regenerated transaction does not match incoming transaction in payload.'
|
|
156
|
+
);
|
|
147
157
|
}
|
|
148
158
|
|
|
149
|
-
if (!
|
|
150
|
-
throw new
|
|
159
|
+
if (!tracCryptoApi.signature.verify(incomingSignature, messageHash, incomingPublicKey)) {
|
|
160
|
+
throw new V1ProtocolError(ResultCode.TX_SIGNATURE_INVALID, 'Invalid signature in payload.');
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
163
|
|
|
@@ -158,7 +168,7 @@ class PartialOperation {
|
|
|
158
168
|
const incomingTxv = operation.txv
|
|
159
169
|
|
|
160
170
|
if (!b4a.equals(currentTxv, incomingTxv)) {
|
|
161
|
-
throw new
|
|
171
|
+
throw new V1ProtocolError(ResultCode.TX_EXPIRED, 'Transaction has expired.');
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -169,7 +179,10 @@ class PartialOperation {
|
|
|
169
179
|
const txHex = tx.toString('hex');
|
|
170
180
|
|
|
171
181
|
if (await this.state.get(txHex) !== null) {
|
|
172
|
-
throw new
|
|
182
|
+
throw new V1ProtocolError(
|
|
183
|
+
ResultCode.TX_ALREADY_EXISTS,
|
|
184
|
+
`Transaction with hash ${txHex} already exists in the state.`
|
|
185
|
+
);
|
|
173
186
|
}
|
|
174
187
|
}
|
|
175
188
|
|
|
@@ -180,7 +193,10 @@ class PartialOperation {
|
|
|
180
193
|
|
|
181
194
|
const condition = va === undefined && vn === undefined && vs === undefined
|
|
182
195
|
if (!condition) {
|
|
183
|
-
throw new
|
|
196
|
+
throw new V1ProtocolError(
|
|
197
|
+
ResultCode.OPERATION_ALREADY_COMPLETED,
|
|
198
|
+
'Transfer operation must not be completed already (va, vn, vs must be undefined).'
|
|
199
|
+
);
|
|
184
200
|
}
|
|
185
201
|
}
|
|
186
202
|
|
|
@@ -194,12 +210,12 @@ class PartialOperation {
|
|
|
194
210
|
}
|
|
195
211
|
|
|
196
212
|
if (!requesterEntry) {
|
|
197
|
-
throw new
|
|
213
|
+
throw new V1ProtocolError(ResultCode.REQUESTER_NOT_FOUND, 'Requester address not found in state');
|
|
198
214
|
}
|
|
199
215
|
|
|
200
216
|
const requesterBalance = bufferToBigInt(requesterEntry.balance);
|
|
201
217
|
if (requesterBalance < FEE_BIGINT) {
|
|
202
|
-
throw new
|
|
218
|
+
throw new V1ProtocolError(ResultCode.INSUFFICIENT_FEE_BALANCE, 'Insufficient balance to cover transaction fee.');
|
|
203
219
|
}
|
|
204
220
|
}
|
|
205
221
|
|
|
@@ -209,7 +225,10 @@ class PartialOperation {
|
|
|
209
225
|
const operation = payload[operationKey];
|
|
210
226
|
const bs = operation.bs;
|
|
211
227
|
if (b4a.equals(this.#config.bootstrap, bs)) {
|
|
212
|
-
throw new
|
|
228
|
+
throw new V1ProtocolError(
|
|
229
|
+
ResultCode.EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP,
|
|
230
|
+
`External bootstrap is the same as MSB bootstrap: ${bs.toString('hex')}`
|
|
231
|
+
);
|
|
213
232
|
}
|
|
214
233
|
}
|
|
215
234
|
|
|
@@ -223,10 +242,13 @@ class PartialOperation {
|
|
|
223
242
|
|
|
224
243
|
const requesterAddress = bufferToAddress(payload.address, this.#config.addressPrefix);
|
|
225
244
|
if (this.#selfAddress === requesterAddress) {
|
|
226
|
-
throw new
|
|
245
|
+
throw new V1ProtocolError(
|
|
246
|
+
ResultCode.SELF_VALIDATION_FORBIDDEN,
|
|
247
|
+
'Requester address cannot be the same as the validator wallet address.'
|
|
248
|
+
);
|
|
227
249
|
}
|
|
228
250
|
}
|
|
229
251
|
|
|
230
252
|
}
|
|
231
253
|
|
|
232
|
-
export default
|
|
254
|
+
export default PartialOperationValidator;
|