npx hardhat compile
npx hardhat coverage
Using the gas reporter:
REPORT_GAS=true npx hardhat test
Running the tests in parallel
npx hardhat test --parallel
npx hardhat compile
You can deploy in the localhost
network following these steps:
- Start a local node
npx hardhat node
- Deploy the Ignition module
npx hardhat ignition deploy ./ignition/modules/CredentialRegistry.ts --network localhost
- Run an interact script
npm run interact
This runs the script in scripts/interact.ts
which has an example code on how the register and verify methods work.
When you deploy to a testnet or mainnet, you probably want to verify the contract at the same time for which you can do:
npx hardhat ignition deploy ignition/modules/CredentialRegistry.ts --network base_sepolia --deployment-id base_sepolia_deployment --verify
npx hardhat accounts
- CredentialMetadata Struct: Holds information about a registered credential.
- Mappings: Stores issuer-to-credential IDs, recipient DID-to-credential IDs, credential type-to-credential IDs, and issued/received credential counts.
- registerCredential Function:
- Checks if the credential ID is already registered.
- Stores the credential metadata.
- Updates issuer, recipient, and type-based mappings.
- Emits a CredentialRegistered event.
- Getter Functions:
- getCredentialsByIssuer: Retrieves credentials issued by a specific address.
- getCredentialsByRecipient: Retrieves credentials associated with a recipient DID.
- getCredentialsByType: Retrieves credentials of a specific type.
- verifyCredential Function:
- Checks if the credential ID exists.
- Uses verifyEvmDid for Ethereum-based DIDs (optional for other DID methods).
- Emits a CredentialVerified event if the signature is valid.
- verifyEvmDid Function:
- Extracts the address from the DID (assuming Ethereum DID format).
- Calculates the message hash as expected by the contract (including the Ethereum Signed Message prefix).
- Recovers the signer's address using ecrecover.
- Compares the recovered address with the recipient address and returns it if valid.