From e7e80cbfd48300d52561efd8a2cd29990004c06a Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Thu, 2 May 2024 21:21:40 -0700 Subject: [PATCH] update NFTEE2.sol constructor, add NFTEE_BASE_URI to .env - replace verifyingAddress with baseUrl - in verifySignature, verifyingAddress is replaced by recipient --- .env.example | 1 + examples/chatGPT-nft-minter/ethL1/NFTEE2.sol | 14 ++++++-------- examples/chatGPT-nft-minter/main.go | 6 +++--- framework/framework.go | 3 +++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index bcc083a..c95b2c1 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,4 @@ export L1_PRIVKEY= export L1_RPC= export BUILDER_URL= export OPENAI_KEY= +export NFTEE_BASE_URI= diff --git a/examples/chatGPT-nft-minter/ethL1/NFTEE2.sol b/examples/chatGPT-nft-minter/ethL1/NFTEE2.sol index 0eeab8f..4d981b6 100644 --- a/examples/chatGPT-nft-minter/ethL1/NFTEE2.sol +++ b/examples/chatGPT-nft-minter/ethL1/NFTEE2.sol @@ -9,7 +9,8 @@ import {LibString} from "solmate/utils/LibString.sol"; contract SuaveNFT is ERC721 { using LibString for uint256; - string private constant BASE_URI = "http://localhost:8080/metadata/"; + // string private constant BASE_URI = "http://localhost:8080/metadata/"; + string private baseUri; // Event declarations event NFTMintedEvent(address indexed recipient, uint256 indexed tokenId); @@ -22,9 +23,6 @@ contract SuaveNFT is ERC721 { // keccak256("Mint(string name,string symbol,uint256 tokenId,address recipient)"); bytes32 public constant MINT_TYPEHASH = 0x686aa0ee2a8dd75ace6f66b3a5e79d3dfd8e25e05a5e494bb85e72214ab37880; - // Authorized signer's address - address public authorizedSigner; - // token data mapping(uint256 => string) public tokenData; @@ -32,8 +30,8 @@ contract SuaveNFT is ERC721 { string public constant NAME = "SUAVE_NFT2"; string public constant SYMBOL = "NFTEE"; - constructor(address _authorizedSigner) ERC721(NAME, SYMBOL) { - authorizedSigner = _authorizedSigner; + constructor(string memory _baseUri) ERC721(NAME, SYMBOL) { + baseUri = _baseUri; } // Mint NFT with a signed EIP-712 message @@ -80,7 +78,7 @@ contract SuaveNFT is ERC721 { ); address recovered = ecrecover(digestHash, v, r, s); - return recovered == authorizedSigner; + return recovered == recipient; } function _exists(uint256 tokenId) internal view returns (bool) { @@ -91,6 +89,6 @@ contract SuaveNFT is ERC721 { /// but we're just using it to hold string data for NFTs. function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); - return string(abi.encodePacked(BASE_URI, tokenId.toString())); + return string(abi.encodePacked(baseUri, tokenId.toString())); } } diff --git a/examples/chatGPT-nft-minter/main.go b/examples/chatGPT-nft-minter/main.go index 65316f1..b01e841 100644 --- a/examples/chatGPT-nft-minter/main.go +++ b/examples/chatGPT-nft-minter/main.go @@ -93,14 +93,14 @@ func parseNFTLogs(chatNft *framework.Contract, receipt *types.Receipt) (*QueryRe return queryResult, nftCreated } -func deployEthNFTEE(ethClient *ethclient.Client, signerAddr common.Address, auth *bind.TransactOpts) (common.Address, common.Hash, *framework.Artifact) { +func deployEthNFTEE(ethClient *ethclient.Client, signerAddr common.Address, auth *bind.TransactOpts, baseURI string) (common.Address, common.Hash, *framework.Artifact) { artifact, err := framework.ReadArtifact("NFTEE2.sol/SuaveNFT.json") if err != nil { panic(err) } // Deploy contract with signer address as a constructor argument - _, tx, _, err := bind.DeployContract(auth, *artifact.Abi, artifact.Code, ethClient, signerAddr) + _, tx, _, err := bind.DeployContract(auth, *artifact.Abi, artifact.Code, ethClient, baseURI) if err != nil { log.Fatalf("Failed to deploy new contract: %v", err) } @@ -196,7 +196,7 @@ func main() { log.Printf("ChatNFT deployed on SUAVE (address=%s)", chatNft.Raw().Address()) // Deploy Ethereum L1 Contract - nfteeAddress, nfteeTxHash, nfteeArtifact := deployEthNFTEE(ethClient, privKey.Address(), auth) + nfteeAddress, nfteeTxHash, nfteeArtifact := deployEthNFTEE(ethClient, privKey.Address(), auth, cfg.NfteeBaseURI) log.Printf("NFTEE deployed on L1 (%s): %s\n", nfteeTxHash.Hex(), nfteeAddress.Hex()) // Create NFT on SUAVE (sign a message to approve a mint on L1) diff --git a/framework/framework.go b/framework/framework.go index ee69e2a..0b46e89 100644 --- a/framework/framework.go +++ b/framework/framework.go @@ -201,6 +201,9 @@ type Config struct { // OpenAI API key OpenAIKey string `env:"OPENAI_KEY"` + + NfteeBaseURI string `env:"NFTEE_BASE_URI, default=http://localhost:8080/metadata/"` + // TODO: change this =============================>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ to a public IPFS node } type ConfigOption func(c *Config)