A simple JWT integration with NFTs (ERC721 standard)
- Install Ganache
npm install
(inside ./Chain)truffle compile --all
(inside ./Chain)truffle deploy
(inside ./Chain)mint
to mint NFTs to any addresssetBits
to update an NFT's bits
let nftContract = await NFTContract.deployed()
await nftContract.mint('some address', some bit value)
await nftContract.setBits(nft id, new bits value)
- Update ChainInfo data to match local chain or remote chain
- Assign any private key
~/challenge
request a challenge to sign.
{
"account":"0x4B4AABaf30921059e3baD5Ab10f8d19d88cccC60",
"nftId": 0
}
{
"message": "0x4B4AABaf30921059e3baD5Ab10f8d19d88cccC60 owns 0 with nonce 1367492758"
}
~/login
submits a signature to login. The response includes the bits of that nft representing whatever access it should have.
{
"account":"0x4B4AABaf30921059e3baD5Ab10f8d19d88cccC60",
"nftId": 0,
"signature": "cf0f0099d24e12dd41213856562cac4928f6eaac4c98bce6b99e05ce7dfedb495cd243ca401dd899a7494c1443bb4a102ad92fbb8c310fbc0a06919126e921ed1c"
}
{
"account": "0x4B4AABaf30921059e3baD5Ab10f8d19d88cccC60",
"nftId": 0,
"bits": 3,
"token": "a jwt token"
}
~/test
a get request which includes Authorization header having the jwt token. The response is a blank 200 ok code but BE would have access to the account, nft and bits.
The account ownership of the NFT and the bits are compared against the chain.
A future enhancement would be to implement caching and a scraper that follows the contract on chain to clear cache when need be.
You can sign using My Ether Wallet
- 2023-12-12: Initial release v1.0.0
This implementation was made for educational / training purposes only.
License is MIT
Birbia is coming