Giter VIP home page Giter VIP logo

nft-authorization's Introduction

SNIP-721 nft-authorization

This contract is a reference implementation using Baedrik's SNIP-721 implementation as a framework, for web3 authentication by proving the ownership of the NFT via a public-private key pair.

The complimentary keys are stored in the extenision field of public and privite metadata respectively. Therefore, this implementation of the SNIP-721 does not allow minting NFTs with no metadata nor using token_uri. The public/private key is stored in the auth_key: Option<[u8; 32]> field of the Extension struct for public/private metadata.

Some changes have been made to the unit tests to ensure they pass. This includes addition of autherization keys to the metadata even before the autherization keys are generated in the contract.

Changes to HandleMessages

No changes were made to query messsages or the init message. Only a few changes were made to the handle messages. A new optional entropy: Option<String> field was added to MintNft, BatchMintNft, and MintNftClones handle messages to add randomness to the prng seed used for key generation.

The only caveat is that Minting with no metadata or with no extenision field causes the program to create a default metadata with all fields inside its extension struct set to None except for auth_key which is generated upon minting.

A new handle message was added called GenerateAuthenticationKeys. This handle message is used to generate a new pair of public/private keys on demand and remove the previous keypair. The owner and the admin can use this, the minter can also use this if minter_may_update_metadata: true in the config.

GenerateAuthenticationKeys {
        token_id: String,
        entropy: Option<String>,
    },

New Functions to understand

The most important new function to understand is metadata_generate_keypair_impl() in contract.rs

pub fn metadata_generate_keypair_impl<S: Storage, A: Api, Q: Querier>(
    deps: &mut Extern<S, A, Q>,
    env: &Env,
    entropy: Option<String>,
    idx: u32,
) -> HandleResult {...

This function takes some optional entropy provided by the user and the NFT's index value, it then generates a new keypair to saves into the metadata of the specified token. The rest of the funtions added are helpers to this function.

nft-authorization's People

Contributors

srdtrk avatar luminaryphi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.