This project demonstrates a basic use case of using Hardhat to register and manage DIDs (Decentralized Identifiers) on Ethereum. It includes deploying the EthereumDIDRegistry contract, registering DIDs, issuing Verifiable Credentials (VCs), and verifying them.
This project utilizes the following libraries and frameworks to support Ethereum DID functionalities:
- uport-project/ethr-did: Provides DID methods for Ethereum.
- uport-project/ethr-did-registry: Ethereum smart contract for registering DIDs.
- decentralized-identity/ethr-did-resolver: Resolves Ethereum-based DIDs to their associated documents.
- Register DIDs: Create and manage decentralized identifiers on Ethereum.
- Issue Verifiable Credentials (VCs): Generate and assign credentials to holders.
- Verify Credentials: Ensure the validity of issued credentials.
- DID Document Resolution: Retrieve DID documents for holders.
git clone <repository-url>
cd did-ethr-experiment
npm install
- Download the Ganache GUI Application from the official Truffle Suite website:
Ganache Downloads - Install the application following the instructions for your operating system.
- Open Ganache and create a new workspace or use the default settings.
- Start the local Ethereum blockchain network by clicking the "Start" button in the Ganache interface.
Create a .env
file in the root directory of your project and add the following configuration:
RPC_URL=http://127.0.0.1:8545
CHAIN_ID=1337
ACCOUNT_PRIVATE_KEY=<private_key_for_issuer>
ACCOUNT_2_PRIVATE_KEY=<private_key_for_holder>
ETHR_DID_CONTRACT_ADDRESS=<deployed_ethereum_did_registry_address>
Replace the placeholder values (<...>
) with the appropriate information:
ACCOUNT_PRIVATE_KEY
andACCOUNT_2_PRIVATE_KEY
: Private keys of the issuer and holder accounts (available in the Ganache UI).ETHR_DID_CONTRACT_ADDRESS
: Contract addresses after deployment.
Deploy the EthereumDIDRegistry
contract on the Ganache network:
npx hardhat ignition deploy ./ignition/modules/EthereumDIDRegistry.ts --network localganache
- Once the deployment is successful, note the contract address.
- Update the
.env
file with theETHR_DID_CONTRACT_ADDRESS
.
The usecase.js
script demonstrates the entire flow, including registering DIDs, issuing VCs, and verifying them. Run the script with:
npx hardhat run ./usecase.js
-
Registering DIDs:
- Use the
registerPublicKey
function to register issuer and holder DIDs. - Private keys for the accounts should already be set in the
.env
file.
- Use the
-
Issuing a Verifiable Credential (VC):
- Use the
issueVc
function to issue a credential from the issuer to the holder. - Example VC content: degree type (e.g., Bachelor), degree name (e.g., Computer Science).
- Use the
-
Resolving the DID Document:
- Use the
resolveDid
function to retrieve the holder's DID document.
- Use the
-
Verifying the VC:
- Use the
verifyVc
function to validate the issued VC.
- Use the
Issuer DID: did:ethr:0x123...
Holder DID: did:ethr:0x456...
VC: eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...
DID Document: { ... }
VC verification result: { ... }
npx hardhat help
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.ts
If you encounter issues with the integration between Hardhat and Ganache, refer to the following resources for guidance: Hardhat and Ganache Integration Troubleshooting
Feel free to enhance this documentation further by:
- Adding detailed explanations for each step.
- Including screenshots or code snippets.
- Providing additional troubleshooting tips.
Happy experimenting with Ethereum DIDs! 🚀