EIP-712 verification of Verifiable Credentials issued by https://github.com/spruceid/didkit
This is a simple example of how Verifiable Credentials can be verified on-chain.
It is based on the EIP-712 standard for typed structured data hashing and signing and Ethereum EIP712 Signature 2021.
yarn ts-node utils/didkitSign.ts
this will sign and generate types for a Verifiable Credential using DIDKit
DIDStampVCVerifier - On chain verification that the signer of the provided credential is the issuer. Test - Verify that signed credential is valid and signed by issuer
Before running any command, you need to create a .env
file and set a BIP-39 compatible mnemonic or a private key as an environment
variable. Follow the example in .env.example
. If you don't already have a mnemonic, use this website to generate one.
Then, proceed with installing dependencies:
$ yarn install
Populate .env
file with at least INFURA_API_KEY
- The proof object is based on Ethereum EIP712 Signature 2021.
- "@" is not a valid character in a variable name in Solidity, hence why the
@context
and@type
properties are renamed_context
and_type
respectively. - The
did:pkh
method is used which allows us to turn the Ethereum address of the VC issuer / signer into a valid DID. The inverse of this "process" is done on-chain by the pseudo-resolver inDIDpkhAdapter.sol
.
Then, the content of the whole VC (minus the proof object) and the signature attached to it is verified on-chain against the Ethereum address in issuer
. This is done by calling verifyStampVc()
. If the verification is successful you should see:
- Create an example of a VC as voucher that can be redeemed against something such as ERC20 tokens or 721 tokens
- Generalize the implementation so that an on-chain VC verifier is not tightly coupled to a specific VC schema
Compile the smart contracts with Hardhat:
$ yarn compile
Compile the smart contracts and generate TypeChain artifacts:
$ yarn typechain
Lint the Solidity code:
$ yarn lint:sol
Lint the TypeScript code:
$ yarn lint:ts
Run the Mocha tests:
$ yarn test
Generate the code coverage report:
$ yarn coverage
See the gas usage per unit test and average gas per method call:
$ REPORT_GAS=true yarn test
Delete the smart contract artifacts, the coverage reports and the Hardhat cache:
$ yarn clean
If you use VSCode, you can get Solidity syntax highlighting via the vscode-solidity extension.