A PHP library for DID (Decentralized Identifier) management and WordPress plugin/theme metadata generation, implementing the FAIR (Federated Asset Integrity Registry) protocol.
- DID Management: Create, update, rotate keys, and deactivate DIDs using the PLC directory
- Key Generation: Generate secp256k1 (rotation) and Ed25519 (verification) key pairs
- Key Export: Export keys in JSON, text, or environment variable formats
- Local Key Storage: Securely store and manage DIDs and their associated keys
- WordPress Integration: Parse plugin/theme headers and readme.txt files
- Metadata Generation: Generate FAIR-compliant metadata.json files
- PHP 8.3 or higher
- Composer
- Extensions:
curl,json
git clone https://github.com/fairpm/did-manager.git
cd did-manager
composer install<?php
require_once 'vendor/autoload.php';
use FairDidManager\Crypto\DidCodec;
use FairDidManager\Storage\KeyStore;
use FairDidManager\Plc\PlcClient;
use FairDidManager\Did\FairDidManager;
// Initialize components
$store = new KeyStore('keys.json');
$client = new PlcClient();
$manager = new FairDidManager($store, $client);
// Create a new DID
$result = $manager->create_did('my-plugin-handle');
echo "Created DID: " . $result['did'];did-manager/
├── src/
│ ├── crypto/ # Cryptographic utilities
│ │ ├── class-did-codec.php
│ │ └── class-canonical-map-object.php
│ ├── did/ # DID lifecycle management
│ │ └── class-fair-did-manager.php
│ ├── keys/ # Key interfaces and implementations
│ │ ├── class-key.php
│ │ ├── class-ec-key.php
│ │ ├── class-ed-dsa-key.php
│ │ ├── class-key-exporter.php
│ │ └── class-key-factory.php
│ ├── parsers/ # WordPress metadata parsing
│ │ ├── class-plugin-header-parser.php
│ │ ├── class-readme-parser.php
│ │ └── class-metadata-generator.php
│ ├── plc/ # PLC directory interaction
│ │ ├── class-plc-client.php
│ │ └── class-plc-operation.php
│ └── storage/ # Local key storage
│ └── class-key-store.php
├── tests/ # PHPUnit tests (200+ tests)
├── examples/ # Usage examples
├── composer.json
├── phpunit.xml
└── fair-did.json # Package DID configuration
| Namespace | Description |
|---|---|
FairDidManager\Keys |
Key interface and implementations (EcKey, EdDsaKey, KeyFactory, KeyExporter) |
FairDidManager\Crypto |
Cryptographic utilities (DidCodec, CanonicalMapObject) |
FairDidManager\Plc |
PLC directory interaction (PlcOperation, PlcClient) |
FairDidManager\Storage |
Local storage (KeyStore) |
FairDidManager\Parsers |
WordPress metadata parsing (PluginHeaderParser, ReadmeParser, MetadataGenerator) |
FairDidManager\Did |
DID lifecycle management (FairDidManager) |
See the examples/ directory for detailed usage examples:
01-generate-keys.php- Key generation and signing02-plc-operations.php- PLC operations and DID generation03-key-storage.php- Local key storage management04-parse-plugin-headers.php- WordPress header parsing05-generate-metadata.php- FAIR metadata generation06-export-keys.php- Export keys in various formats
Run an example:
php examples/01-generate-keys.phpuse FairDidManager\Crypto\DidCodec;
// Generate secp256k1 key pair (for rotation keys)
$rotationKey = DidCodec::generate_key_pair();
// Generate Ed25519 key pair (for verification keys)
$verificationKey = DidCodec::generate_ed25519_key_pair();
// Sign data
$signature = $rotationKey->sign(hash('sha256', $data, false));use FairDidManager\Keys\EcKey;
$key = EcKey::generate();
// Export as JSON (default)
echo $key->export();
// Export with private key included
echo $key->export(null, true);
// Export as human-readable text
echo $key->export(null, true, 'text');
// Export as environment variables
echo $key->export(null, true, 'env');
// Save to file
$key->export('/path/to/key.json', true, 'json');
// Get as array for programmatic use
$data = $key->to_array(true);use FairDidManager\Crypto\DidCodec;
// Create a PLC operation
$operation = DidCodec::create_plc_operation(
$rotationKey,
$verificationKey,
'my-handle',
'https://api.example.com'
);
// Sign the operation
$signedOperation = DidCodec::sign_plc_operation($operation, $rotationKey);
// Generate the DID
$did = DidCodec::generate_plc_did($signedOperation);use FairDidManager\Storage\KeyStore;
$store = new KeyStore('keys.json');
// Store a DID with keys
$store->store_did(
$did,
$rotationKey->encode_private(),
$rotationKey->encode_public(),
$verificationKey->encode_private(),
$verificationKey->encode_public(),
'plugin',
['name' => 'My Plugin']
);
// Retrieve keys
$rotationPrivate = $store->get_rotation_key($did);use FairDidManager\Parsers\PluginHeaderParser;
use FairDidManager\Parsers\ReadmeParser;
use FairDidManager\Parsers\MetadataGenerator;
// Parse plugin header
$headerParser = new PluginHeaderParser();
$headerData = $headerParser->parse_file('/path/to/plugin.php');
// Parse readme.txt
$readmeParser = new ReadmeParser();
$readmeData = $readmeParser->parse_file('/path/to/readme.txt');
// Generate FAIR metadata
$generator = new MetadataGenerator($headerData, $readmeData);
$generator->set_did($did);
$metadata = $generator->generate();Run the test suite:
composer testRun with coverage:
composer test -- --coverage-html coverageLint the code:
composer lintFix coding standards:
composer lint:fix- simplito/elliptic-php - Elliptic curve cryptography
- spomky-labs/cbor-php - CBOR encoding for DAG-CBOR
- yocto/yoclib-multibase - Multibase encoding
- Private keys are stored locally in JSON files (e.g.,
keys.json) - The
.gitignorefile excludes common key storage patterns - Always back up your keys securely
MIT License - see LICENSE for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request