@dashevo/wasm-dpp 0.24.0-dev.12 → 0.24.0-dev.14
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/.mocharc.yml +1 -1
- package/Cargo.toml +5 -2
- package/README.md +5 -1
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/wasm/wasm_dpp.d.ts +3397 -1237
- package/karma.conf.js +5 -0
- package/lib/identifier/patchIdentifier.ts +5 -4
- package/lib/index.ts +1 -1
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/fixtures/getDataContractFixture.js +267 -0
- package/lib/test/fixtures/getDocumentsFixture.js +43 -0
- package/lib/test/mocks/createStateRepositoryMock.js +64 -0
- package/lib/test/mocks/getBlsAdapterMock.js +51 -0
- package/package.json +11 -8
- package/src/bls_adapter.rs +17 -1
- package/src/buffer.rs +3 -0
- package/src/dash_platform_protocol.rs +107 -10
- package/src/data_contract/data_contract.rs +59 -10
- package/src/data_contract/data_contract_facade.rs +128 -0
- package/src/data_contract/errors/invalid_data_contract.rs +16 -16
- package/src/data_contract/errors/invalid_document_type.rs +8 -8
- package/src/data_contract/errors/mod.rs +10 -16
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +4 -0
- package/src/data_contract/state_transition/data_contract_create_transition/apply.rs +1 -1
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +41 -10
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +35 -4
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +1 -1
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +20 -7
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +47 -11
- package/src/data_contract_factory/data_contract_factory.rs +19 -17
- package/src/data_trigger/data_trigger_execution_context.rs +95 -0
- package/src/data_trigger/data_trigger_execution_result.rs +48 -0
- package/src/data_trigger/execute_data_triggers_factory.rs +60 -0
- package/src/data_trigger/get_data_triggers_factory.rs +65 -0
- package/src/data_trigger/mod.rs +121 -0
- package/src/document/document_facade.rs +125 -0
- package/src/document/errors/invalid_document_error.rs +10 -9
- package/src/document/errors/invalid_initial_revision_error.rs +1 -1
- package/src/document/errors/mismatch_owners_ids_error.rs +14 -4
- package/src/document/errors/mod.rs +17 -13
- package/src/document/errors/no_documents_supplied_error.rs +4 -4
- package/src/document/factory.rs +257 -0
- package/src/document/fetch_and_validate_data_contract.rs +77 -0
- package/src/document/generate_document_id.rs +17 -0
- package/src/document/mod.rs +311 -37
- package/src/document/state_transition/document_batch_transition/apply_document_batch_transition.rs +22 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +253 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +60 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +263 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +302 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/find_duplicates_by_id.rs +40 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/find_duplicates_by_indices.rs +50 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/mod.rs +8 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/validate_documents_batch_transition_basic.rs +34 -0
- package/src/document/state_transition/document_batch_transition/validation/basic/validate_partial_compound_indices.rs +39 -0
- package/src/document/state_transition/document_batch_transition/validation/mod.rs +2 -0
- package/src/document/state_transition/document_batch_transition/validation/state/fetch_documents.rs +43 -0
- package/src/document/state_transition/document_batch_transition/validation/state/mod.rs +3 -0
- package/src/document/state_transition/document_batch_transition/validation/state/validate_documents_batch_transitions_state.rs +27 -0
- package/src/document/state_transition/document_batch_transition/validation/state/validate_documents_uniqueness_by_indices.rs +47 -0
- package/src/document/validator.rs +52 -0
- package/src/errors/compatible_protocol_version_is_not_defined_error.rs +24 -0
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +1 -1
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +1 -1
- package/src/errors/consensus/basic/document/inconsistent_compound_index_data_error.rs +2 -2
- package/src/errors/consensus/basic/document/invalid_document_type_error.rs +15 -1
- package/src/errors/consensus/basic/document/missing_data_contract_id_error.rs +16 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +1 -1
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +1 -1
- package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +6 -2
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +5 -2
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +3 -3
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_core_fee_error.rs +2 -2
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_pooling_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_key_signature_error.rs +4 -3
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_data_error.rs +1 -1
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +1 -1
- package/src/errors/consensus/basic/identity/missing_public_key_error.rs +4 -3
- package/src/errors/consensus/basic/identity/mod.rs +2 -0
- package/src/errors/consensus/basic/invalid_identifier_error.rs +1 -1
- package/src/errors/consensus/basic/json_schema_error.rs +8 -2
- package/src/errors/consensus/basic/public_key_is_disabled_error.rs +1 -1
- package/src/errors/consensus/state/document/document_timestamp_window_violation_error.rs +9 -9
- package/src/errors/consensus/state/document/invalid_document_revision_error.rs +4 -4
- package/src/errors/consensus/state/identity/duplicated_identity_public_key_id_state_error.rs +35 -0
- package/src/errors/consensus/state/identity/duplicated_identity_public_key_state_error.rs +34 -0
- package/src/errors/consensus/state/identity/identity_public_key_disabled_at_window_violation_error.rs +10 -7
- package/src/errors/consensus/state/identity/identity_public_key_is_disabled_error.rs +2 -3
- package/src/errors/consensus/state/identity/identity_public_key_is_read_only_error.rs +7 -3
- package/src/errors/consensus/state/identity/invalid_identity_public_key_id_error.rs +2 -3
- package/src/errors/consensus/state/identity/invalid_identity_revision_error.rs +7 -4
- package/src/errors/consensus/state/identity/max_identity_public_key_limit_reached_error.rs +2 -1
- package/src/errors/consensus/state/identity/mod.rs +4 -0
- package/src/errors/consensus_error.rs +218 -268
- package/src/errors/data_contract_not_present_error.rs +23 -0
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +22 -0
- package/src/errors/js_conversion.rs +52 -5
- package/src/errors/mod.rs +6 -0
- package/src/errors/protocol_error.rs +14 -3
- package/src/identifier/errors.rs +30 -0
- package/src/identifier/mod.rs +95 -11
- package/src/identity/errors/asset_lock_output_not_found_error.rs +11 -0
- package/src/identity/errors/asset_lock_transaction_is_not_found_error.rs +20 -0
- package/src/identity/errors/invalid_identity_error.rs +32 -0
- package/src/identity/errors/mod.rs +9 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/identity/factory_utils.rs +87 -0
- package/src/identity/identity_facade.rs +194 -20
- package/src/identity/identity_factory.rs +209 -0
- package/src/identity/identity_public_key/mod.rs +51 -40
- package/src/identity/mod.rs +31 -17
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +132 -0
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/chain/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +177 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/instant/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/mod.rs +269 -0
- package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs +26 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +337 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_basic_validator.rs +153 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_create_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +45 -0
- package/src/identity/state_transition/identity_public_key_transitions.rs +207 -0
- package/src/identity/state_transition/identity_topup_transition/apply_identity_topup_transition.rs +31 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +278 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_basic_validator.rs +113 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_topup_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +42 -0
- package/src/identity/state_transition/identity_update_transition/apply_identity_update_transition.rs +24 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_public_keys_validator.rs +55 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition.rs +448 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition_basic_validator.rs +94 -0
- package/src/identity/state_transition/identity_update_transition/identity_update_transition_state_validator.rs +53 -0
- package/src/identity/state_transition/identity_update_transition/mod.rs +9 -0
- package/src/identity/state_transition/identity_update_transition/to_object.rs +66 -0
- package/src/identity/state_transition/mod.rs +12 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +61 -0
- package/src/identity/validation/identity_validator.rs +50 -0
- package/src/identity/validation/mod.rs +2 -0
- package/src/identity/validation/public_keys_validator.rs +14 -13
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/lib.rs +6 -0
- package/src/lodash.rs +7 -0
- package/src/metadata.rs +54 -10
- package/src/state_repository.rs +598 -101
- package/src/state_transition/conversion.rs +104 -0
- package/src/state_transition/errors/invalid_state_transition_error.rs +32 -0
- package/src/state_transition/errors/mod.rs +1 -0
- package/src/state_transition/mod.rs +46 -0
- package/src/state_transition/state_transition_facade.rs +263 -0
- package/src/state_transition/state_transition_factory.rs +216 -0
- package/src/state_transition/validation/mod.rs +1 -0
- package/src/state_transition/validation/validate_state_transition_key_signature.rs +62 -0
- package/src/utils.rs +210 -8
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +2 -0
- package/src/validation/validation_result.rs +29 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +103 -0
- package/test/integration/dataContract/DataContractFacade.spec.js +46 -30
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +45 -127
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +91 -139
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +577 -503
- package/test/integration/document/Document.spec.js +55 -29
- package/test/integration/document/DocumentFacade.spec.js +51 -64
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +38 -16
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +341 -396
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +116 -218
- package/test/integration/document/validation/validateDocumentFactory.spec.js +123 -171
- package/test/integration/identity/IdentityFacade.spec.js +52 -27
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +185 -164
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +84 -114
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +120 -137
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +106 -91
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +50 -16
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +78 -86
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +74 -30
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -147
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +65 -77
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +60 -23
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +46 -114
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +9 -3
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +12 -8
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +95 -233
- package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +53 -0
- package/test/unit/Identifier.spec.js +36 -36
- package/test/unit/Metadata.spec.js +17 -3
- package/test/unit/dataContract/DataContract.spec.js +9 -4
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +2 -2
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +25 -31
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +3 -3
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +2 -0
- package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
- package/test/unit/document/Document.spec.js +147 -155
- package/test/unit/document/DocumentFactory.spec.js +153 -153
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +59 -14
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +131 -62
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +144 -56
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +38 -8
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +11 -7
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +29 -18
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +38 -29
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +53 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +357 -493
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +133 -72
- package/test/unit/identity/Identity.spec.js +26 -9
- package/test/unit/identity/IdentityFactory.spec.js +81 -89
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +73 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +38 -38
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +34 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +85 -50
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +44 -22
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +58 -103
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +63 -0
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +90 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +18 -3
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +38 -11
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +49 -101
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +23 -25
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +73 -46
- package/test/unit/version/validateProtocolVersionFactory.spec.js +45 -27
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +3397 -1237
- package/wasm/wasm_dpp.js +7158 -1384
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +777 -389
- package/webpack.config.js +9 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_update_transition.rs +0 -22
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +0 -135
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +0 -54
|
@@ -1,52 +1,33 @@
|
|
|
1
|
-
const { getRE2Class } = require('@dashevo/wasm-re2');
|
|
2
|
-
|
|
3
|
-
const createAjv = require('@dashevo/dpp/lib/ajv/createAjv');
|
|
4
|
-
|
|
5
1
|
const getIdentityFixture = require('@dashevo/dpp/lib/test/fixtures/getIdentityFixture');
|
|
2
|
+
const { expectValidationError, expectJsonSchemaError } = require('../../../../lib/test/expect/expectError');
|
|
6
3
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
const { expectValidationError, expectJsonSchemaError } = require(
|
|
12
|
-
'@dashevo/dpp/lib/test/expect/expectError',
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const validateIdentityFactory = require(
|
|
16
|
-
'@dashevo/dpp/lib/identity/validation/validateIdentityFactory',
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const JsonSchemaError = require(
|
|
20
|
-
'@dashevo/dpp/lib/errors/consensus/basic/JsonSchemaError',
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const ValidationResult = require('@dashevo/dpp/lib/validation/ValidationResult');
|
|
24
|
-
const SomeConsensusError = require('@dashevo/dpp/lib/test/mocks/SomeConsensusError');
|
|
4
|
+
const { default: loadWasmDpp } = require('../../../../dist');
|
|
5
|
+
const getBlsAdapterMock = require('../../../../lib/test/mocks/getBlsAdapterMock');
|
|
6
|
+
const generateRandomIdentifierAsync = require('../../../../lib/test/utils/generateRandomIdentifierAsync');
|
|
25
7
|
|
|
26
8
|
describe('validateIdentityFactory', () => {
|
|
27
9
|
let rawIdentity;
|
|
28
10
|
let validateIdentity;
|
|
29
11
|
let identity;
|
|
30
|
-
let validatePublicKeysMock;
|
|
31
|
-
let validateProtocolVersionMock;
|
|
32
12
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
let IdentityValidator;
|
|
14
|
+
let Identity;
|
|
15
|
+
let UnsupportedProtocolVersionError;
|
|
36
16
|
|
|
37
|
-
|
|
17
|
+
before(async () => {
|
|
18
|
+
({ IdentityValidator, Identity, UnsupportedProtocolVersionError } = await loadWasmDpp());
|
|
19
|
+
});
|
|
38
20
|
|
|
39
|
-
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
const blsAdapter = await getBlsAdapterMock();
|
|
40
23
|
|
|
41
|
-
|
|
24
|
+
const validator = new IdentityValidator(blsAdapter);
|
|
42
25
|
|
|
43
|
-
validateIdentity =
|
|
44
|
-
schemaValidator,
|
|
45
|
-
validatePublicKeysMock,
|
|
46
|
-
validateProtocolVersionMock,
|
|
47
|
-
);
|
|
26
|
+
validateIdentity = (value) => validator.validate(value);
|
|
48
27
|
|
|
49
|
-
|
|
28
|
+
const identityObjectJS = getIdentityFixture().toObject();
|
|
29
|
+
identityObjectJS.id = await generateRandomIdentifierAsync();
|
|
30
|
+
identity = new Identity(identityObjectJS);
|
|
50
31
|
|
|
51
32
|
rawIdentity = identity.toObject();
|
|
52
33
|
});
|
|
@@ -57,7 +38,7 @@ describe('validateIdentityFactory', () => {
|
|
|
57
38
|
|
|
58
39
|
const result = validateIdentity(rawIdentity);
|
|
59
40
|
|
|
60
|
-
expectJsonSchemaError(result);
|
|
41
|
+
await expectJsonSchemaError(result);
|
|
61
42
|
|
|
62
43
|
const [error] = result.getErrors();
|
|
63
44
|
|
|
@@ -71,7 +52,7 @@ describe('validateIdentityFactory', () => {
|
|
|
71
52
|
|
|
72
53
|
const result = validateIdentity(rawIdentity);
|
|
73
54
|
|
|
74
|
-
expectJsonSchemaError(result);
|
|
55
|
+
await expectJsonSchemaError(result);
|
|
75
56
|
|
|
76
57
|
const [error] = result.getErrors();
|
|
77
58
|
|
|
@@ -80,91 +61,66 @@ describe('validateIdentityFactory', () => {
|
|
|
80
61
|
});
|
|
81
62
|
|
|
82
63
|
it('should be valid', async () => {
|
|
83
|
-
rawIdentity.protocolVersion =
|
|
84
|
-
|
|
85
|
-
const protocolVersionError = new SomeConsensusError('test');
|
|
86
|
-
const protocolVersionResult = new ValidationResult([
|
|
87
|
-
protocolVersionError,
|
|
88
|
-
]);
|
|
89
|
-
|
|
90
|
-
validateProtocolVersionMock.returns(protocolVersionResult);
|
|
64
|
+
rawIdentity.protocolVersion = 100;
|
|
91
65
|
|
|
92
66
|
const result = validateIdentity(rawIdentity);
|
|
93
67
|
|
|
94
|
-
expectValidationError(result,
|
|
95
|
-
|
|
96
|
-
const [error] = result.getErrors();
|
|
97
|
-
|
|
98
|
-
expect(error).to.equal(protocolVersionError);
|
|
99
|
-
|
|
100
|
-
expect(validateProtocolVersionMock).to.be.calledOnceWith(
|
|
101
|
-
rawIdentity.protocolVersion,
|
|
102
|
-
);
|
|
68
|
+
await expectValidationError(result, UnsupportedProtocolVersionError);
|
|
103
69
|
});
|
|
104
70
|
});
|
|
105
71
|
|
|
106
72
|
describe('id', () => {
|
|
107
|
-
it('should be present', () => {
|
|
73
|
+
it('should be present', async () => {
|
|
108
74
|
rawIdentity.id = undefined;
|
|
109
75
|
|
|
110
76
|
const result = validateIdentity(rawIdentity);
|
|
111
77
|
|
|
112
|
-
expectJsonSchemaError(result);
|
|
78
|
+
await expectJsonSchemaError(result);
|
|
113
79
|
|
|
114
80
|
const [error] = result.getErrors();
|
|
115
81
|
|
|
116
82
|
expect(error.getInstancePath()).to.equal('');
|
|
117
83
|
expect(error.getParams().missingProperty).to.equal('id');
|
|
118
84
|
expect(error.getKeyword()).to.equal('required');
|
|
119
|
-
|
|
120
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
121
85
|
});
|
|
122
86
|
|
|
123
|
-
it('should be a byte array', () => {
|
|
87
|
+
it('should be a byte array', async () => {
|
|
124
88
|
rawIdentity.id = new Array(32).fill('string');
|
|
125
89
|
|
|
126
90
|
const result = validateIdentity(rawIdentity);
|
|
127
91
|
|
|
128
|
-
expectJsonSchemaError(result,
|
|
92
|
+
await expectJsonSchemaError(result, 32);
|
|
129
93
|
|
|
130
|
-
const [error
|
|
94
|
+
const [error] = result.getErrors();
|
|
131
95
|
|
|
132
96
|
expect(error.getInstancePath()).to.equal('/id/0');
|
|
133
97
|
expect(error.getKeyword()).to.equal('type');
|
|
134
|
-
|
|
135
|
-
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
136
|
-
|
|
137
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
138
98
|
});
|
|
139
99
|
|
|
140
|
-
it('should not be less than 32 bytes', () => {
|
|
100
|
+
it('should not be less than 32 bytes', async () => {
|
|
141
101
|
rawIdentity.id = Buffer.alloc(31);
|
|
142
102
|
|
|
143
103
|
const result = validateIdentity(rawIdentity);
|
|
144
104
|
|
|
145
|
-
expectJsonSchemaError(result);
|
|
105
|
+
await expectJsonSchemaError(result);
|
|
146
106
|
|
|
147
107
|
const [error] = result.getErrors();
|
|
148
108
|
|
|
149
109
|
expect(error.getKeyword()).to.equal('minItems');
|
|
150
110
|
expect(error.getInstancePath()).to.equal('/id');
|
|
151
|
-
|
|
152
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
153
111
|
});
|
|
154
112
|
|
|
155
|
-
it('should not be more than 32 bytes', () => {
|
|
113
|
+
it('should not be more than 32 bytes', async () => {
|
|
156
114
|
rawIdentity.id = Buffer.alloc(33);
|
|
157
115
|
|
|
158
116
|
const result = validateIdentity(rawIdentity);
|
|
159
117
|
|
|
160
|
-
expectJsonSchemaError(result);
|
|
118
|
+
await expectJsonSchemaError(result);
|
|
161
119
|
|
|
162
120
|
const [error] = result.getErrors();
|
|
163
121
|
|
|
164
122
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
165
123
|
expect(error.getInstancePath()).to.equal('/id');
|
|
166
|
-
|
|
167
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
168
124
|
});
|
|
169
125
|
});
|
|
170
126
|
|
|
@@ -174,15 +130,13 @@ describe('validateIdentityFactory', () => {
|
|
|
174
130
|
|
|
175
131
|
const result = validateIdentity(rawIdentity);
|
|
176
132
|
|
|
177
|
-
expectJsonSchemaError(result);
|
|
133
|
+
await expectJsonSchemaError(result);
|
|
178
134
|
|
|
179
135
|
const [error] = result.getErrors();
|
|
180
136
|
|
|
181
137
|
expect(error.getInstancePath()).to.equal('');
|
|
182
138
|
expect(error.getParams().missingProperty).to.equal('balance');
|
|
183
139
|
expect(error.getKeyword()).to.equal('required');
|
|
184
|
-
|
|
185
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
186
140
|
});
|
|
187
141
|
|
|
188
142
|
it('should be an integer', async () => {
|
|
@@ -190,14 +144,12 @@ describe('validateIdentityFactory', () => {
|
|
|
190
144
|
|
|
191
145
|
const result = validateIdentity(rawIdentity);
|
|
192
146
|
|
|
193
|
-
expectJsonSchemaError(result);
|
|
147
|
+
await expectJsonSchemaError(result);
|
|
194
148
|
|
|
195
149
|
const [error] = result.getErrors();
|
|
196
150
|
|
|
197
151
|
expect(error.getKeyword()).to.equal('type');
|
|
198
152
|
expect(error.getInstancePath()).to.equal('/balance');
|
|
199
|
-
|
|
200
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
201
153
|
});
|
|
202
154
|
|
|
203
155
|
it('should be greater or equal 0', async () => {
|
|
@@ -205,15 +157,13 @@ describe('validateIdentityFactory', () => {
|
|
|
205
157
|
|
|
206
158
|
let result = validateIdentity(rawIdentity);
|
|
207
159
|
|
|
208
|
-
expectJsonSchemaError(result);
|
|
160
|
+
await expectJsonSchemaError(result);
|
|
209
161
|
|
|
210
162
|
const [error] = result.getErrors();
|
|
211
163
|
|
|
212
164
|
expect(error.getKeyword()).to.equal('minimum');
|
|
213
165
|
expect(error.getInstancePath()).to.equal('/balance');
|
|
214
166
|
|
|
215
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
216
|
-
|
|
217
167
|
rawIdentity.balance = 0;
|
|
218
168
|
|
|
219
169
|
result = validateIdentity(rawIdentity);
|
|
@@ -223,51 +173,45 @@ describe('validateIdentityFactory', () => {
|
|
|
223
173
|
});
|
|
224
174
|
|
|
225
175
|
describe('publicKeys', () => {
|
|
226
|
-
it('should be present', () => {
|
|
176
|
+
it('should be present', async () => {
|
|
227
177
|
rawIdentity.publicKeys = undefined;
|
|
228
178
|
|
|
229
179
|
const result = validateIdentity(rawIdentity);
|
|
230
180
|
|
|
231
|
-
expectJsonSchemaError(result);
|
|
181
|
+
await expectJsonSchemaError(result);
|
|
232
182
|
|
|
233
183
|
const [error] = result.getErrors();
|
|
234
184
|
|
|
235
185
|
expect(error.getInstancePath()).to.equal('');
|
|
236
186
|
expect(error.getParams().missingProperty).to.equal('publicKeys');
|
|
237
187
|
expect(error.getKeyword()).to.equal('required');
|
|
238
|
-
|
|
239
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
240
188
|
});
|
|
241
189
|
|
|
242
|
-
it('should be an array', () => {
|
|
190
|
+
it('should be an array', async () => {
|
|
243
191
|
rawIdentity.publicKeys = 1;
|
|
244
192
|
|
|
245
193
|
const result = validateIdentity(rawIdentity);
|
|
246
194
|
|
|
247
|
-
|
|
195
|
+
await expectJsonSchemaError(result);
|
|
248
196
|
|
|
249
197
|
const [error] = result.getErrors();
|
|
250
198
|
|
|
251
199
|
expect(error.getCode()).to.equal(1005);
|
|
252
200
|
expect(error.getInstancePath()).to.equal('/publicKeys');
|
|
253
201
|
expect(error.getKeyword()).to.equal('type');
|
|
254
|
-
|
|
255
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
256
202
|
});
|
|
257
203
|
|
|
258
|
-
it('should not be empty', () => {
|
|
204
|
+
it('should not be empty', async () => {
|
|
259
205
|
rawIdentity.publicKeys = [];
|
|
260
206
|
|
|
261
207
|
const result = validateIdentity(rawIdentity);
|
|
262
208
|
|
|
263
|
-
expectJsonSchemaError(result);
|
|
209
|
+
await expectJsonSchemaError(result);
|
|
264
210
|
|
|
265
211
|
const [error] = result.getErrors();
|
|
266
212
|
|
|
267
213
|
expect(error.getKeyword()).to.equal('minItems');
|
|
268
214
|
expect(error.getInstancePath()).to.equal('/publicKeys');
|
|
269
|
-
|
|
270
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
271
215
|
});
|
|
272
216
|
|
|
273
217
|
it('should be unique', async () => {
|
|
@@ -275,34 +219,30 @@ describe('validateIdentityFactory', () => {
|
|
|
275
219
|
|
|
276
220
|
const result = validateIdentity(rawIdentity);
|
|
277
221
|
|
|
278
|
-
expectJsonSchemaError(result);
|
|
222
|
+
await expectJsonSchemaError(result);
|
|
279
223
|
|
|
280
224
|
const [error] = result.getErrors();
|
|
281
225
|
|
|
282
226
|
expect(error.getKeyword()).to.equal('uniqueItems');
|
|
283
227
|
expect(error.getInstancePath()).to.equal('/publicKeys');
|
|
284
|
-
|
|
285
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
286
228
|
});
|
|
287
229
|
|
|
288
|
-
it('should throw an error if publicKeys have more than 100 keys', () => {
|
|
230
|
+
it('should throw an error if publicKeys have more than 100 keys', async () => {
|
|
289
231
|
const [key] = rawIdentity.publicKeys;
|
|
290
232
|
|
|
291
233
|
rawIdentity.publicKeys = [];
|
|
292
234
|
for (let i = 0; i < 101; i++) {
|
|
293
|
-
rawIdentity.publicKeys.push(key);
|
|
235
|
+
rawIdentity.publicKeys.push({ ...key, id: i });
|
|
294
236
|
}
|
|
295
237
|
|
|
296
238
|
const result = validateIdentity(rawIdentity);
|
|
297
239
|
|
|
298
|
-
expectJsonSchemaError(result);
|
|
240
|
+
await expectJsonSchemaError(result);
|
|
299
241
|
|
|
300
242
|
const [error] = result.getErrors();
|
|
301
243
|
|
|
302
244
|
expect(error.getKeyword()).to.equal('maxItems');
|
|
303
245
|
expect(error.getInstancePath()).to.equal('/publicKeys');
|
|
304
|
-
|
|
305
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
306
246
|
});
|
|
307
247
|
});
|
|
308
248
|
|
|
@@ -312,15 +252,13 @@ describe('validateIdentityFactory', () => {
|
|
|
312
252
|
|
|
313
253
|
const result = validateIdentity(rawIdentity);
|
|
314
254
|
|
|
315
|
-
expectJsonSchemaError(result);
|
|
255
|
+
await expectJsonSchemaError(result);
|
|
316
256
|
|
|
317
257
|
const [error] = result.getErrors();
|
|
318
258
|
|
|
319
259
|
expect(error.getInstancePath()).to.equal('');
|
|
320
260
|
expect(error.getParams().missingProperty).to.equal('revision');
|
|
321
261
|
expect(error.getKeyword()).to.equal('required');
|
|
322
|
-
|
|
323
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
324
262
|
});
|
|
325
263
|
|
|
326
264
|
it('should be an integer', async () => {
|
|
@@ -328,14 +266,12 @@ describe('validateIdentityFactory', () => {
|
|
|
328
266
|
|
|
329
267
|
const result = validateIdentity(rawIdentity);
|
|
330
268
|
|
|
331
|
-
expectJsonSchemaError(result);
|
|
269
|
+
await expectJsonSchemaError(result);
|
|
332
270
|
|
|
333
271
|
const [error] = result.getErrors();
|
|
334
272
|
|
|
335
273
|
expect(error.getKeyword()).to.equal('type');
|
|
336
274
|
expect(error.getInstancePath()).to.equal('/revision');
|
|
337
|
-
|
|
338
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
339
275
|
});
|
|
340
276
|
|
|
341
277
|
it('should be greater or equal 0', async () => {
|
|
@@ -343,15 +279,13 @@ describe('validateIdentityFactory', () => {
|
|
|
343
279
|
|
|
344
280
|
let result = validateIdentity(rawIdentity);
|
|
345
281
|
|
|
346
|
-
expectJsonSchemaError(result);
|
|
282
|
+
await expectJsonSchemaError(result);
|
|
347
283
|
|
|
348
284
|
const [error] = result.getErrors();
|
|
349
285
|
|
|
350
286
|
expect(error.getKeyword()).to.equal('minimum');
|
|
351
287
|
expect(error.getInstancePath()).to.equal('/revision');
|
|
352
288
|
|
|
353
|
-
expect(validatePublicKeysMock).to.not.be.called();
|
|
354
|
-
|
|
355
289
|
rawIdentity.revision = 0;
|
|
356
290
|
|
|
357
291
|
result = validateIdentity(rawIdentity);
|
|
@@ -363,8 +297,6 @@ describe('validateIdentityFactory', () => {
|
|
|
363
297
|
it('should return valid result if a raw identity is valid', () => {
|
|
364
298
|
const result = validateIdentity(rawIdentity);
|
|
365
299
|
|
|
366
|
-
expect(validatePublicKeysMock).to.be.calledOnceWithExactly(rawIdentity.publicKeys);
|
|
367
|
-
|
|
368
300
|
expect(result.isValid()).to.be.true();
|
|
369
301
|
});
|
|
370
302
|
});
|
|
@@ -11,7 +11,9 @@ const {
|
|
|
11
11
|
|
|
12
12
|
const { default: loadWasmDpp } = require('../../../../dist');
|
|
13
13
|
|
|
14
|
-
describe('validatePublicKeysFactory', ()
|
|
14
|
+
describe('validatePublicKeysFactory', function main() {
|
|
15
|
+
this.timeout(10000);
|
|
16
|
+
|
|
15
17
|
let rawPublicKeys;
|
|
16
18
|
let validatePublicKeys;
|
|
17
19
|
let bls;
|
|
@@ -44,9 +46,13 @@ describe('validatePublicKeysFactory', () => {
|
|
|
44
46
|
let pk;
|
|
45
47
|
|
|
46
48
|
try {
|
|
47
|
-
pk = bls.
|
|
49
|
+
pk = bls.G1Element.fromBytes(publicKeyBuffer);
|
|
48
50
|
} catch (e) {
|
|
49
51
|
return false;
|
|
52
|
+
} finally {
|
|
53
|
+
if (pk) {
|
|
54
|
+
pk.delete();
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
return Boolean(pk);
|
|
@@ -363,7 +369,7 @@ describe('validatePublicKeysFactory', () => {
|
|
|
363
369
|
purpose: 0,
|
|
364
370
|
securityLevel: 0,
|
|
365
371
|
readOnly: true,
|
|
366
|
-
data: Buffer.from('
|
|
372
|
+
data: Buffer.from('928f4cdf8d7e05527f26e43348764832d55f5cca0107097fe9af57383f46da612428f617d810186419344f76a14efe96', 'hex'),
|
|
367
373
|
}];
|
|
368
374
|
|
|
369
375
|
const result = validatePublicKeys(rawPublicKeys);
|
|
@@ -41,11 +41,11 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
41
41
|
|
|
42
42
|
blsInstance = await BlsSignatures.getInstance();
|
|
43
43
|
const {
|
|
44
|
-
|
|
44
|
+
BasicSchemeMPL,
|
|
45
45
|
} = blsInstance;
|
|
46
46
|
|
|
47
47
|
const randomBytes = new Uint8Array(crypto.randomBytes(256));
|
|
48
|
-
blsPrivateKey =
|
|
48
|
+
blsPrivateKey = BasicSchemeMPL.keyGen(randomBytes);
|
|
49
49
|
blsPrivateKeyHex = Buffer.from(blsPrivateKey.serialize()).toString('hex');
|
|
50
50
|
|
|
51
51
|
identityPublicKey = new IdentityPublicKey()
|
|
@@ -56,6 +56,10 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
56
56
|
.setPurpose(IdentityPublicKey.PURPOSES.AUTHENTICATION);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
blsPrivateKey.delete();
|
|
61
|
+
});
|
|
62
|
+
|
|
59
63
|
describe('#toObject', () => {
|
|
60
64
|
it('should return raw state transition', () => {
|
|
61
65
|
const rawStateTransition = stateTransition.toObject();
|
|
@@ -225,7 +229,7 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
225
229
|
|
|
226
230
|
it('should sign data and validate signature with BLS12_381 identityPublicKey', async () => {
|
|
227
231
|
identityPublicKey.setType(IdentityPublicKey.TYPES.BLS12_381);
|
|
228
|
-
identityPublicKey.setData(Buffer.from(blsPrivateKey.
|
|
232
|
+
identityPublicKey.setData(Buffer.from(blsPrivateKey.getG1().serialize()));
|
|
229
233
|
|
|
230
234
|
await stateTransition.sign(identityPublicKey, blsPrivateKeyHex);
|
|
231
235
|
|
|
@@ -251,14 +255,14 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
251
255
|
|
|
252
256
|
it('should sign and validate with BLS private key', async () => {
|
|
253
257
|
identityPublicKey.setType(IdentityPublicKey.TYPES.BLS12_381);
|
|
254
|
-
identityPublicKey.setData(Buffer.from(blsPrivateKey.
|
|
258
|
+
identityPublicKey.setData(Buffer.from(blsPrivateKey.getG1().serialize()));
|
|
255
259
|
|
|
256
260
|
await stateTransition.signByPrivateKey(blsPrivateKeyHex, IdentityPublicKey.TYPES.BLS12_381);
|
|
257
261
|
|
|
258
262
|
expect(stateTransition.signature).to.be.an.instanceOf(Buffer);
|
|
259
263
|
|
|
260
264
|
const isValid = await stateTransition.verifyBLSSignatureByPublicKey(
|
|
261
|
-
blsPrivateKey.
|
|
265
|
+
blsPrivateKey.getG1(),
|
|
262
266
|
);
|
|
263
267
|
|
|
264
268
|
expect(isValid).to.be.true();
|
|
@@ -354,7 +358,7 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
354
358
|
|
|
355
359
|
it('should validate BLS signature', async () => {
|
|
356
360
|
identityPublicKey.setType(IdentityPublicKey.TYPES.BLS12_381);
|
|
357
|
-
identityPublicKey.setData(Buffer.from(blsPrivateKey.
|
|
361
|
+
identityPublicKey.setData(Buffer.from(blsPrivateKey.getG1().serialize()));
|
|
358
362
|
|
|
359
363
|
await stateTransition.sign(identityPublicKey, blsPrivateKeyHex);
|
|
360
364
|
|
|
@@ -451,7 +455,7 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
451
455
|
|
|
452
456
|
describe('#verifyBLSSignatureByPublicKey', () => {
|
|
453
457
|
it('should validate sign by public key', async () => {
|
|
454
|
-
const publicKey = blsPrivateKey.
|
|
458
|
+
const publicKey = blsPrivateKey.getG1();
|
|
455
459
|
|
|
456
460
|
identityPublicKey.setType(IdentityPublicKey.TYPES.BLS12_381);
|
|
457
461
|
identityPublicKey.setData(Buffer.from(publicKey.serialize()));
|
|
@@ -464,7 +468,7 @@ describe('AbstractStateTransitionIdentitySigned', () => {
|
|
|
464
468
|
});
|
|
465
469
|
|
|
466
470
|
it('should throw an StateTransitionIsNotSignedError error if transition is not signed', async () => {
|
|
467
|
-
const publicKey = Buffer.from(blsPrivateKey.
|
|
471
|
+
const publicKey = Buffer.from(blsPrivateKey.getG1().serialize());
|
|
468
472
|
try {
|
|
469
473
|
await stateTransition.verifyBLSSignatureByPublicKey(publicKey);
|
|
470
474
|
|