-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e3369c
commit 1cd70b4
Showing
11 changed files
with
395 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"bracketSpacing": true, | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 100, | ||
"tabWidth": 4, | ||
"useTabs": true, | ||
"singleQuote": false, | ||
"bracketSpacing": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
import {Counter} from "../src/Counter.sol"; | ||
import { Script, console } from "forge-std/Script.sol"; | ||
import { Counter } from "../src/Counter.sol"; | ||
|
||
contract CounterScript is Script { | ||
Counter public counter; | ||
Counter public counter; | ||
|
||
function setUp() public {} | ||
function setUp() public {} | ||
|
||
function run() public { | ||
vm.startBroadcast(); | ||
function run() public { | ||
vm.startBroadcast(); | ||
|
||
counter = new Counter(); | ||
counter = new Counter(); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,84 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "./Stamp.sol"; | ||
import "./interfaces/IAccountOwnershipStamp.sol"; | ||
import { Stamp } from "./Stamp.sol"; | ||
import { IAccountOwnershipStamp } from "./interfaces/IAccountOwnershipStamp.sol"; | ||
|
||
/// @title AccountOwnershipStamp | ||
/// @notice A contract for minting and managing account ownership stamps on specific platforms | ||
/// @dev Inherits from Stamp and implements IAccountOwnershipStamp | ||
contract AccountOwnershipStamp is Stamp, IAccountOwnershipStamp { | ||
/// @inheritdoc IAccountOwnershipStamp | ||
string public override PLATFORM; | ||
/// @notice The platform this stamp is associated with (e.g., "Twitter", "GitHub") | ||
string public override PLATFORM; | ||
|
||
mapping(string username => uint256 stampId) private _usedUsernames; | ||
mapping(uint256 stampId => string username) private _tokenUsernames; | ||
/// @notice Mapping to track used usernames and their associated stamp IDs | ||
mapping(string username => uint256 stampId) private _usedUsernames; | ||
/// @notice Mapping to store usernames for each stamp ID | ||
mapping(uint256 stampId => string username) private _tokenUsernames; | ||
|
||
constructor( | ||
address _signer, | ||
string memory _platform | ||
) Stamp("Account Ownership Stamp", "AOS", "0.1.0", _signer) { | ||
PLATFORM = _platform; | ||
} | ||
/// @notice Initializes the contract with a signer and platform name | ||
/// @param _signer The address authorized to sign mint requests | ||
/// @param _platform The platform name for this stamp | ||
constructor( | ||
address _signer, | ||
string memory _platform | ||
) Stamp("Account Ownership Stamp", "AOS", "0.1.0", _signer) { | ||
PLATFORM = _platform; | ||
} | ||
|
||
/// @inheritdoc IAccountOwnershipStamp | ||
function mintStamp( | ||
string calldata username, | ||
uint256 deadline, | ||
bytes calldata signature | ||
) external override returns (uint256) { | ||
if (msg.sender == address(0)) revert InvalidRecipient(); | ||
if (_usedUsernames[username] != 0) | ||
revert UsernameAlreadyRegistered( | ||
username, | ||
_usedUsernames[username], | ||
msg.sender | ||
); | ||
/// @notice Mints a new stamp for a given username | ||
/// @dev Verifies the signature and ensures the username is not already registered | ||
/// @param username The username to mint the stamp for | ||
/// @param deadline The expiration timestamp for the signature | ||
/// @param signature The cryptographic signature authorizing the mint | ||
/// @return The ID of the newly minted stamp | ||
function mintStamp( | ||
string calldata username, | ||
uint256 deadline, | ||
bytes calldata signature | ||
) external override returns (uint256) { | ||
if (msg.sender == address(0)) revert InvalidRecipient(); | ||
if (_usedUsernames[username] != 0) | ||
revert UsernameAlreadyRegistered(username, _usedUsernames[username], msg.sender); | ||
|
||
bytes memory encodedData = abi.encode( | ||
PLATFORM, | ||
username, | ||
msg.sender, | ||
deadline | ||
); | ||
bytes memory encodedData = abi.encode(PLATFORM, username, msg.sender, deadline); | ||
|
||
uint256 tokenId = _mintStamp( | ||
msg.sender, | ||
encodedData, | ||
signature, | ||
deadline | ||
); | ||
uint256 tokenId = _mintStamp(msg.sender, encodedData, signature, deadline); | ||
|
||
_usedUsernames[username] = tokenId; | ||
_tokenUsernames[tokenId] = username; | ||
_usedUsernames[username] = tokenId; | ||
_tokenUsernames[tokenId] = username; | ||
|
||
emit AccountOwner(PLATFORM, username, tokenId, msg.sender); | ||
emit AccountOwner(PLATFORM, username, tokenId, msg.sender); | ||
|
||
return tokenId; | ||
} | ||
return tokenId; | ||
} | ||
|
||
/// @inheritdoc Stamp | ||
function getTypedDataHash( | ||
bytes memory data | ||
) internal pure override returns (bytes32) { | ||
( | ||
string memory platform, | ||
string memory id, | ||
address recipient, | ||
uint256 deadline | ||
) = abi.decode(data, (string, string, address, uint256)); | ||
/// @notice Generates a hash of the typed data for signature verification | ||
/// @dev Overrides the base Stamp contract's implementation | ||
/// @param data The encoded data containing platform, username, recipient, and deadline | ||
/// @return The keccak256 hash of the encoded data | ||
function getTypedDataHash(bytes memory data) internal 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 | ||
) | ||
); | ||
} | ||
return | ||
keccak256( | ||
abi.encode( | ||
keccak256( | ||
"AccountOwnership(string platform,string id,address recipient,uint256 deadline)" | ||
), | ||
keccak256(bytes(platform)), | ||
keccak256(bytes(id)), | ||
recipient, | ||
deadline | ||
) | ||
); | ||
} | ||
|
||
/// @notice Retrieves the username associated with a token ID | ||
/// @param tokenId The ID of the token | ||
/// @return The username associated with the token ID | ||
function getTokenId(uint256 tokenId) external view returns (string memory) { | ||
return _tokenUsernames[tokenId]; | ||
} | ||
/// @notice Retrieves the username associated with a token ID | ||
/// @param tokenId The ID of the token | ||
/// @return The username associated with the token ID | ||
function getTokenId(uint256 tokenId) external view returns (string memory) { | ||
return _tokenUsernames[tokenId]; | ||
} | ||
} |
Oops, something went wrong.