@dashevo/wasm-dpp 0.23.0-dev.15 → 0.24.0-dev.10
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/.eslintignore +1 -0
- package/Cargo.toml +23 -0
- package/README.md +21 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +8 -0
- package/dist/lib/patchIdentifier.d.ts +2 -0
- package/dist/wasm/wasm_dpp.d.ts +2756 -0
- package/index.ts +30 -0
- package/karma.conf.js +6 -3
- package/lib/patchIdentifier.ts +37 -0
- package/lib/test/.eslintrc +9 -0
- package/lib/test/bootstrap.js +27 -0
- package/lib/test/expect/expectError.js +34 -0
- package/lib/test/karma/loader.js +6 -0
- package/lib/test/utils/generateRandomIdentifierAsync.js +14 -0
- package/package.json +31 -55
- package/scripts/build.sh +69 -0
- package/scripts/clean.sh +4 -0
- package/src/bls_adapter.rs +71 -0
- package/src/buffer.rs +15 -0
- package/src/dash_platform_protocol.rs +26 -0
- package/src/data_contract/data_contract.rs +290 -0
- package/src/data_contract/errors/data_contract_already_exists.rs +1 -0
- package/src/data_contract/errors/invalid_data_contract.rs +29 -0
- package/src/data_contract/errors/invalid_document_type.rs +33 -0
- package/src/data_contract/errors/mod.rs +37 -0
- package/src/data_contract/index.rs +61 -0
- package/src/data_contract/mod.rs +10 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +37 -0
- package/src/data_contract/state_transition/mod.rs +3 -0
- package/src/data_contract_factory/data_contract_factory.rs +155 -0
- package/src/data_contract_factory/mod.rs +1 -0
- package/src/document/errors/document_already_exists_error.rs +28 -0
- package/src/document/errors/document_not_provided_error.rs +28 -0
- package/src/document/errors/invalid_action_name_error.rs +24 -0
- package/src/document/errors/invalid_document_action_error.rs +28 -0
- package/src/document/errors/invalid_document_error.rs +32 -0
- package/src/document/errors/invalid_initial_revision_error.rs +25 -0
- package/src/document/errors/mismatch_owners_ids_error.rs +27 -0
- package/src/document/errors/mod.rs +55 -0
- package/src/document/errors/no_documents_supplied_error.rs +22 -0
- package/src/document/mod.rs +158 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +22 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +22 -0
- package/src/document/state_transition/document_batch_transition/document_transition/document_update_transition.rs +22 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +24 -0
- package/src/document/state_transition/document_batch_transition/mod.rs +1 -0
- package/src/document/state_transition/mod.rs +1 -0
- package/src/errors/consensus/basic/data_contract/data_contract_have_new_unique_index_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/data_contract_immutable_properties_update_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/data_contract_invalid_index_definition_update_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/data_contract_max_depth_exceed_error.rs +26 -0
- package/src/errors/consensus/basic/data_contract/data_contract_unique_indices_changed_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/duplicate_index_name_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/incompatible_data_contract_schema_error.rs +66 -0
- package/src/errors/consensus/basic/data_contract/incompatible_re2_pattern_error.rs +43 -0
- package/src/errors/consensus/basic/data_contract/index_error/duplicate_index_error.rs +39 -0
- package/src/errors/consensus/basic/data_contract/index_error/invalid_compound_index_error.rs +39 -0
- package/src/errors/consensus/basic/data_contract/index_error/invalid_index_property_type_error.rs +59 -0
- package/src/errors/consensus/basic/data_contract/index_error/invalid_indexed_property_constraint_error.rs +67 -0
- package/src/errors/consensus/basic/data_contract/index_error/mod.rs +15 -0
- package/src/errors/consensus/basic/data_contract/index_error/system_property_index_already_present_error.rs +51 -0
- package/src/errors/consensus/basic/data_contract/index_error/undefined_index_property_error.rs +51 -0
- package/src/errors/consensus/basic/data_contract/index_error/unique_indices_limit_reached_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/invalid_data_contract_id_error.rs +37 -0
- package/src/errors/consensus/basic/data_contract/invalid_data_contract_version_error.rs +36 -0
- package/src/errors/consensus/basic/data_contract/invalid_json_schema_ref_error.rs +26 -0
- package/src/errors/consensus/basic/data_contract/mod.rs +25 -0
- package/src/errors/consensus/basic/decode/mod.rs +5 -0
- package/src/errors/consensus/basic/decode/protocol_version_parsing_error.rs +29 -0
- package/src/errors/consensus/basic/decode/serialized_object_parsing_error.rs +29 -0
- package/src/errors/consensus/basic/document/data_contract_not_present_error.rs +32 -0
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +36 -0
- package/src/errors/consensus/basic/document/inconsistent_compound_index_data_error.rs +40 -0
- package/src/errors/consensus/basic/document/invalid_document_transition_action_error.rs +26 -0
- package/src/errors/consensus/basic/document/invalid_document_transition_id_error.rs +38 -0
- package/src/errors/consensus/basic/document/invalid_document_type_error.rs +39 -0
- package/src/errors/consensus/basic/document/missing_data_contract_id_error.rs +20 -0
- package/src/errors/consensus/basic/document/missing_document_transition_action_error.rs +20 -0
- package/src/errors/consensus/basic/document/missing_document_type_error.rs +20 -0
- package/src/errors/consensus/basic/document/mod.rs +19 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +32 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +32 -0
- package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +38 -0
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_is_not_found_error.rs +31 -0
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +37 -0
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_output_not_found_error.rs +29 -0
- package/src/errors/consensus/basic/identity/identity_insufficient_balance_error.rs +33 -0
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_core_chain_height_error.rs +34 -0
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +34 -0
- package/src/errors/consensus/basic/identity/invalid_asset_lock_transaction_output_return_size_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_asset_lock_transaction_error.rs +60 -0
- package/src/errors/consensus/basic/identity/invalid_identity_asset_lock_transaction_output_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_core_fee_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_output_script_error.rs +32 -0
- package/src/errors/consensus/basic/identity/invalid_identity_key_signature_error.rs +29 -0
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_data_error.rs +39 -0
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +42 -0
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_type_error.rs +30 -0
- package/src/errors/consensus/basic/identity/invalid_instant_asset_lock_proof_error.rs +22 -0
- package/src/errors/consensus/basic/identity/invalid_instant_asset_lock_proof_signature_error.rs +24 -0
- package/src/errors/consensus/basic/identity/missing_master_public_key_error.rs +22 -0
- package/src/errors/consensus/basic/identity/missing_public_key_error.rs +29 -0
- package/src/errors/consensus/basic/identity/mod.rs +45 -0
- package/src/errors/consensus/basic/incompatible_protocol_version_error.rs +32 -0
- package/src/errors/consensus/basic/invalid_identifier_error.rs +36 -0
- package/src/errors/consensus/basic/invalid_signature_public_key_security_level_error.rs +41 -0
- package/src/errors/consensus/basic/invalid_state_transition_signature_error.rs +20 -0
- package/src/errors/consensus/basic/json_schema_compilation_error.rs +26 -0
- package/src/errors/consensus/basic/json_schema_error.rs +274 -0
- package/src/errors/consensus/basic/mod.rs +30 -0
- package/src/errors/consensus/basic/public_key_is_disabled_error.rs +30 -0
- package/src/errors/consensus/basic/public_key_security_level_not_met_error.rs +41 -0
- package/src/errors/consensus/basic/state_transition/invalid_state_transition_type_error.rs +29 -0
- package/src/errors/consensus/basic/state_transition/missing_state_transition_type_error.rs +20 -0
- package/src/errors/consensus/basic/state_transition/mod.rs +7 -0
- package/src/errors/consensus/basic/state_transition/state_transition_max_size_exceeded_error.rs +36 -0
- package/src/errors/consensus/basic/test_consensus_error.rs +21 -0
- package/src/errors/consensus/basic/unsupported_protocol_version_error.rs +32 -0
- package/src/errors/consensus/basic/wrong_public_key_purpose_error.rs +37 -0
- package/src/errors/consensus/fee/balance_is_not_enough_error.rs +32 -0
- package/src/errors/consensus/fee/mod.rs +3 -0
- package/src/errors/consensus/mod.rs +4 -0
- package/src/errors/consensus/signature/identity_not_found_error.rs +29 -0
- package/src/errors/consensus/signature/mod.rs +3 -0
- package/src/errors/consensus/state/data_contract/data_contract_already_present_error.rs +31 -0
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_condition_error.rs +74 -0
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_execution_error.rs +82 -0
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_invalid_result_error.rs +66 -0
- package/src/errors/consensus/state/data_contract/data_trigger/mod.rs +7 -0
- package/src/errors/consensus/state/data_contract/mod.rs +4 -0
- package/src/errors/consensus/state/document/document_already_present_error.rs +28 -0
- package/src/errors/consensus/state/document/document_not_found_error.rs +28 -0
- package/src/errors/consensus/state/document/document_owner_id_mismatch_error.rs +50 -0
- package/src/errors/consensus/state/document/document_timestamp_window_violation_error.rs +72 -0
- package/src/errors/consensus/state/document/document_timestamps_mismatch_error.rs +28 -0
- package/src/errors/consensus/state/document/duplicate_unique_index_error.rs +42 -0
- package/src/errors/consensus/state/document/invalid_document_revision_error.rs +38 -0
- package/src/errors/consensus/state/document/mod.rs +15 -0
- package/src/errors/consensus/state/identity/identity_already_exists_error.rs +28 -0
- package/src/errors/consensus/state/identity/identity_public_key_disabled_at_window_violation_error.rs +49 -0
- package/src/errors/consensus/state/identity/identity_public_key_is_disabled_error.rs +31 -0
- package/src/errors/consensus/state/identity/identity_public_key_is_read_only_error.rs +28 -0
- package/src/errors/consensus/state/identity/invalid_identity_public_key_id_error.rs +28 -0
- package/src/errors/consensus/state/identity/invalid_identity_revision_error.rs +38 -0
- package/src/errors/consensus/state/identity/max_identity_public_key_limit_reached_error.rs +26 -0
- package/src/errors/consensus/state/identity/mod.rs +15 -0
- package/src/errors/consensus/state/mod.rs +3 -0
- package/src/errors/consensus_error.rs +612 -0
- package/src/errors/from.rs +24 -0
- package/src/errors/js_conversion.rs +63 -0
- package/src/errors/mod.rs +10 -0
- package/src/errors/public_key_validation_error.rs +23 -0
- package/src/identifier.rs +103 -0
- package/src/identity.rs +253 -0
- package/src/identity_facade.rs +55 -0
- package/src/identity_public_key/key_type.rs +22 -0
- package/src/identity_public_key/mod.rs +192 -0
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/identity_public_key/purpose.rs +24 -0
- package/src/identity_public_key/security_level.rs +21 -0
- package/src/lib.rs +28 -0
- package/src/metadata.rs +54 -0
- package/src/utils.rs +59 -0
- package/src/validation_result.rs +41 -0
- package/test/integration/DashPlatformProtocol.spec.js +4 -4
- package/test/integration/ajv/keywords/byteArray/addByteArrayKeyword.spec.js +2 -2
- package/test/integration/dataContract/DataContractFacade.spec.js +6 -6
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +10 -10
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +14 -14
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +22 -22
- package/test/integration/document/Document.spec.js +10 -5
- package/test/integration/document/DocumentFacade.spec.js +11 -11
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +5 -5
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +25 -25
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +15 -15
- package/test/integration/document/validation/validateDocumentFactory.spec.js +12 -12
- package/test/integration/error/consensus/createConsensusError.spec.js +3 -3
- package/test/integration/identity/IdentityFacade.spec.js +13 -13
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +12 -12
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +11 -11
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +8 -8
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +24 -39
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +7 -7
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +29 -35
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +8 -8
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +11 -11
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +10 -10
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +7 -7
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +8 -8
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +50 -24
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +14 -14
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +15 -19
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +8 -11
- package/test/integration/util/generateEntropy.spec.js +1 -1
- package/test/integration/util/serializer.spec.js +2 -2
- package/test/unit/DashPlatformProtocol.spec.js +4 -4
- package/test/unit/Identifier.spec.js +2 -2
- package/test/unit/Metadata.spec.js +1 -1
- package/test/unit/dataContract/DataContract.spec.js +100 -159
- package/test/unit/dataContract/DataContractFactory.spec.js +55 -111
- package/test/unit/dataContract/createDataContract.spec.js +20 -10
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +2 -2
- package/test/unit/dataContract/generateDataContractId.spec.js +23 -6
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +1 -1
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +1 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +8 -8
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +6 -6
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +8 -8
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +8 -8
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +6 -6
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +6 -6
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +9 -9
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +6 -6
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +3 -3
- package/test/unit/dataTrigger/DataTrigger.spec.js +8 -8
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +4 -4
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +13 -15
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +12 -12
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +11 -13
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +7 -7
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +8 -8
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +9 -9
- package/test/unit/decodeProtocolEntityFactory.spec.js +4 -4
- package/test/unit/document/Document.spec.js +9 -9
- package/test/unit/document/DocumentFactory.spec.js +19 -19
- package/test/unit/document/errors/InvalidDocumentError.spec.js +2 -2
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +8 -8
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +8 -8
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +16 -17
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +1 -1
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +2 -2
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +6 -6
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +7 -7
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +6 -6
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +27 -34
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +9 -9
- package/test/unit/errors/consensus/codes.spec.js +7 -7
- package/test/unit/identity/Identity.spec.js +98 -69
- package/test/unit/identity/IdentityFactory.spec.js +15 -15
- package/test/unit/identity/IdentityPublicKey.spec.js +53 -66
- package/test/unit/identity/creditsConverter.spec.js +1 -1
- package/test/unit/identity/errors/InvalidIdentityError.spec.js +2 -2
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +7 -7
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +8 -8
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +6 -6
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +4 -4
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +7 -7
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +2 -2
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +6 -6
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +6 -6
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +5 -5
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +3 -3
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +5 -5
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +8 -8
- package/test/unit/stateTransition/createStateTransitionFactory.spec.js +8 -8
- package/test/unit/stateTransition/errors/InvalidStateTransitionError.spec.js +3 -3
- package/test/unit/stateTransition/validation/validateStateTransitionBasicFactory.spec.js +12 -12
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +15 -15
- package/test/unit/stateTransition/validation/validateStateTransitionIdentitySignatureFactory.spec.js +22 -22
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +6 -6
- package/test/unit/stateTransition/validation/validateStateTransitionStateFactory.spec.js +9 -9
- package/test/unit/version/validateProtocolVersionFactory.spec.js +7 -7
- package/tsconfig.json +18 -0
- package/wasm/wasm_dpp.d.ts +2756 -0
- package/wasm/wasm_dpp.js +7750 -0
- package/wasm/wasm_dpp_bg.js +1 -0
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +518 -0
- package/webpack.config.js +22 -19
- package/CHANGELOG.md +0 -397
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
use dpp::PublicKeyValidationError;
|
|
2
|
+
use wasm_bindgen::prelude::*;
|
|
3
|
+
use wasm_bindgen::JsValue;
|
|
4
|
+
|
|
5
|
+
#[wasm_bindgen(js_name=PublicKeyValidationError)]
|
|
6
|
+
#[derive(Clone, Debug)]
|
|
7
|
+
pub struct PublicKeyValidationErrorWasm {
|
|
8
|
+
inner: PublicKeyValidationError,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
impl From<PublicKeyValidationError> for PublicKeyValidationErrorWasm {
|
|
12
|
+
fn from(e: PublicKeyValidationError) -> Self {
|
|
13
|
+
Self { inner: e }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[wasm_bindgen(js_class=PublicKeyValidationError)]
|
|
18
|
+
impl PublicKeyValidationErrorWasm {
|
|
19
|
+
#[wasm_bindgen(getter)]
|
|
20
|
+
pub fn message(&self) -> JsValue {
|
|
21
|
+
self.inner.message().into()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
pub use serde::{Deserialize, Serialize};
|
|
2
|
+
use wasm_bindgen::prelude::*;
|
|
3
|
+
use wasm_bindgen::JsCast;
|
|
4
|
+
|
|
5
|
+
use crate::buffer::Buffer;
|
|
6
|
+
use crate::errors::from_dpp_err;
|
|
7
|
+
use dpp::identifier;
|
|
8
|
+
|
|
9
|
+
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
|
10
|
+
enum IdentifierSource {
|
|
11
|
+
String(String),
|
|
12
|
+
Buffer(Vec<u8>),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[wasm_bindgen]
|
|
16
|
+
extern "C" {
|
|
17
|
+
fn alert(s: &str);
|
|
18
|
+
|
|
19
|
+
#[wasm_bindgen(js_namespace = console, js_name=log)]
|
|
20
|
+
fn log(a: &str);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#[wasm_bindgen(js_name=Identifier, inspectable)]
|
|
24
|
+
pub struct IdentifierWrapper {
|
|
25
|
+
wrapped: identifier::Identifier,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
impl std::convert::From<identifier::Identifier> for IdentifierWrapper {
|
|
29
|
+
fn from(s: identifier::Identifier) -> Self {
|
|
30
|
+
IdentifierWrapper { wrapped: s }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[wasm_bindgen(js_class=Identifier)]
|
|
35
|
+
impl IdentifierWrapper {
|
|
36
|
+
#[wasm_bindgen(constructor)]
|
|
37
|
+
pub fn new(buffer: Vec<u8>) -> Result<IdentifierWrapper, JsValue> {
|
|
38
|
+
// TODO: remove unwrap
|
|
39
|
+
let identifier = identifier::Identifier::from_bytes(&buffer).map_err(from_dpp_err)?;
|
|
40
|
+
|
|
41
|
+
Ok(IdentifierWrapper {
|
|
42
|
+
wrapped: identifier,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn from(value: JsValue, encoding: Option<String>) -> Result<IdentifierWrapper, JsValue> {
|
|
47
|
+
if value.is_string() {
|
|
48
|
+
let string = value.as_string().unwrap();
|
|
49
|
+
Ok(IdentifierWrapper::from_string(string, encoding))
|
|
50
|
+
} else if value.has_type::<js_sys::Uint8Array>() {
|
|
51
|
+
let vec = value.dyn_into::<js_sys::Uint8Array>()?.to_vec();
|
|
52
|
+
IdentifierWrapper::new(vec)
|
|
53
|
+
} else {
|
|
54
|
+
Err(JsValue::from(
|
|
55
|
+
"Identifier.from received an unexpected value",
|
|
56
|
+
))
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#[wasm_bindgen(js_name=fromString)]
|
|
61
|
+
pub fn from_string(value: String, encoding: Option<String>) -> IdentifierWrapper {
|
|
62
|
+
// TODO: remove unwrap
|
|
63
|
+
let identifier = identifier::Identifier::from_string_with_encoding_string(
|
|
64
|
+
&value[..],
|
|
65
|
+
encoding.as_deref(),
|
|
66
|
+
)
|
|
67
|
+
.unwrap();
|
|
68
|
+
|
|
69
|
+
IdentifierWrapper {
|
|
70
|
+
wrapped: identifier,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#[wasm_bindgen(js_name=toBuffer)]
|
|
75
|
+
pub fn to_buffer(&self) -> Buffer {
|
|
76
|
+
Buffer::from_bytes(self.wrapped.buffer.as_slice())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
80
|
+
pub fn to_json(&self) -> String {
|
|
81
|
+
self.to_string(None)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#[wasm_bindgen(js_name=toString)]
|
|
85
|
+
pub fn to_string(&self, encoding: Option<String>) -> String {
|
|
86
|
+
// Converting string to a string slice. Rust interfaces work
|
|
87
|
+
// with immutable string slices more often, while js interop accepts mutable String.
|
|
88
|
+
// as_deref dereferences value in the Option
|
|
89
|
+
// dereferencing is accessing the underlying value of the reference, which in
|
|
90
|
+
// case of the string would be a string slice
|
|
91
|
+
self.wrapped
|
|
92
|
+
.to_string_with_encoding_string(encoding.as_deref())
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(getter)]
|
|
96
|
+
pub fn length(&self) -> usize {
|
|
97
|
+
self.wrapped.buffer.len()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub fn inner(&self) -> Vec<u8> {
|
|
101
|
+
self.wrapped.buffer.to_vec()
|
|
102
|
+
}
|
|
103
|
+
}
|
package/src/identity.rs
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
use js_sys::Array;
|
|
2
|
+
use serde_json::Value;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
use dpp::identity::state_transition::asset_lock_proof::AssetLockProof;
|
|
6
|
+
use dpp::identity::IdentityPublicKey;
|
|
7
|
+
use dpp::identity::{Identity, KeyID};
|
|
8
|
+
use dpp::metadata::Metadata;
|
|
9
|
+
use dpp::{ProtocolError, SerdeParsingError};
|
|
10
|
+
|
|
11
|
+
use crate::errors::from_dpp_err;
|
|
12
|
+
use crate::identifier::IdentifierWrapper;
|
|
13
|
+
use crate::utils;
|
|
14
|
+
use crate::utils::to_vec_of_serde_values;
|
|
15
|
+
use crate::IdentityPublicKeyWasm;
|
|
16
|
+
use crate::MetadataWasm;
|
|
17
|
+
|
|
18
|
+
#[wasm_bindgen(js_name=Identity)]
|
|
19
|
+
#[derive(Clone)]
|
|
20
|
+
pub struct IdentityWasm(Identity);
|
|
21
|
+
|
|
22
|
+
#[wasm_bindgen(js_name=AssetLockProof)]
|
|
23
|
+
pub struct AssetLockProofWasm(AssetLockProof);
|
|
24
|
+
impl From<AssetLockProof> for AssetLockProofWasm {
|
|
25
|
+
fn from(v: AssetLockProof) -> Self {
|
|
26
|
+
AssetLockProofWasm(v)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[wasm_bindgen(js_class=Identity)]
|
|
31
|
+
impl IdentityWasm {
|
|
32
|
+
#[wasm_bindgen(constructor)]
|
|
33
|
+
pub fn new(raw_identity: JsValue) -> Result<IdentityWasm, JsValue> {
|
|
34
|
+
let identity_json = utils::stringify(&raw_identity)?;
|
|
35
|
+
let raw_identity: Value =
|
|
36
|
+
serde_json::from_str(&identity_json).map_err(|e| e.to_string())?;
|
|
37
|
+
|
|
38
|
+
let identity = Identity::from_json_object(raw_identity).unwrap();
|
|
39
|
+
Ok(IdentityWasm(identity))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
43
|
+
pub fn get_protocol_version(&self) -> u32 {
|
|
44
|
+
self.0.get_protocol_version()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[wasm_bindgen(js_name=getId)]
|
|
48
|
+
pub fn get_id(&self) -> IdentifierWrapper {
|
|
49
|
+
self.0.get_id().clone().into()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[wasm_bindgen(js_name=setPublicKeys)]
|
|
53
|
+
pub fn set_public_keys(&mut self, public_keys: js_sys::Array) -> Result<usize, JsValue> {
|
|
54
|
+
let raw_public_keys = to_vec_of_serde_values(public_keys.iter())?;
|
|
55
|
+
if raw_public_keys.is_empty() {
|
|
56
|
+
return Err(format!("Setting public keys failed. The input ('{}') is invalid. You must use array of PublicKeys", public_keys.to_string()).into());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let public_keys = raw_public_keys
|
|
60
|
+
.into_iter()
|
|
61
|
+
.map(IdentityPublicKey::from_json_object)
|
|
62
|
+
.collect::<Result<_, _>>()
|
|
63
|
+
.map_err(|e| {
|
|
64
|
+
format!(
|
|
65
|
+
"converting to collection of IdentityPublicKeys failed: {:#}",
|
|
66
|
+
e
|
|
67
|
+
)
|
|
68
|
+
})?;
|
|
69
|
+
|
|
70
|
+
self.0.set_public_keys(public_keys);
|
|
71
|
+
|
|
72
|
+
Ok(self.0.get_public_keys().len())
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[wasm_bindgen(js_name=getPublicKeys)]
|
|
76
|
+
pub fn get_public_keys(&self) -> Vec<JsValue> {
|
|
77
|
+
self.0
|
|
78
|
+
.get_public_keys()
|
|
79
|
+
.iter()
|
|
80
|
+
.map(IdentityPublicKey::to_owned)
|
|
81
|
+
.map(IdentityPublicKeyWasm::from)
|
|
82
|
+
.map(JsValue::from)
|
|
83
|
+
.collect()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[wasm_bindgen(js_name=getPublicKeyById)]
|
|
87
|
+
pub fn get_public_key_by_id(&self, key_id: u32) -> Option<IdentityPublicKeyWasm> {
|
|
88
|
+
let key_id = key_id as KeyID;
|
|
89
|
+
self.0
|
|
90
|
+
.get_public_key_by_id(key_id)
|
|
91
|
+
.map(IdentityPublicKey::to_owned)
|
|
92
|
+
.map(Into::into)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name=getBalance)]
|
|
96
|
+
pub fn get_balance(&self) -> f64 {
|
|
97
|
+
self.0.get_balance() as f64
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[wasm_bindgen(js_name=setBalance)]
|
|
101
|
+
pub fn set_balance(&mut self, balance: f64) {
|
|
102
|
+
self.0.set_balance(balance as u64);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#[wasm_bindgen(js_name=increaseBalance)]
|
|
106
|
+
pub fn increase_balance(&mut self, amount: f64) -> f64 {
|
|
107
|
+
self.0.increase_balance(amount as u64) as f64
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[wasm_bindgen(js_name=reduceBalance)]
|
|
111
|
+
pub fn reduce_balance(&mut self, amount: f64) -> f64 {
|
|
112
|
+
self.0.reduce_balance(amount as u64) as f64
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#[wasm_bindgen(js_name=setAssetLockProof)]
|
|
116
|
+
pub fn set_asset_lock_proof(&mut self, lock: JsValue) {
|
|
117
|
+
self.0
|
|
118
|
+
.set_asset_lock_proof(serde_wasm_bindgen::from_value(lock).unwrap());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#[wasm_bindgen(js_name=getAssetLockProof)]
|
|
122
|
+
pub fn get_asset_lock_proof(&self) -> Option<AssetLockProofWasm> {
|
|
123
|
+
self.0
|
|
124
|
+
.get_asset_lock_proof()
|
|
125
|
+
.map(AssetLockProof::to_owned)
|
|
126
|
+
.map(Into::into)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(js_name=setRevision)]
|
|
130
|
+
pub fn set_revision(&mut self, revision: f64) {
|
|
131
|
+
self.0.set_revision(revision as u64);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name=getRevision)]
|
|
135
|
+
pub fn get_revision(&self) -> f64 {
|
|
136
|
+
self.0.get_revision() as f64
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[wasm_bindgen(js_name=setMetadata)]
|
|
140
|
+
pub fn set_metadata(&mut self, metadata: MetadataWasm) {
|
|
141
|
+
self.0.set_metadata(metadata.into());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#[wasm_bindgen(js_name=getMetadata)]
|
|
145
|
+
pub fn get_metadata(&self) -> Option<MetadataWasm> {
|
|
146
|
+
self.0
|
|
147
|
+
.get_metadata()
|
|
148
|
+
.map(Metadata::to_owned)
|
|
149
|
+
.map(Into::into)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#[wasm_bindgen(js_name=from)]
|
|
153
|
+
pub fn from(object: JsValue) -> Self {
|
|
154
|
+
let i: Identity = serde_json::from_str(&object.as_string().unwrap()).unwrap();
|
|
155
|
+
IdentityWasm(i)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
159
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
160
|
+
let pks = self
|
|
161
|
+
.0
|
|
162
|
+
.public_keys
|
|
163
|
+
.iter()
|
|
164
|
+
.map(|pk| pk.to_json())
|
|
165
|
+
.collect::<Result<Vec<serde_json::Value>, SerdeParsingError>>()
|
|
166
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
167
|
+
|
|
168
|
+
let mut identity_json =
|
|
169
|
+
serde_json::to_value(self.0.clone()).map_err(|e| from_dpp_err(e.into()))?;
|
|
170
|
+
|
|
171
|
+
let map = identity_json.as_object_mut().ok_or_else(|| {
|
|
172
|
+
from_dpp_err(ProtocolError::Generic(
|
|
173
|
+
"Expect identity to be a json map".into(),
|
|
174
|
+
))
|
|
175
|
+
})?;
|
|
176
|
+
map.insert("publicKeys".into(), serde_json::Value::from(pks));
|
|
177
|
+
|
|
178
|
+
let identity_json_string =
|
|
179
|
+
serde_json::to_string(&identity_json).map_err(|e| from_dpp_err(e.into()))?;
|
|
180
|
+
|
|
181
|
+
js_sys::JSON::parse(&identity_json_string)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
185
|
+
pub fn to_object(&self, _some_option: Option<bool>) -> Result<JsValue, JsValue> {
|
|
186
|
+
let js_public_keys = js_sys::Array::new();
|
|
187
|
+
for pk in self.0.public_keys.iter() {
|
|
188
|
+
let pk_wasm = IdentityPublicKeyWasm::from(pk.to_owned());
|
|
189
|
+
js_public_keys.push(&pk_wasm.to_object(None)?);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let identity_json =
|
|
193
|
+
serde_json::to_value(self.0.clone()).map_err(|e| from_dpp_err(e.into()))?;
|
|
194
|
+
let identity_json_string =
|
|
195
|
+
serde_json::to_string(&identity_json).map_err(|e| from_dpp_err(e.into()))?;
|
|
196
|
+
let js_object = js_sys::JSON::parse(&identity_json_string)?;
|
|
197
|
+
|
|
198
|
+
let id: IdentifierWrapper = self.0.id.clone().into();
|
|
199
|
+
|
|
200
|
+
js_sys::Reflect::set(
|
|
201
|
+
&js_object,
|
|
202
|
+
&"id".to_owned().into(),
|
|
203
|
+
&JsValue::from(id.to_buffer()),
|
|
204
|
+
)?;
|
|
205
|
+
js_sys::Reflect::set(
|
|
206
|
+
&js_object,
|
|
207
|
+
&"publicKeys".to_owned().into(),
|
|
208
|
+
&JsValue::from(&js_public_keys),
|
|
209
|
+
)?;
|
|
210
|
+
|
|
211
|
+
Ok(js_object)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#[wasm_bindgen(js_name=toBuffer)]
|
|
215
|
+
pub fn to_buffer(&self) -> Vec<u8> {
|
|
216
|
+
self.0.to_buffer().unwrap()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
#[wasm_bindgen]
|
|
220
|
+
pub fn hash(&self) -> Result<Vec<u8>, JsValue> {
|
|
221
|
+
self.0.hash().map_err(from_dpp_err)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#[wasm_bindgen(js_name=addPublicKey)]
|
|
225
|
+
pub fn add_public_key(&mut self, public_key: IdentityPublicKeyWasm) {
|
|
226
|
+
self.0.public_keys.push(public_key.into());
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// The method `addPublicKeys()` takes an variadic array of `IdentityPublicKeyWasm` as an input. But elements of the array
|
|
230
|
+
// are available ONLY as `JsValue`. WASM-bindgen uses output from `toJSON()` to store WASM-object as `JsValue`.
|
|
231
|
+
// `toJSON()` converts binary data to `base64` or `base58`. Therefore we need to use `from_json_object()` constructor to
|
|
232
|
+
// to convert strings back into bytes and get `IdentityPublicKeyWasm`
|
|
233
|
+
#[wasm_bindgen(js_name=addPublicKeys, variadic)]
|
|
234
|
+
pub fn add_public_keys(&mut self, js_public_keys: JsValue) -> Result<(), JsValue> {
|
|
235
|
+
let js_public_keys_array = Array::from(&js_public_keys);
|
|
236
|
+
let json_objects = to_vec_of_serde_values(js_public_keys_array.iter())?;
|
|
237
|
+
|
|
238
|
+
let public_keys: Vec<IdentityPublicKey> = json_objects
|
|
239
|
+
.into_iter()
|
|
240
|
+
.map(IdentityPublicKey::from_json_object)
|
|
241
|
+
.collect::<Result<Vec<IdentityPublicKey>, ProtocolError>>()
|
|
242
|
+
.map_err(from_dpp_err)?;
|
|
243
|
+
|
|
244
|
+
self.0
|
|
245
|
+
.add_public_keys(public_keys.into_iter().map(Into::into));
|
|
246
|
+
Ok(())
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#[wasm_bindgen(js_name=getPublicKeyMaxId)]
|
|
250
|
+
pub fn get_public_ke_max_id(&self) -> f64 {
|
|
251
|
+
self.0.get_public_key_max_id() as f64
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
use std::sync::Arc;
|
|
2
|
+
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
use dpp::identity::validation::PublicKeysValidator;
|
|
6
|
+
use dpp::identity::IdentityFacade;
|
|
7
|
+
|
|
8
|
+
use crate::bls_adapter::{BlsAdapter, JsBlsAdapter};
|
|
9
|
+
use crate::validation_result::ValidationResultWasm;
|
|
10
|
+
use dpp::version::ProtocolVersionValidator;
|
|
11
|
+
use dpp::NonConsensusError;
|
|
12
|
+
|
|
13
|
+
#[wasm_bindgen(js_name=IdentityFacade)]
|
|
14
|
+
pub struct IdentityFacadeWasm(IdentityFacade<BlsAdapter>);
|
|
15
|
+
|
|
16
|
+
#[wasm_bindgen(js_class=IdentityFacade)]
|
|
17
|
+
impl IdentityFacadeWasm {
|
|
18
|
+
#[wasm_bindgen(constructor)]
|
|
19
|
+
pub fn new(bls_adapter: JsBlsAdapter) -> IdentityFacadeWasm {
|
|
20
|
+
let bls = BlsAdapter(bls_adapter);
|
|
21
|
+
// TODO: REMOVE THAT LINE, TAKE IT AS AN ARGUMENT
|
|
22
|
+
let protocol_version_validator = ProtocolVersionValidator::default();
|
|
23
|
+
let public_keys_validator = PublicKeysValidator::new(bls).unwrap();
|
|
24
|
+
let identity_facade = IdentityFacade::new(
|
|
25
|
+
Arc::new(protocol_version_validator),
|
|
26
|
+
Arc::new(public_keys_validator),
|
|
27
|
+
)
|
|
28
|
+
.unwrap();
|
|
29
|
+
|
|
30
|
+
IdentityFacadeWasm(identity_facade)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[wasm_bindgen()]
|
|
34
|
+
pub fn validate(
|
|
35
|
+
&self,
|
|
36
|
+
raw_identity_object: JsValue,
|
|
37
|
+
) -> Result<ValidationResultWasm, NonConsensusErrorWasm> {
|
|
38
|
+
let identity_json = serde_wasm_bindgen::from_value(raw_identity_object)
|
|
39
|
+
.expect("unable to serialize identity");
|
|
40
|
+
// TODO: handle the case when
|
|
41
|
+
self.0
|
|
42
|
+
.validate(&identity_json)
|
|
43
|
+
.map(|res| res.into())
|
|
44
|
+
.map_err(|err| err.into())
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[wasm_bindgen(js_name=NonConsensusErrorWasm)]
|
|
49
|
+
pub struct NonConsensusErrorWasm(NonConsensusError);
|
|
50
|
+
|
|
51
|
+
impl From<NonConsensusError> for NonConsensusErrorWasm {
|
|
52
|
+
fn from(err: NonConsensusError) -> Self {
|
|
53
|
+
Self(err)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
use dpp::identity::KeyType;
|
|
2
|
+
use wasm_bindgen::prelude::*;
|
|
3
|
+
|
|
4
|
+
#[wasm_bindgen(js_name=KeyType)]
|
|
5
|
+
#[allow(non_camel_case_types)]
|
|
6
|
+
pub enum KeyTypeWasm {
|
|
7
|
+
ECDSA_SECP256K1 = 0,
|
|
8
|
+
BLS12_381 = 1,
|
|
9
|
+
ECDSA_HASH160 = 2,
|
|
10
|
+
BIP13_SCRIPT_HASH = 3,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
impl From<KeyType> for KeyTypeWasm {
|
|
14
|
+
fn from(key_type: KeyType) -> Self {
|
|
15
|
+
match key_type {
|
|
16
|
+
KeyType::ECDSA_SECP256K1 => Self::ECDSA_SECP256K1,
|
|
17
|
+
KeyType::BLS12_381 => Self::BLS12_381,
|
|
18
|
+
KeyType::ECDSA_HASH160 => Self::ECDSA_HASH160,
|
|
19
|
+
KeyType::BIP13_SCRIPT_HASH => Self::BIP13_SCRIPT_HASH,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
use dpp::dashcore::anyhow;
|
|
2
|
+
pub use serde::{Deserialize, Serialize};
|
|
3
|
+
use std::convert::{TryFrom, TryInto};
|
|
4
|
+
use wasm_bindgen::prelude::*;
|
|
5
|
+
|
|
6
|
+
use crate::errors::from_dpp_err;
|
|
7
|
+
use crate::{buffer::Buffer, utils};
|
|
8
|
+
use dpp::identity::IdentityPublicKey;
|
|
9
|
+
|
|
10
|
+
mod purpose;
|
|
11
|
+
pub use purpose::*;
|
|
12
|
+
|
|
13
|
+
mod security_level;
|
|
14
|
+
pub use security_level::*;
|
|
15
|
+
|
|
16
|
+
mod key_type;
|
|
17
|
+
mod public_keys_validator;
|
|
18
|
+
|
|
19
|
+
pub use public_keys_validator::*;
|
|
20
|
+
|
|
21
|
+
pub use key_type::*;
|
|
22
|
+
|
|
23
|
+
#[wasm_bindgen(js_name=IdentityPublicKey)]
|
|
24
|
+
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
25
|
+
pub struct IdentityPublicKeyWasm(IdentityPublicKey);
|
|
26
|
+
|
|
27
|
+
#[wasm_bindgen(js_class = IdentityPublicKey)]
|
|
28
|
+
impl IdentityPublicKeyWasm {
|
|
29
|
+
#[wasm_bindgen(constructor)]
|
|
30
|
+
pub fn new(raw_public_key: JsValue) -> Result<IdentityPublicKeyWasm, JsValue> {
|
|
31
|
+
let data_string = utils::stringify(&raw_public_key)?;
|
|
32
|
+
let pk: IdentityPublicKeyWasm =
|
|
33
|
+
serde_json::from_str(&data_string).map_err(|e| e.to_string())?;
|
|
34
|
+
|
|
35
|
+
Ok(pk)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[wasm_bindgen(js_name=getId)]
|
|
39
|
+
pub fn get_id(&self) -> u32 {
|
|
40
|
+
self.0.get_id() as u32
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[wasm_bindgen(js_name=setId)]
|
|
44
|
+
pub fn set_id(&mut self, id: u32) {
|
|
45
|
+
self.0.set_id(id.into());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[wasm_bindgen(js_name=getType)]
|
|
49
|
+
pub fn get_type(&self) -> u8 {
|
|
50
|
+
self.0.get_type() as u8
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen(js_name=setType)]
|
|
54
|
+
pub fn set_type(&mut self, key_type: u8) -> Result<(), JsValue> {
|
|
55
|
+
self.0.set_type(
|
|
56
|
+
key_type
|
|
57
|
+
.try_into()
|
|
58
|
+
.map_err(|e: anyhow::Error| e.to_string())?,
|
|
59
|
+
);
|
|
60
|
+
Ok(())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#[wasm_bindgen(js_name=setData)]
|
|
64
|
+
pub fn set_data(&mut self, data: Vec<u8>) -> Result<(), JsValue> {
|
|
65
|
+
self.0.set_data(data);
|
|
66
|
+
Ok(())
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[wasm_bindgen(js_name=getData)]
|
|
70
|
+
pub fn get_data(&self) -> Vec<u8> {
|
|
71
|
+
self.0.get_data().to_vec()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#[wasm_bindgen(js_name=setPurpose)]
|
|
75
|
+
pub fn set_purpose(&mut self, purpose: u8) -> Result<(), JsValue> {
|
|
76
|
+
self.0.set_purpose(
|
|
77
|
+
purpose
|
|
78
|
+
.try_into()
|
|
79
|
+
.map_err(|e: anyhow::Error| e.to_string())?,
|
|
80
|
+
);
|
|
81
|
+
Ok(())
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#[wasm_bindgen(js_name=getPurpose)]
|
|
85
|
+
pub fn get_purpose(&self) -> u8 {
|
|
86
|
+
self.0.get_purpose() as u8
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[wasm_bindgen(js_name=setSecurityLevel)]
|
|
90
|
+
pub fn set_security_level(&mut self, purpose: u8) -> Result<(), JsValue> {
|
|
91
|
+
self.0.set_security_level(
|
|
92
|
+
purpose
|
|
93
|
+
.try_into()
|
|
94
|
+
.map_err(|e: anyhow::Error| e.to_string())?,
|
|
95
|
+
);
|
|
96
|
+
Ok(())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#[wasm_bindgen(js_name=getSecurityLevel)]
|
|
100
|
+
pub fn get_security_level(&self) -> u8 {
|
|
101
|
+
self.0.get_security_level() as u8
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#[wasm_bindgen(js_name=setReadOnly)]
|
|
105
|
+
pub fn set_readonly(&mut self, purpose: bool) {
|
|
106
|
+
self.0.set_readonly(purpose);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#[wasm_bindgen(js_name=isReadOnly)]
|
|
110
|
+
pub fn is_readonly(&self) -> bool {
|
|
111
|
+
self.0.get_readonly()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[wasm_bindgen(js_name=setDisabledAt)]
|
|
115
|
+
pub fn set_disabled_at(&mut self, timestamp: u32) {
|
|
116
|
+
self.0.set_disabled_at(timestamp as u64);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[wasm_bindgen(js_name=getDisabledAt)]
|
|
120
|
+
pub fn get_disabled_at(&self) -> Option<u32> {
|
|
121
|
+
self.0.get_disabled_at().map(|timestamp| timestamp as u32)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name=hash)]
|
|
125
|
+
pub fn hash(&self) -> Result<Vec<u8>, JsValue> {
|
|
126
|
+
self.0.hash().map_err(from_dpp_err)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(js_name=isMaster)]
|
|
130
|
+
pub fn is_master(&self) -> bool {
|
|
131
|
+
self.0.is_master()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
135
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
136
|
+
let val = self.0.to_json().map_err(|e| from_dpp_err(e.into()))?;
|
|
137
|
+
let json = val.to_string();
|
|
138
|
+
js_sys::JSON::parse(&json)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
142
|
+
pub fn to_object(&self, some_option: Option<bool>) -> Result<JsValue, JsValue> {
|
|
143
|
+
let val = self
|
|
144
|
+
.0
|
|
145
|
+
.to_raw_json_object(some_option.unwrap_or(false))
|
|
146
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
147
|
+
|
|
148
|
+
let data_buffer = Buffer::from_bytes(self.0.get_data());
|
|
149
|
+
let signature_buffer = Buffer::from_bytes(self.0.get_signature());
|
|
150
|
+
|
|
151
|
+
let json = val.to_string();
|
|
152
|
+
let js_object = js_sys::JSON::parse(&json)?;
|
|
153
|
+
|
|
154
|
+
js_sys::Reflect::set(
|
|
155
|
+
&js_object,
|
|
156
|
+
&"data".to_owned().into(),
|
|
157
|
+
&JsValue::from(data_buffer),
|
|
158
|
+
)?;
|
|
159
|
+
|
|
160
|
+
js_sys::Reflect::set(
|
|
161
|
+
&js_object,
|
|
162
|
+
&"signature".to_owned().into(),
|
|
163
|
+
&JsValue::from(signature_buffer),
|
|
164
|
+
)?;
|
|
165
|
+
|
|
166
|
+
Ok(js_object)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
impl From<IdentityPublicKey> for IdentityPublicKeyWasm {
|
|
171
|
+
fn from(v: IdentityPublicKey) -> Self {
|
|
172
|
+
IdentityPublicKeyWasm(v)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
impl TryFrom<JsValue> for IdentityPublicKeyWasm {
|
|
177
|
+
type Error = JsValue;
|
|
178
|
+
|
|
179
|
+
fn try_from(value: JsValue) -> Result<Self, Self::Error> {
|
|
180
|
+
let str = String::from(js_sys::JSON::stringify(&value)?);
|
|
181
|
+
let val = serde_json::from_str(&str).map_err(|e| from_dpp_err(e.into()))?;
|
|
182
|
+
Ok(Self(
|
|
183
|
+
IdentityPublicKey::from_raw_object(val).map_err(from_dpp_err)?,
|
|
184
|
+
))
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
impl From<IdentityPublicKeyWasm> for IdentityPublicKey {
|
|
189
|
+
fn from(pk: IdentityPublicKeyWasm) -> Self {
|
|
190
|
+
pk.0
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
use crate::bls_adapter::{BlsAdapter, JsBlsAdapter};
|
|
2
|
+
|
|
3
|
+
use crate::utils::{to_vec_of_serde_values, ToSerdeJSONExt};
|
|
4
|
+
use crate::validation_result::ValidationResultWasm;
|
|
5
|
+
use dpp::identity::validation::{PublicKeysValidator, TPublicKeysValidator};
|
|
6
|
+
|
|
7
|
+
use wasm_bindgen::prelude::*;
|
|
8
|
+
|
|
9
|
+
#[wasm_bindgen(js_name = PublicKeysValidator)]
|
|
10
|
+
pub struct PublicKeysValidatorWasm(PublicKeysValidator<BlsAdapter>);
|
|
11
|
+
|
|
12
|
+
#[wasm_bindgen(js_class = PublicKeysValidator)]
|
|
13
|
+
impl PublicKeysValidatorWasm {
|
|
14
|
+
#[wasm_bindgen(constructor)]
|
|
15
|
+
pub fn new(adapter: JsBlsAdapter) -> PublicKeysValidatorWasm {
|
|
16
|
+
Self(PublicKeysValidator::new(BlsAdapter(adapter)).unwrap())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#[wasm_bindgen(js_name=validateKeys)]
|
|
20
|
+
pub fn validate_keys(
|
|
21
|
+
&self,
|
|
22
|
+
public_keys: js_sys::Array,
|
|
23
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
24
|
+
let raw_public_keys = to_vec_of_serde_values(public_keys.iter())?;
|
|
25
|
+
|
|
26
|
+
self.0
|
|
27
|
+
.validate_keys(&raw_public_keys)
|
|
28
|
+
.map(ValidationResultWasm::from)
|
|
29
|
+
.map_err(|e| JsValue::from(e.to_string()))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#[wasm_bindgen(js_name=validatePublicKeyStructure)]
|
|
33
|
+
pub fn validate_public_key_structure(
|
|
34
|
+
&self,
|
|
35
|
+
public_key: JsValue,
|
|
36
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
37
|
+
let pk_serde_json = public_key.to_serde_json_value()?;
|
|
38
|
+
|
|
39
|
+
self.0
|
|
40
|
+
.validate_public_key_structure(&pk_serde_json)
|
|
41
|
+
.map(ValidationResultWasm::from)
|
|
42
|
+
.map_err(|e| JsValue::from(e.to_string()))
|
|
43
|
+
}
|
|
44
|
+
}
|