Description
openedon May 20, 2022
Issue To Be Solved
A generic proposal to apply commit reveal to NFT metadata. This approach is used for blind sale where we want to hide the metadata information and only then reveal it, using provenance hash to ensure that there was no manipulation in the metadata.
(Optional): Suggest A Solution
My suggestion is to create an interface with public access and apply it to the Collection, that way it would be possible for the administrator to access the NFT within the collection of a third party. Only the admin can use the interface because it requires Admin resource reference.
The interface receiving NFT Id, admin resource reference and the original metadata with all information
pub resource interface IRevealNFT {
pub fun revealNFT(id: UInt64, admin: &Admin, metadata: {String: String})
}
The standard collection applying the IRevealNFT to call reveal function to a specific NFT
pub resource Collection: NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection, IRevealNFT {
....
pub fun revealNFT(id: UInt64, admin: &Admin, metadata: {String: String}) {
if self.ownedNFTs[id] != nil {
let nft = &self.ownedNFTs[id] as auth &NonFungibleToken.NFT
let storeFrontNFT = nft as! &NFT
storeFrontNFT.reveal(metadata: metadata)
} else {
panic("can't find nft id")
}
}
....
}
The HashMetadata struct to save the hash from a specific range of NFTs, considering that we can have multiples hash from one collection/drop
pub struct HashMetadata {
pub let hash: String
pub let start: UInt64
pub let end: UInt64
init(hash: String, start: UInt64, end: UInt64) {
self.hash = hash
self.start = start
self.end = end
}
}
The NFT resource with reveal function where it update the metadata field - just add here to exemplify, it is not part of suggestion
pub resource NFT: NonFungibleToken.INFT, MetadataViews.Resolver {
pub let id: UInt64
access(contract) var metadata: {String: String}
pub let hashMetadata: HashMetadata
....
access(account) fun reveal(metadata: {String: String}) {
self.metadata = metadata
}
....
}