Package Exports
- @ensdomains/dnsprovejs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ensdomains/dnsprovejs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
dnsprove.js
Functionalities
- Fetches DNS information of given domain name and type
- Validates DNS reponses and constructs proofs
- Submits the proofs into DNSSEC(Domain Name System Security Extensions) Oracle smart contract
- Works from both browser and from node.js
Installing
npm install '@ensdomains/dnsprovejs' --saveUsage
var provider = web3.currentProvider;
var DnsProve = require('dnsprove');
var dnsprove = new DnsProve(provider);
if(!dnsResult.found) throw('DNS entry not found');
var dnsResult = await dnsprove.lookup('TXT', '_ens.matoken.xyz');
var oracle = await dnsprove.getOracle('0x123...');
var proofs = dnsResult.proofs;
for(i = 0; i < proofs.length; i++){
var proof = proofs[i];
if(!await oracle.knownProof(proof)){
await oracle.submitProof(proof, proofs[i-1], {from:address})
}
}Or you can submit all in one transaction.
let dnsResult = await dnsprove.lookup('TXT', '_ens.matoken.xyz', address);
let oracle = await dnsprove.getOracle(address);
await oracle.submitAll(dnsResult, {from:nonOwner});API
DnsProve
lookup(type, name)takes DNS record type and name. It returnsDnsResultobject.getOracle(address)returns DNSSEC oracle(Oracle) object.
DnsResult
foundis a proparty containingtrueif the given DNS record is found.resultsis an array of DNS records.proofsis an array of proofs which can be submitted toOraclecontract.lastProofis a hex representation of the last resource record data (aka rrdata)
Oracle
Oracle is a wrapper object of DNSSEC.sol Oracle smart contract.
knownProof(proof)returns true if the given proof already exists inOracle.submit(dnsresult, params)sends all unproven proofs into DNSSEC Oracle as one transaction in a batch.submitProof(proof, prevProof, params)submits a proof to Oracle contract. IfprevProofisnull, the oracle contract uses hard-coded root anchor proof to validate the validity of the proof given.paramsis used to pass any params to be sent to transaction, such as{from:address}.
Testing
npm run testRunning demo
# The test page extracts contract info from build/contracts/*.json
truffle migrate --network development
# compile example/main.js into example/dist/bundle.js
npm run example
cd example
python -m SimpleHTTPServer
open http://localhost:8000TODO
- Raise an error message when proofs are not valid.
- Raise an error message when failed to submit proof to oracle
- Add unit tests