DNSProvejs 是一个在以太坊的 DNSSEC oracle 合约上建立可信 DNS 记录内容的工具(源代码)。
功能
按照给定的域名和类型获取其 DNS 信息
验证 DNS 并构造证明
将证明提交到 DNSSEC(域名系统安全扩展)Oracle 智能合约
在浏览器和 node.js 中应用
快速开始
安装
npm install '@ensdomains/dnsprovejs' --save
使用
var provider = web3.currentProvider; var DnsProve = require('dnsprove'); var dnsprove = new DnsProve(provider); var textDomain = '_ens.matoken.xyz'; var dnsResult = await dnsprove.lookup('TXT', textDomain); var oracle = await dnsprove.getOracle('0x123...'); var proofs = dnsResult.proofs;
To construct a proof to submit to Oracle smart contract, you first need to provide name, rrsig, and rrset. 要构造一个提交给 Oracle 智能合约的证明,您首先需要提供 namerrsig 和 rrset 。
构建好数据,并将用于建立证明的数据实例化到一个 Result 对象,然后 toSubmit 就能够生成输入数据。
const Result = require('@ensdomains/dnsprovejs/dist/dns/result') let result = new Result([{name,sig,rrs}]) result.proofs[0].toSubmit() // [ '0x0030fd0000000e1096b0e2d05b01a692160f00000030000100000e100006010103fd1111000030000100000e100006010103fd1111000030000100000e100006010103fd1112', '0x' ]
相关库
DnsProver 库及其函数
DnsProver 允许您查找给定 DNS 类型的域名,并返回可以提交给 DNSSEC Oracle 的 DNS 记录和证明。
DnsProver.lookup(type, query)
/** * lookup takes DNS record type and name and returns `DnsResult` object. * * @param {string} type - eg: TXT * @param {string} query - eg: _ens.yourdomain.xyz * @returns {Object} DnsResult - contains list of results retrieved from DNS record and proofs which are constructed from the record and used to submit into DNSSEC Oracle */
/** * kownProof * @param {Object} proof * @param {string} proof.name - eg 'ethlab.xyz' * @param {type} proof.type - eg 'TXT' * @returns {Object} oracle_proof - contains list of results retrieved from DNS record and proofs */
Oracle.submitAll(result, params)
/** * submitAll submits all required proofs into the DNSSEC oracle as one transaction in a batch. * @param {Object} result * @param {Object} params - from, gas, gasPrice, etc */
Oracle.getAllProofs(result)
/** * getAllProofs returns all the proofs needs to be submitted into DNSSEC Oracle. * It traverses from the leaf of the chain of proof to check if proof in DNSSEC Oracle * and the one from DNS record matches with valid inception value. * This function is used so that it can pass the necessary proof to `dnsregistrar.proveAndClaim` function. * * @param {Object} result * @returns {string} data * @returns {Object} prevProof */
Oracle.submitProof(proof, prevProof, params)
/** * submitProof submits a proof to Oracle contract. * If `prevProof` is `null`, the oracle contract uses hard-coded root anchor proof to validate the validity of the proof given. * `params` is used to pass any params to be sent to transaction, such as `{from:address}`. * @param {Object} proof * @param {Object} prevProof * @param {Object} params - from, gas, gasPrice, etc * @returns {boolean} success - returns true unless transaction fails */
/** * @constructor * @param {Object} proof * @param {number} proof.inception - time the signature was generated * @param {number} proof.inserted - time the record was inserted into DNSSEC oracle * @param {string} proof.hash - hash of proof stored in DNSSEC oracle * @param {string} proof.hashToProve - hash of proof constructed from DNS record * @param {boolean} proof.validInception - true if inception in DNSSEC oracle is older than the one from DNS record. * @param {boolean} proof.matched - true if inception is valid and hash is matched */
Proof 库及其函数
Proof 包含提交到 DNSSEC Oracle 的 rrset 和签名数据。
Proof
/** * @constructor * @param {string} name * @param {string} type * @param {string} sig * @param {number} inception * @param {string} sigwire * @param {string} rrdata */
Proof.toSubmit()
/** * toSubmit returns an array consisting of hex string of sigwiredata (concatinatd string of sigwire and rrdata) and its signature * @returns {array} data */
DnsResult 库
DnsResult 是一个通过调用 lookup 函数返回的对象,它包含有关 DNS 记录的信息。
DnsResult
/** * * @constructor * @param {Object} dns_result * @param {boolean} dns_result.found - true if the given record exists * @param {boolean} dns_result.nsec - true if the given record does not exist and NSEC/NSEC3 is enabled * @param {Array} dns_result.results - an array of SignedSet containing name, signature, and rrs * @param {Array} dns_result.proofs - an array of proofs constructed using results * @param {string} dns_result.lastProof - the last proof which you submit into Oracle contruct */