Giter Site home page Giter Site logo

dnslink-std / js Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 1.0 170 KB

The reference implementation for DNSLink resolver in JavaScript. Tested in Node.js and in the Browser.

License: Other

JavaScript 95.79% TypeScript 4.21%
dnslink javascript p2p dweb decentralized-web

js's Introduction

@dnslink/js

The reference implementation for DNSLink resolver in JavaScript. Tested in Node.js and in the Browser.

Usage

You can use dnslink both as a CLI tool or a library.

JavaScript API

Getting started with DNSLink resolution in a jiffy:

import { resolve, DNSRcodeError } from '@dnslink/js'

// assumes top-level await
let result
try {
  result = await resolve('dnslink.dev/abcd?foo=bar', {
    endpoints: ['dns.google'], // required! see more below.
    /* (optional) */
    signal, // AbortSignal that you can use to abort the request
    timeout: 1000, // timeout for the operation
    retries: 3 // retries in case of transport error
  })
} catch (err) {
  // Errors provided by DNS server
  if (err instanceof DNSRcodeError) {
    err.rcode // Error code number following - https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
    err.error // Error code name following (same list)
    err.code // `RCODE_${err.code}
    err.domain // Domain lookup that resulted in the error
    if (err.rcode === 3) {
      // NXDomain = Domain not found; most relevant error
    }
  } else {
    // A variety other errors may be thrown as well. Possible causes include, but are not limited to:
    // - Invalid input
    // - Timeouts / aborts
    // - Networking errors
    // - Incompatible dns packets provided by server
  }
}
const { links, log, txtEntries } = result

// `links` is an object containing given links for the different namespaces
// Each names contains an identifier and a ttl.
links.ipfs === [{ identifier: 'QmTg....yomU', ttl: 60 }]

// The `log` is always an Array and contains a list of log entries
// that were should help to trace back how the linked data was resolved.
Array.isArray(log)

// The `txtEntries` are a reduced form of the links that contains the namespace 
// as part of the value
txtEntries === [{ value: '/ipfs/QmTg....yomU', ttl: 60 }]

Endpoints

You need to specify endpoints to be used with the API. You can specify them the same way as you would in dns-query.

Possible log statements

The log statements follow the DNSLink specification.

Command Line

To use dnslink in the command line you will need Node.js installed.

Install it permanently using npm i -g @dnslink/js or run in on-the-fly using npx @dnslink/js.

You can get detailed help for the app by passing a --help option at the end:

$ npx @dnslink/js --help

License

Published under dual-license: MIT OR Apache-2.0

js's People

Contributors

lidel avatar martinheidegger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bhaskarvilles

js's Issues

Load domain and fallback domain in parallel

Currently the code is written to value formal correctness and brevity over performance. This meant a neglect of performance in particular for loading the _dnslink.<fqdn> and <fqdn> domains. Those requests should be done in parallel, preferably cancelling the <fqdn> request if _dnslink.<fqdn> was successful.

Change CLI argument to redirect by default

Currently, in the spirit of resolve and resolveN, the -r flag of the command line tool is optional, making redirects optional. In standard operation I would guess however that redirects are desired. It would be better to have a --no-redirect flag instead assuming redirect as standard.

Align API with @dnslink-std/go

In the go implementation following API seems to be useful here too:

const resolver = new dnslink.Resolver({
   async lookupTXT(domain) {
      // implementation
   }
})
resolver.resolveN("dnslink.dev")

Chaining not getting resolved properly

What we did

I assume the extension is using this lib under the hood. IPFS Browser extension 0.11.0. The URL in browser (Brave) is ipns://wiki.polkadot.network , and I was able to reproduce the error using a HTTP gateway (https://ipfs.w3f.community/ipns/wiki.polkadot.network).

Error:

ipfs resolve -r /ipns/wiki.polkadot.network: could not resolve name: "wiki.polkadot.network" is missing a DNSLink record (https://docs.ipfs.io/concepts/dnslink/)

Expected resolving

browser -> _dnslink.wiki.polkadot.network -> _dnslink.polkadot-wiki.w3f.services -> resolve the wiki's hash

DNS TXT values

❯ dig +short TXT _dnslink.wiki.polkadot.network
"dnslink=/dnslink/polkadot-wiki.w3f.services"
                                                                                      
❯ dig +short TXT _dnslink.polkadot-wiki.w3f.services    
"dnslink=/ipfs/QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha"

Any clear misconfigurations on our part? Pretty sure we're doing it exactly how its described here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.