@dashevo/wasm-dpp 0.24.0-dev.12 → 0.24.0-dev.13
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/Cargo.toml +3 -0
- 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 +1495 -565
- 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/mocks/getBlsAdapterMock.js +36 -0
- package/lib/test/utils/newDocumentsContainer.js +36 -0
- package/package.json +7 -4
- package/src/bls_adapter.rs +16 -1
- package/src/data_contract/data_contract.rs +35 -7
- package/src/data_contract/errors/invalid_document_type.rs +1 -1
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +1 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +2 -4
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +3 -3
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +2 -4
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +9 -6
- package/src/data_contract_factory/data_contract_factory.rs +4 -6
- 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 +192 -0
- package/src/document/mod.rs +222 -30
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +47 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +25 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +65 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +123 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/validator.rs +30 -0
- 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/dpp_error.rs +17 -0
- package/src/errors/from.rs +5 -0
- package/src/errors/js_conversion.rs +19 -4
- package/src/errors/mod.rs +2 -0
- package/src/errors/protocol_error.rs +7 -4
- package/src/identifier/mod.rs +48 -3
- 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/mod.rs +7 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/identity/identity_facade.rs +2 -4
- package/src/identity/identity_public_key/mod.rs +41 -7
- package/src/identity/mod.rs +14 -5
- 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 +335 -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 +46 -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 +280 -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/mod.rs +9 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +59 -0
- package/src/identity/validation/public_keys_validator.rs +16 -10
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/lib.rs +2 -0
- package/src/lodash.rs +7 -0
- package/src/state_repository.rs +188 -36
- package/src/state_transition/mod.rs +12 -0
- package/src/utils.rs +102 -7
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +2 -0
- package/src/validation/validation_result.rs +23 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +26 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +579 -502
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +175 -165
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +83 -114
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +82 -91
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +75 -31
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -148
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +63 -75
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +48 -19
- package/test/unit/dataContract/DataContract.spec.js +3 -3
- 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/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -3
- package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
- package/test/unit/document/Document.spec.js +147 -155
- package/test/unit/document/DocumentFactory.spec.js +325 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +142 -64
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +69 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +32 -32
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +56 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +48 -46
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- 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/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +1495 -565
- package/wasm/wasm_dpp.js +3654 -1206
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +557 -386
- package/webpack.config.js +9 -0
package/karma.conf.js
CHANGED
|
@@ -11,8 +11,8 @@ export default function (dppModule: typeof dpp_module) {
|
|
|
11
11
|
//@ts-ignore
|
|
12
12
|
Object.setPrototypeOf(Identifier.prototype, Buffer.prototype);
|
|
13
13
|
|
|
14
|
-
Identifier.prototype.valueOf = function() {
|
|
15
|
-
return Buffer.from(this.
|
|
14
|
+
Identifier.prototype.valueOf = function () {
|
|
15
|
+
return Buffer.from(this.toBytes());
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
// @ts-ignore
|
|
@@ -24,7 +24,7 @@ export default function (dppModule: typeof dpp_module) {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// @ts-ignore
|
|
27
|
-
Identifier.prototype.inspect = function(...args) {
|
|
27
|
+
Identifier.prototype.inspect = function (...args) {
|
|
28
28
|
return this.valueOf().inspect(...args);
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -34,4 +34,5 @@ export default function (dppModule: typeof dpp_module) {
|
|
|
34
34
|
// console.log("custom:", inspect.custom);
|
|
35
35
|
// //@ts-ignore
|
|
36
36
|
// Identifier.prototype[inspect.custom] = Identifier.prototype.inspect;
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
|
+
|
package/lib/index.ts
CHANGED
package/lib/test/bootstrap.js
CHANGED
|
@@ -5,6 +5,7 @@ const dirtyChai = require('dirty-chai');
|
|
|
5
5
|
const chaiAsPromised = require('chai-as-promised');
|
|
6
6
|
const chaiString = require('chai-string');
|
|
7
7
|
const chaiExclude = require('chai-exclude');
|
|
8
|
+
const crypto = require('crypto');
|
|
8
9
|
|
|
9
10
|
use(sinonChai);
|
|
10
11
|
use(chaiAsPromised);
|
|
@@ -12,6 +13,10 @@ use(dirtyChai);
|
|
|
12
13
|
use(chaiString);
|
|
13
14
|
use(chaiExclude);
|
|
14
15
|
|
|
16
|
+
/* eslint-disable */
|
|
17
|
+
// TODO this should be loaded with library - not with tests.
|
|
18
|
+
globalThis.crypto = crypto.webcrypto;
|
|
19
|
+
|
|
15
20
|
beforeEach(function beforeEach() {
|
|
16
21
|
if (!this.sinonSandbox) {
|
|
17
22
|
this.sinonSandbox = sinon.createSandbox();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const BlsSignatures = require('@dashevo/dpp/lib/bls/bls');
|
|
2
|
+
|
|
3
|
+
module.exports = async function getBlsAdapterMock() {
|
|
4
|
+
const bls = await BlsSignatures.getInstance();
|
|
5
|
+
|
|
6
|
+
const blsAdapter = {
|
|
7
|
+
validatePublicKey(publicKeyBuffer) {
|
|
8
|
+
let pk;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
pk = bls.PublicKey.fromBytes(publicKeyBuffer);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return Boolean(pk);
|
|
17
|
+
},
|
|
18
|
+
sign(data, key) {
|
|
19
|
+
const blsKey = bls.PrivateKey.fromBytes(key, true);
|
|
20
|
+
const signature = blsKey.sign(data);
|
|
21
|
+
return Buffer.from(signature.serialize());
|
|
22
|
+
},
|
|
23
|
+
verifySignature(signature, data, publicKey) {
|
|
24
|
+
const { PublicKey, Signature: BlsSignature, AggregationInfo } = bls;
|
|
25
|
+
|
|
26
|
+
const blsKey = PublicKey.fromBytes(publicKey);
|
|
27
|
+
|
|
28
|
+
const aggregationInfo = AggregationInfo.fromMsg(blsKey, data);
|
|
29
|
+
const blsSignature = BlsSignature.fromBytesAndAggregationInfo(signature, aggregationInfo);
|
|
30
|
+
|
|
31
|
+
return blsSignature.verify();
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return blsAdapter;
|
|
36
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { default: loadWasmDpp } = require('../../../dist');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates container with documents
|
|
5
|
+
*
|
|
6
|
+
* @return {DocumentsContainer}
|
|
7
|
+
*/
|
|
8
|
+
async function newDocumentsContainer(documents) {
|
|
9
|
+
const {
|
|
10
|
+
create: createDocuments,
|
|
11
|
+
replace: replaceDocuments,
|
|
12
|
+
delete: deleteDocuments,
|
|
13
|
+
} = documents;
|
|
14
|
+
const { DocumentsContainer } = await loadWasmDpp();
|
|
15
|
+
|
|
16
|
+
const documentsContainer = new DocumentsContainer();
|
|
17
|
+
if (createDocuments != null) {
|
|
18
|
+
createDocuments.forEach((document) => {
|
|
19
|
+
documentsContainer.pushDocumentCreate(document);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (replaceDocuments != null) {
|
|
23
|
+
replaceDocuments.forEach((document) => {
|
|
24
|
+
documentsContainer.pushDocumentReplace(document);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (deleteDocuments != null) {
|
|
28
|
+
deleteDocuments.forEach((document) => {
|
|
29
|
+
documentsContainer.pushDocumentDelete(document);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return documentsContainer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = newDocumentsContainer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/wasm-dpp",
|
|
3
|
-
"version": "0.24.0-dev.
|
|
3
|
+
"version": "0.24.0-dev.13",
|
|
4
4
|
"description": "The JavaScript implementation of the Dash Platform Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/lib/index.d.ts",
|
|
@@ -30,13 +30,15 @@
|
|
|
30
30
|
],
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@dashevo/bls": "~1.0.0-beta.2"
|
|
33
|
+
"@dashevo/bls": "~1.0.0-beta.2",
|
|
34
|
+
"lodash": "^4.17.21",
|
|
35
|
+
"varint": "^6.0.0"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@apidevtools/json-schema-ref-parser": "^8.0.0",
|
|
37
39
|
"@dashevo/dashcore-lib": "~0.19.44",
|
|
38
|
-
"@dashevo/dpns-contract": "0.24.0-dev.
|
|
39
|
-
"@dashevo/dpp": "0.24.0-dev.
|
|
40
|
+
"@dashevo/dpns-contract": "0.24.0-dev.13",
|
|
41
|
+
"@dashevo/dpp": "0.24.0-dev.13",
|
|
40
42
|
"@dashevo/wasm-re2": "~1.0.2",
|
|
41
43
|
"@types/node": "^14.6.0",
|
|
42
44
|
"ajv": "^8.6.0",
|
|
@@ -73,6 +75,7 @@
|
|
|
73
75
|
"stream-browserify": "^3.0.0",
|
|
74
76
|
"stream-http": "^3.2.0",
|
|
75
77
|
"string_decoder": "^1.3.0",
|
|
78
|
+
"terser-webpack-plugin": "^5.3.1",
|
|
76
79
|
"ts-loader": "^8.0.2",
|
|
77
80
|
"typescript": "^3.9.5",
|
|
78
81
|
"url": "^0.11.0",
|
package/src/bls_adapter.rs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
use dpp::dashcore::anyhow::anyhow;
|
|
2
2
|
use dpp::{BlsModule, PublicKeyValidationError};
|
|
3
3
|
use wasm_bindgen::prelude::*;
|
|
4
|
+
use wasm_bindgen::JsCast;
|
|
4
5
|
|
|
5
6
|
#[wasm_bindgen]
|
|
6
7
|
extern "C" {
|
|
8
|
+
#[derive(Clone)]
|
|
7
9
|
pub type JsBlsAdapter;
|
|
8
10
|
|
|
9
11
|
#[wasm_bindgen(method)]
|
|
@@ -66,6 +68,19 @@ impl BlsModule for BlsAdapter {
|
|
|
66
68
|
self.0
|
|
67
69
|
.sign(data, private_key)
|
|
68
70
|
.map(|arr| arr.to_vec())
|
|
69
|
-
.map_err(|
|
|
71
|
+
.map_err(|e: JsValue| {
|
|
72
|
+
let error = e.dyn_into::<js_sys::Error>();
|
|
73
|
+
|
|
74
|
+
match error {
|
|
75
|
+
Ok(e) => {
|
|
76
|
+
let message: String = e
|
|
77
|
+
.message()
|
|
78
|
+
.as_string()
|
|
79
|
+
.unwrap_or_else(|| String::from("Unknown error, can't sign"));
|
|
80
|
+
anyhow!(message).into()
|
|
81
|
+
}
|
|
82
|
+
Err(_) => anyhow!("Unknown error, can't sign").into(),
|
|
83
|
+
}
|
|
84
|
+
})
|
|
70
85
|
}
|
|
71
86
|
}
|
|
@@ -12,6 +12,7 @@ use dpp::util::string_encoding::Encoding;
|
|
|
12
12
|
|
|
13
13
|
use crate::errors::{from_dpp_err, RustConversionError};
|
|
14
14
|
use crate::metadata::MetadataWasm;
|
|
15
|
+
use crate::utils::WithJsError;
|
|
15
16
|
use crate::{bail_js, with_js_error};
|
|
16
17
|
use crate::{buffer::Buffer, identifier::IdentifierWrapper};
|
|
17
18
|
|
|
@@ -34,11 +35,16 @@ impl std::convert::Into<DataContract> for DataContractWasm {
|
|
|
34
35
|
#[derive(Debug, Serialize, Deserialize)]
|
|
35
36
|
#[serde(rename_all = "camelCase")]
|
|
36
37
|
pub(crate) struct DataContractParameters {
|
|
37
|
-
#[serde(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
#[serde(
|
|
39
|
+
rename = "$schema",
|
|
40
|
+
skip_serializing_if = "serde_json::Value::is_null",
|
|
41
|
+
default
|
|
42
|
+
)]
|
|
43
|
+
schema: serde_json::Value,
|
|
44
|
+
#[serde(rename = "$id", skip_serializing_if = "Option::is_none")]
|
|
45
|
+
id: Option<Vec<u8>>,
|
|
46
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
47
|
+
owner_id: Option<Vec<u8>>,
|
|
42
48
|
#[serde(skip_serializing_if = "serde_json::Value::is_null", default)]
|
|
43
49
|
documents: serde_json::Value,
|
|
44
50
|
#[serde(
|
|
@@ -47,8 +53,13 @@ pub(crate) struct DataContractParameters {
|
|
|
47
53
|
rename = "$defs"
|
|
48
54
|
)]
|
|
49
55
|
defs: serde_json::Value,
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
#[serde(skip_serializing_if = "serde_json::Value::is_null", default)]
|
|
57
|
+
protocol_version: serde_json::Value,
|
|
58
|
+
#[serde(skip_serializing_if = "serde_json::Value::is_null", default)]
|
|
59
|
+
version: serde_json::Value,
|
|
60
|
+
|
|
61
|
+
#[serde(flatten)]
|
|
62
|
+
_extras: serde_json::Value, // Captures excess fields to trigger validation failure later.
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
#[wasm_bindgen(js_class=DataContract)]
|
|
@@ -75,6 +86,11 @@ impl DataContractWasm {
|
|
|
75
86
|
self.0.id.clone().into()
|
|
76
87
|
}
|
|
77
88
|
|
|
89
|
+
#[wasm_bindgen(js_name=setId)]
|
|
90
|
+
pub fn set_id(&mut self, id: IdentifierWrapper) {
|
|
91
|
+
self.0.id = id.inner();
|
|
92
|
+
}
|
|
93
|
+
|
|
78
94
|
#[wasm_bindgen(js_name=getOwnerId)]
|
|
79
95
|
pub fn get_owner_id(&self) -> IdentifierWrapper {
|
|
80
96
|
self.0.owner_id.clone().into()
|
|
@@ -276,6 +292,12 @@ impl DataContractWasm {
|
|
|
276
292
|
.map_err(from_dpp_err)?
|
|
277
293
|
.into())
|
|
278
294
|
}
|
|
295
|
+
|
|
296
|
+
#[wasm_bindgen(js_name=fromBuffer)]
|
|
297
|
+
pub fn from_buffer(b: &[u8]) -> Result<DataContractWasm, JsValue> {
|
|
298
|
+
let data_contract = DataContract::from_cbor(b).with_js_error()?;
|
|
299
|
+
Ok(data_contract.into())
|
|
300
|
+
}
|
|
279
301
|
}
|
|
280
302
|
|
|
281
303
|
#[wasm_bindgen(js_name=DataContractDefaults)]
|
|
@@ -288,3 +310,9 @@ impl DataContractDefaults {
|
|
|
288
310
|
SCHEMA_URI.to_string()
|
|
289
311
|
}
|
|
290
312
|
}
|
|
313
|
+
|
|
314
|
+
impl DataContractWasm {
|
|
315
|
+
pub fn inner(&self) -> &DataContract {
|
|
316
|
+
&self.0
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
use dpp::{data_contract::
|
|
1
|
+
use dpp::{data_contract::document_type::IndexProperty, util::json_schema::Index};
|
|
2
|
+
use serde::{ser::SerializeMap, Serialize, Serializer};
|
|
2
3
|
use wasm_bindgen::prelude::*;
|
|
3
4
|
|
|
5
|
+
use crate::{errors::RustConversionError, with_js_error};
|
|
6
|
+
|
|
4
7
|
#[wasm_bindgen(js_name=IndexProperty)]
|
|
5
8
|
#[derive(Debug, Clone)]
|
|
6
9
|
pub struct IndexPropertyWasm {
|
|
@@ -38,6 +41,51 @@ impl From<Index> for IndexDefinitionWasm {
|
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
/// Wrapper structure to serialize `Index` the way js-dpp expects it.
|
|
45
|
+
#[derive(Debug)]
|
|
46
|
+
struct IndexSerializeJs<'a>(&'a Index);
|
|
47
|
+
|
|
48
|
+
impl Serialize for IndexSerializeJs<'_> {
|
|
49
|
+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
50
|
+
where
|
|
51
|
+
S: Serializer,
|
|
52
|
+
{
|
|
53
|
+
let mut map = serializer.serialize_map(Some(3))?;
|
|
54
|
+
map.serialize_entry("name", &self.0.name)?;
|
|
55
|
+
if self.0.unique {
|
|
56
|
+
map.serialize_entry("unique", &true)?;
|
|
57
|
+
}
|
|
58
|
+
map.serialize_entry(
|
|
59
|
+
"properties",
|
|
60
|
+
&self
|
|
61
|
+
.0
|
|
62
|
+
.properties
|
|
63
|
+
.iter()
|
|
64
|
+
.map(IndexPropertySerializeJs)
|
|
65
|
+
.collect::<Vec<_>>(),
|
|
66
|
+
)?;
|
|
67
|
+
|
|
68
|
+
map.end()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// Wrapper structure to serialize `InderProperty` the way js-dpp expects it.
|
|
73
|
+
#[derive(Debug)]
|
|
74
|
+
struct IndexPropertySerializeJs<'a>(&'a IndexProperty);
|
|
75
|
+
|
|
76
|
+
impl Serialize for IndexPropertySerializeJs<'_> {
|
|
77
|
+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
78
|
+
where
|
|
79
|
+
S: Serializer,
|
|
80
|
+
{
|
|
81
|
+
let mut map = serializer.serialize_map(Some(1))?;
|
|
82
|
+
let order_str = if self.0.ascending { "asc" } else { "desc" };
|
|
83
|
+
map.serialize_entry(&self.0.name, order_str)?;
|
|
84
|
+
|
|
85
|
+
map.end()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
41
89
|
#[wasm_bindgen(js_class=IndexDefinition)]
|
|
42
90
|
impl IndexDefinitionWasm {
|
|
43
91
|
#[wasm_bindgen(js_name=getName)]
|
|
@@ -58,4 +106,11 @@ impl IndexDefinitionWasm {
|
|
|
58
106
|
pub fn is_unique(&self) -> bool {
|
|
59
107
|
self.inner.unique
|
|
60
108
|
}
|
|
109
|
+
|
|
110
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
111
|
+
pub fn to_object(&self) -> Result<JsValue, JsValue> {
|
|
112
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
113
|
+
let object = with_js_error!(IndexSerializeJs(&self.inner).serialize(&serializer))?;
|
|
114
|
+
Ok(object)
|
|
115
|
+
}
|
|
61
116
|
}
|
package/src/data_contract/mod.rs
CHANGED
|
@@ -14,10 +14,8 @@ use serde::{Deserialize, Serialize};
|
|
|
14
14
|
use wasm_bindgen::prelude::*;
|
|
15
15
|
|
|
16
16
|
use crate::{
|
|
17
|
-
buffer::Buffer,
|
|
18
|
-
|
|
19
|
-
identifier::IdentifierWrapper,
|
|
20
|
-
with_js_error, DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
|
|
17
|
+
buffer::Buffer, errors::from_dpp_err, identifier::IdentifierWrapper, with_js_error,
|
|
18
|
+
DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
#[wasm_bindgen(js_name=DataContractCreateTransition)]
|
|
@@ -14,11 +14,11 @@ pub async fn validate_data_contract_create_transition_state(
|
|
|
14
14
|
state_transition: DataContractCreateTransitionWasm,
|
|
15
15
|
) -> Result<ValidationResultWasm, JsValue> {
|
|
16
16
|
let wrapped_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
|
|
17
|
-
dpp_validate_data_contract_create_transition_state(
|
|
17
|
+
let validation_result = dpp_validate_data_contract_create_transition_state(
|
|
18
18
|
&wrapped_state_repository,
|
|
19
19
|
&state_transition.into(),
|
|
20
20
|
)
|
|
21
21
|
.await
|
|
22
|
-
.
|
|
23
|
-
.
|
|
22
|
+
.map_err(from_dpp_err)?;
|
|
23
|
+
Ok(validation_result.map(|_| JsValue::undefined()).into())
|
|
24
24
|
}
|
|
@@ -14,10 +14,8 @@ use serde::{Deserialize, Serialize};
|
|
|
14
14
|
use wasm_bindgen::prelude::*;
|
|
15
15
|
|
|
16
16
|
use crate::{
|
|
17
|
-
buffer::Buffer,
|
|
18
|
-
|
|
19
|
-
identifier::IdentifierWrapper,
|
|
20
|
-
with_js_error, DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
|
|
17
|
+
buffer::Buffer, errors::from_dpp_err, identifier::IdentifierWrapper, with_js_error,
|
|
18
|
+
DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
#[wasm_bindgen(js_name=DataContractUpdateTransition)]
|
|
@@ -19,13 +19,14 @@ pub async fn validate_data_contract_update_transition_state(
|
|
|
19
19
|
state_transition: DataContractUpdateTransitionWasm,
|
|
20
20
|
) -> Result<ValidationResultWasm, JsValue> {
|
|
21
21
|
let wrapped_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
|
|
22
|
-
dpp_validate_data_contract_update_transition_state(
|
|
22
|
+
let result = dpp_validate_data_contract_update_transition_state(
|
|
23
23
|
&wrapped_state_repository,
|
|
24
24
|
&state_transition.into(),
|
|
25
25
|
)
|
|
26
26
|
.await
|
|
27
|
-
.
|
|
28
|
-
|
|
27
|
+
.map_err(from_dpp_err)?;
|
|
28
|
+
|
|
29
|
+
Ok(result.map(|_| JsValue::undefined()).into())
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
#[wasm_bindgen(js_name=validateIndicesAreBackwardCompatible)]
|
|
@@ -40,7 +41,9 @@ pub fn validate_indices_are_backward_compatible(
|
|
|
40
41
|
new_documents_schema,
|
|
41
42
|
)?;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
.
|
|
45
|
-
|
|
44
|
+
let result =
|
|
45
|
+
dpp_validate_indices_are_backward_compatible(old_documents.iter(), new_documents.iter())
|
|
46
|
+
.map_err(from_protocol_error)?;
|
|
47
|
+
|
|
48
|
+
Ok(result.map(|_| JsValue::undefined()).into())
|
|
46
49
|
}
|
|
@@ -14,7 +14,6 @@ use crate::{
|
|
|
14
14
|
data_contract::errors::InvalidDataContractError,
|
|
15
15
|
errors::{
|
|
16
16
|
consensus_error::from_consensus_error, from_dpp_err, protocol_error::from_protocol_error,
|
|
17
|
-
RustConversionError,
|
|
18
17
|
},
|
|
19
18
|
validation::ValidationResultWasm,
|
|
20
19
|
with_js_error, DataContractCreateTransitionWasm, DataContractParameters, DataContractWasm,
|
|
@@ -42,15 +41,14 @@ impl DataContractValidatorWasm {
|
|
|
42
41
|
DataContractValidator::new(std::sync::Arc::new(ProtocolVersionValidator::default())).into()
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
#[wasm_bindgen
|
|
44
|
+
#[wasm_bindgen]
|
|
46
45
|
pub fn validate(&self, raw_data_contract: JsValue) -> Result<ValidationResultWasm, JsValue> {
|
|
47
46
|
let parameters: DataContractParameters =
|
|
48
47
|
with_js_error!(serde_wasm_bindgen::from_value(raw_data_contract))?;
|
|
49
48
|
let json_object = serde_json::to_value(parameters).expect("Implements Serialize");
|
|
50
|
-
self.0
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.map_err(from_protocol_error)
|
|
49
|
+
let validation_result = self.0.validate(&json_object).map_err(from_protocol_error)?;
|
|
50
|
+
|
|
51
|
+
Ok(validation_result.map(|_| JsValue::undefined()).into())
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
use thiserror::Error;
|
|
2
2
|
|
|
3
|
-
use crate::DocumentWasm;
|
|
4
|
-
|
|
5
3
|
use super::*;
|
|
6
4
|
|
|
7
5
|
#[wasm_bindgen]
|
|
@@ -10,14 +8,17 @@ use super::*;
|
|
|
10
8
|
pub struct InvalidDocumentError {
|
|
11
9
|
// the point is how we hold all there different types in the Vector
|
|
12
10
|
errors: Vec<JsValue>,
|
|
13
|
-
|
|
11
|
+
raw_document: JsValue,
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
#[wasm_bindgen]
|
|
14
|
+
#[wasm_bindgen(js_class=InvalidDocumentError)]
|
|
17
15
|
impl InvalidDocumentError {
|
|
18
16
|
#[wasm_bindgen(constructor)]
|
|
19
|
-
pub fn new(
|
|
20
|
-
Self {
|
|
17
|
+
pub fn new(raw_document: JsValue, errors: Vec<JsValue>) -> InvalidDocumentError {
|
|
18
|
+
Self {
|
|
19
|
+
raw_document,
|
|
20
|
+
errors,
|
|
21
|
+
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
#[wasm_bindgen(js_name=getErrors)]
|
|
@@ -25,8 +26,8 @@ impl InvalidDocumentError {
|
|
|
25
26
|
self.errors.clone()
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
#[wasm_bindgen(js_name=
|
|
29
|
-
pub fn get_document(&self) ->
|
|
30
|
-
self.
|
|
29
|
+
#[wasm_bindgen(js_name=getRawDocument)]
|
|
30
|
+
pub fn get_document(&self) -> JsValue {
|
|
31
|
+
self.raw_document.clone()
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
use dpp::prelude::Document;
|
|
2
|
+
use itertools::Itertools;
|
|
1
3
|
use thiserror::Error;
|
|
2
4
|
|
|
3
5
|
use crate::DocumentWasm;
|
|
@@ -7,21 +9,29 @@ use super::*;
|
|
|
7
9
|
#[wasm_bindgen]
|
|
8
10
|
#[derive(Error, Debug)]
|
|
9
11
|
#[error("Documents have mixed owner ids")]
|
|
10
|
-
pub struct
|
|
12
|
+
pub struct MismatchOwnerIdsError {
|
|
11
13
|
documents: Vec<DocumentWasm>,
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
#[wasm_bindgen]
|
|
15
|
-
impl
|
|
17
|
+
impl MismatchOwnerIdsError {
|
|
16
18
|
#[wasm_bindgen(constructor)]
|
|
17
|
-
pub fn new(documents: Vec<JsValue>) ->
|
|
19
|
+
pub fn new(documents: Vec<JsValue>) -> MismatchOwnerIdsError {
|
|
18
20
|
Self {
|
|
19
21
|
documents: into_vec_of(&documents),
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
#[wasm_bindgen(js_name=
|
|
25
|
+
#[wasm_bindgen(js_name=getDocuments)]
|
|
24
26
|
pub fn get_documents(&self) -> Vec<JsValue> {
|
|
25
27
|
to_vec_js(self.documents.clone())
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
|
|
31
|
+
impl MismatchOwnerIdsError {
|
|
32
|
+
pub fn from_documents(documents: Vec<Document>) -> MismatchOwnerIdsError {
|
|
33
|
+
Self {
|
|
34
|
+
documents: documents.into_iter().map(DocumentWasm::from).collect_vec(),
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
use serde::Serialize;
|
|
1
2
|
use wasm_bindgen::prelude::*;
|
|
2
3
|
|
|
3
4
|
pub use document_already_exists_error::*;
|
|
@@ -11,7 +12,7 @@ pub use mismatch_owners_ids_error::*;
|
|
|
11
12
|
pub use no_documents_supplied_error::*;
|
|
12
13
|
|
|
13
14
|
use crate::errors::consensus_error::from_consensus_error;
|
|
14
|
-
use crate::
|
|
15
|
+
use crate::utils::*;
|
|
15
16
|
|
|
16
17
|
mod document_already_exists_error;
|
|
17
18
|
mod document_not_provided_error;
|
|
@@ -24,32 +25,35 @@ mod no_documents_supplied_error;
|
|
|
24
25
|
|
|
25
26
|
pub fn from_document_to_js_error(e: DocumentError) -> JsValue {
|
|
26
27
|
match e {
|
|
27
|
-
DocumentError::
|
|
28
|
+
DocumentError::DocumentAlreadyExistsError {
|
|
28
29
|
document_transition,
|
|
29
30
|
} => DocumentAlreadyExistsError::new(document_transition).into(),
|
|
30
|
-
DocumentError::
|
|
31
|
+
DocumentError::DocumentNotProvidedError {
|
|
31
32
|
document_transition,
|
|
32
33
|
} => DocumentNotProvidedError::new(document_transition).into(),
|
|
33
34
|
|
|
34
|
-
DocumentError::
|
|
35
|
+
DocumentError::InvalidActionNameError { actions } => {
|
|
35
36
|
InvalidActionNameError::new(to_vec_js(actions)).into()
|
|
36
37
|
}
|
|
37
|
-
DocumentError::
|
|
38
|
-
|
|
38
|
+
DocumentError::InvalidDocumentError {
|
|
39
|
+
errors,
|
|
40
|
+
raw_document,
|
|
41
|
+
} => InvalidDocumentError::new(
|
|
42
|
+
raw_document
|
|
43
|
+
.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
44
|
+
.expect("Raw Document should be serializable into JsValue"),
|
|
39
45
|
errors.into_iter().map(from_consensus_error).collect(),
|
|
40
46
|
)
|
|
41
47
|
.into(),
|
|
42
|
-
DocumentError::
|
|
48
|
+
DocumentError::InvalidDocumentActionError {
|
|
43
49
|
document_transition,
|
|
44
50
|
} => InvalidDocumentActionError::new(document_transition).into(),
|
|
45
|
-
DocumentError::
|
|
51
|
+
DocumentError::InvalidInitialRevisionError { document } => {
|
|
46
52
|
InvalidInitialRevisionError::new((*document).into()).into()
|
|
47
53
|
}
|
|
48
|
-
DocumentError::
|
|
49
|
-
|
|
50
|
-
documents.into_iter().map(DocumentWasm::from).collect();
|
|
51
|
-
MismatchOwnersIdsError::new(to_vec_js(documents_wasm)).into()
|
|
54
|
+
DocumentError::MismatchOwnerIdsError { documents } => {
|
|
55
|
+
MismatchOwnerIdsError::from_documents(documents).into()
|
|
52
56
|
}
|
|
53
|
-
DocumentError::
|
|
57
|
+
DocumentError::NoDocumentsSuppliedError => NoDocumentsSuppliedError::new().into(),
|
|
54
58
|
}
|
|
55
59
|
}
|
|
@@ -5,17 +5,17 @@ use super::*;
|
|
|
5
5
|
#[wasm_bindgen]
|
|
6
6
|
#[derive(Error, Debug)]
|
|
7
7
|
#[error("No documents were supplied to state transition")]
|
|
8
|
-
pub struct
|
|
8
|
+
pub struct NoDocumentsSuppliedError {}
|
|
9
9
|
|
|
10
10
|
#[wasm_bindgen]
|
|
11
|
-
impl
|
|
11
|
+
impl NoDocumentsSuppliedError {
|
|
12
12
|
#[wasm_bindgen(constructor)]
|
|
13
13
|
pub fn new() -> Self {
|
|
14
|
-
|
|
14
|
+
NoDocumentsSuppliedError {}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
impl Default for
|
|
18
|
+
impl Default for NoDocumentsSuppliedError {
|
|
19
19
|
fn default() -> Self {
|
|
20
20
|
Self::new()
|
|
21
21
|
}
|