Skip to content

Commit

Permalink
use identity of the reader instead of his address
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Oct 28, 2022
1 parent 2b81b23 commit 2080fcd
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions contracts/SoulLinker.sol
Expand Up @@ -129,32 +129,39 @@ contract SoulLinker is Ownable, EIP712 {

/// @notice Validates the signature of the given read link request
/// @dev The token must be linked to this soul linker
/// @param reader Address of the reader
/// @param identityId Id of the identity
/// @param readerIdentityId Id of the identity of the reader
/// @param ownerIdentityId Id of the identity of the owner of the SBT
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @param expirationDate Expiration date of the signature
/// @param signature Signature of the read link request made by the owner
/// @return `true` if the signature is valid, `false` otherwise
function validateLinkData(
address reader,
uint256 identityId,
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 expirationDate,
bytes calldata signature
) external view returns (bool) {
require(linkedSBT[token], "SBT_NOT_LINKED");

address identityOwner = soulboundIdentity.ownerOf(identityId);
address identityReader = soulboundIdentity.ownerOf(readerIdentityId);
address identityOwner = soulboundIdentity.ownerOf(ownerIdentityId);
address tokenOwner = IERC721Enumerable(token).ownerOf(tokenId);

require(identityOwner == tokenOwner, "IDENTITY_OWNER_NOT_TOKEN_OWNER");
require(reader == _msgSender(), "CALLER_NOT_READER");
require(identityReader == _msgSender(), "CALLER_NOT_READER");
require(expirationDate >= block.timestamp, "VALID_PERIOD_EXPIRED");
require(
_verify(
_hash(reader, identityId, token, tokenId, expirationDate),
_hash(
readerIdentityId,
ownerIdentityId,
token,
tokenId,
expirationDate
),
signature,
identityOwner
),
Expand All @@ -177,8 +184,8 @@ contract SoulLinker is Ownable, EIP712 {
}

function _hash(
address reader,
uint256 identityId,
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 expirationDate
Expand All @@ -188,10 +195,10 @@ contract SoulLinker is Ownable, EIP712 {
keccak256(
abi.encode(
keccak256(
"Link(address reader,uint256 identityId,address token,uint256 tokenId,uint256 expirationDate)"
"Link(uint256 readerIdentityId,uint256 ownerIdentityId,address token,uint256 tokenId,uint256 expirationDate)"
),
reader,
identityId,
readerIdentityId,
ownerIdentityId,
token,
tokenId,
expirationDate
Expand Down

0 comments on commit 2080fcd

Please sign in to comment.