Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dnslink

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dnslink - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

cli.js

3

index.d.ts
declare module 'dnslink' {
export default function dnslink(domain: string): Promise<string>;
function resolve(domain: string): Promise<string>;
function update(domain: string, cid: string): Promise<void>;
}

@@ -1,32 +0,7 @@

const dns = require('dns');
const resolve = require('./cmds/resolve');
const update = require('./cmds/update');
const DNSLINK_REGEX = /^dnslink=.+/;
/**
* Return the string path that is dnslinked in the txt records.
**/
module.exports = function dnslink(_domain) {
return new Promise((rs, rj) => {
const domainParts = _domain.split('.');
// We've got a subdomain, add _dnslink subdomain prefix
if (domainParts.length > 2) {
domainParts.unshift('_dnslink');
}
const domain = domainParts.join('.');
dns.resolveTxt(domain, (err, records) => {
if (err) return rj(err);
const flatRecords = [].concat(...records);
const dnslinks = flatRecords.filter(item => {
return DNSLINK_REGEX.test(item);
});
if (dnslinks.length > 1) {
rj(`Found multiple dnslink entries for ${domain}. Rejecting as there should only be 1.`);
return;
} else if (dnslinks.length === 0) {
rj(`Unable to find dnslink TXT record for domain ${domain}`);
return;
}
rs(dnslinks[0].slice('dnslink='.length));
});
});
}
module.exports = {
resolve,
update,
};

@@ -9,6 +9,6 @@ const assert = require('assert');

assert.rejects(() => dnslink(`${random()}.commontheory.io`));
assert.doesNotReject(() => dnslink(`commontheory.io`));
assert.doesNotReject(() => dnslink(`coverage.commontheory.io`));
assert.rejects(() => dnslink.resolve(`${random()}.commontheory.io`));
assert.doesNotReject(() => dnslink.resolve(`commontheory.io`));
assert.doesNotReject(() => dnslink.resolve(`coverage.commontheory.io`));
console.log('Test passed');
console.log('Tests passed');
{
"name": "dnslink",
"version": "0.0.4",
"version": "0.1.0",
"description": "Resolve dnslink TXT records for domains",
"main": "index.js",
"bin": {
"dnslink": "./cli.js"
},
"types": "index.d.ts",

@@ -19,3 +22,7 @@ "scripts": {

},
"homepage": "https://github.com/common-theory/dnslink#readme"
"homepage": "https://github.com/common-theory/dnslink#readme",
"dependencies": {
"digitalocean": "^1.2.0",
"yargs": "^12.0.2"
}
}
# dnslink [![Build Status](https://travis-ci.org/common-theory/dnslink.svg?branch=master)](https://travis-ci.org/common-theory/dnslink) [![npm](https://img.shields.io/npm/v/dnslink.svg)](https://www.npmjs.com/package/dnslink) [![npm type definitions](https://img.shields.io/npm/types/dnslink.svg)](https://github.com/common-theory/dnslink)
A javascript [dnslink](https://docs.ipfs.io/guides/concepts/dnslink/) resolution implementation.
## Usage
### `update`
#### Command Line
Create a dnslink binding via digitalocean.
An environment variable called `DIGITAL_OCEAN_TOKEN` should be set.
```sh
$ dnslink update commontheory.io /ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy
Unable to find dnslink record, creating a new one
DNS record updated
```
#### JS/TS
```ts
import { update } from 'dnslink';
// async/await
await update('commontheory.io', '/ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy');
// promises
update('commontheory.io', '/ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy')
.then(cid => /* Your logic */);
```
### `resolve`
Get the CID associated with a domain.
#### Command Line
```sh
$ dnslink resolve commontheory.io
/ipfs/QmStyTZJJugmdFub1GBBGhtXpwxghT4EGvBCz8jNSLdBcy
```
#### JS/TS
```ts
import { resolve } from 'dnslink';
// async/await
const cid = await resolve('commontheory.io');
// promises
resolve('commontheory.io')
.then(cid => /* Your logic */);
```
## Note
This package is not maintained by, or affiliated with IPFS or Protocol Labs.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc