Skip to content

Commit 88368b7

Browse files
committed
compute the tokenId from poi hash and reuse the authoriseMint function
1 parent 0070789 commit 88368b7

File tree

3 files changed

+35
-47
lines changed

3 files changed

+35
-47
lines changed

src/IAuthorizeMints.sol

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ struct SignedMintAuthorization {
88
bytes authorization;
99
}
1010

11-
struct SignedPoiAuthorization {
12-
string poi;
13-
string tokenURI;
14-
address to;
15-
bytes authorization;
16-
}
17-
1811
/// @title IAuthorizeMints
1912
/// @author molecule.to
2013
/// @notice a flexible interface to gate token mint calls on another contract, built for IP-NFTs
@@ -29,7 +22,4 @@ interface IAuthorizeMints {
2922
/// @notice called by the gated token contract to signal that a token has been minted and an authorization can be invalidated
3023
/// @param data implementation specific data
3124
function redeem(bytes memory data) external;
32-
33-
/// @notice checks whether the poi is owned by address to by verifying the trustee's signature
34-
function verifyPoi(bytes memory signedAuthorization) external view returns (bool);
3525
}

src/IPNFT.sol

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/O
88
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
99
import { CountersUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
1010
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
11-
import { IAuthorizeMints, SignedMintAuthorization, SignedPoiAuthorization } from "./IAuthorizeMints.sol";
11+
import { IAuthorizeMints, SignedMintAuthorization } from "./IAuthorizeMints.sol";
1212
import { IReservable } from "./IReservable.sol";
1313

1414
/*
@@ -102,6 +102,39 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
102102
emit Reserved(_msgSender(), reservationId);
103103
}
104104

105+
/**
106+
* @notice mints an IPNFT with `tokenURI` as source of metadata. This IPNFT is linked a proof of idea (POI) which is a hash of any collection of files that represents an idea, anchored on any chain.
107+
* @notice We are charging a nominal fee to symbolically represent the transfer of ownership rights, for a price of .001 ETH (<$2USD at current prices). This helps ensure the protocol is affordable to almost all projects, but discourages frivolous IP-NFT minting.
108+
*
109+
* @param to the recipient of the NFT
110+
* @param poi the hash of the poi that will be computed to the tokenId
111+
* @param _tokenURI a location that resolves to a valid IP-NFT metadata structure
112+
* @param _symbol a symbol that represents the IPNFT's derivatives. Can be changed by the owner
113+
* @param authorization a bytes encoded parameter that ensures that the poi is owned by the owner (to param)
114+
* @return computedTokenId
115+
*/
116+
function mintWithPOI(address to, bytes calldata poi, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization)
117+
external
118+
payable
119+
whenNotPaused
120+
returns (uint256)
121+
{
122+
uint256 computedTokenId = uint256(keccak256(poi));
123+
if (msg.value < SYMBOLIC_MINT_FEE) {
124+
revert MintingFeeTooLow();
125+
}
126+
127+
if (!mintAuthorizer.authorizeMint(_msgSender(), to, abi.encode(SignedMintAuthorization(computedTokenId, _tokenURI, authorization)))) {
128+
revert Unauthorized();
129+
}
130+
131+
mintAuthorizer.redeem(authorization);
132+
_mint(to, computedTokenId);
133+
_setTokenURI(computedTokenId, _tokenURI);
134+
emit IPNFTMinted(to, computedTokenId, _tokenURI, _symbol);
135+
return computedTokenId;
136+
}
137+
105138
/**
106139
* @notice mints an IPNFT with `tokenURI` as source of metadata. Invalidates the reservation. Redeems `mintpassId` on the authorizer contract
107140
* @notice We are charging a nominal fee to symbolically represent the transfer of ownership rights, for a price of .001 ETH (<$2USD at current prices). This helps ensure the protocol is affordable to almost all projects, but discourages frivolous IP-NFT minting.
@@ -142,31 +175,6 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
142175
return reservationId;
143176
}
144177

145-
/**
146-
* @notice mints an IPNFT with `tokenURI` as source of metadata. This IPNFT is linked a proof of idea (POI) which is a hash of any collection of files that represents an idea, anchored on any chain.
147-
* @notice We are charging a nominal fee to symbolically represent the transfer of ownership rights, for a price of .001 ETH (<$2USD at current prices). This helps ensure the protocol is affordable to almost all projects, but discourages frivolous IP-NFT minting.
148-
*
149-
* @param to the recipient of the NFT
150-
* @param _tokenURI a location that resolves to a valid IP-NFT metadata structure
151-
* @param _symbol a symbol that represents the IPNFT's derivatives. Can be changed by the owner
152-
* @param authorization a bytes encoded parameter that ensures that the poi is owned by the owner (to param)
153-
* @param poi the hash of the poi that will be the tokenId
154-
* @return reservationId the tokenId
155-
*/
156-
function mintWithPOI(
157-
address to,
158-
uint256 reservationId,
159-
string calldata _tokenURI,
160-
string calldata _symbol,
161-
bytes calldata authorization,
162-
string memory poi
163-
) external payable whenNotPaused returns (uint256) {
164-
if (!mintAuthorizer.verifyPoi(abi.encode(SignedPoiAuthorization(poi, _tokenURI, to, authorization)))) {
165-
revert Unauthorized();
166-
}
167-
return this.mintReservation(to, reservationId, _tokenURI, _symbol, authorization);
168-
}
169-
170178
/**
171179
* @notice grants time limited "read" access to gated resources
172180
* @param reader the address that should be able to access gated content

src/SignedMintAuthorizer.sol

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity 0.8.18;
33

44
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
55
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
6-
import { IAuthorizeMints, SignedMintAuthorization, SignedPoiAuthorization } from "./IAuthorizeMints.sol";
6+
import { IAuthorizeMints, SignedMintAuthorization } from "./IAuthorizeMints.sol";
77

88
/// @title SignedMintAuthorizer
99
/// @author molecule.to
@@ -36,16 +36,6 @@ contract SignedMintAuthorizer is IAuthorizeMints, Ownable {
3636
return trustedSigners[signer];
3737
}
3838

39-
function verifyPoi(bytes memory signedPoiAuthorization) external view override returns (bool) {
40-
SignedPoiAuthorization memory auth = abi.decode(signedPoiAuthorization, (SignedPoiAuthorization));
41-
42-
bytes32 signedHash = ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(auth.poi, auth.tokenURI, auth.to)));
43-
44-
(address signer,) = ECDSA.tryRecover(signedHash, auth.authorization);
45-
46-
return trustedSigners[signer];
47-
}
48-
4939
/// @inheritdoc IAuthorizeMints
5040
/// @dev this authorizer does not restrict reservations
5141
function authorizeReservation(address) external pure override returns (bool) {

0 commit comments

Comments
 (0)