Skip to content

Commit

Permalink
Add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Dec 5, 2018
1 parent e8a5aac commit b826ba3
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
build
dist
_build
_static
_templates
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ dnsregistrar.claim('foo.test').then((claim)=>{
})
```


NOTE: `submit()` calls different functions depending on the following three different conditions

- if not all proofs on DNSSEC oracle are valid, it will send proof to DNSSEC Oracle and claim ETH address.
- if all proofs on DNSSEC oracle are valid, it will not send proof to DNSSEC Oracle and just claim ETH address.
- if `nsec` is found, it deletes proof on DNSSEC oracle, then set ETH address to empty.
For more detail, please [read the doc](https://dnsregistrar.readthedocs.io/en/latest/)

## Contribution guide

Expand Down
19 changes: 10 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# -- Project information -----------------------------------------------------

project = 'dnsregistrar'
copyright = '2018, ENS'
author = 'ENS'
copyright = '2018, Makoto Inoue'
author = 'Makoto Inoue'

# The short X.Y version
version = ''
Expand All @@ -38,17 +38,17 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
extensions = ['sphinx_js', 'sphinx.ext.autodoc']
js_source_path = '../lib'
primary_domain = 'js'

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'
Expand All @@ -74,7 +74,8 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -129,7 +130,7 @@
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'dnsregistrar.tex', 'dnsregistrar Documentation',
'ENS', 'manual'),
'Makoto Inoue', 'manual'),
]


Expand Down Expand Up @@ -170,4 +171,4 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ['search.html']
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Welcome to dnsregistrar's documentation!
:maxdepth: 2
:caption: Contents:

introduction
libraries


Indices and tables
Expand Down
16 changes: 16 additions & 0 deletions docs/introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*******************
Introduction
*******************

In addition to `DNSRegistrar` Truffle based artifact which you can call the smart contract directly, we provide a javascript wrapper which looks up DNS record, extract a proof, submit the proof via DNSSec Oracle, and register to ENS via DNSRegistrar using the proof (or delete if the entry does not exist).

Example

.. code-block:: javascript
var DNSRegistrarJs = require('@ensdomains/dnsregistrar');
dnsregistrar = new DNSRegistrarJs(provider, dnsregistraraddress);
dnsregistrar.claim('foo.test').then((claim)=>{
claim.submit({from:account});
})
16 changes: 16 additions & 0 deletions docs/libraries.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*******************
Libraries
*******************

DnsRegistrar
============

`DnsRegistrar` lookups a domainname for a given DNS type and returns a claim which you use to submit proof into or delete proof from DNSSEC Oracle as well as register the domain to ENS through the DNSRegistrar contract

.. autofunction:: DNSRegistrar#claim


.. autofunction:: Claim#getOwner
.. autofunction:: Claim#submit


1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sphinx-js==2.5
122 changes: 77 additions & 45 deletions lib/dnsregistrar.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,100 @@
const DnsProve = require('@ensdomains/dnsprovejs');
const dns = require('./dns.js');
const artifact = require("../build/contracts/DNSRegistrar.json");
const Web3 = require('web3');
const abi = artifact.abi;
var packet = require('dns-packet');

class Claim{
constructor({oracle, registrar, proveResult, textDomain, encodeName}){
this.oracle = oracle
this.registrar = registrar
this.proveResult = proveResult
this.textDomain = textDomain
this.encodeName = encodeName
}

/**
* returns owner ETH address from the DNS record.
*/
getOwner(){
return this.proveResult.results[this.proveResult.results.length -1].rrs[0].data[0].toString().split('=')[1];
}

async getProven(){
return await this.oracle.getProven(this.proveResult)
}

async submitAll(params = {}){
await this.oracle.submitAll(this.proveResult, params);
}

/**
* submit functions either submit or delete proof depending on the state of DNSRecord and DNSSEC Oracle
*
* - it deletes an entry if DNS record returns NSEC/NSEC3(Next Secure)
* - it submits proof to DNSSEC Oracle contract if not all proofs are in the contract
* - it submits proof to DNSSEC Oracle contract and claims via DNSRegistrar contract if not all proofs are in the DNSSEC Oracle contract
*
* @param {Object} params - optional parameter to send to smart contract, such as from, gas, etc
*/
async submit(params = {}){
if(this.proveResult.nsec){
let proofs = this.proveResult.proofs;
await this.oracle.deleteProof(
'TXT', this.textDomain,
proofs[proofs.length -1],
proofs[proofs.length -2],
params
);

// Anyone can put empty byte if no record on DNSSEC Oracle
await this.registrar.methods.claim(this.encodedName, '0x').send(params);
}else if(proveResult.found){
let data = await this.oracle.getAllProofs(proveResult, params);
let allProven = await this.oracle.allProven(proveResult)
if(allProven){
await this.registrar.methods
.claim(this.encodedName, data[1])
.send(params)
}else{
await this.registrar.methods
.proveAndClaim(this.encodedName, data[0], data[1])
.send(params)
}
}else{
throw("Nothing to prove")
}
}
}

class DNSRegistrar{
constructor(provider, registrarAddress){
let web3 = new Web3(provider);
this.registrar = new web3.eth.Contract(abi, registrarAddress)
this.dnsprover = new DnsProve(provider);
}

/**
* Claim function returns a claim object with functions which allow you to claim
* the ownership of a given name on ENS by submitting the proof
* into DNSSEC oracle as well as claiming the name via the registrar
* @param {string} name - name of the domain you want to claim
*/
async claim(name){
// for caching purpose.
if(!this.oracleAddress){
this.oracleAddress = (await this.registrar.methods.oracle().call()).toLowerCase();
}
let encodedName = dns.hexEncodeName(name + '.');
let encodedName = '0x' + packet.name.encode(name).toString('hex');
let textDomain = '_ens.' + name;
let proveResult = await this.dnsprover.lookup('TXT', textDomain);
let oracle = await this.dnsprover.getOracle(this.oracleAddress);
return {
return new Claim({
oracle:oracle,
result:proveResult,
found:proveResult.found,
nsec:proveResult.nsec,
getProven: async () => {
return await oracle.getProven(proveResult)
},
getOwner: () => {
return proveResult.results[proveResult.results.length -1].rrs[0].data[0].toString().split('=')[1];
},
submitAll: async (params = {}) => {
await oracle.submitAll(proveResult, params);
},
submit: async (params = {}) => {
if(proveResult.nsec){
let proofs = proveResult.proofs;
await oracle.deleteProof(
'TXT', textDomain,
proofs[proofs.length -1],
proofs[proofs.length -2],
params
);

// Anyone can put empty byte if no record on DNSSEC Oracle
await this.registrar.methods.claim(encodedName, '0x').send(params);
}else if(proveResult.found){
let data = await oracle.getAllProofs(proveResult, params);
let allProven = await oracle.allProven(proveResult)
if(allProven){
await this.registrar.methods
.claim(encodedName, data[1])
.send(params)
}else{
await this.registrar.methods
.proveAndClaim(encodedName, data[0], data[1])
.send(params)
}
}else{
throw("Nothing to prove")
}
}
}
proveResult:proveResult,
registrar:this.registrar,
textDomain: textDomain,
encodedName: encodedName
})
}
}
module.exports = DNSRegistrar;

0 comments on commit b826ba3

Please sign in to comment.