kikocis/gaiax-credentials-tool public
Changesets · Branches · Tags · Compare
| Changeset | 95d28ca644eeeed6a6271efc3e92d0be282ff7e0ec32fef26f5bef36b8febb34 |
|---|---|
| Author | Andrés García Mangas <andres.garcia@fundacionctic.org> · 2023-09-04 11:39 UTC |
| Committer | Andrés García Mangas <andres.garcia@fundacionctic.org> · 2023-09-04 11:39 UTC |
| Parents | d0d12362c067 |
2 files changed
modified Taskfile.yml +9 −7
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | sh: echo "{{.CERTBOT_DOMAIN}}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-|-$//g' |
| 8 | 8 | STATIC_DIR: "{{.ROOT_DIR}}/htdocs" |
| 9 | 9 | X5U_FILENAME: x5u.pem |
| 10 | + DID_FILENAME: did.json | |
| 11 | + VP_FILENAME: vp.json | |
| 10 | 12 | NGINX_CONTAINER_NAME: gaiax_nginx |
| 11 | 13 | NGINX_IMAGE_TAG: 1.23 |
| 12 | 14 | |
| @@ -16,7 +18,8 @@ | ||
| 16 | 18 | X5U_URL: "https://{{.CERTBOT_DOMAIN}}/{{.STATIC_PATH}}/{{.X5U_FILENAME}}" |
| 17 | 19 | DID_URL: "https://{{.CERTBOT_DOMAIN}}/{{.STATIC_PATH}}" |
| 18 | 20 | 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}}" | |
| 20 | 23 | |
| 21 | 24 | # Create a dotenv .env file in the root folder |
| 22 | 25 | # to override the default values defined in .env.default |
| @@ -57,7 +60,7 @@ | ||
| 57 | 60 | - task: chown-certs |
| 58 | 61 | |
| 59 | 62 | build-did: |
| 60 | - desc: Build and write the DID document | |
| 63 | + desc: Build and write the DID and x.509 certificate chain | |
| 61 | 64 | cmds: |
| 62 | 65 | - mkdir -p {{.STATIC_DIR}}/{{.STATIC_PATH}} |
| 63 | 66 | - npm run build-did |
| @@ -70,11 +73,10 @@ | ||
| 70 | 73 | - sh: test -f {{.CERTS_DIR}}/fullchain.pem |
| 71 | 74 | msg: Please run the task to get the SSL certificates first |
| 72 | 75 | |
| 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 | |
| 77 | 78 | cmds: |
| 79 | + - task: build-did | |
| 78 | 80 | - cmd: docker stop {{.NGINX_CONTAINER_NAME}} |
| 79 | 81 | ignore_error: true |
| 80 | 82 | - cmd: docker rm -f {{.NGINX_CONTAINER_NAME}} |
| @@ -92,6 +94,6 @@ | ||
| 92 | 94 | request-compliance: |
| 93 | 95 | desc: Call the Compliance API to get integrity proofs |
| 94 | 96 | deps: |
| 95 | - - expose-did | |
| 97 | + - start-webserver | |
| 96 | 98 | cmds: |
| 97 | 99 | - npm run validate-compliance |
modified index.js +90 −13
| @@ -104,6 +104,22 @@ | ||
| 104 | 104 | return proof; |
| 105 | 105 | } |
| 106 | 106 | |
| 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 | + | |
| 107 | 123 | async function buildParticipantVC() { |
| 108 | 124 | const issuanceDate = new Date().toISOString(); |
| 109 | 125 | |
| @@ -114,14 +130,14 @@ | ||
| 114 | 130 | "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#", |
| 115 | 131 | ], |
| 116 | 132 | type: ["VerifiableCredential"], |
| 117 | - id: process.env.DID_URL, | |
| 118 | - issuer: process.env.DID_WEB_ID, | |
| 133 | + id: getParticipantId(), | |
| 134 | + issuer: getIssuer(), | |
| 119 | 135 | issuanceDate: issuanceDate, |
| 120 | 136 | credentialSubject: { |
| 121 | 137 | type: "gx:LegalParticipant", |
| 122 | 138 | "gx:legalName": process.env.LEGAL_NAME, |
| 123 | 139 | "gx:legalRegistrationNumber": { |
| 124 | - id: `${process.env.DID_URL}#lrn`, | |
| 140 | + id: getLegalRegistrationNumberId(), | |
| 125 | 141 | }, |
| 126 | 142 | "gx:headquarterAddress": { |
| 127 | 143 | "gx:countrySubdivisionCode": process.env.COUNTRY_SUBDIVISION_CODE, |
| @@ -129,9 +145,8 @@ | ||
| 129 | 145 | "gx:legalAddress": { |
| 130 | 146 | "gx:countrySubdivisionCode": process.env.COUNTRY_SUBDIVISION_CODE, |
| 131 | 147 | }, |
| 132 | - "gx-terms-and-conditions:gaiaxTermsAndConditions": | |
| 133 | - "70c1d713215f95191a11d38fe2341faed27d19e083917bc8732ca4fea4976700", | |
| 134 | - id: process.env.DID_URL, | |
| 148 | + "gx-terms-and-conditions:gaiaxTermsAndConditions": getTermsConditionsId(), | |
| 149 | + id: getParticipantId(), | |
| 135 | 150 | }, |
| 136 | 151 | }; |
| 137 | 152 | |
| @@ -150,11 +165,11 @@ | ||
| 150 | 165 | "https://w3id.org/security/suites/jws-2020/v1", |
| 151 | 166 | ], |
| 152 | 167 | type: "VerifiableCredential", |
| 153 | - id: `${process.env.DID_URL}#lrn`, | |
| 154 | - issuer: process.env.DID_WEB_ID, | |
| 168 | + id: getLegalRegistrationNumberId(), | |
| 169 | + issuer: getIssuer(), | |
| 155 | 170 | issuanceDate: issuanceDate, |
| 156 | 171 | credentialSubject: { |
| 157 | - id: `${process.env.DID_URL}#lrn`, | |
| 172 | + id: getLegalRegistrationNumberId(), | |
| 158 | 173 | "@context": |
| 159 | 174 | "https://registry.lab.gaia-x.eu/development/api/trusted-shape-registry/v1/shapes/jsonld/trustframework#", |
| 160 | 175 | type: "gx:legalRegistrationNumber", |
| @@ -169,25 +184,73 @@ | ||
| 169 | 184 | return doc; |
| 170 | 185 | } |
| 171 | 186 | |
| 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 | + | |
| 172 | 227 | async function requestCompliance() { |
| 173 | - console.log(chalk.blue("Building Participant Verifiable Credential...")); | |
| 228 | + console.log(chalk.blue("Building Participant Verifiable Credential")); | |
| 174 | 229 | const vcParticipant = await buildParticipantVC(); |
| 175 | 230 | console.log(chalk.cyan(JSON.stringify(vcParticipant, null, 2))); |
| 176 | 231 | |
| 177 | 232 | console.log( |
| 178 | - chalk.blue("Building Legal Registration Number Verifiable Credential...") | |
| 233 | + chalk.blue("Building Legal Registration Number Verifiable Credential") | |
| 179 | 234 | ); |
| 235 | + | |
| 180 | 236 | const vcLRN = await buildLegalRegistrationNumberVC(); |
| 181 | 237 | console.log(chalk.cyan(JSON.stringify(vcLRN, null, 2))); |
| 182 | 238 | |
| 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 | + | |
| 183 | 246 | const verifiablePresentation = { |
| 184 | 247 | "@context": "https://www.w3.org/2018/credentials/v1", |
| 185 | 248 | type: "VerifiablePresentation", |
| 186 | - verifiableCredential: [vcParticipant, vcLRN], | |
| 249 | + verifiableCredential: [vcParticipant, vcLRN, vcTC], | |
| 187 | 250 | }; |
| 188 | 251 | |
| 189 | 252 | console.log( |
| 190 | - chalk.blue("Sending Verifiable Presentation to Compliance API...") | |
| 253 | + chalk.blue("Sending Verifiable Presentation to Compliance API") | |
| 191 | 254 | ); |
| 192 | 255 | console.log(chalk.blue("POST", process.env.API_COMPLIANCE_CREDENTIAL_OFFER)); |
| 193 | 256 | |
| @@ -196,8 +259,22 @@ | ||
| 196 | 259 | process.env.API_COMPLIANCE_CREDENTIAL_OFFER, |
| 197 | 260 | verifiablePresentation |
| 198 | 261 | ); |
| 262 | + | |
| 199 | 263 | console.log(chalk.green("✅ Compliance success")); |
| 200 | 264 | 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); | |
| 201 | 278 | } catch (err) { |
| 202 | 279 | console.error(chalk.red("🔴 Compliance error")); |
| 203 | 280 | console.error(err.response.data); |