-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-vdls.js
76 lines (72 loc) · 2.04 KB
/
generate-vdls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*!
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
*/
'use strict';
const {join} = require('path');
const {writeJSON} = require('./files');
const {paths} = require('./paths');
const {CONTEXT_URL} = require('vdl-context');
const stateList = require('./states');
const didKeyDriver = require('@digitalbazaar/did-method-key').driver();
async function createVC(state) {
const contexts = [
'https://www.w3.org/2018/credentials/v1',
CONTEXT_URL,
];
const type = [
'VerifiableCredential',
'Iso18013DriversLicenseCredential'
];
const fileName = `${state.name}.json`;
const {didDocument} = await didKeyDriver.generate();
const credential = {
'@context': contexts,
type,
credentialSubject: {
id: didDocument.id,
license: {
type: 'Iso18013DriversLicense',
document_number: '542426814',
family_name: 'TURNER',
given_name: 'SUSAN',
portrait: '/9j/4AAQSkZJRgABAQEAkACQA...gcdgck5HtRRSClooooP/2Q==',
birth_date: '1998-08-28',
issue_date: '2018-01-15T10:00:00Z',
expiry_date: '2022-08-27T12:00:00Z',
issuing_country: 'US',
issuing_authority: state.code,
driving_privileges: [{
codes: [{code: 'D'}],
vehicle_category_code: 'D',
issue_date: '2019-01-01',
expiry_date: '2027-01-01'
},
{
codes: [{code: 'C'}],
vehicle_category_code: 'C',
issue_date: '2019-01-01',
expiry_date: '2017-01-01'
}],
un_distinguishing_sign: 'USA',
}
}
};
return {fileName, credential};
}
/**
* Formats data into VCs.
*
* @returns {Promise} Writes data to `/credentials` and exits.
*/
async function generateCertificates() {
try {
await Promise.all(stateList.flatMap(async state => {
const {fileName, credential} = await createVC(state);
const filePath = join(paths.credentials, fileName);
return writeJSON({path: filePath, data: credential});
}));
} catch(e) {
console.error(e);
}
}
generateCertificates();