---
# System prepended metadata

title: RNS Improvements

---

# RNS Improvements

[TOC]

## Contracts

1. join resolver and registry repositories.
2. export types from typechain to npm.
3. clean up repos and move legacy to another one.
4. which organization should we use for this? (rnsdomains or rsksmart or both?)
5. [rns-registrar](##rns-rskregistrar)
    * Update dependencies node v12
    * solidity v0.5.3
    * Immprove natSpec (missing functions and typos)
7. [rns-registry](##rns-registry)
    * Update dependencies node v12
    * solidity v0.5.0
8. [rns-resolver](##rns-resolver)
    * Update dependencies node v12
    * solidity v0.5.0
10. [rns-reverse](##rns-reverse)
    * Update dependencies node v12
    * solidity v0.5.3
 
## SDK

1. use contract types generated with typechain.
2. fix github issues

## UI

1. use the new rns-sdk instead of the rns-js
2. Update dependencies to be compatible with lastest version of npm(now v12)


# Architecture

## rns-rskregistrar
https://github.com/rnsdomains/rns-rskregistrar
Node v12, truffle
Solidity 0.5.3

* All tests passing (523)
* Remove empty `Dummy.sol`.
* Immprove Natspec, missing functions and typos.

```mermaid
classDiagram
class oppenzeppelinOwnable{
    -address _owner
    +owner() address
    +isOwner() bool
    +renounceOwnership()
    +transferOwnership(newOwner)
    -_transferOwnership(newOwner)
}
class oppenzeppelinERC721{
    +balanceOf(owner) uint256
    +ownerOf(tokenId) address
    +safeTransferFrom(from, to, tokenId)
    +transferFrom(from, to, tokenId)
    +approve(to, tokenId)
    +getApproved(tokenId) address
    +setApprovalForAll(operator, _approved)
    +isApprovedForAll(owner, operator) bool
    +safeTransferFrom(from, to, tokenId, data)
}
class rsksmartERC677TransferReceiver{
    +tokenFallback(from, amount, data) bool
}
```

```mermaid
classDiagram
class libraryBytesUtils{
    +toBytes32(input, offset) bytes32
    +toBytes4(input, offset) bytes4
    +toUint(input, offset) uint
    +toString(input, offset, strLength) string
    +toAddress(input, offset) address
}
```

```mermaid
classDiagram
AbstractNamePrice <|-- NamePrice
class NamePrice{
    +price (name, expires, duration) uint
}
class AbstractNamePrice{
    +price (name, expires, duration) uint
}
```

```mermaid
classDiagram
NodeOwner <|-- RSKOwner
oppenzeppelinERC721 <|-- NodeOwner
oppenzeppelinOwnable <|-- NodeOwner
AbstractNodeOwner <|-- NodeOwner
oppenzeppelinERC721 <|-- AbstractNodeOwner
class RSKOwner{
    -TokenRegistrar previousRegistrar
    +available(tokenId) bool
    +acceptRegistrarTransfer(label, deed)
}
class NodeOwner{
    -AbstractRNS rns
    -bytes32 rootNode
    +mapping[uint256 => uint] expirationTime
    +ownerOf(tokenId) address
    +available(tokenId) bool
    +setRootResolver( resolver)
    +setRootTT(ttl)
    +addRegistrar(registrar)
    +isRegistrar(registrar) bool
    +removeRegistrar(registrar)
    +register(label, tokenOwner, duration)
    +reclaim(tokenId, newOwner)
    +addRenewer(renewer)
    +isRenewer(renewer) bool
    +removeRenewer(renewer)
    +renew (label, time)
    +removeExpired(tokenIds)
}
class AbstractNodeOwner{
    +available(tokenId) bool
    +reclaim(tokenId, newOwner)
    +removeExpired(tokenIds)
}
```

```mermaid
classDiagram
oppenzeppelinOwnable <|-- FIFSRegistrarBase
rsksmartERC677TransferReceiver <|-- FIFSRegistrarBase
FIFSRegistrarBase <|-- FIFSRegistrar
PricedContract <|-- FIFSRegistrar
FIFSRegistrarBase <|-- FIFSAddrRegistrar
PricedContract <|-- FIFSAddrRegistrar
rsksmartERC677TransferReceiver <|-- Renewer
PricedContract <|-- Renewer
oppenzeppelinOwnable <|-- PricedContract
class FIFSRegistrar{
    -address pool
    -bytes4 REGISTER_SIGNATURE = 0xc2c414c8
    +register(name, nameOwner, secret, duration)
    +tokenFallback(from, value, data) bool
    -registerWithToken(name, nameOwner, secret, duration, from, amount)
    -executeRegistration(name, nameOwner, secret, duration) uint price
}
class FIFSAddrRegistrar{
    -address pool
    -AbstractRNS rns
    -bytes32 rootNode
    -bytes4 REGISTER_SIGNATURE = 0x5f7b99d5
    +register(name, nameOwner, secret, duration, addr)
    +tokenFallback(from, value, data) bool
    -registerWithToken(name, nameOwner, secret, duration, from, amount, addr)
    -executeRegistration (name, nameOwner, secret, duration, addr) uint
}
class FIFSRegistrarBase{
    -mapping[bytes32 => uint] commitmentRevealTime
    +uint minCommitmentAge = 1 minutes
    +uint minLength = 5
    -ERC677 rif
    -NodeOwner nodeOwner
    +makeCommitment (label, nameOwner, secret) bytes32
    +commit(commitment)
    +canReveal(commitment) bool
    +setMinCommitmentAge(newMinCommitmentAge)
    +setMinLength(newMinLength)
}
class Renewer{
    -ERC677 rif
    -NodeOwner nodeOwner
    -address pool
    +renew(name, duration)
    +tokenFallback(from, value, data) bool
    -renewWithToken(name, duration, from, amount)
    -executeRenovation(name, duration) uint
}
class PricedContract{
    +AbstractNamePrice namePrice
    +setNamePrice(newNamePrice)
    +price (name, expires, duration) uint
}
```

## rns-registry
https://github.com/rnsdomains/rns-registry
Node v12, truffle
Solidity 0.5.0

- All test passing (8)

```mermaid
classDiagram
AbstractRNS <|-- RNS
class AbstractRNS{
    +owner(node) address
    +resolver(node) address
    +ttl(node) uint64
    +setOwner(node, ownerAddress)
    +setSubnodeOwner(node, label, ownerAddress)
    +setResolver(node, resolverAddress)
    +setTTL(node, ttlValue)
}
class RNS{
    -mapping [bytes32 => Record] records
    +owner(node) address
    +resolver(node) address
    +ttl(node) uint64
    +setOwner(node, ownerAddress)
    +setSubnodeOwner(node, label, ownerAddress)
    +setResolver(node, resolverAddress)
    +setTTL(node, ttlValue)
    +setDefaultResolver(_resolver)
}
```

## rns-resolver
https://github.com/rnsdomains/rns-resolver
Node v12, truffle
Solidity 0.5.0

* All test passing (148)
* Remove legacy/dummy folders?

```mermaid
classDiagram
RSKAddrResolver <|-- ResolverV1
openzeppelinInitializable <|-- ResolverV1
ensContentHashResolver <|-- ResolverV1
ensABIResolver <|-- ResolverV1
ensPubkeyResolver <|-- ResolverV1
ensTextResolver <|-- ResolverV1
ensInterfaceResolver <|-- ResolverV1
class ResolverV1{
    +AbstractRNS rns REGISTRY
    +mapping [bytes32 => mapping[address => mapping [address => bool]]] authorisations
    +setAuthorisation(node, target, isAuthorised)
    -isAuthorised(node) bool
    +multicall(data) bytes[]
}
class RSKAddrResolver{
    -uint COIN_TYPE_RSK = 137
    +setAddr(node, a)
    +addr(node) address
    +setAddr(node, coinType, a)
}
```

## rns-reverse
https://github.com/rnsdomains/rns-reverse
Node v12, truffle
Solidity 0.5.3

* All test passing (17)
* Remove `Dummy.sol` 

```mermaid
classDiagram
ReverseResolverBase <|-- NameResolver
openzeppelinOwnable <|-- ReverseRegistrar
class NameResolver{
    -bytes4 NAME_INTERFACE_ID = 0x691f3431
    -AbstractRNS rns REGISTRY
    -mapping [bytes32 => string] names
    +setName(node, newName)
    +name(node) string
    +supportsInterface(interfaceID) bool
}
class ReverseResolverBase{
    -bytes4 INTERFACE_META_ID = 0x01ffc9a7
    +supportsInterface(interfaceID) bool
}
class ReverseSetup{
    -AbstractRNS rns REGISTRY
    -address nameResolver
    -address reverseRegistrar
    -address payable reverseOwner
    -bytes32 REVERSE
    -bytes32 ADDR_REVERSE
    +run()
}
class ReverseRegistrar{
    +bytes32 ADDR_REVERSE_NODE
    +AbstractRNS rns REGISTRY
    +setName(name) bytes32
    +claim(recordOwner) bytes32
    +claimWithResolver(recordOwner, resolver) bytes32
    +node(addr) bytes32
    -sha3HexAddress(addr) bytes32
    +rskClaim(addr, label)
    +addRskRegistrar(registrar)
    +isRskRegistrar(registrar) bool
    +removeRskRegistrar(registrar)
}
```

## rns-sdk
https://github.com/rsksmart/rns-sdk
Node v12

* Remove warning `Duplicate definition of Transfer (Transfer(address,address,uint256,bytes), Transfer(address,address,uint256))`

### Purchase domain
```mermaid
sequenceDiagram
    actor User
    participant DApp
    participant SDK
    participant FIFSAddrRegistrar
    User->>DApp: search(label)
    DApp-->>SDK: rskOwner.available(hashLabel(label))
    SDK-->>RSKOwner: available(hashLabel(label))
    RSKOwner-->>SDK: isAvailable
    SDK-->>DApp: isAvailable
    alt isAvailable
        DApp-->>SDK: rskRegistrar.price(label, duration)
        SDK-->>FIFSAddrRegistrar: price(name, constants.Zero, duration)
        FIFSAddrRegistrar-->>SDK: uint price 
        SDK-->>DApp: price
        DApp-->>User: price
    else
        DApp-->>User: Please search another domain
    end
    User-->>DApp: purchase(label)
    DApp-->>SDK: rskRegistrar.commitToRegister(label, address)
    SDK-->>FIFSAddrRegistrar: makeCommitment(hashlabel(label), owner, secret)
    FIFSAddrRegistrar-->>SDK: commitmentHash
    SDK-->>FIFSAddrRegistrar: commit(commitmentHash)
    FIFSAddrRegistrar-->>SDK: { makeCommitmentTransaction, secret, canReveal }
    FIFSAddrRegistrar-->>SDK: contractTx
    SDK-->>DApp: { makeCommitmentTransaction, secret, canReveal() }
    DApp-->>DApp: canReveal() every 3 seconds
    DApp-->>SDK: canReveal()
    SDK-->>FIFSAddrRegistrar: canReveal(commitmentHash)
    FIFSAddrRegistrar-->>SDK: true
    SDK-->>DApp: commitmentReady
    DApp-->>SDK: rskRegistrar.register(label, owner, secret, duration, price)
    SDK-->>FIFSAddrRegistrar: 
    SDK-)DApp: ...
    DApp-)User: domain purchased!
```


# INFO
## VIDEOS

101 RNS 101 [(2022-05-26 09:04 GMT-7).mp4](https://drive.google.com/file/d/16OJFc7va8A90HM6n1HaAsKjYBEdK996z/view?usp=drive_web)
102 RNS 102 [(2022-06-01 08:02 GMT-7).mp4](https://drive.google.com/file/d/1tFyzHHbCLafKpEBfw4Go3Y3KaF0d4_5P/view?usp=drive_web)
103 RNS 103 [(2022-06-06 09:29 GMT-7).mp4](https://drive.google.com/file/d/1ov17lcIeL8c3Rpy8JZfY5jb6GZTKJkqO/view?usp=drive_web)

### Videos summary

#### Layers
- Protocol: Smart contracts 
- Libraries: Tools for developers
    - Resolving
    - Updating records (similar to [DNS records](https://www.cloudflare.com/learning/dns/dns-records/))
- SDKs: Tools to administrate domains
    - Edit records by owner
    - Registration (zones): Registration model for each zone. Paid in RIF.
- RNS Manager(npm v12 or dependency conflicts): [DApp](https://github.com/rsksmart/rns-manager-react) with SDK [old version](https://github.com/rnsdomains/rns-js) (web3.js), [new version](https://github.com/rsksmart/rns-sdk)(ethers.js).
    * https://testnet.manager.rns.rifos.org/
    * https://manager.rns.rifos.org/


#### Search for subdomain
##### [Registrar](https://github.com/rnsdomains/rns-rskregistrar)
Owns and sell subdomains
- Queries .rsk
- Asks the [price](https://github.com/rnsdomains/rns-rskregistrar/blob/b20ce07dce3290de0b0bedcc8c8ba3aca30ea039/contracts/NamePrice.sol#L18) to purchase a subdomain on their zone


###### 1. Sealing (First tx):
![ENS registration steps](https://i.imgur.com/zTmlSYZ.png)

To prevent front running, same as [ENS](https://app.ens.domains/name/lancenn.eth/register):
* Submiting a seal pruchase (submiting the hash)
* Submit the actual domain (after 1m)

**Note:** Stores in *LocalStorage*  data from the first tx, this way even if loses connection it won't lose the first tx. Every 10 seconds asks to the smart contract if **can I unseal.**

###### 2. Unsealing (Second tx):
* Sends the hash and the **sealing secret**( duration(# years), salt, hashOfthe Domain)
* Unsealing -> sais exactly the domain and registered.

**Privacy problem:** The domain it's being saved on the blockchain ex: 'lancenn' this string its beeing saved, even submiting a hash could be crack. If you don't want to share your on chain balance or history, then the domain should not be created for that account.



#### Admin domain(NFT)
##### Registrar
* Renew ownership
* Transfer ownership
    * Set controller: Controller is the address that can update records
    * NFT owner: can update Controller address
##### Records
* Update addresses
* Decentralized URL
* Multicoin addresses

## Links

https://github.com/rnsdomains/rns-registry
https://github.com/rnsdomains/rns-rskregistrar
https://github.com/rnsdomains/rns-resolver
https://github.com/rnsdomains/rns-reverse
https://github.com/rsksmart/rns-sdk
https://github.com/rsksmart/rns-manager-react

https://developers.rsk.co/rif/rns/

# RNS NEW VERSION

## LINKS
- https://manager.rns.rifos.org/
- https://github.com/rsksmart/rns-partner-registrar
- https://github.com/rsksmart/rns-sdk
- https://github.com/rnsdomains/rns-rskregistrar
    - NodeOwner implementation

## ARCH


```mermaid
sequenceDiagram
    actor User
    participant PartnerProxyContract
    participant PartnerRegistrar
    participant Controller
    participant RNS

    
    PartnerRegistrar->>PartnerRegistrar: whitelist(PartnerProxyContract)
    
    User->>PartnerProxyContract: commit(commitment)
    
    User->>PartnerProxyContract: canReveal(commitment)
    
    User->>PartnerProxyContract: register(name, nameOwner, secret, duration)
    
    PartnerProxyContract->>PartnerRegistrar: register(name, nameOwner, secret, duration)
    
    PartnerRegistrar->>PartnerRegistrar: validateName()
    
    PartnerRegistrar->>PartnerRegistrar: validatePrice()
    
    PartnerRegistrar->>Controller: register(label, nameOwner, duration)
    
    PartnerRegistrar--)Analytics Server: registerEvent(name, owner, etc)
    
    Controller->>Controller: _mint()
    
    Controller->>RNS: setSubnodeOwner(rootNode, label, tokenOwner)
    
    RNS->>Controller: ...
    
    Controller->>PartnerRegistrar: ...
    
    PartnerRegistrar->>PartnerProxyContract: ...
    
    PartnerProxyContract->>User: Name Registered

```

```mermaid
classDiagram
IBaseRegistrar <|-- PartnerRegistrar
IAccessControl <|-- RegistrarAccessControl
IAccessControl <|-- RegistrarAccessControl
HasAccessControl <|-- PartnerRegistrar
IERC677TransferReceiver <|-- PartnerRegistrar
class IBaseRegistrar{
    +event NameRegistered(address indexed partner, uint256 duration)
    +event FeeManagerChanged(address hostContract, address feeManagerContract)
    +getPartnerManager() IPartnerManager
    +setFeeManager(IFeeManager feeManager)
    +register(string calldata name,address nameOwner,bytes32 secret,uint256 duration,address addr,address partner)
    +price(string calldata name,uint256 expires,uint256 duration,address partner) uint256
    +makeCommitment(bytes32 label,address nameOwner,bytes32 secret,uint256 duration,address addr) bytes32
    +commit(bytes32 commitment, address partner)
    +canReveal(bytes32 commitment) bool
}
class PartnerRegistrar{
    +getPartnerManager() IPartnerManager
    +setFeeManager(IFeeManager feeManager)
    +tokenFallback(address from, uint256 value, bytes calldata data) bool
    -_registerWithToken(address from, uint256 amount, string memory name, bytes32 secret, uint256 duration, address nameOwner, address addr,baddress partner)
    -_collectFees(address partner, uint256 amount)
    +register(string calldata name, address nameOwner, bytes32 secret, uint256 duration, address addr, address partner)
    +price(string calldata name, uint256 expires, uint256 duration, address partner) uint256
    +makeCommitment(bytes32 label, address nameOwner, bytes32 secret, uint256 duration, address addr) bytes32
    +canReveal(bytes32 commitment) bool
    +commit(bytes32 commitment, address partner)
    -_executeRegistration(string memory name, address nameOwner, bytes32 secret, uint256 duration, address addr, address partner) uint256
    -_getPartnerConfiguration(address partner) IPartnerConfiguration
}
class IAccessControl{
    +isOwnerRole(address owner) bool
    +isHighLevelOperator(address highLevelOperator) bool
    +addHighLevelOperator(address highLevelOperator)
    +removeHighLevelOperator(address highLevelOperator)
    +transferOwnership(address newOwner)
}
class NodeOwner{
    +register(bytes32 label, address tokenOwner, uint256 duration)
    +expirationTime(uint256 label) uint256
    +addRegistrar(address registrar)
    +removeRegistrar(address registrar)
    +isRegistrar(address registrar) bool
    +addRenewer(address renewer)
    +isRenewer(address renewer) bool
    +removeRenewer(address renewer)
    +renew(bytes32 label, uint256 time)
    +removeExpired(uint256[] calldata tokenIds)
    +reclaim(uint256 tokenId, address newOwner)
    +setRootResolver(address resolver)
    +available(uint256 tokenId) bool
    +ownerOf(uint256 tokenId) address
    +transferFrom(address from, address to, uint256 tokenId)
}
class RNS {
    +owner(bytes32 node) address
    +resolver(bytes32 node) address
    +ttl(bytes32 node) uint64
    +setOwner(bytes32 node, address ownerAddress)
    +setSubnodeOwner(bytes32 node,bytes32 label, address ownerAddress)
    +setResolver(bytes32 node, address resolverAddress)
    +setTTL(bytes32 node, uint64 ttlValue)
    +setDefaultResolver(address _resolver)
}
```