Elffuss BraidHub

kikocis/gaiax-credentials-tool public

Build T&Cs and expose resulting VP
Changeset95d28ca644eeeed6a6271efc3e92d0be282ff7e0ec32fef26f5bef36b8febb34
AuthorAndrés García Mangas <andres.garcia@fundacionctic.org> · 2023-09-04 11:39 UTC
CommitterAndrés García Mangas <andres.garcia@fundacionctic.org> · 2023-09-04 11:39 UTC
Parentsd0d12362c067

Browse the files at this changeset

2 files changed

modified Taskfile.yml +9 −7
@@ -7,6 +7,8 @@
77 sh: echo "{{.CERTBOT_DOMAIN}}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-|-$//g'
88 STATIC_DIR: "{{.ROOT_DIR}}/htdocs"
99 X5U_FILENAME: x5u.pem
10+ DID_FILENAME: did.json
11+ VP_FILENAME: vp.json
1012 NGINX_CONTAINER_NAME: gaiax_nginx
1113 NGINX_IMAGE_TAG: 1.23
1214
@@ -16,7 +18,8 @@
1618 X5U_URL: "https://{{.CERTBOT_DOMAIN}}/{{.STATIC_PATH}}/{{.X5U_FILENAME}}"
1719 DID_URL: "https://{{.CERTBOT_DOMAIN}}/{{.STATIC_PATH}}"
1820 DID_WEB_ID: "did:web:{{.CERTBOT_DOMAIN}}:{{.STATIC_PATH}}"
19- DID_OUTPUT_PATH: "{{.STATIC_DIR}}/{{.STATIC_PATH}}/did.json"
21+ DID_OUTPUT_PATH: "{{.STATIC_DIR}}/{{.STATIC_PATH}}/{{.DID_FILENAME}}"
22+ VP_OUTPUT_PATH: "{{.STATIC_DIR}}/{{.STATIC_PATH}}/{{.VP_FILENAME}}"
2023
2124 # Create a dotenv .env file in the root folder
2225 # to override the default values defined in .env.default
@@ -57,7 +60,7 @@
5760 - task: chown-certs
5861
5962 build-did:
60- desc: Build and write the DID document
63+ desc: Build and write the DID and x.509 certificate chain
6164 cmds:
6265 - mkdir -p {{.STATIC_DIR}}/{{.STATIC_PATH}}
6366 - npm run build-did
@@ -70,11 +73,10 @@
7073 - sh: test -f {{.CERTS_DIR}}/fullchain.pem
7174 msg: Please run the task to get the SSL certificates first
7275
73- expose-did:
74- desc: Start the nginx container to expose the DID and x.509 certificate chain
75- deps:
76- - build-did
76+ start-webserver:
77+ desc: Build the DID and x.509 certificate chain and then start the NGINX web server
7778 cmds:
79+ - task: build-did
7880 - cmd: docker stop {{.NGINX_CONTAINER_NAME}}
7981 ignore_error: true
8082 - cmd: docker rm -f {{.NGINX_CONTAINER_NAME}}
@@ -92,6 +94,6 @@
9294 request-compliance:
9395 desc: Call the Compliance API to get integrity proofs
9496 deps:
95- - expose-did
97+ - start-webserver
9698 cmds:
9799 - npm run validate-compliance
modified index.js +90 −13
@@ -104,6 +104,22 @@
104104 return proof;
105105 }
106106
107+function getIssuer() {
108+ return process.env.DID_WEB_ID;
109+}
110+
111+function getParticipantId() {
112+ return `${process.env.DID_URL}`;
113+}
114+
115+function getLegalRegistrationNumberId() {
116+ return `${process.env.DID_URL}#lrn`;
117+}
118+
119+function getTermsConditionsId() {
120+ return `${process.env.DID_URL}#tsandcs`;
121+}
122+
107123 async function buildParticipantVC() {
108124 const issuanceDate = new Date().toISOString();
109125
@@ -114,14 +130,14 @@
114130 "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
115131 ],
116132 type: ["VerifiableCredential"],
117- id: process.env.DID_URL,
118- issuer: process.env.DID_WEB_ID,
133+ id: getParticipantId(),
134+ issuer: getIssuer(),
119135 issuanceDate: issuanceDate,
120136 credentialSubject: {
121137 type: "gx:LegalParticipant",
122138 "gx:legalName": process.env.LEGAL_NAME,
123139 "gx:legalRegistrationNumber": {
124- id: `${process.env.DID_URL}#lrn`,
140+ id: getLegalRegistrationNumberId(),
125141 },
126142 "gx:headquarterAddress": {
127143 "gx:countrySubdivisionCode": process.env.COUNTRY_SUBDIVISION_CODE,
@@ -129,9 +145,8 @@
129145 "gx:legalAddress": {
130146 "gx:countrySubdivisionCode": process.env.COUNTRY_SUBDIVISION_CODE,
131147 },
132- "gx-terms-and-conditions:gaiaxTermsAndConditions":
133- "70c1d713215f95191a11d38fe2341faed27d19e083917bc8732ca4fea4976700",
134- id: process.env.DID_URL,
148+ "gx-terms-and-conditions:gaiaxTermsAndConditions": getTermsConditionsId(),
149+ id: getParticipantId(),
135150 },
136151 };
137152
@@ -150,11 +165,11 @@
150165 "https://w3id.org/security/suites/jws-2020/v1",
151166 ],
152167 type: "VerifiableCredential",
153- id: `${process.env.DID_URL}#lrn`,
154- issuer: process.env.DID_WEB_ID,
168+ id: getLegalRegistrationNumberId(),
169+ issuer: getIssuer(),
155170 issuanceDate: issuanceDate,
156171 credentialSubject: {
157- id: `${process.env.DID_URL}#lrn`,
172+ id: getLegalRegistrationNumberId(),
158173 "@context":
159174 "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
160175 type: "gx:legalRegistrationNumber",
@@ -169,25 +184,73 @@
169184 return doc;
170185 }
171186
187+async function buildTermsConditionsVC() {
188+ const issuanceDate = new Date().toISOString();
189+
190+ const termsAndConditions =
191+ "The PARTICIPANT signing the Self-Description agrees as follows:\n- " +
192+ "to update its descriptions about any changes, " +
193+ "be it technical, organizational, or legal - " +
194+ "especially but not limited to contractual in regards to " +
195+ "the indicated attributes present in the descriptions.\n\n" +
196+ "The keypair used to sign Verifiable Credentials will be revoked " +
197+ "where Gaia-X Association becomes aware of any inaccurate statements " +
198+ "in regards to the claims which result in a non-compliance " +
199+ "with the Trust Framework and policy rules defined " +
200+ "in the Policy Rules and Labelling Document (PRLD).";
201+
202+ const doc = {
203+ "@context": [
204+ "https://www.w3.org/2018/credentials/v1",
205+ "https://w3id.org/security/suites/jws-2020/v1",
206+ "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
207+ ],
208+ type: "VerifiableCredential",
209+ id: getTermsConditionsId(),
210+ issuer: getIssuer(),
211+ issuanceDate: issuanceDate,
212+ credentialSubject: {
213+ "@context":
214+ "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#",
215+ type: "gx:GaiaXTermsAndConditions",
216+ id: getTermsConditionsId(),
217+ "gx:termsAndConditions": termsAndConditions,
218+ },
219+ };
220+
221+ const proof = await createProof(doc);
222+ Object.assign(doc, { proof });
223+
224+ return doc;
225+}
226+
172227 async function requestCompliance() {
173- console.log(chalk.blue("Building Participant Verifiable Credential..."));
228+ console.log(chalk.blue("Building Participant Verifiable Credential"));
174229 const vcParticipant = await buildParticipantVC();
175230 console.log(chalk.cyan(JSON.stringify(vcParticipant, null, 2)));
176231
177232 console.log(
178- chalk.blue("Building Legal Registration Number Verifiable Credential...")
233+ chalk.blue("Building Legal Registration Number Verifiable Credential")
179234 );
235+
180236 const vcLRN = await buildLegalRegistrationNumberVC();
181237 console.log(chalk.cyan(JSON.stringify(vcLRN, null, 2)));
182238
239+ console.log(
240+ chalk.blue("Building Terms and Conditions Verifiable Credential")
241+ );
242+
243+ const vcTC = await buildTermsConditionsVC();
244+ console.log(chalk.cyan(JSON.stringify(vcTC, null, 2)));
245+
183246 const verifiablePresentation = {
184247 "@context": "https://www.w3.org/2018/credentials/v1",
185248 type: "VerifiablePresentation",
186- verifiableCredential: [vcParticipant, vcLRN],
249+ verifiableCredential: [vcParticipant, vcLRN, vcTC],
187250 };
188251
189252 console.log(
190- chalk.blue("Sending Verifiable Presentation to Compliance API...")
253+ chalk.blue("Sending Verifiable Presentation to Compliance API")
191254 );
192255 console.log(chalk.blue("POST", process.env.API_COMPLIANCE_CREDENTIAL_OFFER));
193256
@@ -196,8 +259,22 @@
196259 process.env.API_COMPLIANCE_CREDENTIAL_OFFER,
197260 verifiablePresentation
198261 );
262+
199263 console.log(chalk.green("✅ Compliance success"));
200264 console.log(chalk.green(JSON.stringify(res.data, null, 2)));
265+
266+ Object.assign(verifiablePresentation, {
267+ verifiableCredential: [vcParticipant, vcLRN, vcTC, res.data],
268+ });
269+
270+ console.log(
271+ chalk.blue(
272+ `Writing resulting Verifiable Presentation to ${process.env.VP_OUTPUT_PATH}`
273+ )
274+ );
275+
276+ const vpData = JSON.stringify(verifiablePresentation, null, 2);
277+ await fs.writeFile(process.env.VP_OUTPUT_PATH, vpData);
201278 } catch (err) {
202279 console.error(chalk.red("🔴 Compliance error"));
203280 console.error(err.response.data);