Skip to content

Commit

Permalink
coin type array + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Nov 22, 2024
1 parent 8209157 commit 814fe31
Show file tree
Hide file tree
Showing 6 changed files with 676 additions and 82 deletions.
6 changes: 4 additions & 2 deletions contracts/reverseRegistrar/IL2ReverseResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ interface IL2ReverseResolver {

/// @notice Sets the `name()` record for the reverse ENS record associated with
/// the contract provided that is owned with `Ownable`.
/// @param contractAddr The address of the contract to set the name for
/// @param contractAddr The address of the contract to set the name for (implementing Ownable)
/// @param owner The owner of the contract (via Ownable)
/// @param name The name to set
/// @param coinTypes The coin types to set. Must be inclusive of the coin type for the contract
/// @param signatureExpiry The expiry of the signature
/// @param signature The signature of an address that will return true on isValidSignature for the owner
/// @return The ENS node hash of the reverse record
function setNameForAddrWithSignatureAndOwnable(
function setNameForOwnableWithSignature(
address contractAddr,
address owner,
string calldata name,
uint256[] memory coinTypes,
uint256 signatureExpiry,
bytes calldata signature
) external returns (bytes32);
Expand Down
5 changes: 5 additions & 0 deletions contracts/reverseRegistrar/ISignatureReverseResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pragma solidity ^0.8.4;

/// @notice Interface for the signature reverse resolver
interface ISignatureReverseResolver {
/// @notice Thrown when the coin type is not found in the provided array
error CoinTypeNotFound();

/// @notice Emitted when the name of a reverse record is changed.
/// @param addr The address of the reverse record
/// @param node The ENS node hash of the reverse record
Expand All @@ -13,12 +16,14 @@ interface ISignatureReverseResolver {
/// the addr provided account using a signature.
/// @param addr The address to set the name for
/// @param name The name of the reverse record
/// @param coinTypes The coin types to set. Must be inclusive of the coin type for the contract
/// @param signatureExpiry Date when the signature expires
/// @param signature The signature from the addr
/// @return The ENS node hash of the reverse record
function setNameForAddrWithSignature(
address addr,
string calldata name,
uint256[] calldata coinTypes,
uint256 signatureExpiry,
bytes calldata signature
) external returns (bytes32);
Expand Down
12 changes: 6 additions & 6 deletions contracts/reverseRegistrar/L2ReverseResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ contract L2ReverseResolver is
}

/// @inheritdoc IL2ReverseResolver
function setNameForAddrWithSignatureAndOwnable(
function setNameForOwnableWithSignature(
address contractAddr,
address owner,
string calldata name,
uint256[] memory coinTypes,
uint256 signatureExpiry,
bytes memory signature
) public returns (bytes32) {
_validateCoinTypes(coinTypes);
bytes32 node = _getNamehash(contractAddr);

// Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191
bytes32 message = keccak256(
abi.encodePacked(
address(this),
IL2ReverseResolver
.setNameForAddrWithSignatureAndOwnable
.selector,
IL2ReverseResolver.setNameForOwnableWithSignature.selector,
name,
contractAddr,
owner,
signatureExpiry,
coinType
coinTypes,
signatureExpiry
)
).toEthSignedMessageHash();

Expand Down
15 changes: 13 additions & 2 deletions contracts/reverseRegistrar/SignatureReverseResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ contract SignatureReverseResolver is ISignatureReverseResolver, ERC165 {
function setNameForAddrWithSignature(
address addr,
string calldata name,
uint256[] memory coinTypes,
uint256 signatureExpiry,
bytes memory signature
) public returns (bytes32) {
_validateCoinTypes(coinTypes);
bytes32 node = _getNamehash(addr);

// Follow ERC191 version 0 https://eips.ethereum.org/EIPS/eip-191
Expand All @@ -58,8 +60,8 @@ contract SignatureReverseResolver is ISignatureReverseResolver, ERC165 {
ISignatureReverseResolver.setNameForAddrWithSignature.selector,
name,
addr,
signatureExpiry,
coinType
coinTypes,
signatureExpiry
)
).toEthSignedMessageHash();

Expand All @@ -79,6 +81,15 @@ contract SignatureReverseResolver is ISignatureReverseResolver, ERC165 {
emit NameChanged(addr, node, newName);
}

/// @dev Ensures the coin type for the contract is included in the provided array
function _validateCoinTypes(uint256[] memory coinTypes) internal view {
for (uint256 i = 0; i < coinTypes.length; i++) {
if (coinTypes[i] == coinType) return;
}

revert CoinTypeNotFound();
}

/// @inheritdoc ISignatureReverseResolver
function name(bytes32 node) public view returns (string memory) {
return names[node];
Expand Down
Loading

0 comments on commit 814fe31

Please sign in to comment.