Commit 52437255 authored by Kegan's avatar Kegan
Browse files

created example SteamToEtherSafe contract that anonymously links steam and eth wallets.

parent 853214ec
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Address.sol";
// this is a way to store steam/eth wallet links without exposing what wallet is linked to what steam account
contract SteamToEtherSafe is Context{
using Address for address;
mapping(uint256 => uint256) internal _links;
constructor() {
console.log("Deployed SteamToEtherSafe Contract!");
}
//verify a eth wallet is a specific steam user
function Verify(uint256 hashed_steamid, address eth_wallet) public view returns(bool) {
uint256 _wallet = uint256(keccak256(abi.encodePacked(eth_wallet)));
return VerifyHashed(hashed_steamid, _wallet);
}
function VerifyHashed(uint256 hashed_steamid, uint256 hashed_eth_wallet) public view returns(bool) {
require(hashed_steamid > 0, "invalid steamid hash");
return _links[hashed_eth_wallet] == hashed_steamid;
}
function DoIHaveAnAccount() public view returns(bool)
{
return HasAccount(_msgSender());
}
function HasAccount(address eth_wallet) public view returns(bool)
{
uint256 _wallet = uint256(keccak256(abi.encodePacked(eth_wallet)));
return HasAccountHashed(_wallet);
}
function HasAccountHashed(uint256 hashed_eth_wallet) public view returns(bool)
{
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 {
uint256 _wallet = uint256(keccak256(abi.encodePacked(_msgSender())));
require(_links[_wallet] == 0, "Account already linked, must unlink from the source wallet"); //prevent hackers/others from taking over an accuont link
_links[_wallet] = hashed_steamid;
}
function UnlinkAccount() public {
uint256 _wallet = uint256(keccak256(abi.encodePacked(_msgSender())));
_links[_wallet] = 0;
}
//unsafe (exposes steamid64)
function LinkAccountUnsafe(uint64 steamid64) public {
uint256 hashed_steamid = uint256(keccak256(abi.encodePacked(steamid64)));
LinkAccount(hashed_steamid);
}
function VerifyUnsafe(uint64 steamid64, address eth_wallet) public view returns(bool) {
uint256 hashed_steamid = uint256(keccak256(abi.encodePacked(steamid64)));
return Verify(hashed_steamid, eth_wallet);
}
}
\ No newline at end of file
...@@ -3,7 +3,7 @@ Hardhat is a newer development environment for the EVM. I think it's a significa ...@@ -3,7 +3,7 @@ Hardhat is a newer development environment for the EVM. I think it's a significa
## Notable functions ## Notable functions
`npx hardhat compile` -> Compiles our smart contracts - `npx hardhat compile` -> Compiles our smart contracts
`npx hardhat test` -> Runs our test files - `npx hardhat test` -> Runs our test files
`npx hardhat run .\script.js` -> Run a JS file w/ hardhat - `npx hardhat run .\script.js` -> Run a JS file w/ hardhat
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