Certificate Signature Creation
To ensure the declaration is verifiable, all metadata must be signed using a private key, which generates a cryptographic signature proving its authenticity. The X.509 certificate provides attribution, linking the signature to a verified identity and enabling trust in the declaration.
Overview
Certificate signatures in CommonsDB serve multiple purposes:
- Authentication: Proves the identity of the declarer
- Integrity: Ensures the metadata hasn't been tampered with
- Non-repudiation: Provides proof that the declaration was made by the certificate holder
Prerequisites
Before creating certificate signatures, ensure you have:
Required Components
- ✓ X.509 certificate (.p12 format)
- ✓ Certificate private key
- ✓ Node.js environment
- ✓ Structured public metadata
Setup Requirements
- ✓ Deployed .well-known/did.json
- ✓ Valid certificate chain
- ✓ JWT signing library
- ✓ Base64 encoding capabilities
The Signing Process
Step 1: Prepare Your Public Metadata
First, structure your public metadata according to CommonsDB requirements:
Code(javascript)
Metadata Requirements: Ensure your metadata includes all required fields as specified in the General Information guide. Missing required fields will cause signature validation to fail.
Step 2: Load Your Certificate
Load your X.509 certificate and extract the necessary components:
Code(javascript)
Step 3: Create the JWT Signature
Generate a JWT (JSON Web Token) signature using your private key:
Code(javascript)
Step 4: Complete Example Implementation
Here's a complete example that demonstrates the entire signing process:
Code(javascript)
Signature Verification
To verify that your signature is correctly formatted, you can decode the JWT header:
Code(javascript)
Expected header structure:
Code(json)
Security Best Practices
Security Considerations:
- Never log or expose private keys
- Use secure key storage solutions in production
- Implement proper error handling for signing failures
- Validate all input data before signing
- Use appropriate JWT expiration times
Key Management
-
Secure Storage
Store private keys in secure locations (HSM, key vaults, encrypted storage)
-
Access Control
Limit access to private keys to authorized systems only
-
Key Rotation
Regularly rotate certificates and update DID documents
-
Monitoring
Monitor certificate usage and detect unauthorized signing attempts
Common Issues and Solutions
| Issue | Cause | Solution |
|---|---|---|
| Invalid signature format | Incorrect algorithm or header | Ensure ES256 algorithm and proper x5c header |
| Certificate not found | Missing x5c in JWT header | Include base64-encoded certificate in header |
| Validation fails | Metadata missing required fields | Validate metadata structure before signing |
| Key mismatch | Private key doesn't match certificate | Verify key pair correspondence |
Integration with CommonsDB
Once you have your certificate signature, include it in your CommonsDB declaration:
Code(javascript)
Next Steps
After creating your certificate signature:
- TSA Signature Creation - Add timestamp signatures for temporal verification
- Test your signatures with the Declaration API
- Implement error handling for production use
- Monitor certificate expiration and plan for renewal
Your certificate signature is now ready for use with CommonsDB declarations, providing cryptographic proof of authenticity and integrity for your metadata.