Setup of .well-known/did.json
If you are using an X.509 certificate for authentication of your declarations, you must set up a .well-known/did.json file on your domain to enable verification of your digital signatures.
Overview
This file associates your domain with a Decentralized Identifier (DID) and provides the necessary cryptographic keys for signature validation. To make digital signatures verifiable, the domain used for your DID and certificate issuance must host a .well-known/did.json file.
What is a DID Document?
A DID (Decentralized Identifier) document is a JSON-LD document that contains cryptographic keys and other metadata associated with a decentralized identifier. In the context of did:web, it enables domain-based identity verification.
Prerequisites
Before starting, ensure you have:
- Your X.509 certificate in .p12 format
- OpenSSL installed on your system
- Node.js and npm (for the key conversion script)
- Access to your domain's web server
Step-by-Step Setup
Step 1: Convert .p12 to .pem Certificate
Convert the .p12 file to a .pem format using OpenSSL to extract the certificate (which contains the public key):
Code(bash)
Replace your_cert.p12 with the path to your .p12 file. The cert.pem file will contain the certificate with the public key.
Step 2: Extract the Public Key
Extract the public key from your certificate:
Code(bash)
This command creates a pubkey.pem file containing just the public key in PEM format.
Step 3: Convert the Public Key to JSON Format
The extracted key must be structured in JSON Web Key (JWK) format to be compatible with did.json. The required format is:
Code(json)
Using Node.js Script
Create a Node.js script to convert the PEM key to JWK format:
Code(javascript)
Installation and Execution:
Code(bash)
Alternative: Using Python
If you prefer Python, you can use the following script:
Code(python)
Step 4: Generate the .well-known/did.json File
Using the extracted values, construct your .well-known/did.json file:
Code(json)
Important Replacements:
- Replace
yourdomain.comwith your actual domain - Replace
your_cert_x_componentandyour_cert_y_componentwith the actual values from your certificate
Step 5: Deploy the .well-known/did.json File
To enable cryptographic verification of your metadata signatures, upload the .well-known/did.json file to the root of your domain at:
Code
Deployment Options
Web Server
Place the file in your web server's document root under the .well-known/ directory.
CDN/Static Hosting
Upload to your CDN or static hosting service ensuring proper MIME type (application/json).
Verification
After deployment, verify your setup by:
- Accessibility Check: Visit
https://yourdomain.com/.well-known/did.jsonin your browser - JSON Validation: Ensure the response is valid JSON
- CORS Headers: Verify that appropriate CORS headers are set if needed
- HTTPS: Confirm the file is served over HTTPS
Testing Your DID Document
You can test your DID document using curl:
Code(bash)
Expected response should be your DID document with proper JSON formatting.
Security Considerations
Critical Security Points:
- Never include private keys in the DID document
- Ensure the
.well-known/did.jsonfile is served over HTTPS
Next Steps
Once your .well-known/did.json file is properly deployed and accessible:
Certificate Signature Creation - Learn how to sign metadata
This ensures that external verifiers can retrieve and validate your DID document, allowing trusted verification of digital signatures associated with your declarations.