@bedrock/validation 6.0.0
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/.eslintrc.cjs +12 -0
- package/.github/workflows/main.yml +67 -0
- package/CHANGELOG.md +244 -0
- package/LICENSE.md +115 -0
- package/README.md +92 -0
- package/lib/Cache.js +24 -0
- package/lib/config.js +18 -0
- package/lib/index.js +250 -0
- package/lib/logger.js +5 -0
- package/package.json +41 -0
- package/schemas/comment.js +24 -0
- package/schemas/credential.js +37 -0
- package/schemas/description.js +24 -0
- package/schemas/email.js +34 -0
- package/schemas/identifier.js +22 -0
- package/schemas/jsonPatch.js +38 -0
- package/schemas/jsonldContext.js +54 -0
- package/schemas/jsonldType.js +72 -0
- package/schemas/label.js +25 -0
- package/schemas/linkedDataSignature.js +46 -0
- package/schemas/linkedDataSignature2018.js +58 -0
- package/schemas/linkedDataSignature2020.js +42 -0
- package/schemas/nonce.js +25 -0
- package/schemas/personName.js +25 -0
- package/schemas/privateKeyPem.js +23 -0
- package/schemas/publicKeyPem.js +23 -0
- package/schemas/sequencedPatch.js +31 -0
- package/schemas/slug.js +27 -0
- package/schemas/title.js +25 -0
- package/schemas/url.js +22 -0
- package/schemas/w3cDateTime.js +24 -0
- package/test/mocha/.eslintrc +9 -0
- package/test/mocha/001-schemas.js +1157 -0
- package/test/mocha/mock.data.js +45 -0
- package/test/package.json +28 -0
- package/test/test.config.js +10 -0
- package/test/test.js +8 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import identifier from './identifier.js';
|
|
5
|
+
import w3cDateTime from './w3cDateTime.js';
|
|
6
|
+
|
|
7
|
+
const baseSignature = {
|
|
8
|
+
title: 'Linked Data Signature',
|
|
9
|
+
description: 'A Linked Data digital signature.',
|
|
10
|
+
// NOTE: id is not required
|
|
11
|
+
required: ['type', 'created', 'jws'],
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
id: identifier(),
|
|
15
|
+
type: {
|
|
16
|
+
title: 'Linked Data Signature Type',
|
|
17
|
+
type: 'string',
|
|
18
|
+
enum: ['Ed25519Signature2018', 'RsaSignature2018']
|
|
19
|
+
},
|
|
20
|
+
creator: identifier(),
|
|
21
|
+
created: w3cDateTime(),
|
|
22
|
+
jws: {
|
|
23
|
+
title: 'Digital Signature Value',
|
|
24
|
+
description: 'The Base64 encoding of the result of the signature ' +
|
|
25
|
+
'algorithm.',
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
verificationMethod: identifier(),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const signature = {
|
|
33
|
+
allOf: [
|
|
34
|
+
baseSignature, {
|
|
35
|
+
// only one of `creator` or `verificationMethod`
|
|
36
|
+
anyOf: [{
|
|
37
|
+
required: ['creator'],
|
|
38
|
+
not: {required: ['verificationMethod']},
|
|
39
|
+
}, {
|
|
40
|
+
required: ['verificationMethod'],
|
|
41
|
+
not: {required: ['creator']},
|
|
42
|
+
}]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const schema = {
|
|
48
|
+
title: 'Linked Data Signatures',
|
|
49
|
+
oneOf: [{
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: signature,
|
|
52
|
+
minItems: 1,
|
|
53
|
+
}, signature]
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default function() {
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import identifier from './identifier.js';
|
|
5
|
+
import w3cDateTime from './w3cDateTime.js';
|
|
6
|
+
|
|
7
|
+
const signature = {
|
|
8
|
+
title: 'Ed25519Signature2020',
|
|
9
|
+
description: 'An Ed25519 Linked Data Signature (2020 cryptosuite).',
|
|
10
|
+
// NOTE: id is not required
|
|
11
|
+
required: ['type', 'created', 'verificationMethod', 'proofValue'],
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
id: identifier(),
|
|
15
|
+
type: {
|
|
16
|
+
title: 'Ed25519 Signature Type for 2020 Cryptosuite',
|
|
17
|
+
type: 'string',
|
|
18
|
+
enum: ['Ed25519Signature2020']
|
|
19
|
+
},
|
|
20
|
+
created: w3cDateTime(),
|
|
21
|
+
proofValue: {
|
|
22
|
+
title: 'Digital Signature Value',
|
|
23
|
+
description: 'The multibase base58-btc encoding of the result of ' +
|
|
24
|
+
'the signature algorithm.',
|
|
25
|
+
type: 'string'
|
|
26
|
+
},
|
|
27
|
+
verificationMethod: identifier(),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const schema = {
|
|
32
|
+
title: 'One or more Ed25519 signatures (2020 cryptosuite)',
|
|
33
|
+
oneOf: [{
|
|
34
|
+
type: 'array',
|
|
35
|
+
items: signature,
|
|
36
|
+
minItems: 1,
|
|
37
|
+
}, signature]
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default function() {
|
|
41
|
+
return schema;
|
|
42
|
+
}
|
package/schemas/nonce.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'Nonce',
|
|
8
|
+
description: 'A single use secure unique string.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
pattern: '^[-a-zA-Z0-9~!$%^&*\\(\\)_=+\\. ]*$',
|
|
11
|
+
minLength: 8,
|
|
12
|
+
maxLength: 64,
|
|
13
|
+
errors: {
|
|
14
|
+
invalid: 'The nonce contains invalid characters or is not between ' +
|
|
15
|
+
'8 and 64 characters in length.',
|
|
16
|
+
missing: 'Please enter a nonce.'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function(extend) {
|
|
21
|
+
if(extend) {
|
|
22
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
23
|
+
}
|
|
24
|
+
return schema;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'Person Name',
|
|
8
|
+
description: 'The name of a person.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
pattern: '^\\S$|^\\S.*\\S$',
|
|
11
|
+
minLength: 1,
|
|
12
|
+
maxLength: 100,
|
|
13
|
+
errors: {
|
|
14
|
+
invalid: 'The name must not start or end with whitespace and must ' +
|
|
15
|
+
'be between 1 and 100 characters in length.',
|
|
16
|
+
missing: 'Please enter a name.'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function(extend) {
|
|
21
|
+
if(extend) {
|
|
22
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
23
|
+
}
|
|
24
|
+
return schema;
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'Private Key PEM',
|
|
8
|
+
description: 'A cryptographic Private Key in PEM format.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
// eslint-disable-next-line max-len
|
|
11
|
+
pattern: '^\\s*-----BEGIN RSA PRIVATE KEY-----[a-zA-Z0-9/+=\\s]*-----END RSA PRIVATE KEY-----\\s*$',
|
|
12
|
+
errors: {
|
|
13
|
+
invalid: 'The private key is not formatted correctly.',
|
|
14
|
+
missing: 'The private key is missing.'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default function(extend) {
|
|
19
|
+
if(extend) {
|
|
20
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
21
|
+
}
|
|
22
|
+
return schema;
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'Public Key PEM',
|
|
8
|
+
description: 'A cryptographic Public Key in PEM format.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
// eslint-disable-next-line max-len
|
|
11
|
+
pattern: '^\\s*-----BEGIN (RSA\\s)?PUBLIC KEY-----[a-zA-Z0-9/+=\\s]*-----END (RSA\\s)?PUBLIC KEY-----\\s*$',
|
|
12
|
+
errors: {
|
|
13
|
+
invalid: 'The public key is not formatted correctly.',
|
|
14
|
+
missing: 'The public key is missing.'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default function(extend) {
|
|
19
|
+
if(extend) {
|
|
20
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
21
|
+
}
|
|
22
|
+
return schema;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
import jsonPatch from './jsonPatch.js';
|
|
6
|
+
|
|
7
|
+
const schema = {
|
|
8
|
+
required: ['patch', 'sequence', 'target'],
|
|
9
|
+
title: 'Sequence-based JSON Patch',
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
target: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
},
|
|
15
|
+
// FIXME: also support `frame` property later
|
|
16
|
+
patch: jsonPatch(),
|
|
17
|
+
sequence: {
|
|
18
|
+
type: 'integer',
|
|
19
|
+
minimum: 0,
|
|
20
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
additionalProperties: false
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default function(extend) {
|
|
27
|
+
if(extend) {
|
|
28
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
29
|
+
}
|
|
30
|
+
return schema;
|
|
31
|
+
}
|
package/schemas/slug.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'Slug',
|
|
8
|
+
description: 'A short identifier within a URL.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
pattern: '^[a-z0-9][-a-z0-9~_\\.]*$',
|
|
11
|
+
minLength: 3,
|
|
12
|
+
maxLength: 40,
|
|
13
|
+
errors: {
|
|
14
|
+
invalid:
|
|
15
|
+
'The slug must start with a letter or number, contain only lowercase ' +
|
|
16
|
+
'letters, numbers, hyphens, periods, underscores, and tildes. It must ' +
|
|
17
|
+
'between 3 and 40 characters in length.',
|
|
18
|
+
missing: 'Please enter a slug.'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default function(extend) {
|
|
23
|
+
if(extend) {
|
|
24
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
25
|
+
}
|
|
26
|
+
return schema;
|
|
27
|
+
}
|
package/schemas/title.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'Title',
|
|
8
|
+
description: 'A descriptive title.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
pattern: '^[-a-zA-Z0-9~`!@#$%^&*\\(\\)\\[\\]{}<>_=+\\\\|:;\'"\\.,/? ]*$',
|
|
11
|
+
minLength: 1,
|
|
12
|
+
maxLength: 200,
|
|
13
|
+
errors: {
|
|
14
|
+
invalid: 'The title contains invalid characters or is not between ' +
|
|
15
|
+
'1 and 200 characters in length.',
|
|
16
|
+
missing: 'Please enter a title.'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function(extend) {
|
|
21
|
+
if(extend) {
|
|
22
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
23
|
+
}
|
|
24
|
+
return schema;
|
|
25
|
+
}
|
package/schemas/url.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'URL',
|
|
8
|
+
description: 'A universal resource location.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
minLength: 1,
|
|
11
|
+
errors: {
|
|
12
|
+
invalid: 'Please enter a valid URL.',
|
|
13
|
+
missing: 'Please enter a URL.'
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default function(extend) {
|
|
18
|
+
if(extend) {
|
|
19
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
20
|
+
}
|
|
21
|
+
return schema;
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2012-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import * as bedrock from '@bedrock/core';
|
|
5
|
+
|
|
6
|
+
const schema = {
|
|
7
|
+
title: 'W3C Date/Time',
|
|
8
|
+
description: 'A W3C-formatted date and time combination.',
|
|
9
|
+
type: 'string',
|
|
10
|
+
// eslint-disable-next-line max-len
|
|
11
|
+
pattern: '^[1-9][0-9]{3}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])T([0-1][0-9]|2[0-3]):([0-5][0-9]):(([0-5][0-9])|60)(\\.[0-9]+)?(Z|((\\+|-)([0-1][0-9]|2[0-3]):([0-5][0-9])))?$',
|
|
12
|
+
errors: {
|
|
13
|
+
// eslint-disable-next-line max-len
|
|
14
|
+
invalid: 'The date/time must be of the W3C date/time format "YYYY-MM-DD( |T)HH:MM:SS.s(Z|(+|-)TZOFFSET)".',
|
|
15
|
+
missing: 'Please enter a date/time.'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function(extend) {
|
|
20
|
+
if(extend) {
|
|
21
|
+
return bedrock.util.extend(true, bedrock.util.clone(schema), extend);
|
|
22
|
+
}
|
|
23
|
+
return schema;
|
|
24
|
+
}
|