Skip to content

Commit

Permalink
contracts: create account ownership implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Oct 11, 2024
1 parent 4158302 commit 8d0a5fa
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
58 changes: 58 additions & 0 deletions src/stamps/AccountOwnershipStamp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./Stamp.sol";

contract AccountOwnershipStamp is Stamp {
string public PLATFORM;

error InvalidRecipient();

constructor(
address _signer,
string memory _platform
) Stamp("Account Ownership Stamp", "AOS", "0.1.0", _signer) {
PLATFORM = _platform;
}

function mintStamp(
string calldata id,
uint256 deadline,
bytes calldata signature
) external returns (uint256) {
if (msg.sender == address(0)) revert InvalidRecipient();

bytes memory encodedData = abi.encode(
PLATFORM,
id,
msg.sender,
deadline
);

return _mintStamp(msg.sender, encodedData, signature, deadline);
}

function getTypedDataHash(
bytes memory data
) public pure override returns (bytes32) {
(
string memory platform,
string memory id,
address recipient,
uint256 deadline
) = abi.decode(data, (string, string, address, uint256));

return
keccak256(
abi.encode(
keccak256(
"AccountOwnership(string platform,string id,address recipient,uint256 deadline)"
),
keccak256(bytes(platform)),
keccak256(bytes(id)),
recipient,
deadline
)
);
}
}
20 changes: 14 additions & 6 deletions src/stamps/Stamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ abstract contract Stamp is ERC721Enumerable, EIP712 {
error AlreadyMintedStamp(address user, uint256 stampId);
// New custom error for invalid signature
error InvalidSignature();
// New custom error for expired deadline
error DeadlineExpired(uint256 deadline, uint256 currentTimestamp);

// Internal minting function
// Modified internal minting function
function _mintStamp(
address to,
bytes calldata data,
bytes calldata signature
bytes memory data,
bytes calldata signature,
uint256 deadline
) internal virtual returns (uint256) {
if (!_verify(data, signature)) {
// Check if the deadline has passed
if (block.timestamp > deadline) {
revert DeadlineExpired(deadline, block.timestamp);
}

if (!_verifySignature(data, signature)) {
revert InvalidSignature();
}

Expand All @@ -51,8 +59,8 @@ abstract contract Stamp is ERC721Enumerable, EIP712 {
}

// Signature verification
function _verify(
bytes calldata data,
function _verifySignature(
bytes memory data,
bytes calldata signature
) internal view returns (bool) {
return
Expand Down

0 comments on commit 8d0a5fa

Please sign in to comment.