@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');
|
|
2
|
+
|
|
3
|
+
const { default: loadWasmDpp } = require('../../../../dist');
|
|
4
|
+
|
|
5
|
+
describe('validateDataContractPatterns', () => {
|
|
6
|
+
let DataContractValidator;
|
|
7
|
+
let IncompatibleRe2PatternError;
|
|
8
|
+
|
|
9
|
+
before(async () => {
|
|
10
|
+
({
|
|
11
|
+
DataContractValidator,
|
|
12
|
+
IncompatibleRe2PatternError,
|
|
13
|
+
} = await loadWasmDpp());
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return valid result', () => {
|
|
17
|
+
const rawDataContract = getDataContractFixture().toObject();
|
|
18
|
+
delete rawDataContract.$defs;
|
|
19
|
+
|
|
20
|
+
const schema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
foo: { type: 'integer' },
|
|
24
|
+
bar: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
pattern: '([a-z]+)+$',
|
|
27
|
+
maxLength: 1337,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ['foo'],
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
rawDataContract.documents.totallyFineDocument = schema;
|
|
35
|
+
|
|
36
|
+
const validator = new DataContractValidator();
|
|
37
|
+
|
|
38
|
+
const result = validator.validate(rawDataContract);
|
|
39
|
+
expect(result.isValid()).to.be.true();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return invalid result on incompatible pattern', () => {
|
|
43
|
+
const rawDataContract = getDataContractFixture().toObject();
|
|
44
|
+
delete rawDataContract.$defs;
|
|
45
|
+
|
|
46
|
+
const schema = {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
foo: { type: 'integer' },
|
|
50
|
+
bar: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
pattern: '^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$',
|
|
53
|
+
maxLength: 1337,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
required: ['foo'],
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
rawDataContract.documents.notFineDocument = schema;
|
|
61
|
+
|
|
62
|
+
const validator = new DataContractValidator();
|
|
63
|
+
|
|
64
|
+
const result = validator.validate(rawDataContract);
|
|
65
|
+
|
|
66
|
+
const [error] = result.getErrors();
|
|
67
|
+
|
|
68
|
+
expect(error).to.be.instanceOf(IncompatibleRe2PatternError);
|
|
69
|
+
expect(error.getCode()).to.equal(1009);
|
|
70
|
+
expect(error.getPattern()).to.equal('^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$');
|
|
71
|
+
expect(error.getPath()).to.equal('/documents/notFineDocument/properties/bar');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -66,7 +66,7 @@ describe('applyDocumentsBatchTransitionFactory', () => {
|
|
|
66
66
|
|
|
67
67
|
stateRepositoryMock = createStateRepositoryMock(this.sinonSandbox);
|
|
68
68
|
stateRepositoryMock.fetchDataContract.resolves(dataContract);
|
|
69
|
-
stateRepositoryMock.fetchLatestPlatformBlockTime.
|
|
69
|
+
stateRepositoryMock.fetchLatestPlatformBlockTime.resolves(blockTimeMs);
|
|
70
70
|
|
|
71
71
|
fetchDocumentsMock = this.sinonSandbox.stub();
|
|
72
72
|
fetchDocumentsMock.resolves([
|
|
@@ -68,7 +68,7 @@ describe('validateDocumentsBatchTransitionStateFactory', () => {
|
|
|
68
68
|
|
|
69
69
|
blockTime = Date.now();
|
|
70
70
|
|
|
71
|
-
stateRepositoryMock.fetchLatestPlatformBlockTime.
|
|
71
|
+
stateRepositoryMock.fetchLatestPlatformBlockTime.resolves(blockTime);
|
|
72
72
|
|
|
73
73
|
fetchDocumentsMock = this.sinonSandbox.stub().resolves([]);
|
|
74
74
|
|
|
@@ -4,24 +4,18 @@ describe('IdentityPublicKey', () => {
|
|
|
4
4
|
let rawPublicKey;
|
|
5
5
|
let publicKey;
|
|
6
6
|
let IdentityPublicKey;
|
|
7
|
-
let KeyPurpose;
|
|
8
|
-
let KeyType;
|
|
9
|
-
let KeySecurityLevel;
|
|
10
7
|
|
|
11
8
|
beforeEach(async () => {
|
|
12
|
-
({
|
|
13
|
-
IdentityPublicKey, KeyPurpose, KeyType, KeySecurityLevel,
|
|
14
|
-
} = await loadWasmDpp());
|
|
9
|
+
({ IdentityPublicKey } = await loadWasmDpp());
|
|
15
10
|
|
|
16
11
|
rawPublicKey = {
|
|
17
12
|
id: 0,
|
|
18
|
-
type:
|
|
13
|
+
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
|
|
19
14
|
data: Buffer.from('AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH', 'base64'),
|
|
20
|
-
purpose:
|
|
21
|
-
securityLevel:
|
|
15
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
16
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
22
17
|
readOnly: false,
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
publicKey = new IdentityPublicKey(rawPublicKey);
|
|
26
20
|
});
|
|
27
21
|
|
|
@@ -89,9 +83,9 @@ describe('IdentityPublicKey', () => {
|
|
|
89
83
|
|
|
90
84
|
describe('#setPurpose', () => {
|
|
91
85
|
it('should set data', () => {
|
|
92
|
-
publicKey.setPurpose(
|
|
86
|
+
publicKey.setPurpose(IdentityPublicKey.PURPOSES.DECRYPTION);
|
|
93
87
|
|
|
94
|
-
expect(publicKey.getPurpose()).to.equal(
|
|
88
|
+
expect(publicKey.getPurpose()).to.equal(IdentityPublicKey.PURPOSES.DECRYPTION);
|
|
95
89
|
});
|
|
96
90
|
});
|
|
97
91
|
|
|
@@ -103,9 +97,9 @@ describe('IdentityPublicKey', () => {
|
|
|
103
97
|
|
|
104
98
|
describe('#setSecurityLevel', () => {
|
|
105
99
|
it('should set data', () => {
|
|
106
|
-
publicKey.setSecurityLevel(
|
|
100
|
+
publicKey.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.MEDIUM);
|
|
107
101
|
|
|
108
|
-
expect(publicKey.getSecurityLevel()).to.equal(
|
|
102
|
+
expect(publicKey.getSecurityLevel()).to.equal(IdentityPublicKey.SECURITY_LEVELS.MEDIUM);
|
|
109
103
|
});
|
|
110
104
|
});
|
|
111
105
|
|
|
@@ -151,10 +145,10 @@ describe('IdentityPublicKey', () => {
|
|
|
151
145
|
it('should return data in case ECDSA_HASH160', () => {
|
|
152
146
|
rawPublicKey = {
|
|
153
147
|
id: 0,
|
|
154
|
-
type:
|
|
148
|
+
type: IdentityPublicKey.TYPES.ECDSA_HASH160,
|
|
155
149
|
data: Buffer.from('AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH', 'base64'),
|
|
156
|
-
purpose:
|
|
157
|
-
securityLevel:
|
|
150
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
151
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
158
152
|
readOnly: false,
|
|
159
153
|
disabledAt: 123,
|
|
160
154
|
};
|
|
@@ -171,10 +165,10 @@ describe('IdentityPublicKey', () => {
|
|
|
171
165
|
it('should return original public key hash in case BLS12_381', () => {
|
|
172
166
|
rawPublicKey = {
|
|
173
167
|
id: 0,
|
|
174
|
-
type:
|
|
168
|
+
type: IdentityPublicKey.TYPES.BLS12_381,
|
|
175
169
|
data: Buffer.from('01fac99ca2c8f39c286717c213e190aba4b7af76db320ec43f479b7d9a2012313a0ae59ca576edf801444bc694686694', 'hex'),
|
|
176
|
-
purpose:
|
|
177
|
-
securityLevel:
|
|
170
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
171
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
178
172
|
readOnly: false,
|
|
179
173
|
disabledAt: 123,
|
|
180
174
|
};
|
|
@@ -191,10 +185,10 @@ describe('IdentityPublicKey', () => {
|
|
|
191
185
|
it('should return data in case BIP13_SCRIPT_HASH', () => {
|
|
192
186
|
rawPublicKey = {
|
|
193
187
|
id: 0,
|
|
194
|
-
type:
|
|
188
|
+
type: IdentityPublicKey.TYPES.BIP13_SCRIPT_HASH,
|
|
195
189
|
data: Buffer.from('54c557e07dde5bb6cb791c7a540e0a4796f5e97e', 'hex'),
|
|
196
|
-
purpose:
|
|
197
|
-
securityLevel:
|
|
190
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
191
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
198
192
|
readOnly: false,
|
|
199
193
|
disabledAt: 123,
|
|
200
194
|
};
|
|
@@ -215,10 +209,10 @@ describe('IdentityPublicKey', () => {
|
|
|
215
209
|
|
|
216
210
|
expect(jsonPublicKey).to.deep.equal({
|
|
217
211
|
id: 0,
|
|
218
|
-
type:
|
|
212
|
+
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
|
|
219
213
|
data: 'AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH',
|
|
220
|
-
purpose:
|
|
221
|
-
securityLevel:
|
|
214
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
215
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
222
216
|
readOnly: false,
|
|
223
217
|
});
|
|
224
218
|
});
|
|
@@ -230,10 +224,10 @@ describe('IdentityPublicKey', () => {
|
|
|
230
224
|
|
|
231
225
|
expect(jsonPublicKey).to.deep.equal({
|
|
232
226
|
id: 0,
|
|
233
|
-
type:
|
|
227
|
+
type: IdentityPublicKey.TYPES.ECDSA_SECP256K1,
|
|
234
228
|
data: 'AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH',
|
|
235
|
-
purpose:
|
|
236
|
-
securityLevel:
|
|
229
|
+
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
|
|
230
|
+
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
|
|
237
231
|
readOnly: false,
|
|
238
232
|
disabledAt: 42,
|
|
239
233
|
});
|
|
@@ -242,7 +236,7 @@ describe('IdentityPublicKey', () => {
|
|
|
242
236
|
|
|
243
237
|
describe('#isMaster', () => {
|
|
244
238
|
it('should return true when public key has MASTER security level', () => {
|
|
245
|
-
publicKey.setSecurityLevel(
|
|
239
|
+
publicKey.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.MASTER);
|
|
246
240
|
|
|
247
241
|
const result = publicKey.isMaster();
|
|
248
242
|
|
|
@@ -250,7 +244,7 @@ describe('IdentityPublicKey', () => {
|
|
|
250
244
|
});
|
|
251
245
|
|
|
252
246
|
it('should return false when public key doesn\'t have MASTER security level', () => {
|
|
253
|
-
publicKey.setSecurityLevel(
|
|
247
|
+
publicKey.setSecurityLevel(IdentityPublicKey.SECURITY_LEVELS.HIGH);
|
|
254
248
|
|
|
255
249
|
const result = publicKey.isMaster();
|
|
256
250
|
|