Sample Implementation of User-Mintable Privacy-Enabled NFTs
This repo is a sample implemtation of user-mintable, privacy-enabled NFTs showing the mint process using an on-chain anchor registry as backing for document verification.
The General Idea
The goals of a user-mintable, privacy-enabled NFT are
- Mint an NFT that represents an off-chain asset consisting of structured data
- Allow anyone to mint the NFT who can provide a proof that they should be allowed to mint this NFT
- Proofs are validate on-chain against an "anchor registry" that holds the merkle root hash of the off-chain document
- Thus turning off-chain assets into on-chain assets, represented as an ERC-721 token
The ERC-721 registry exposes a
mint method that allows anyone to mint an NFT, provided they can supply a proof that they should be allowed to do so. Specifically, the registry allows minting NFTs for off-chain datasets/assets utilizing merkle proofs that are supplied to the
mint method is called with plaintext fields and their corresponding proofs. The NFT registry checks the validity of the data & merkle proof against an on-chain anchor registry. The anchor registry contains a mapping of document identifier to the merkle root of the respective document (the off-chain asset). If the merkle proof that was supplied to the mint method validates correctly, the NFT registry mints the token that represents the off-chain asset.
The sample implementation utilizes the precise-proofs library to generate merkle trees and proofs for structured off-chain data.
precise-proofs supports multiple hashing algorithms. This NFT implementation uses keccak256 as the hashing algorithm for the merkle tree/proof generation.
Please read the paper on User-Mintable, Privacy-Enabled NFTs for more background on the on-chain and off-chain components and the minting process.
This sample implementation is a truffle project.
The easiest starting point is look at the the ERC721Document implementation of the mint method. It accepts clear text values, verifies the merkle proof, and proceeds on to minting the NFT is all checks pass.
Start by installing dependencies via
To run the tests in one go with ganache starting up in the same terminal (messier output and slower when running tests multiple times):
npm run test:withganache
Alternatively, run ganache in one terminal
npm run ganache-cli
And run the tests in second terminal
npm run test
If you are using reflex you can run the tests whenever a file changes.
reflex -r "\.test\.js|\.sol" -R "node_modules" -- npm run test