Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ethereum
Skin Z
Commits
4e111b3f
Commit
4e111b3f
authored
Sep 09, 2021
by
Kegan
Browse files
finished cleaning the new SteamToEtherSafe contract
parent
ac564630
Changes
1
Hide whitespace changes
Inline
Side-by-side
contracts/SteamToEtherSafe.sol
View file @
4e111b3f
...
...
@@ -10,9 +10,11 @@ import "@openzeppelin/contracts/utils/Address.sol";
contract
SteamToEtherSafe
is
Context
{
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
()
{
console
.
log
(
"Deployed SteamToEtherSafe Contract!"
);
...
...
@@ -21,42 +23,60 @@ contract SteamToEtherSafe is Context {
//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
)));
require
(
hashed_steamid
>
0
,
"invalid steamid hash"
);
require
(
eth_wallet
!=
address
(
0x0
),
"invalid address"
);
uint256
_wallet
=
HASH
(
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"
);
require
(
hashed_eth_wallet
!=
0
,
"invalid wallet hash"
);
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
());
}
function
HasAccount
(
address
eth_wallet
)
public
view
returns
(
bool
)
{
uint256
_wallet
=
uint256
(
keccak256
(
abi
.
encodePacked
(
eth_wallet
)
))
;
function
HasAccount
(
address
eth_wallet
)
public
view
returns
(
bool
)
{
require
(
eth_wallet
!=
address
(
0x0
),
"invalid address"
);
uint256
_wallet
=
HASH
(
eth_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
;
}
// 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
(
!
_msgSender
().
isContract
(),
"cannot link account as a contract"
);
uint256
_wallet
=
HASH
(
_msgSender
());
_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
{
uint256
hashed_steamid
=
uint256
(
keccak256
(
abi
.
encodePacked
(
steamid64
)
))
;
uint256
hashed_steamid
=
HASH
(
steamid64
);
LinkAccount
(
hashed_steamid
);
}
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
);
}
// 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment