@dashevo/wasm-dpp 0.23.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/.babelrc +5 -0
- package/.editorconfig +13 -0
- package/.eslintignore +1 -0
- package/.eslintrc +15 -0
- package/.mocharc.yml +4 -0
- package/CHANGELOG.md +397 -0
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/karma.conf.js +53 -0
- package/package.json +107 -0
- package/test/.eslintrc +12 -0
- package/test/integration/DashPlatformProtocol.spec.js +53 -0
- package/test/integration/ajv/keywords/byteArray/addByteArrayKeyword.spec.js +148 -0
- package/test/integration/dataContract/DataContractFacade.spec.js +84 -0
- package/test/integration/dataContract/stateTransition/DataContractCreateTransition/validation/basic/validateDataContractCreateTransitionBasicFactory.spec.js +357 -0
- package/test/integration/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateDataContractUpdateTransitionBasicFactory.spec.js +444 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +2191 -0
- package/test/integration/document/Document.spec.js +90 -0
- package/test/integration/document/DocumentFacade.spec.js +155 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +83 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +1146 -0
- package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +294 -0
- package/test/integration/document/validation/validateDocumentFactory.spec.js +447 -0
- package/test/integration/error/consensus/createConsensusError.spec.js +21 -0
- package/test/integration/identity/IdentityFacade.spec.js +187 -0
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +422 -0
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +361 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/basic/validateIdentityUpdateTransitionBasicFactory.spec.js +595 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +299 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validatePublicKeysState.spec.js +66 -0
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +415 -0
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +134 -0
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +401 -0
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +205 -0
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +127 -0
- package/test/integration/identity/validation/validateIdentityFactory.spec.js +370 -0
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +497 -0
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +507 -0
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +418 -0
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +35 -0
- package/test/integration/util/generateEntropy.spec.js +17 -0
- package/test/integration/util/serializer.spec.js +24 -0
- package/test/unit/DashPlatformProtocol.spec.js +79 -0
- package/test/unit/Identifier.spec.js +123 -0
- package/test/unit/Metadata.spec.js +37 -0
- package/test/unit/dataContract/DataContract.spec.js +407 -0
- package/test/unit/dataContract/DataContractFactory.spec.js +178 -0
- package/test/unit/dataContract/createDataContract.spec.js +57 -0
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +46 -0
- package/test/unit/dataContract/generateDataContractId.spec.js +19 -0
- package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +103 -0
- package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +84 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +160 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +48 -0
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +85 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +158 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +47 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +121 -0
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +111 -0
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +93 -0
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +64 -0
- package/test/unit/dataTrigger/DataTrigger.spec.js +132 -0
- package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +29 -0
- package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +109 -0
- package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +382 -0
- package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +101 -0
- package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +113 -0
- package/test/unit/dataTrigger/rejectDataTrigger.spec.js +51 -0
- package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +200 -0
- package/test/unit/decodeProtocolEntityFactory.spec.js +75 -0
- package/test/unit/document/Document.spec.js +444 -0
- package/test/unit/document/DocumentFactory.spec.js +376 -0
- package/test/unit/document/errors/InvalidDocumentError.spec.js +46 -0
- package/test/unit/document/fetchAndValidateDataContractFactory.spec.js +66 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +168 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +171 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/documentTransition/DocumentCreateTransition.spec.js +25 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesById.spec.js +31 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +122 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +75 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +128 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +811 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +279 -0
- package/test/unit/errors/consensus/codes.spec.js +102 -0
- package/test/unit/identity/Identity.spec.js +243 -0
- package/test/unit/identity/IdentityFactory.spec.js +274 -0
- package/test/unit/identity/IdentityPublicKey.spec.js +273 -0
- package/test/unit/identity/creditsConverter.spec.js +34 -0
- package/test/unit/identity/errors/InvalidIdentityError.spec.js +46 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +184 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +90 -0
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +71 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +137 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +108 -0
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +22 -0
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/IdentityUpdateTransition.spec.js +219 -0
- package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +149 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +21 -0
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +36 -0
- package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +47 -0
- package/test/unit/stateTransition/StateTransitionFactory.spec.js +160 -0
- package/test/unit/stateTransition/createStateTransitionFactory.spec.js +72 -0
- package/test/unit/stateTransition/errors/InvalidStateTransitionError.spec.js +51 -0
- package/test/unit/stateTransition/validation/validateStateTransitionBasicFactory.spec.js +138 -0
- package/test/unit/stateTransition/validation/validateStateTransitionFeeFactory.spec.js +372 -0
- package/test/unit/stateTransition/validation/validateStateTransitionIdentitySignatureFactory.spec.js +339 -0
- package/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +86 -0
- package/test/unit/stateTransition/validation/validateStateTransitionStateFactory.spec.js +89 -0
- package/test/unit/version/validateProtocolVersionFactory.spec.js +80 -0
- package/webpack.config.js +49 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
const { getRE2Class } = require('@dashevo/wasm-re2');
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
const createAjv = require('../../../../lib/ajv/createAjv');
|
|
6
|
+
|
|
7
|
+
const JsonSchemaValidator = require(
|
|
8
|
+
'../../../../lib/validation/JsonSchemaValidator',
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const validatePublicKeysFactory = require(
|
|
12
|
+
'../../../../lib/identity/validation/validatePublicKeysFactory',
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const getIdentityFixture = require('../../../../lib/test/fixtures/getIdentityFixture');
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
expectValidationError,
|
|
19
|
+
expectJsonSchemaError,
|
|
20
|
+
} = require('../../../../lib/test/expect/expectError');
|
|
21
|
+
|
|
22
|
+
const DuplicatedIdentityPublicKeyError = require(
|
|
23
|
+
'../../../../lib/errors/consensus/basic/identity/DuplicatedIdentityPublicKeyError',
|
|
24
|
+
);
|
|
25
|
+
const DuplicatedIdentityPublicKeyIdError = require(
|
|
26
|
+
'../../../../lib/errors/consensus/basic/identity/DuplicatedIdentityPublicKeyIdError',
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const InvalidIdentityPublicKeyDataError = require(
|
|
30
|
+
'../../../../lib/errors/consensus/basic/identity/InvalidIdentityPublicKeyDataError',
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const InvalidIdentityPublicKeySecurityLevelError = require(
|
|
34
|
+
'../../../../lib/errors/consensus/basic/identity/InvalidIdentityPublicKeySecurityLevelError',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const IdentityPublicKey = require(
|
|
38
|
+
'../../../../lib/identity/IdentityPublicKey',
|
|
39
|
+
);
|
|
40
|
+
const BlsSignatures = require('../../../../lib/bls/bls');
|
|
41
|
+
|
|
42
|
+
const identityPublicKeySchema = require('../../../../schema/identity/publicKey.json');
|
|
43
|
+
const stateTransitionPublicKeySchema = require('../../../../schema/identity/stateTransition/publicKey.json');
|
|
44
|
+
|
|
45
|
+
describe('validatePublicKeysFactory', () => {
|
|
46
|
+
let rawPublicKeys;
|
|
47
|
+
let validatePublicKeys;
|
|
48
|
+
let validator;
|
|
49
|
+
let bls;
|
|
50
|
+
|
|
51
|
+
beforeEach(async () => {
|
|
52
|
+
({ publicKeys: rawPublicKeys } = getIdentityFixture().toObject());
|
|
53
|
+
|
|
54
|
+
const RE2 = await getRE2Class();
|
|
55
|
+
const ajv = createAjv(RE2);
|
|
56
|
+
bls = await BlsSignatures.getInstance();
|
|
57
|
+
|
|
58
|
+
validator = new JsonSchemaValidator(ajv);
|
|
59
|
+
|
|
60
|
+
validatePublicKeys = validatePublicKeysFactory(
|
|
61
|
+
validator,
|
|
62
|
+
identityPublicKeySchema,
|
|
63
|
+
bls,
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('id', () => {
|
|
68
|
+
it('should be present', () => {
|
|
69
|
+
delete rawPublicKeys[1].id;
|
|
70
|
+
|
|
71
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
72
|
+
|
|
73
|
+
expectJsonSchemaError(result);
|
|
74
|
+
|
|
75
|
+
const [error] = result.getErrors();
|
|
76
|
+
|
|
77
|
+
expect(error.getInstancePath()).to.equal('');
|
|
78
|
+
expect(error.getKeyword()).to.equal('required');
|
|
79
|
+
expect(error.getParams().missingProperty).to.equal('id');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should be a number', () => {
|
|
83
|
+
rawPublicKeys[1].id = 'string';
|
|
84
|
+
|
|
85
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
86
|
+
|
|
87
|
+
expectJsonSchemaError(result);
|
|
88
|
+
|
|
89
|
+
const [error] = result.getErrors();
|
|
90
|
+
|
|
91
|
+
expect(error.getInstancePath()).to.equal('/id');
|
|
92
|
+
expect(error.getKeyword()).to.equal('type');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should be an integer', () => {
|
|
96
|
+
rawPublicKeys[1].id = 1.1;
|
|
97
|
+
|
|
98
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
99
|
+
|
|
100
|
+
expectJsonSchemaError(result);
|
|
101
|
+
|
|
102
|
+
const [error] = result.getErrors();
|
|
103
|
+
|
|
104
|
+
expect(error.getInstancePath()).to.equal('/id');
|
|
105
|
+
expect(error.getKeyword()).to.equal('type');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should be greater or equal to one', () => {
|
|
109
|
+
rawPublicKeys[1].id = -1;
|
|
110
|
+
|
|
111
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
112
|
+
|
|
113
|
+
expectJsonSchemaError(result);
|
|
114
|
+
|
|
115
|
+
const [error] = result.getErrors();
|
|
116
|
+
|
|
117
|
+
expect(error.getInstancePath()).to.equal('/id');
|
|
118
|
+
expect(error.getKeyword()).to.equal('minimum');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('type', () => {
|
|
123
|
+
it('should be present', () => {
|
|
124
|
+
delete rawPublicKeys[1].type;
|
|
125
|
+
|
|
126
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
127
|
+
|
|
128
|
+
expectJsonSchemaError(result);
|
|
129
|
+
|
|
130
|
+
const [error] = result.getErrors();
|
|
131
|
+
|
|
132
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
133
|
+
expect(error.getKeyword()).to.equal('minItems');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should be a number', () => {
|
|
137
|
+
rawPublicKeys[1].type = 'string';
|
|
138
|
+
|
|
139
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
140
|
+
|
|
141
|
+
expectJsonSchemaError(result);
|
|
142
|
+
|
|
143
|
+
const [error] = result.getErrors();
|
|
144
|
+
|
|
145
|
+
expect(error.getInstancePath()).to.equal('/type');
|
|
146
|
+
expect(error.getKeyword()).to.equal('type');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('data', () => {
|
|
151
|
+
it('should be present', () => {
|
|
152
|
+
delete rawPublicKeys[1].data;
|
|
153
|
+
|
|
154
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
155
|
+
|
|
156
|
+
expectJsonSchemaError(result);
|
|
157
|
+
|
|
158
|
+
const [error] = result.getErrors();
|
|
159
|
+
|
|
160
|
+
expect(error.getInstancePath()).to.equal('');
|
|
161
|
+
expect(error.getKeyword()).to.equal('required');
|
|
162
|
+
expect(error.getParams().missingProperty).to.equal('data');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should be a byte array', () => {
|
|
166
|
+
rawPublicKeys[1].data = new Array(33).fill('string');
|
|
167
|
+
|
|
168
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
169
|
+
|
|
170
|
+
expectJsonSchemaError(result, 2);
|
|
171
|
+
|
|
172
|
+
const [error, byteArrayError] = result.getErrors();
|
|
173
|
+
|
|
174
|
+
expect(error.getInstancePath()).to.equal('/data/0');
|
|
175
|
+
expect(error.getKeyword()).to.equal('type');
|
|
176
|
+
|
|
177
|
+
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('ECDSA_SECP256K1', () => {
|
|
181
|
+
it('should be no less than 33 bytes', () => {
|
|
182
|
+
rawPublicKeys[1].data = Buffer.alloc(32);
|
|
183
|
+
|
|
184
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
185
|
+
|
|
186
|
+
expectJsonSchemaError(result);
|
|
187
|
+
|
|
188
|
+
const [error] = result.getErrors();
|
|
189
|
+
|
|
190
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
191
|
+
expect(error.getKeyword()).to.equal('minItems');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should be no longer than 33 bytes', () => {
|
|
195
|
+
rawPublicKeys[1].data = Buffer.alloc(34);
|
|
196
|
+
|
|
197
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
198
|
+
|
|
199
|
+
expectJsonSchemaError(result);
|
|
200
|
+
|
|
201
|
+
const [error] = result.getErrors();
|
|
202
|
+
|
|
203
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
204
|
+
expect(error.getKeyword()).to.equal('maxItems');
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('BLS12_381', () => {
|
|
209
|
+
it('should be no less than 48 bytes', () => {
|
|
210
|
+
rawPublicKeys[1].data = Buffer.alloc(47);
|
|
211
|
+
rawPublicKeys[1].type = 1;
|
|
212
|
+
|
|
213
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
214
|
+
|
|
215
|
+
expectJsonSchemaError(result);
|
|
216
|
+
|
|
217
|
+
const [error] = result.getErrors();
|
|
218
|
+
|
|
219
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
220
|
+
expect(error.getKeyword()).to.equal('minItems');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should be no longer than 48 bytes', () => {
|
|
224
|
+
rawPublicKeys[1].data = Buffer.alloc(49);
|
|
225
|
+
rawPublicKeys[1].type = 1;
|
|
226
|
+
|
|
227
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
228
|
+
|
|
229
|
+
expectJsonSchemaError(result);
|
|
230
|
+
|
|
231
|
+
const [error] = result.getErrors();
|
|
232
|
+
|
|
233
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
234
|
+
expect(error.getKeyword()).to.equal('maxItems');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe('ECDSA_HASH160', () => {
|
|
239
|
+
it('should be no less than 20 bytes', () => {
|
|
240
|
+
rawPublicKeys[1].data = Buffer.alloc(19);
|
|
241
|
+
rawPublicKeys[1].type = 2;
|
|
242
|
+
|
|
243
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
244
|
+
|
|
245
|
+
expectJsonSchemaError(result);
|
|
246
|
+
|
|
247
|
+
const [error] = result.getErrors();
|
|
248
|
+
|
|
249
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
250
|
+
expect(error.getKeyword()).to.equal('minItems');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should be no longer than 20 bytes', () => {
|
|
254
|
+
rawPublicKeys[1].data = Buffer.alloc(21);
|
|
255
|
+
rawPublicKeys[1].type = 2;
|
|
256
|
+
|
|
257
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
258
|
+
|
|
259
|
+
expectJsonSchemaError(result);
|
|
260
|
+
|
|
261
|
+
const [error] = result.getErrors();
|
|
262
|
+
|
|
263
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
264
|
+
expect(error.getKeyword()).to.equal('maxItems');
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('BIP13_SCRIPT_HASH', () => {
|
|
269
|
+
it('should be no less than 20 bytes', () => {
|
|
270
|
+
rawPublicKeys[1].data = Buffer.alloc(19);
|
|
271
|
+
rawPublicKeys[1].type = 3;
|
|
272
|
+
|
|
273
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
274
|
+
|
|
275
|
+
expectJsonSchemaError(result);
|
|
276
|
+
|
|
277
|
+
const [error] = result.getErrors();
|
|
278
|
+
|
|
279
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
280
|
+
expect(error.getKeyword()).to.equal('minItems');
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('should be no longer than 20 bytes', () => {
|
|
284
|
+
rawPublicKeys[1].data = Buffer.alloc(21);
|
|
285
|
+
rawPublicKeys[1].type = 3;
|
|
286
|
+
|
|
287
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
288
|
+
|
|
289
|
+
expectJsonSchemaError(result);
|
|
290
|
+
|
|
291
|
+
const [error] = result.getErrors();
|
|
292
|
+
|
|
293
|
+
expect(error.getInstancePath()).to.equal('/data');
|
|
294
|
+
expect(error.getKeyword()).to.equal('maxItems');
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('should return invalid result if there are duplicate key ids', () => {
|
|
300
|
+
rawPublicKeys[1].id = rawPublicKeys[0].id;
|
|
301
|
+
|
|
302
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
303
|
+
|
|
304
|
+
expectValidationError(result, DuplicatedIdentityPublicKeyIdError);
|
|
305
|
+
|
|
306
|
+
const [error] = result.getErrors();
|
|
307
|
+
|
|
308
|
+
expect(error.getCode()).to.equal(1030);
|
|
309
|
+
expect(error.getDuplicatedIds()).to.deep.equal([rawPublicKeys[1].id]);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should return invalid result if there are duplicate keys', () => {
|
|
313
|
+
rawPublicKeys[1].data = rawPublicKeys[0].data;
|
|
314
|
+
|
|
315
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
316
|
+
|
|
317
|
+
expectValidationError(result, DuplicatedIdentityPublicKeyError);
|
|
318
|
+
|
|
319
|
+
const [error] = result.getErrors();
|
|
320
|
+
|
|
321
|
+
expect(error.getCode()).to.equal(1029);
|
|
322
|
+
expect(error.getDuplicatedPublicKeysIds()).to.deep.equal([rawPublicKeys[1].id]);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('should return invalid result if key data is not a valid DER', () => {
|
|
326
|
+
rawPublicKeys[1].data = Buffer.alloc(33);
|
|
327
|
+
|
|
328
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
329
|
+
|
|
330
|
+
expectValidationError(result, InvalidIdentityPublicKeyDataError);
|
|
331
|
+
|
|
332
|
+
const [error] = result.getErrors();
|
|
333
|
+
|
|
334
|
+
expect(error.getCode()).to.equal(1040);
|
|
335
|
+
expect(error.getPublicKeyId()).to.deep.equal(rawPublicKeys[1].id);
|
|
336
|
+
expect(error.getValidationError()).to.be.instanceOf(TypeError);
|
|
337
|
+
expect(error.getValidationError().message).to.equal('Invalid DER format public key');
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('should return invalid result if key has an invalid combination of purpose and security level', () => {
|
|
341
|
+
rawPublicKeys[1].purpose = IdentityPublicKey.PURPOSES.ENCRYPTION;
|
|
342
|
+
rawPublicKeys[1].securityLevel = IdentityPublicKey.SECURITY_LEVELS.MASTER;
|
|
343
|
+
|
|
344
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
345
|
+
|
|
346
|
+
expectValidationError(result, InvalidIdentityPublicKeySecurityLevelError);
|
|
347
|
+
|
|
348
|
+
const [error] = result.getErrors();
|
|
349
|
+
|
|
350
|
+
expect(error.getCode()).to.equal(1047);
|
|
351
|
+
expect(error.getPublicKeyId()).to.deep.equal(rawPublicKeys[1].id);
|
|
352
|
+
expect(error.getPublicKeySecurityLevel()).to.be.equal(rawPublicKeys[1].securityLevel);
|
|
353
|
+
expect(error.getPublicKeyPurpose()).to.equal(rawPublicKeys[1].purpose);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('should pass valid public keys', () => {
|
|
357
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
358
|
+
|
|
359
|
+
expect(result.isValid()).to.be.true();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should pass valid BLS12_381 public key', () => {
|
|
363
|
+
rawPublicKeys = [{
|
|
364
|
+
id: 0,
|
|
365
|
+
type: IdentityPublicKey.TYPES.BLS12_381,
|
|
366
|
+
purpose: 0,
|
|
367
|
+
securityLevel: 0,
|
|
368
|
+
readOnly: true,
|
|
369
|
+
data: Buffer.from('01fac99ca2c8f39c286717c213e190aba4b7af76db320ec43f479b7d9a2012313a0ae59ca576edf801444bc694686694', 'hex'),
|
|
370
|
+
}];
|
|
371
|
+
|
|
372
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
373
|
+
|
|
374
|
+
expect(result.isValid()).to.be.true();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('should pass valid ECDSA_HASH160 public key', () => {
|
|
378
|
+
rawPublicKeys = [{
|
|
379
|
+
id: 0,
|
|
380
|
+
type: IdentityPublicKey.TYPES.ECDSA_HASH160,
|
|
381
|
+
purpose: 0,
|
|
382
|
+
securityLevel: 0,
|
|
383
|
+
readOnly: true,
|
|
384
|
+
data: Buffer.from('6086389d3fa4773aa950b8de18c5bd6d8f2b73bc', 'hex'),
|
|
385
|
+
}];
|
|
386
|
+
|
|
387
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
388
|
+
|
|
389
|
+
expect(result.isValid()).to.be.true();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('should return invalid result if BLS12_381 public key is invalid', () => {
|
|
393
|
+
rawPublicKeys = [{
|
|
394
|
+
id: 0,
|
|
395
|
+
type: IdentityPublicKey.TYPES.BLS12_381,
|
|
396
|
+
purpose: 0,
|
|
397
|
+
securityLevel: 0,
|
|
398
|
+
readOnly: true,
|
|
399
|
+
data: Buffer.from('11fac99ca2c8f39c286717c213e190aba4b7af76db320ec43f479b7d9a2012313a0ae59ca576edf801444bc694686694', 'hex'),
|
|
400
|
+
}];
|
|
401
|
+
|
|
402
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
403
|
+
|
|
404
|
+
expectValidationError(result, InvalidIdentityPublicKeyDataError);
|
|
405
|
+
|
|
406
|
+
const [error] = result.getErrors();
|
|
407
|
+
|
|
408
|
+
expect(error.getCode()).to.equal(1040);
|
|
409
|
+
expect(error.getPublicKeyId()).to.deep.equal(rawPublicKeys[0].id);
|
|
410
|
+
expect(error.getValidationError()).to.be.instanceOf(TypeError);
|
|
411
|
+
expect(error.getValidationError().message).to.equal('Invalid public key');
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
describe('Identity Schema', () => {
|
|
415
|
+
beforeEach(() => {
|
|
416
|
+
rawPublicKeys[0].disabledAt = new Date().getTime();
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe('disabledAt', () => {
|
|
420
|
+
it('should be an integer');
|
|
421
|
+
|
|
422
|
+
it('should be greater than 0');
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe('State Transition Schema', () => {
|
|
427
|
+
beforeEach(() => {
|
|
428
|
+
validatePublicKeys = validatePublicKeysFactory(
|
|
429
|
+
validator,
|
|
430
|
+
stateTransitionPublicKeySchema,
|
|
431
|
+
bls,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
rawPublicKeys.forEach((rawPublicKey) => {
|
|
435
|
+
// eslint-disable-next-line no-param-reassign
|
|
436
|
+
rawPublicKey.signature = crypto.randomBytes(65);
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe('signature', () => {
|
|
441
|
+
it('should be present', () => {
|
|
442
|
+
delete rawPublicKeys[0].signature;
|
|
443
|
+
|
|
444
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
445
|
+
|
|
446
|
+
expectJsonSchemaError(result);
|
|
447
|
+
|
|
448
|
+
const [error] = result.getErrors();
|
|
449
|
+
|
|
450
|
+
expect(error.instancePath).to.equal('');
|
|
451
|
+
expect(error.getKeyword()).to.equal('required');
|
|
452
|
+
expect(error.getParams().missingProperty).to.equal('signature');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('should be a byte array', async () => {
|
|
456
|
+
rawPublicKeys[0].signature = new Array(65).fill('string');
|
|
457
|
+
|
|
458
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
459
|
+
|
|
460
|
+
expectJsonSchemaError(result, 2);
|
|
461
|
+
|
|
462
|
+
const [error, byteArrayError] = result.getErrors();
|
|
463
|
+
|
|
464
|
+
expect(error.instancePath).to.equal('/signature/0');
|
|
465
|
+
expect(error.getKeyword()).to.equal('type');
|
|
466
|
+
|
|
467
|
+
expect(byteArrayError.getKeyword()).to.equal('byteArray');
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('should be not shorter than 65 bytes', () => {
|
|
471
|
+
rawPublicKeys[0].signature = Buffer.alloc(64);
|
|
472
|
+
|
|
473
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
474
|
+
|
|
475
|
+
expectJsonSchemaError(result);
|
|
476
|
+
|
|
477
|
+
const [error] = result.getErrors();
|
|
478
|
+
|
|
479
|
+
expect(error.instancePath).to.equal('/signature');
|
|
480
|
+
expect(error.getKeyword()).to.equal('minItems');
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('should be not longer than 65 bytes', () => {
|
|
484
|
+
rawPublicKeys[0].signature = Buffer.alloc(66);
|
|
485
|
+
|
|
486
|
+
const result = validatePublicKeys(rawPublicKeys);
|
|
487
|
+
|
|
488
|
+
expectJsonSchemaError(result);
|
|
489
|
+
|
|
490
|
+
const [error] = result.getErrors();
|
|
491
|
+
|
|
492
|
+
expect(error.instancePath).to.equal('/signature');
|
|
493
|
+
expect(error.getKeyword()).to.equal('maxItems');
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
});
|