diff --git a/projects/xid/chains/evm/src/ForeignRegistrar.sol b/projects/xid/chains/evm/src/ForeignRegistrar.sol index 6afffb1..8613c0d 100644 --- a/projects/xid/chains/evm/src/ForeignRegistrar.sol +++ b/projects/xid/chains/evm/src/ForeignRegistrar.sol @@ -1,6 +1,27 @@ // SPDX-License-Identifier: Apache 2 pragma solidity ^0.8.0; -contract ForeignRegistrar { - -} +import "./XID.sol"; + +contract HomeRegistrar { + XID xid; + bytes32 rootNode; + + modifier only_owner(bytes32 label) { + address currentOwner = xid.owner(keccak256(abi.encodePacked(rootNode, label))); + require(currentOwner == address(0x0) || currentOwner == msg.sender); + _; + } + + constructor(XID xidAddr, bytes32 node){ + xid = xidAddr; + rootNode = node; + } + + /** + Registers label to the first account that claims it. + */ + function register(bytes32 label, address owner) public only_owner(label) { + xid.setSubnodeOwner(rootNode, label, owner); + } +} \ No newline at end of file diff --git a/projects/xid/chains/evm/src/Registry.sol b/projects/xid/chains/evm/src/Registry.sol index 1cf5339..9211cb6 100644 --- a/projects/xid/chains/evm/src/Registry.sol +++ b/projects/xid/chains/evm/src/Registry.sol @@ -1,176 +1,176 @@ -pragma solidity ^0.8.0; +// pragma solidity ^0.8.0; -/** - * The ENS registry contract. - */ -contract ENSRegistry { +// /** +// * The ENS registry contract +// */ +// contract ENSRegistry { - struct Record { - address owner; - address resolver; - uint64 ttl; - } +// struct Record { +// address owner; +// address resolver; +// uint64 ttl; +// } - mapping (bytes32 => Record) records; - mapping (address => mapping(address => bool)) operators; +// mapping (bytes32 => Record) records; +// mapping (address => mapping(address => bool)) operators; - // Permits modifications only by the owner of the specified node. - modifier authorised(bytes32 node) { - address owner = records[node].owner; - require(owner == msg.sender || operators[owner][msg.sender]); - _; - } +// // Permits modifications only by the owner of the specified node. +// modifier authorised(bytes32 node) { +// address owner = records[node].owner; +// require(owner == msg.sender || operators[owner][msg.sender]); +// _; +// } - /** - * @dev Constructs a new ENS registrar. - */ - constructor() public { - records[0x0].owner = msg.sender; - } +// /** +// * @dev Constructs a new ENS registrar. +// */ +// constructor() public { +// records[0x0].owner = msg.sender; +// } - /** - * @dev Sets the record for a node. - * @param node The node to update. - * @param owner The address of the new owner. - * @param resolver The address of the resolver. - * @param ttl The TTL in seconds. - */ - function setRecord(bytes32 node, address owner, address resolver, uint64 ttl) external virtual override { - setOwner(node, owner); - _setResolverAndTTL(node, resolver, ttl); - } +// /** +// * @dev Sets the record for a node. +// * @param node The node to update. +// * @param owner The address of the new owner. +// * @param resolver The address of the resolver. +// * @param ttl The TTL in seconds. +// */ +// function setRecord(bytes32 node, address owner, address resolver, uint64 ttl) external virtual override { +// setOwner(node, owner); +// _setResolverAndTTL(node, resolver, ttl); +// } - /** - * @dev Sets the record for a subnode. - * @param node The parent node. - * @param label The hash of the label specifying the subnode. - * @param owner The address of the new owner. - * @param resolver The address of the resolver. - * @param ttl The TTL in seconds. - */ - function setSubnodeRecord(bytes32 node, bytes32 label, address owner, address resolver, uint64 ttl) external virtual override { - bytes32 subnode = setSubnodeOwner(node, label, owner); - _setResolverAndTTL(subnode, resolver, ttl); - } +// /** +// * @dev Sets the record for a subnode. +// * @param node The parent node. +// * @param label The hash of the label specifying the subnode. +// * @param owner The address of the new owner. +// * @param resolver The address of the resolver. +// * @param ttl The TTL in seconds. +// */ +// function setSubnodeRecord(bytes32 node, bytes32 label, address owner, address resolver, uint64 ttl) external virtual override { +// bytes32 subnode = setSubnodeOwner(node, label, owner); +// _setResolverAndTTL(subnode, resolver, ttl); +// } - /** - * @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node. - * @param node The node to transfer ownership of. - * @param owner The address of the new owner. - */ - function setOwner(bytes32 node, address owner) public virtual override authorised(node) { - _setOwner(node, owner); - emit Transfer(node, owner); - } +// /** +// * @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node. +// * @param node The node to transfer ownership of. +// * @param owner The address of the new owner. +// */ +// function setOwner(bytes32 node, address owner) public virtual override authorised(node) { +// _setOwner(node, owner); +// emit Transfer(node, owner); +// } - /** - * @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node. - * @param node The parent node. - * @param label The hash of the label specifying the subnode. - * @param owner The address of the new owner. - */ - function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public virtual override authorised(node) returns(bytes32) { - bytes32 subnode = keccak256(abi.encodePacked(node, label)); - _setOwner(subnode, owner); - emit NewOwner(node, label, owner); - return subnode; - } +// /** +// * @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node. +// * @param node The parent node. +// * @param label The hash of the label specifying the subnode. +// * @param owner The address of the new owner. +// */ +// function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public virtual override authorised(node) returns(bytes32) { +// bytes32 subnode = keccak256(abi.encodePacked(node, label)); +// _setOwner(subnode, owner); +// emit NewOwner(node, label, owner); +// return subnode; +// } - /** - * @dev Sets the resolver address for the specified node. - * @param node The node to update. - * @param resolver The address of the resolver. - */ - function setResolver(bytes32 node, address resolver) public virtual override authorised(node) { - emit NewResolver(node, resolver); - records[node].resolver = resolver; - } +// /** +// * @dev Sets the resolver address for the specified node. +// * @param node The node to update. +// * @param resolver The address of the resolver. +// */ +// function setResolver(bytes32 node, address resolver) public virtual override authorised(node) { +// emit NewResolver(node, resolver); +// records[node].resolver = resolver; +// } - /** - * @dev Sets the TTL for the specified node. - * @param node The node to update. - * @param ttl The TTL in seconds. - */ - function setTTL(bytes32 node, uint64 ttl) public virtual override authorised(node) { - emit NewTTL(node, ttl); - records[node].ttl = ttl; - } +// /** +// * @dev Sets the TTL for the specified node. +// * @param node The node to update. +// * @param ttl The TTL in seconds. +// */ +// function setTTL(bytes32 node, uint64 ttl) public virtual override authorised(node) { +// emit NewTTL(node, ttl); +// records[node].ttl = ttl; +// } - /** - * @dev Enable or disable approval for a third party ("operator") to manage - * all of `msg.sender`'s ENS records. Emits the ApprovalForAll event. - * @param operator Address to add to the set of authorized operators. - * @param approved True if the operator is approved, false to revoke approval. - */ - function setApprovalForAll(address operator, bool approved) external virtual override { - operators[msg.sender][operator] = approved; - emit ApprovalForAll(msg.sender, operator, approved); - } +// /** +// * @dev Enable or disable approval for a third party ("operator") to manage +// * all of `msg.sender`'s ENS records. Emits the ApprovalForAll event. +// * @param operator Address to add to the set of authorized operators. +// * @param approved True if the operator is approved, false to revoke approval. +// */ +// function setApprovalForAll(address operator, bool approved) external virtual override { +// operators[msg.sender][operator] = approved; +// emit ApprovalForAll(msg.sender, operator, approved); +// } - /** - * @dev Returns the address that owns the specified node. - * @param node The specified node. - * @return address of the owner. - */ - function owner(bytes32 node) public virtual override view returns (address) { - address addr = records[node].owner; - if (addr == address(this)) { - return address(0x0); - } +// /** +// * @dev Returns the address that owns the specified node. +// * @param node The specified node. +// * @return address of the owner. +// */ +// function owner(bytes32 node) public virtual override view returns (address) { +// address addr = records[node].owner; +// if (addr == address(this)) { +// return address(0x0); +// } - return addr; - } +// return addr; +// } - /** - * @dev Returns the address of the resolver for the specified node. - * @param node The specified node. - * @return address of the resolver. - */ - function resolver(bytes32 node) public virtual override view returns (address) { - return records[node].resolver; - } +// /** +// * @dev Returns the address of the resolver for the specified node. +// * @param node The specified node. +// * @return address of the resolver. +// */ +// function resolver(bytes32 node) public virtual override view returns (address) { +// return records[node].resolver; +// } - /** - * @dev Returns the TTL of a node, and any records associated with it. - * @param node The specified node. - * @return ttl of the node. - */ - function ttl(bytes32 node) public virtual override view returns (uint64) { - return records[node].ttl; - } +// /** +// * @dev Returns the TTL of a node, and any records associated with it. +// * @param node The specified node. +// * @return ttl of the node. +// */ +// function ttl(bytes32 node) public virtual override view returns (uint64) { +// return records[node].ttl; +// } - /** - * @dev Returns whether a record has been imported to the registry. - * @param node The specified node. - * @return Bool if record exists - */ - function recordExists(bytes32 node) public virtual override view returns (bool) { - return records[node].owner != address(0x0); - } +// /** +// * @dev Returns whether a record has been imported to the registry. +// * @param node The specified node. +// * @return Bool if record exists +// */ +// function recordExists(bytes32 node) public virtual override view returns (bool) { +// return records[node].owner != address(0x0); +// } - /** - * @dev Query if an address is an authorized operator for another address. - * @param owner The address that owns the records. - * @param operator The address that acts on behalf of the owner. - * @return True if `operator` is an approved operator for `owner`, false otherwise. - */ - function isApprovedForAll(address owner, address operator) external virtual override view returns (bool) { - return operators[owner][operator]; - } +// /** +// * @dev Query if an address is an authorized operator for another address. +// * @param owner The address that owns the records. +// * @param operator The address that acts on behalf of the owner. +// * @return True if `operator` is an approved operator for `owner`, false otherwise. +// */ +// function isApprovedForAll(address owner, address operator) external virtual override view returns (bool) { +// return operators[owner][operator]; +// } - function _setOwner(bytes32 node, address owner) internal virtual { - records[node].owner = owner; - } +// function _setOwner(bytes32 node, address owner) internal virtual { +// records[node].owner = owner; +// } - function _setResolverAndTTL(bytes32 node, address resolver, uint64 ttl) internal { - if(resolver != records[node].resolver) { - records[node].resolver = resolver; - emit NewResolver(node, resolver); - } +// function _setResolverAndTTL(bytes32 node, address resolver, uint64 ttl) internal { +// if(resolver != records[node].resolver) { +// records[node].resolver = resolver; +// emit NewResolver(node, resolver); +// } - if(ttl != records[node].ttl) { - records[node].ttl = ttl; - emit NewTTL(node, ttl); - } - } -} \ No newline at end of file +// if(ttl != records[node].ttl) { +// records[node].ttl = ttl; +// emit NewTTL(node, ttl); +// } +// } +// } \ No newline at end of file diff --git a/projects/xid/chains/evm/src/XIDRegistry.sol b/projects/xid/chains/evm/src/XIDRegistry.sol index 8e6e449..195bfac 100644 --- a/projects/xid/chains/evm/src/XIDRegistry.sol +++ b/projects/xid/chains/evm/src/XIDRegistry.sol @@ -35,6 +35,20 @@ contract XIDRegistry is XID { records[0x0].owner = msg.sender; } + /** + * @dev Returns the address that owns the specified node. + * @param node The specified node. + * @return address of the owner. + */ + function owner(bytes32 node) public virtual override view returns (address) { + address addr = records[node].owner; + if (addr == address(this)) { + return address(0x0); + } + + return addr; + } + /** * @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node. * @param node The node to transfer ownership of.