Commit 4e111b3f authored by Kegan's avatar Kegan
Browse files

finished cleaning the new SteamToEtherSafe contract

parent ac564630
...@@ -10,9 +10,11 @@ import "@openzeppelin/contracts/utils/Address.sol"; ...@@ -10,9 +10,11 @@ import "@openzeppelin/contracts/utils/Address.sol";
contract SteamToEtherSafe is Context { contract SteamToEtherSafe is Context {
using Address for address; using Address for address;
mapping(uint256 => uint256) internal _links; mapping(uint256 => uint256) internal _links; // HASH( ETH_WALLET ) => HASH( STEAMID )
event AccountLinked(uint256 account_hash);
constructor() { constructor() {
console.log("Deployed SteamToEtherSafe Contract!"); console.log("Deployed SteamToEtherSafe Contract!");
...@@ -21,42 +23,60 @@ contract SteamToEtherSafe is Context { ...@@ -21,42 +23,60 @@ contract SteamToEtherSafe is Context {
//verify a eth wallet is a specific steam user //verify a eth wallet is a specific steam user
function Verify(uint256 hashed_steamid, address eth_wallet) public view returns(bool) { function Verify(uint256 hashed_steamid, address eth_wallet) public view returns(bool) {
uint256 _wallet = uint256(keccak256(abi.encodePacked(eth_wallet))); require(hashed_steamid > 0, "invalid steamid hash");
require(eth_wallet != address(0x0), "invalid address");
uint256 _wallet = HASH(eth_wallet);
return VerifyHashed(hashed_steamid, _wallet); return VerifyHashed(hashed_steamid, _wallet);
} }
function VerifyHashed(uint256 hashed_steamid, uint256 hashed_eth_wallet) public view returns(bool) { function VerifyHashed(uint256 hashed_steamid, uint256 hashed_eth_wallet) public view returns(bool) {
require(hashed_steamid > 0, "invalid steamid hash"); require(hashed_steamid > 0, "invalid steamid hash");
require(hashed_eth_wallet != 0, "invalid wallet hash");
return _links[hashed_eth_wallet] == hashed_steamid; return _links[hashed_eth_wallet] == hashed_steamid;
} }
function DoIHaveAnAccount() public view returns(bool) function DoIHaveAnAccount() public view returns(bool) {
{ require(!_msgSender().isContract(), "contract cannot have an account");
return HasAccount(_msgSender()); return HasAccount(_msgSender());
} }
function HasAccount(address eth_wallet) public view returns(bool) function HasAccount(address eth_wallet) public view returns(bool) {
{ require(eth_wallet != address(0x0), "invalid address");
uint256 _wallet = uint256(keccak256(abi.encodePacked(eth_wallet))); uint256 _wallet = HASH(eth_wallet);
return HasAccountHashed(_wallet); return HasAccountHashed(_wallet);
} }
function HasAccountHashed(uint256 hashed_eth_wallet) public view returns(bool) function HasAccountHashed(uint256 hashed_eth_wallet) public view returns(bool) {
{ require(hashed_eth_wallet != 0, "invalid wallet hash");
return _links[hashed_eth_wallet] != 0; return _links[hashed_eth_wallet] != 0;
} }
// what do we do if someone loses their account? forever broken steamid64 link?
function LinkAccount(uint256 hashed_steamid) public { function LinkAccount(uint256 hashed_steamid) public {
uint256 _wallet = uint256(keccak256(abi.encodePacked(_msgSender()))); require(!_msgSender().isContract(), "cannot link account as a contract");
uint256 _wallet = HASH(_msgSender());
_links[_wallet] = hashed_steamid; _links[_wallet] = hashed_steamid;
emit AccountLinked(hashed_steamid);
} }
//unsafe (exposes steamid64) //unsafe (exposes steamid64) (should not be used! hashes should be precalculated!)
function LinkAccountUnsafe(uint64 steamid64) public { function LinkAccountUnsafe(uint64 steamid64) public {
uint256 hashed_steamid = uint256(keccak256(abi.encodePacked(steamid64))); uint256 hashed_steamid = HASH(steamid64);
LinkAccount(hashed_steamid); LinkAccount(hashed_steamid);
} }
function VerifyUnsafe(uint64 steamid64, address eth_wallet) public view returns(bool) { function VerifyUnsafe(uint64 steamid64, address eth_wallet) public view returns(bool) {
uint256 hashed_steamid = uint256(keccak256(abi.encodePacked(steamid64))); require(steamid64 > 0, "invalid steamid64");
require(eth_wallet != address(0x0), "invalid address");
uint256 hashed_steamid = HASH(steamid64);
return Verify(hashed_steamid, eth_wallet); return Verify(hashed_steamid, eth_wallet);
} }
// hash steamid and wallet
function HASH(address value) internal pure returns(uint256) {
return uint256(keccak256(abi.encodePacked(value)));
}
function HASH(uint64 value) internal pure returns(uint256) {
return uint256(keccak256(abi.encodePacked(value)));
}
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment