@dashevo/wasm-dpp 0.24.0-dev.11 → 0.24.0-dev.12
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/dist/index.js +1 -1
- package/dist/lib/dpp.d.ts +9 -0
- package/dist/lib/errors/AbstractConsensusError.d.ts +10 -0
- package/dist/lib/errors/DPPError.d.ts +5 -0
- package/dist/lib/errors/patchConsensusErrors.d.ts +1 -0
- package/dist/lib/{patchIdentifier.d.ts → identifier/patchIdentifier.d.ts} +1 -1
- package/dist/{index.d.ts → lib/index.d.ts} +1 -1
- package/dist/lib/utils/extend.d.ts +1 -0
- package/dist/wasm/wasm_dpp.d.ts +352 -205
- package/lib/dpp.ts +24 -0
- package/lib/errors/AbstractConsensusError.ts +13 -0
- package/lib/errors/DPPError.ts +15 -0
- package/lib/errors/patchConsensusErrors.ts +175 -0
- package/lib/{patchIdentifier.ts → identifier/patchIdentifier.ts} +1 -1
- package/{index.ts → lib/index.ts} +4 -3
- package/lib/test/expect/expectError.js +4 -2
- package/lib/utils/extend.ts +6 -0
- package/package.json +5 -5
- package/src/data_contract/errors/invalid_data_contract.rs +21 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +4 -4
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +2 -2
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +147 -0
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +46 -0
- package/src/data_contract/state_transition/mod.rs +2 -0
- package/src/data_contract_factory/data_contract_factory.rs +27 -12
- package/src/errors/consensus/basic/data_contract/data_contract_max_depth_exceed_error.rs +5 -5
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +4 -4
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +36 -0
- package/src/errors/consensus/basic/document/missing_document_transition_type_error.rs +20 -0
- package/src/errors/consensus/basic/document/mod.rs +4 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +2 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +2 -2
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +2 -2
- package/src/errors/consensus/basic/json_schema_error.rs +1 -1
- package/src/errors/consensus_error.rs +15 -8
- package/src/errors/from.rs +1 -1
- package/src/errors/mod.rs +1 -0
- package/src/errors/protocol_error.rs +12 -0
- package/src/{identifier.rs → identifier/mod.rs} +0 -0
- package/src/{identity_facade.rs → identity/identity_facade.rs} +1 -1
- package/src/{identity_public_key → identity/identity_public_key}/key_type.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/mod.rs +0 -3
- package/src/{identity_public_key → identity/identity_public_key}/purpose.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/security_level.rs +0 -0
- package/src/{identity.rs → identity/mod.rs} +6 -7
- package/src/identity/validation/mod.rs +3 -0
- package/src/identity/validation/public_keys_validator.rs +70 -0
- package/src/lib.rs +1 -6
- package/src/utils.rs +2 -2
- package/src/validation/mod.rs +3 -0
- package/src/{validation_result.rs → validation/validation_result.rs} +0 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +1 -1
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +79 -114
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -11
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +135 -0
- package/test/unit/dataContract/DataContract.spec.js +5 -9
- package/test/unit/dataContract/DataContractFactory.spec.js +13 -6
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +11 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +20 -16
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +23 -59
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +27 -23
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +29 -12
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +66 -49
- package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +73 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +1 -1
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +1 -1
- package/test/unit/identity/IdentityPublicKey.spec.js +25 -31
- package/tsconfig.json +1 -1
- package/wasm/wasm_dpp.d.ts +352 -205
- package/wasm/wasm_dpp.js +759 -372
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +205 -175
- package/webpack.config.js +1 -1
- package/src/identity_public_key/public_keys_validator.rs +0 -44
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +0 -32
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +0 -93
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +0 -64
package/lib/dpp.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as dpp_module from '../wasm/wasm_dpp';
|
|
2
|
+
import { patchConsensusErrors } from './errors/patchConsensusErrors';
|
|
3
|
+
|
|
4
|
+
patchConsensusErrors();
|
|
5
|
+
|
|
6
|
+
// While we declared it above, those fields do not hold any values - let's assign them.
|
|
7
|
+
// We need to suppress the compiler here, as he won't be happy about those reassignments.
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
dpp_module.IdentityPublicKey.TYPES = dpp_module.KeyType;
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
dpp_module.IdentityPublicKey.PURPOSES = dpp_module.KeyPurpose;
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
dpp_module.IdentityPublicKey.SECURITY_LEVELS = dpp_module.KeySecurityLevel;
|
|
14
|
+
|
|
15
|
+
export * from '../wasm/wasm_dpp';
|
|
16
|
+
export * from './errors/AbstractConsensusError';
|
|
17
|
+
export * from './errors/DPPError';
|
|
18
|
+
|
|
19
|
+
// Declarations written prior to "export *" will overwrite exports
|
|
20
|
+
export declare class IdentityPublicKey extends dpp_module.IdentityPublicKey {
|
|
21
|
+
static TYPES: typeof dpp_module.KeyType;
|
|
22
|
+
static PURPOSES: typeof dpp_module.KeyPurpose;
|
|
23
|
+
static SECURITY_LEVELS: typeof dpp_module.KeySecurityLevel;
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class DPPError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
message: string;
|
|
4
|
+
|
|
5
|
+
constructor(message: string) {
|
|
6
|
+
super();
|
|
7
|
+
|
|
8
|
+
this.name = this.constructor.name;
|
|
9
|
+
this.message = message;
|
|
10
|
+
|
|
11
|
+
if (Error.captureStackTrace) {
|
|
12
|
+
Error.captureStackTrace(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as dpp_module from '../../wasm/wasm_dpp';
|
|
2
|
+
import { extend } from "../utils/extend";
|
|
3
|
+
import { AbstractConsensusError } from "./AbstractConsensusError";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
ProtocolVersionParsingError,
|
|
7
|
+
UnsupportedProtocolVersionError,
|
|
8
|
+
IncompatibleProtocolVersionError,
|
|
9
|
+
SerializedObjectParsingError,
|
|
10
|
+
JsonSchemaError,
|
|
11
|
+
InvalidIdentifierError,
|
|
12
|
+
DataContractMaxDepthExceedError,
|
|
13
|
+
DuplicateIndexError,
|
|
14
|
+
InvalidCompoundIndexError,
|
|
15
|
+
InvalidDataContractIdError,
|
|
16
|
+
InvalidIndexedPropertyConstraintError,
|
|
17
|
+
InvalidIndexPropertyTypeError,
|
|
18
|
+
SystemPropertyIndexAlreadyPresentError,
|
|
19
|
+
UndefinedIndexPropertyError,
|
|
20
|
+
UniqueIndicesLimitReachedError,
|
|
21
|
+
InconsistentCompoundIndexDataError,
|
|
22
|
+
InvalidDocumentTransitionActionError,
|
|
23
|
+
InvalidDocumentTransitionIdError,
|
|
24
|
+
DataContractNotPresentError,
|
|
25
|
+
InvalidDocumentTypeError,
|
|
26
|
+
MissingDataContractIdError,
|
|
27
|
+
MissingDocumentTransitionActionError,
|
|
28
|
+
MissingDocumentTransitionTypeError,
|
|
29
|
+
MissingDocumentTypeError,
|
|
30
|
+
DuplicatedIdentityPublicKeyError,
|
|
31
|
+
DuplicatedIdentityPublicKeyIdError,
|
|
32
|
+
MissingMasterPublicKeyError,
|
|
33
|
+
IdentityAssetLockProofLockedTransactionMismatchError,
|
|
34
|
+
IdentityAssetLockTransactionIsNotFoundError,
|
|
35
|
+
IdentityAssetLockTransactionOutPointAlreadyExistsError,
|
|
36
|
+
IdentityAssetLockTransactionOutputNotFoundError,
|
|
37
|
+
InvalidAssetLockProofCoreChainHeightError,
|
|
38
|
+
InvalidAssetLockProofTransactionHeightError,
|
|
39
|
+
InvalidIdentityAssetLockTransactionError,
|
|
40
|
+
InvalidIdentityAssetLockTransactionOutputError,
|
|
41
|
+
InvalidIdentityPublicKeyDataError,
|
|
42
|
+
InvalidIdentityPublicKeySecurityLevelError,
|
|
43
|
+
InvalidStateTransitionTypeError,
|
|
44
|
+
MissingStateTransitionTypeError,
|
|
45
|
+
StateTransitionMaxSizeExceededError,
|
|
46
|
+
IdentityNotFoundError,
|
|
47
|
+
InvalidIdentityPublicKeyTypeError,
|
|
48
|
+
InvalidStateTransitionSignatureError,
|
|
49
|
+
MissingPublicKeyError,
|
|
50
|
+
BalanceIsNotEnoughError,
|
|
51
|
+
DataContractAlreadyPresentError,
|
|
52
|
+
DataTriggerConditionError,
|
|
53
|
+
DataTriggerExecutionError,
|
|
54
|
+
DataTriggerInvalidResultError,
|
|
55
|
+
DocumentAlreadyPresentError,
|
|
56
|
+
DocumentNotFoundError,
|
|
57
|
+
DocumentOwnerIdMismatchError,
|
|
58
|
+
DocumentTimestampsMismatchError,
|
|
59
|
+
DocumentTimestampWindowViolationError,
|
|
60
|
+
DuplicateUniqueIndexError,
|
|
61
|
+
InvalidDocumentRevisionError,
|
|
62
|
+
IdentityAlreadyExistsError,
|
|
63
|
+
InvalidJsonSchemaRefError,
|
|
64
|
+
JsonSchemaCompilationError,
|
|
65
|
+
DuplicateDocumentTransitionsWithIdsError,
|
|
66
|
+
DuplicateDocumentTransitionsWithIndicesError,
|
|
67
|
+
InvalidAssetLockTransactionOutputReturnSizeError,
|
|
68
|
+
InvalidInstantAssetLockProofError,
|
|
69
|
+
InvalidInstantAssetLockProofSignatureError,
|
|
70
|
+
IncompatibleRe2PatternError,
|
|
71
|
+
InvalidDataContractVersionError,
|
|
72
|
+
IncompatibleDataContractSchemaError,
|
|
73
|
+
DataContractImmutablePropertiesUpdateError,
|
|
74
|
+
DataContractUniqueIndicesChangedError,
|
|
75
|
+
DuplicateIndexNameError,
|
|
76
|
+
DataContractInvalidIndexDefinitionUpdateError,
|
|
77
|
+
DataContractHaveNewUniqueIndexError,
|
|
78
|
+
IdentityPublicKeyDisabledAtWindowViolationError,
|
|
79
|
+
IdentityPublicKeyIsReadOnlyError,
|
|
80
|
+
InvalidIdentityPublicKeyIdError,
|
|
81
|
+
InvalidIdentityRevisionError,
|
|
82
|
+
MaxIdentityPublicKeyLimitReachedError,
|
|
83
|
+
InvalidIdentityKeySignatureError,
|
|
84
|
+
InvalidSignaturePublicKeySecurityLevelError,
|
|
85
|
+
PublicKeyIsDisabledError,
|
|
86
|
+
PublicKeySecurityLevelNotMetError,
|
|
87
|
+
WrongPublicKeyPurposeError,
|
|
88
|
+
IdentityPublicKeyIsDisabledError,
|
|
89
|
+
} = dpp_module;
|
|
90
|
+
|
|
91
|
+
export function patchConsensusErrors() {
|
|
92
|
+
extend(ProtocolVersionParsingError, AbstractConsensusError);
|
|
93
|
+
extend(UnsupportedProtocolVersionError, AbstractConsensusError);
|
|
94
|
+
extend(IncompatibleProtocolVersionError, AbstractConsensusError);
|
|
95
|
+
extend(SerializedObjectParsingError, AbstractConsensusError);
|
|
96
|
+
extend(JsonSchemaError, AbstractConsensusError);
|
|
97
|
+
extend(InvalidIdentifierError, AbstractConsensusError);
|
|
98
|
+
extend(DataContractMaxDepthExceedError, AbstractConsensusError);
|
|
99
|
+
extend(DuplicateIndexError, AbstractConsensusError);
|
|
100
|
+
extend(InvalidCompoundIndexError, AbstractConsensusError);
|
|
101
|
+
extend(InvalidDataContractIdError, AbstractConsensusError);
|
|
102
|
+
extend(InvalidIndexedPropertyConstraintError, AbstractConsensusError);
|
|
103
|
+
extend(InvalidIndexPropertyTypeError, AbstractConsensusError);
|
|
104
|
+
extend(SystemPropertyIndexAlreadyPresentError, AbstractConsensusError);
|
|
105
|
+
extend(UndefinedIndexPropertyError, AbstractConsensusError);
|
|
106
|
+
extend(UniqueIndicesLimitReachedError, AbstractConsensusError);
|
|
107
|
+
extend(InconsistentCompoundIndexDataError, AbstractConsensusError);
|
|
108
|
+
extend(InvalidDocumentTransitionActionError, AbstractConsensusError);
|
|
109
|
+
extend(InvalidDocumentTransitionIdError, AbstractConsensusError);
|
|
110
|
+
extend(DataContractNotPresentError, AbstractConsensusError);
|
|
111
|
+
extend(InvalidDocumentTypeError, AbstractConsensusError);
|
|
112
|
+
extend(MissingDataContractIdError, AbstractConsensusError);
|
|
113
|
+
extend(MissingDocumentTransitionActionError, AbstractConsensusError);
|
|
114
|
+
extend(MissingDocumentTransitionTypeError, AbstractConsensusError);
|
|
115
|
+
extend(MissingDocumentTypeError, AbstractConsensusError);
|
|
116
|
+
extend(DuplicatedIdentityPublicKeyError, AbstractConsensusError);
|
|
117
|
+
extend(DuplicatedIdentityPublicKeyIdError, AbstractConsensusError);
|
|
118
|
+
extend(MissingMasterPublicKeyError, AbstractConsensusError);
|
|
119
|
+
extend(IdentityAssetLockProofLockedTransactionMismatchError, AbstractConsensusError);
|
|
120
|
+
extend(IdentityAssetLockTransactionIsNotFoundError, AbstractConsensusError);
|
|
121
|
+
extend(IdentityAssetLockTransactionOutPointAlreadyExistsError, AbstractConsensusError);
|
|
122
|
+
extend(IdentityAssetLockTransactionOutputNotFoundError, AbstractConsensusError);
|
|
123
|
+
extend(InvalidAssetLockProofCoreChainHeightError, AbstractConsensusError);
|
|
124
|
+
extend(InvalidAssetLockProofTransactionHeightError, AbstractConsensusError);
|
|
125
|
+
extend(InvalidIdentityAssetLockTransactionError, AbstractConsensusError);
|
|
126
|
+
extend(InvalidIdentityAssetLockTransactionOutputError, AbstractConsensusError);
|
|
127
|
+
extend(InvalidIdentityPublicKeyDataError, AbstractConsensusError);
|
|
128
|
+
extend(InvalidIdentityPublicKeySecurityLevelError, AbstractConsensusError);
|
|
129
|
+
extend(InvalidStateTransitionTypeError, AbstractConsensusError);
|
|
130
|
+
extend(MissingStateTransitionTypeError, AbstractConsensusError);
|
|
131
|
+
extend(StateTransitionMaxSizeExceededError, AbstractConsensusError);
|
|
132
|
+
extend(IdentityNotFoundError, AbstractConsensusError);
|
|
133
|
+
extend(InvalidIdentityPublicKeyTypeError, AbstractConsensusError);
|
|
134
|
+
extend(InvalidStateTransitionSignatureError, AbstractConsensusError);
|
|
135
|
+
extend(MissingPublicKeyError, AbstractConsensusError);
|
|
136
|
+
extend(BalanceIsNotEnoughError, AbstractConsensusError);
|
|
137
|
+
extend(DataContractAlreadyPresentError, AbstractConsensusError);
|
|
138
|
+
extend(DataTriggerConditionError, AbstractConsensusError);
|
|
139
|
+
extend(DataTriggerExecutionError, AbstractConsensusError);
|
|
140
|
+
extend(DataTriggerInvalidResultError, AbstractConsensusError);
|
|
141
|
+
extend(DocumentAlreadyPresentError, AbstractConsensusError);
|
|
142
|
+
extend(DocumentNotFoundError, AbstractConsensusError);
|
|
143
|
+
extend(DocumentOwnerIdMismatchError, AbstractConsensusError);
|
|
144
|
+
extend(DocumentTimestampsMismatchError, AbstractConsensusError);
|
|
145
|
+
extend(DocumentTimestampWindowViolationError, AbstractConsensusError);
|
|
146
|
+
extend(DuplicateUniqueIndexError, AbstractConsensusError);
|
|
147
|
+
extend(InvalidDocumentRevisionError, AbstractConsensusError);
|
|
148
|
+
extend(IdentityAlreadyExistsError, AbstractConsensusError);
|
|
149
|
+
extend(InvalidJsonSchemaRefError, AbstractConsensusError);
|
|
150
|
+
extend(JsonSchemaCompilationError, AbstractConsensusError);
|
|
151
|
+
extend(DuplicateDocumentTransitionsWithIdsError, AbstractConsensusError);
|
|
152
|
+
extend(DuplicateDocumentTransitionsWithIndicesError, AbstractConsensusError);
|
|
153
|
+
extend(InvalidAssetLockTransactionOutputReturnSizeError, AbstractConsensusError);
|
|
154
|
+
extend(InvalidInstantAssetLockProofError, AbstractConsensusError);
|
|
155
|
+
extend(InvalidInstantAssetLockProofSignatureError, AbstractConsensusError);
|
|
156
|
+
extend(IncompatibleRe2PatternError, AbstractConsensusError);
|
|
157
|
+
extend(InvalidDataContractVersionError, AbstractConsensusError);
|
|
158
|
+
extend(IncompatibleDataContractSchemaError, AbstractConsensusError);
|
|
159
|
+
extend(DataContractImmutablePropertiesUpdateError, AbstractConsensusError);
|
|
160
|
+
extend(DataContractUniqueIndicesChangedError, AbstractConsensusError);
|
|
161
|
+
extend(DuplicateIndexNameError, AbstractConsensusError);
|
|
162
|
+
extend(DataContractInvalidIndexDefinitionUpdateError, AbstractConsensusError);
|
|
163
|
+
extend(DataContractHaveNewUniqueIndexError, AbstractConsensusError);
|
|
164
|
+
extend(IdentityPublicKeyDisabledAtWindowViolationError, AbstractConsensusError);
|
|
165
|
+
extend(IdentityPublicKeyIsReadOnlyError, AbstractConsensusError);
|
|
166
|
+
extend(InvalidIdentityPublicKeyIdError, AbstractConsensusError);
|
|
167
|
+
extend(InvalidIdentityRevisionError, AbstractConsensusError);
|
|
168
|
+
extend(MaxIdentityPublicKeyLimitReachedError, AbstractConsensusError);
|
|
169
|
+
extend(InvalidIdentityKeySignatureError, AbstractConsensusError);
|
|
170
|
+
extend(InvalidSignaturePublicKeySecurityLevelError, AbstractConsensusError);
|
|
171
|
+
extend(PublicKeyIsDisabledError, AbstractConsensusError);
|
|
172
|
+
extend(PublicKeySecurityLevelNotMetError, AbstractConsensusError);
|
|
173
|
+
extend(WrongPublicKeyPurposeError, AbstractConsensusError);
|
|
174
|
+
extend(IdentityPublicKeyIsDisabledError, AbstractConsensusError);
|
|
175
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import init
|
|
1
|
+
import init from '../wasm/wasm_dpp';
|
|
2
|
+
import * as dpp_module from './dpp';
|
|
2
3
|
// @ts-ignore
|
|
3
|
-
import wasmBase from '
|
|
4
|
-
import patchIdentifier from "./
|
|
4
|
+
import wasmBase from '../wasm/wasm_dpp_bg.js';
|
|
5
|
+
import patchIdentifier from "./identifier/patchIdentifier";
|
|
5
6
|
|
|
6
7
|
let isInitialized = false;
|
|
7
8
|
|
|
@@ -12,12 +12,14 @@ const expectError = {
|
|
|
12
12
|
const wasmDpp = await loadWasmDpp();
|
|
13
13
|
if (!errorClass) {
|
|
14
14
|
// eslint-disable-next-line no-param-reassign
|
|
15
|
-
errorClass = wasmDpp.
|
|
15
|
+
errorClass = wasmDpp.AbstractConsensusError;
|
|
16
16
|
}
|
|
17
17
|
expect(result).to.be.an.instanceOf(wasmDpp.ValidationResult);
|
|
18
18
|
expect(result.getErrors()).to.have.lengthOf(count);
|
|
19
19
|
|
|
20
|
-
result.getErrors().forEach((error) =>
|
|
20
|
+
result.getErrors().forEach((error) => {
|
|
21
|
+
expect(error).to.be.an.instanceOf(errorClass);
|
|
22
|
+
});
|
|
21
23
|
},
|
|
22
24
|
|
|
23
25
|
/**
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/wasm-dpp",
|
|
3
|
-
"version": "0.24.0-dev.
|
|
3
|
+
"version": "0.24.0-dev.12",
|
|
4
4
|
"description": "The JavaScript implementation of the Dash Platform Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"types": "dist/lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "yarn exec scripts/build.sh && webpack",
|
|
9
9
|
"test": "yarn run test:node && yarn run test:browsers",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@apidevtools/json-schema-ref-parser": "^8.0.0",
|
|
37
37
|
"@dashevo/dashcore-lib": "~0.19.44",
|
|
38
|
-
"@dashevo/dpns-contract": "0.24.0-dev.
|
|
39
|
-
"@dashevo/dpp": "0.24.0-dev.
|
|
38
|
+
"@dashevo/dpns-contract": "0.24.0-dev.12",
|
|
39
|
+
"@dashevo/dpp": "0.24.0-dev.12",
|
|
40
40
|
"@dashevo/wasm-re2": "~1.0.2",
|
|
41
41
|
"@types/node": "^14.6.0",
|
|
42
42
|
"ajv": "^8.6.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"eslint-config-airbnb-base": "^14.2.1",
|
|
54
54
|
"eslint-plugin-import": "^2.24.2",
|
|
55
55
|
"events": "^3.3.0",
|
|
56
|
-
"fast-json-patch": "^3.1.
|
|
56
|
+
"fast-json-patch": "^3.1.1",
|
|
57
57
|
"https-browserify": "^1.0.0",
|
|
58
58
|
"json-schema-diff-validator": "^0.4.1",
|
|
59
59
|
"karma": "^6.4.1",
|
|
@@ -10,6 +10,7 @@ pub struct InvalidDataContractError {
|
|
|
10
10
|
|
|
11
11
|
#[wasm_bindgen(js_class=InvalidDataContractError)]
|
|
12
12
|
impl InvalidDataContractError {
|
|
13
|
+
#[wasm_bindgen(constructor)]
|
|
13
14
|
pub fn new(errors: Vec<JsValue>, raw_data_contract: JsValue) -> Self {
|
|
14
15
|
InvalidDataContractError {
|
|
15
16
|
errors,
|
|
@@ -26,4 +27,24 @@ impl InvalidDataContractError {
|
|
|
26
27
|
pub fn get_raw_data_contract(&self) -> JsValue {
|
|
27
28
|
self.raw_data_contract.clone()
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
#[wasm_bindgen(js_name=getMessage)]
|
|
32
|
+
pub fn get_message(&self) -> String {
|
|
33
|
+
let extended_message = if let Some(error_message) = self
|
|
34
|
+
.errors
|
|
35
|
+
.first()
|
|
36
|
+
.map(|e| Into::<js_sys::Error>::into(e.clone()).message())
|
|
37
|
+
{
|
|
38
|
+
let narrowed_message = if self.errors.len() > 1 {
|
|
39
|
+
format!(" and {} more", self.errors.len() - 1)
|
|
40
|
+
} else {
|
|
41
|
+
"".to_owned()
|
|
42
|
+
};
|
|
43
|
+
format!(": \"{error_message}\"{narrowed_message}")
|
|
44
|
+
} else {
|
|
45
|
+
"".to_owned()
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
format!("Data contract decode error{extended_message}")
|
|
49
|
+
}
|
|
29
50
|
}
|
|
@@ -29,9 +29,9 @@ impl From<DataContractCreateTransition> for DataContractCreateTransitionWasm {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
impl
|
|
33
|
-
fn
|
|
34
|
-
|
|
32
|
+
impl From<DataContractCreateTransitionWasm> for DataContractCreateTransition {
|
|
33
|
+
fn from(val: DataContractCreateTransitionWasm) -> Self {
|
|
34
|
+
val.0
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -69,7 +69,7 @@ impl DataContractCreateTransitionWasm {
|
|
|
69
69
|
|
|
70
70
|
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
71
71
|
pub fn get_protocol_version(&self) -> u32 {
|
|
72
|
-
self.0.protocol_version
|
|
72
|
+
self.0.protocol_version
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
#[wasm_bindgen(js_name=getEntropy)]
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
use dpp::data_contract::state_transition::data_contract_create_transition::validation::state::validate_data_contract_create_transition_state::validate_data_contract_create_transition_state as dpp_validate_data_contract_create_transition_state;
|
|
2
2
|
use wasm_bindgen::prelude::*;
|
|
3
3
|
|
|
4
|
+
use crate::validation::ValidationResultWasm;
|
|
4
5
|
use crate::{
|
|
5
6
|
errors::from_dpp_err,
|
|
6
7
|
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
7
|
-
validation_result::ValidationResultWasm,
|
|
8
8
|
DataContractCreateTransitionWasm,
|
|
9
9
|
};
|
|
10
10
|
|
|
@@ -19,6 +19,6 @@ pub async fn validate_data_contract_create_transition_state(
|
|
|
19
19
|
&state_transition.into(),
|
|
20
20
|
)
|
|
21
21
|
.await
|
|
22
|
-
.map(Into
|
|
22
|
+
.map(Into::<ValidationResultWasm>::into)
|
|
23
23
|
.map_err(from_dpp_err)
|
|
24
24
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
use std::ops::Deref;
|
|
2
|
+
|
|
3
|
+
use dpp::data_contract::state_transition::apply_data_contract_update_transition_factory::ApplyDataContractUpdateTransition;
|
|
4
|
+
use wasm_bindgen::prelude::*;
|
|
5
|
+
|
|
6
|
+
use crate::{
|
|
7
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
8
|
+
DataContractUpdateTransitionWasm,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
#[wasm_bindgen(js_name=ApplyDataContractUpdateTransition)]
|
|
12
|
+
pub struct ApplyDataContractUpdateTransitionWasm(
|
|
13
|
+
ApplyDataContractUpdateTransition<ExternalStateRepositoryLikeWrapper>,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
impl From<ApplyDataContractUpdateTransition<ExternalStateRepositoryLikeWrapper>>
|
|
17
|
+
for ApplyDataContractUpdateTransitionWasm
|
|
18
|
+
{
|
|
19
|
+
fn from(wa: ApplyDataContractUpdateTransition<ExternalStateRepositoryLikeWrapper>) -> Self {
|
|
20
|
+
ApplyDataContractUpdateTransitionWasm(wa)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#[wasm_bindgen(js_class=ApplyDataContractUpdateTransition)]
|
|
25
|
+
impl ApplyDataContractUpdateTransitionWasm {
|
|
26
|
+
#[wasm_bindgen(constructor)]
|
|
27
|
+
pub fn new(
|
|
28
|
+
state_repository: ExternalStateRepositoryLike,
|
|
29
|
+
) -> ApplyDataContractUpdateTransitionWasm {
|
|
30
|
+
let pinned_js_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
|
|
31
|
+
ApplyDataContractUpdateTransition::new(pinned_js_state_repository).into()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[wasm_bindgen(js_name=applyDataContractUpdateTransition)]
|
|
35
|
+
pub async fn apply_data_contract_update_transition(
|
|
36
|
+
&self,
|
|
37
|
+
transition: DataContractUpdateTransitionWasm,
|
|
38
|
+
) -> Result<(), JsError> {
|
|
39
|
+
self.0
|
|
40
|
+
.apply_data_contract_update_transition(&transition.into())
|
|
41
|
+
.await
|
|
42
|
+
.map_err(|e| e.deref().into())
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
mod apply;
|
|
2
|
+
mod validation;
|
|
3
|
+
|
|
4
|
+
pub use apply::*;
|
|
5
|
+
pub use validation::*;
|
|
6
|
+
|
|
7
|
+
use dpp::{
|
|
8
|
+
data_contract::state_transition::DataContractUpdateTransition,
|
|
9
|
+
state_transition::{
|
|
10
|
+
StateTransitionConvert, StateTransitionIdentitySigned, StateTransitionLike,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
use serde::{Deserialize, Serialize};
|
|
14
|
+
use wasm_bindgen::prelude::*;
|
|
15
|
+
|
|
16
|
+
use crate::{
|
|
17
|
+
buffer::Buffer,
|
|
18
|
+
errors::{from_dpp_err, RustConversionError},
|
|
19
|
+
identifier::IdentifierWrapper,
|
|
20
|
+
with_js_error, DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
#[wasm_bindgen(js_name=DataContractUpdateTransition)]
|
|
24
|
+
pub struct DataContractUpdateTransitionWasm(DataContractUpdateTransition);
|
|
25
|
+
|
|
26
|
+
impl From<DataContractUpdateTransition> for DataContractUpdateTransitionWasm {
|
|
27
|
+
fn from(v: DataContractUpdateTransition) -> Self {
|
|
28
|
+
DataContractUpdateTransitionWasm(v)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl From<DataContractUpdateTransitionWasm> for DataContractUpdateTransition {
|
|
33
|
+
fn from(val: DataContractUpdateTransitionWasm) -> Self {
|
|
34
|
+
val.0
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[derive(Debug, Serialize, Deserialize)]
|
|
39
|
+
#[serde(rename_all = "camelCase")]
|
|
40
|
+
struct DataContractUpdateTransitionParameters {
|
|
41
|
+
protocol_version: u32,
|
|
42
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
43
|
+
data_contract: Option<DataContractParameters>,
|
|
44
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
45
|
+
entropy: Option<Vec<u8>>,
|
|
46
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
47
|
+
signature_public_key_id: Option<u64>,
|
|
48
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
49
|
+
signature: Option<Vec<u8>>,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[wasm_bindgen(js_class=DataContractUpdateTransition)]
|
|
53
|
+
impl DataContractUpdateTransitionWasm {
|
|
54
|
+
#[wasm_bindgen(constructor)]
|
|
55
|
+
pub fn new(raw_parameters: JsValue) -> Result<DataContractUpdateTransitionWasm, JsValue> {
|
|
56
|
+
let parameters: DataContractUpdateTransitionParameters =
|
|
57
|
+
with_js_error!(serde_wasm_bindgen::from_value(raw_parameters))?;
|
|
58
|
+
DataContractUpdateTransition::from_raw_object(
|
|
59
|
+
serde_json::to_value(parameters).expect("the struct will be a valid json"),
|
|
60
|
+
)
|
|
61
|
+
.map(Into::into)
|
|
62
|
+
.map_err(from_dpp_err)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[wasm_bindgen(js_name=getDataContract)]
|
|
66
|
+
pub fn get_data_contract(&self) -> DataContractWasm {
|
|
67
|
+
self.0.data_contract.clone().into()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
71
|
+
pub fn get_protocol_version(&self) -> u32 {
|
|
72
|
+
self.0.protocol_version
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[wasm_bindgen(js_name=getEntropy)]
|
|
76
|
+
pub fn get_entropy(&self) -> Buffer {
|
|
77
|
+
Buffer::from_bytes(&self.0.data_contract.entropy)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#[wasm_bindgen(js_name=getOwnerId)]
|
|
81
|
+
pub fn get_owner_id(&self) -> IdentifierWrapper {
|
|
82
|
+
self.0.get_owner_id().clone().into()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#[wasm_bindgen(js_name=getType)]
|
|
86
|
+
pub fn get_type(&self) -> u32 {
|
|
87
|
+
self.0.get_type() as u32
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
91
|
+
pub fn to_json(&self, skip_signature: Option<bool>) -> Result<JsValue, JsValue> {
|
|
92
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
93
|
+
Ok(self
|
|
94
|
+
.0
|
|
95
|
+
.to_json(skip_signature.unwrap_or(false))
|
|
96
|
+
.map_err(from_dpp_err)?
|
|
97
|
+
.serialize(&serializer)
|
|
98
|
+
.expect("JSON is a valid object"))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#[wasm_bindgen(js_name=toBuffer)]
|
|
102
|
+
pub fn to_buffer(&self, skip_signature: Option<bool>) -> Result<Buffer, JsValue> {
|
|
103
|
+
let bytes = self
|
|
104
|
+
.0
|
|
105
|
+
.to_buffer(skip_signature.unwrap_or(false))
|
|
106
|
+
.map_err(from_dpp_err)?;
|
|
107
|
+
Ok(Buffer::from_bytes(&bytes))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[wasm_bindgen(js_name=getModifiedDataIds)]
|
|
111
|
+
pub fn get_modified_data_ids(&self) -> Vec<JsValue> {
|
|
112
|
+
self.0
|
|
113
|
+
.get_modified_data_ids()
|
|
114
|
+
.into_iter()
|
|
115
|
+
.map(|identifier| Into::<IdentifierWrapper>::into(identifier.clone()).into())
|
|
116
|
+
.collect()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[wasm_bindgen(js_name=isDataContractStateTransition)]
|
|
120
|
+
pub fn is_data_contract_state_transition(&self) -> bool {
|
|
121
|
+
self.0.is_data_contract_state_transition()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name=isDocumentStateTransition)]
|
|
125
|
+
pub fn is_document_state_transition(&self) -> bool {
|
|
126
|
+
self.0.is_document_state_transition()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(js_name=isIdentityStateTransition)]
|
|
130
|
+
pub fn is_identity_state_transition(&self) -> bool {
|
|
131
|
+
self.0.is_identity_state_transition()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name=setExecutionContext)]
|
|
135
|
+
pub fn set_execution_context(&mut self, context: &StateTransitionExecutionContextWasm) {
|
|
136
|
+
self.0.set_execution_context(context.into())
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[wasm_bindgen(js_name=hash)]
|
|
140
|
+
pub fn hash(&self, skip_signature: Option<bool>) -> Result<Buffer, JsValue> {
|
|
141
|
+
let bytes = self
|
|
142
|
+
.0
|
|
143
|
+
.hash(skip_signature.unwrap_or(false))
|
|
144
|
+
.map_err(from_dpp_err)?;
|
|
145
|
+
Ok(Buffer::from_bytes(&bytes))
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
use std::collections::BTreeMap;
|
|
2
|
+
|
|
3
|
+
use dpp::data_contract::state_transition::data_contract_update_transition::validation::{
|
|
4
|
+
basic::validate_indices_are_backward_compatible as dpp_validate_indices_are_backward_compatible,
|
|
5
|
+
state::validate_data_contract_update_transition_state::validate_data_contract_update_transition_state as dpp_validate_data_contract_update_transition_state,
|
|
6
|
+
};
|
|
7
|
+
use wasm_bindgen::prelude::*;
|
|
8
|
+
|
|
9
|
+
use crate::{
|
|
10
|
+
errors::{from_dpp_err, protocol_error::from_protocol_error},
|
|
11
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
12
|
+
validation::ValidationResultWasm,
|
|
13
|
+
DataContractUpdateTransitionWasm,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
#[wasm_bindgen(js_name=validateDataContractUpdateTransitionState)]
|
|
17
|
+
pub async fn validate_data_contract_update_transition_state(
|
|
18
|
+
state_repository: ExternalStateRepositoryLike,
|
|
19
|
+
state_transition: DataContractUpdateTransitionWasm,
|
|
20
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
21
|
+
let wrapped_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
|
|
22
|
+
dpp_validate_data_contract_update_transition_state(
|
|
23
|
+
&wrapped_state_repository,
|
|
24
|
+
&state_transition.into(),
|
|
25
|
+
)
|
|
26
|
+
.await
|
|
27
|
+
.map(Into::into)
|
|
28
|
+
.map_err(from_dpp_err)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#[wasm_bindgen(js_name=validateIndicesAreBackwardCompatible)]
|
|
32
|
+
pub fn validate_indices_are_backward_compatible(
|
|
33
|
+
old_documents_schema: JsValue,
|
|
34
|
+
new_documents_schema: JsValue,
|
|
35
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
36
|
+
let old_documents = serde_wasm_bindgen::from_value::<BTreeMap<String, serde_json::Value>>(
|
|
37
|
+
old_documents_schema,
|
|
38
|
+
)?;
|
|
39
|
+
let new_documents = serde_wasm_bindgen::from_value::<BTreeMap<String, serde_json::Value>>(
|
|
40
|
+
new_documents_schema,
|
|
41
|
+
)?;
|
|
42
|
+
|
|
43
|
+
dpp_validate_indices_are_backward_compatible(old_documents.iter(), new_documents.iter())
|
|
44
|
+
.map(Into::into)
|
|
45
|
+
.map_err(from_protocol_error)
|
|
46
|
+
}
|