Skip to content

Commit

Permalink
repurpose MintAuthorizer to allow signed metadata amendments
Browse files Browse the repository at this point in the history
Signed-off-by: stadolf <[email protected]>
  • Loading branch information
elmariachi111 committed Sep 24, 2024
1 parent b115841 commit d10adb8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/IPNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
emit ReadAccessGranted(tokenId, reader, until);
}

function amendMetadata(uint256 tokenId, string calldata _newTokenURI, bytes calldata authorization) external {
if (ownerOf(tokenId) != _msgSender()) {
revert Unauthorized();
}

if (!mintAuthorizer.authorizeMint(_msgSender(), _msgSender(), abi.encode(SignedMintAuthorization(tokenId, _newTokenURI, authorization)))) {
revert Unauthorized();
}

_setTokenURI(tokenId, _newTokenURI);
}

/**
* @notice check whether `reader` currently is able to access gated content behind `tokenId`
* @param reader the address in question
Expand All @@ -177,6 +189,7 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
require(success, "transfer failed");
}


/// @inheritdoc UUPSUpgradeable
function _authorizeUpgrade(address /*newImplementation*/ )
internal
Expand Down
22 changes: 22 additions & 0 deletions test/IPNFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract IPNFTTest is IPNFTMintHelper {
event IPNFTMinted(address indexed owner, uint256 indexed tokenId, string tokenURI, string symbol);
event SymbolUpdated(uint256 indexed tokenId, string symbol);
event ReadAccessGranted(uint256 indexed tokenId, address indexed reader, uint256 until);
event MetadataUpdate(uint256 tokenId);

IPNFT internal ipnft;

Expand Down Expand Up @@ -216,4 +217,25 @@ contract IPNFTTest is IPNFTMintHelper {
vm.warp(block.timestamp + 60);
assertFalse(ipnft.canRead(bob, tokenId));
}

function testOwnerCanAmendMetadataAfterSignoff() public {
mintAToken(ipnft, alice);

vm.startPrank(deployer);
ipnft.setAuthorizer(new SignedMintAuthorizer(deployer));
vm.stopPrank();

bytes32 authMessageHash = ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(alice, alice, uint256(1), "ipfs://QmNewUri")));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(deployerPk, authMessageHash);
bytes memory authorization = abi.encodePacked(r, s, v);

vm.startPrank(alice);
vm.expectEmit(true, true, false, false);
emit MetadataUpdate(1);
ipnft.amendMetadata(1, "ipfs://QmNewUri", authorization);
assertEq(ipnft.tokenURI(1), "ipfs://QmNewUri");
vm.stopPrank();
}


}

0 comments on commit d10adb8

Please sign in to comment.