Elffuss BraidHub

kikocis/gaiax-credentials-tool public

main · 5.0 KiBRawPermalink
1import * as jose from "jose";
2import fs from "node:fs/promises";
3import { getConfig } from "./config.js";
4import {
5 ALGORITHM_RSASSA_PSS,
6 createProof,
7 publicKeyMatchesCertificate,
8 writeFile,
9} from "./utils.js";
10
11export async function writeDIDFile() {
12 const config = getConfig();
13
14 const certificatePem = await fs.readFile(config.pathCertificate, {
15 encoding: "utf8",
16 });
17
18 const x509 = await jose.importX509(certificatePem, ALGORITHM_RSASSA_PSS);
19 const publicKeyJwk = await jose.exportJWK(x509);
20 publicKeyJwk.alg = ALGORITHM_RSASSA_PSS;
21 publicKeyJwk.x5u = config.urlX5U;
22
23 // A sanity check to catch upstream errors in the Compliance API calls
24 if (!publicKeyMatchesCertificate(publicKeyJwk, certificatePem)) {
25 throw new Error("Public key does not match certificate");
26 }
27
28 const did = {
29 "@context": ["https://www.w3.org/ns/did/v1"],
30 id: config.didWebId,
31 verificationMethod: [
32 {
33 "@context": "https://w3c-ccg.github.io/lds-jws2020/contexts/v1/",
34 id: config.didWebId,
35 type: "JsonWebKey2020",
36 publicKeyJwk,
37 },
38 ],
39 assertionMethod: [`${config.didWebId}`],
40 };
41
42 await writeFile(config.pathDID, did);
43}
44
45export async function buildParticipantVC() {
46 const config = getConfig();
47 const issuanceDate = new Date().toISOString();
48
49 const doc = {
50 "@context": [
51 "https://www.w3.org/2018/credentials/v1",
52 "https://w3id.org/security/suites/jws-2020/v1",
53 "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
54 "https://schema.org/version/latest/schemaorg-current-https.jsonld",
55 ],
56 type: ["VerifiableCredential"],
57 id: config.urlParticipant,
58 issuer: config.didWebId,
59 issuanceDate: issuanceDate,
60 credentialSubject: {
61 type: "gx:LegalParticipant",
62 "gx:legalName": config.legalName,
63 "gx:legalRegistrationNumber": {
64 id: config.urlLRN,
65 },
66 "gx:headquarterAddress": {
67 "gx:countrySubdivisionCode": config.countrySubdivisionCode,
68 },
69 "gx:legalAddress": {
70 "gx:countrySubdivisionCode": config.countrySubdivisionCode,
71 },
72 "gx-terms-and-conditions:gaiaxTermsAndConditions":
73 config.urlTermsConditions,
74 id: config.urlParticipant,
75 "schema:description":
76 "This field demonstrates the possibility of using additional ontologies to add fields that are not explicitly included in the Trust Framework specification.",
77 },
78 };
79
80 const proof = await createProof(doc);
81 Object.assign(doc, { proof });
82
83 await writeFile(config.pathParticipant, doc);
84
85 return doc;
86}
87
88export async function buildLegalRegistrationNumberVC() {
89 const config = getConfig();
90 const issuanceDate = new Date().toISOString();
91
92 const doc = {
93 "@context": [
94 "https://www.w3.org/2018/credentials/v1",
95 "https://w3id.org/security/suites/jws-2020/v1",
96 ],
97 type: "VerifiableCredential",
98 id: config.urlLRN,
99 issuer: config.didWebId,
100 issuanceDate: issuanceDate,
101 credentialSubject: {
102 id: config.urlLRN,
103 "@context":
104 "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
105 type: "gx:legalRegistrationNumber",
106 "gx:vatID": config.vatID,
107 "gx:vatID-countryCode": config.countryCode,
108 },
109 };
110
111 const proof = await createProof(doc);
112 Object.assign(doc, { proof });
113
114 await writeFile(config.pathLRN, doc);
115
116 return doc;
117}
118
119export async function buildTermsConditionsVC() {
120 const config = getConfig();
121 const issuanceDate = new Date().toISOString();
122
123 const termsAndConditions =
124 "The PARTICIPANT signing the Self-Description agrees as follows:\n- " +
125 "to update its descriptions about any changes, " +
126 "be it technical, organizational, or legal - " +
127 "especially but not limited to contractual in regards to " +
128 "the indicated attributes present in the descriptions.\n\n" +
129 "The keypair used to sign Verifiable Credentials will be revoked " +
130 "where Gaia-X Association becomes aware of any inaccurate statements " +
131 "in regards to the claims which result in a non-compliance " +
132 "with the Trust Framework and policy rules defined " +
133 "in the Policy Rules and Labelling Document (PRLD).";
134
135 const doc = {
136 "@context": [
137 "https://www.w3.org/2018/credentials/v1",
138 "https://w3id.org/security/suites/jws-2020/v1",
139 "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
140 ],
141 type: "VerifiableCredential",
142 id: config.urlTermsConditions,
143 issuer: config.didWebId,
144 issuanceDate: issuanceDate,
145 credentialSubject: {
146 "@context":
147 "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
148 type: "gx:GaiaXTermsAndConditions",
149 id: config.urlTermsConditions,
150 "gx:termsAndConditions": termsAndConditions,
151 },
152 };
153
154 const proof = await createProof(doc);
155 Object.assign(doc, { proof });
156
157 await writeFile(config.pathTermsConditions, doc);
158
159 return doc;
160}