Skip to content

humuhimi/did-ethr-experiment

Repository files navigation

DID Ethr Experiment Project

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:


🚀 Features

  • 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.

🛠️ Setup

1. Clone the Repository

git clone <repository-url>
cd did-ethr-experiment

2. Install Dependencies

npm install

3. Install and Start Ganache (GUI Application)

  1. Download the Ganache GUI Application from the official Truffle Suite website:
    Ganache Downloads
  2. Install the application following the instructions for your operating system.
  3. Open Ganache and create a new workspace or use the default settings.
  4. Start the local Ethereum blockchain network by clicking the "Start" button in the Ganache interface.

4. Configure the .env File

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 and ACCOUNT_2_PRIVATE_KEY: Private keys of the issuer and holder accounts (available in the Ganache UI).
  • ETHR_DID_CONTRACT_ADDRESS: Contract addresses after deployment.

📜 Deploying the EthereumDIDRegistry Contract

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 the ETHR_DID_CONTRACT_ADDRESS.

🔄 Executing the Use Case

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

Use Case Flow

  1. 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.
  2. 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).
  3. Resolving the DID Document:

    • Use the resolveDid function to retrieve the holder's DID document.
  4. Verifying the VC:

    • Use the verifyVc function to validate the issued VC.

🔍 Example Output

Issuer DID: did:ethr:0x123...
Holder DID: did:ethr:0x456...
VC: eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...
DID Document: { ... }
VC verification result: { ... }

🛠️ Additional Commands

List All Available Hardhat Tasks

npx hardhat help

Start a Local Hardhat Node

npx hardhat node

Deploy the Lock Contract

npx hardhat ignition deploy ./ignition/modules/Lock.ts

❓ Troubleshooting

If you encounter issues with the integration between Hardhat and Ganache, refer to the following resources for guidance: Hardhat and Ganache Integration Troubleshooting


✨ Enhancements

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! 🚀

About

experiment repository for Ethereum and did

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published