Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Oct 11, 2024
1 parent 1e3369c commit 1cd70b4
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 379 deletions.
15 changes: 15 additions & 0 deletions .prettierrc
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
}
}
]
}
18 changes: 9 additions & 9 deletions script/Counter.s.sol
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();
}
}
14 changes: 7 additions & 7 deletions src/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity ^0.8.13;

contract Counter {
uint256 public number;
uint256 public number;

function setNumber(uint256 newNumber) public {
number = newNumber;
}
function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
}
function increment() public {
number++;
}
}
20 changes: 0 additions & 20 deletions src/Interfaces.sol

This file was deleted.

138 changes: 67 additions & 71 deletions src/stamps/AccountOwnershipStamp.sol
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];
}
}
Loading

0 comments on commit 1cd70b4

Please sign in to comment.