IdentityBound Token is a Solidity smart contract that implements non-transferable tokens representing a unique identity. The contract allows for the creation, deletion, and updating of identity tokens, as well as the creation, deletion, and retrieval of user data associated with each token.
To install the required dependencies, run:
npm install
To compile the contracts, run:
npx hardhat compile
To run the tests, run:
npx hardhat test
To deploy the contracts to a local Hardhat network, run:
npx hardhat node
In a separate terminal, run:
npx hardhat run --network localhost scripts/deploy.js
This will deploy the contract to the local network and output the contract address.
The IdentityBoundToken
contract defines a struct called IdentityInfo
, which contains the following fields:
receiverIdentity
: a string representing the identity of the token holderurl
: a string representing a URL associated with the identityidNum
: an integer representing an ID number associated with the identitytimestamp
: a timestamp representing the time when the identity information was last updated
The contract provides the following functions:
createToken
: creates a new identity token with the given identity dataremoveToken
: removes an existing identity tokenupdateIdentityData
: updates the identity data associated with an existing identityisIdentityExists
: checks if an identity existsgetIdentityData
: retrieves the identity data associated with an identity
The contract also defines a modifier called onlyIssuer
, which restricts access to certain functions to the issuer of the contract.
The IdentityBoundToken
contract is thoroughly tested using Hardhat's built-in testing framework and the chai
assertion library. The test file test/IdentityBoundToken.js
covers the following scenarios:
- Creating a new token with the given identity data
- Trying to create a new token for an existing identity
- Removing an existing token
- Trying to remove a token from a third-party account
- Updating the identity data associated with an existing token
- Trying to update the identity data for a non-existing token
The IdentityBoundToken
contract can be deployed to a local Hardhat network using the deployment script scripts/deploy.js
.
This project is licensed under the MIT License.