UNPKG

1.33 kBJavaScriptView Raw
1/*!
2 * Copyright (c) 2012-2018 Digital Bazaar, Inc. All rights reserved.
3 */
4'use strict';
5
6const w3cDateTime = require('./w3cDateTime');
7const identifier = require('./identifier');
8
9const baseSignature = {
10 title: 'Linked Data Signature',
11 description: 'A Linked Data digital signature.',
12 // NOTE: id is not required
13 required: ['type', 'created', 'jws'],
14 type: 'object',
15 properties: {
16 id: identifier(),
17 type: {
18 title: 'Linked Data Signature Type',
19 type: 'string',
20 enum: ['Ed25519Signature2018', 'RsaSignature2018']
21 },
22 creator: identifier(),
23 created: w3cDateTime(),
24 jws: {
25 title: 'Digital Signature Value',
26 description: 'The Base64 encoding of the result of the signature ' +
27 'algorithm.',
28 type: 'string'
29 },
30 verificationMethod: identifier(),
31 },
32};
33
34const signature = {
35 allOf: [
36 baseSignature, {
37 // only one of `creator` or `verificationMethod`
38 anyOf: [{
39 required: ['creator'],
40 not: {required: ['verificationMethod']},
41 }, {
42 required: ['verificationMethod'],
43 not: {required: ['creator']},
44 }]
45 }
46 ]
47};
48
49const schema = {
50 title: 'Linked Data Signatures',
51 oneOf: [{
52 type: 'array',
53 items: signature,
54 minItems: 1,
55 }, signature]
56};
57
58module.exports = () => (schema);