New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@multiformats/multiaddr

Package Overview
Dependencies
Maintainers
10
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@multiformats/multiaddr - npm Package Compare versions

Comparing version 10.2.1 to 10.3.0

7

dist/src/index.d.ts

@@ -23,4 +23,7 @@ import { getProtocol } from './protocols-table.js';

export interface Resolver {
(addr: Multiaddr): Promise<string[]>;
(addr: Multiaddr, options?: AbortOptions): Promise<string[]>;
}
export interface AbortOptions {
signal?: AbortSignal;
}
declare const resolvers: Map<string, Resolver>;

@@ -257,3 +260,3 @@ /**

*/
resolve(): Promise<Multiaddr[]>;
resolve(options?: AbortOptions): Promise<Multiaddr[]>;
/**

@@ -260,0 +263,0 @@ * Gets a Multiaddrs node-friendly address object. Note that protocol information

@@ -369,3 +369,3 @@ import * as codec from './codec.js';

*/
async resolve() {
async resolve(options) {
const resolvableProto = this.protos().find((p) => p.resolvable);

@@ -380,3 +380,3 @@ // Multiaddr is not resolvable?

}
const addresses = await resolver(this);
const addresses = await resolver(this, options);
return addresses.map((a) => new Multiaddr(a));

@@ -383,0 +383,0 @@ }

@@ -1,6 +0,6 @@

import type { Multiaddr } from '../index.js';
import type { AbortOptions, Multiaddr } from '../index.js';
/**
* Resolver for dnsaddr addresses.
*/
export declare function dnsaddrResolver(addr: Multiaddr): Promise<string[]>;
export declare function dnsaddrResolver(addr: Multiaddr, options?: AbortOptions): Promise<string[]>;
//# sourceMappingURL=index.d.ts.map

@@ -7,4 +7,9 @@ import { getProtocol } from '../protocols-table.js';

*/
export async function dnsaddrResolver(addr) {
export async function dnsaddrResolver(addr, options = {}) {
const resolver = new Resolver();
if (options.signal != null) {
options.signal.addEventListener('abort', () => {
resolver.cancel();
});
}
const peerId = addr.getPeerId();

@@ -11,0 +16,0 @@ const [, hostname] = addr.stringTuples().find(([proto]) => proto === dnsaddrCode) ?? [];

{
"name": "@multiformats/multiaddr",
"version": "10.2.1",
"version": "10.3.0",
"description": "multiaddr implementation (binary + string representation of network addresses)",

@@ -49,8 +49,11 @@ "license": "Apache-2.0 OR MIT",

".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
},
"./convert": {
"types": "./dist/src/convert.d.ts",
"import": "./dist/src/convert.js"
},
"./resolvers": {
"types": "./dist/src/resolvers/index.d.ts",
"import": "./dist/src/resolvers/index.js"

@@ -130,5 +133,9 @@ }

"type": "docs",
"section": "Trivial Changes"
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",

@@ -149,16 +156,15 @@ "section": "Tests"

"lint": "aegir lint",
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
"build": "tsc",
"pretest": "npm run build",
"test": "aegir test -f ./dist/test/**/*.js",
"test:chrome": "npm run test -- -t browser",
"test:chrome-webworker": "npm run test -- -t webworker",
"test:firefox": "npm run test -- -t browser -- --browser firefox",
"test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
"test:node": "npm run test -- -t node --cov",
"test:electron-main": "npm run test -- -t electron-main",
"release": "semantic-release"
"dep-check": "aegir dep-check",
"build": "aegir build",
"test": "aegir test -f",
"test:chrome": "aegir test -t browser",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:node": "aegir test -t node --cov",
"test:electron-main": "aegir test -t electron-main",
"release": "aegir release"
},
"dependencies": {
"dns-over-http-resolver": "^2.0.1",
"dns-over-http-resolver": "^2.1.0",
"err-code": "^3.0.1",

@@ -172,3 +178,3 @@ "is-ip": "^4.0.0",

"@types/varint": "^6.0.0",
"aegir": "^36.1.3",
"aegir": "^37.4.5",
"sinon": "^13.0.1",

@@ -175,0 +181,0 @@ "util": "^0.12.3"

@@ -1,15 +0,29 @@

js-multiaddr
============
# @multiformats/multiaddr <!-- omit in toc -->
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
[![Dependency Status](https://david-dm.org/multiformats/js-multiaddr.svg?style=flat-square)](https://david-dm.org/multiformats/js-multiaddr)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![](https://img.shields.io/travis/multiformats/js-multiaddr.svg?style=flat-square)](https://travis-ci.com/multiformats/js-multiaddr)
[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiaddr.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiaddr)
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/multiformats/js-multiaddr/actions/workflows/js-test-and-release.yml)
> JavaScript implementation of [multiaddr](https://github.com/multiformats/multiaddr).
> multiaddr implementation (binary + string representation of network addresses)
## Table of contents <!-- omit in toc -->
- [Install](#install)
- [Lead Maintainer](#lead-maintainer)
- [Background](#background)
- [What is multiaddr?](#what-is-multiaddr)
- [Browser: `<script>` Tag](#browser-script-tag)
- [Usage](#usage)
- [API](#api)
- [Resolvers](#resolvers)
- [Contribute](#contribute)
- [License](#license)
- [Contribution](#contribution)
## Install
```console
$ npm i @multiformats/multiaddr
```
## Lead Maintainer

@@ -19,18 +33,2 @@

## Table of Contents
- [js-multiaddr](#js-multiaddr)
- [Lead Maintainer](#lead-maintainer)
- [Table of Contents](#table-of-contents)
- [Background](#background)
- [What is multiaddr?](#what-is-multiaddr)
- [Install](#install)
- [NPM](#npm)
- [Browser: `<script>` Tag](#browser-script-tag)
- [Usage](#usage)
- [API](#api)
- [Resolvers](#resolvers)
- [Contribute](#contribute)
- [License](#license)
## Background

@@ -48,5 +46,2 @@

## Install
### NPM
```sh

@@ -69,8 +64,8 @@ npm i multiaddr

// if we are coming from <= 8.x you can use the factory function
const { multiaddr } = require('multiaddr')
const addr =  multiaddr("/ip4/127.0.0.1/udp/1234")
const { multiaddr } = require('multiaddr')
const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>
// or just the class directly
const { Multiaddr } = require('multiaddr')
const { Multiaddr } = require('multiaddr')

@@ -110,7 +105,7 @@ const addr = new Multiaddr("/ip4/127.0.0.1/udp/1234")

https://multiformats.github.io/js-multiaddr/
<https://multiformats.github.io/js-multiaddr/>
## Resolvers
`multiaddr` allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own. Resolvers should always be set in the same module that is calling `multiaddr.resolve()` to avoid conflicts if multiple versions of `multiaddr` are in your dependency tree.
`multiaddr` allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own. Resolvers should always be set in the same module that is calling `multiaddr.resolve()` to avoid conflicts if multiple versions of `multiaddr` are in your dependency tree.
To provide multiaddr resolvers you can do:

@@ -127,4 +122,4 @@

| Name | type | Description |
|-------------|------|-------------|
| Name | type | Description |
| ----------------- | --------- | ----------------------------------- |
| `dnsaddrResolver` | `dnsaddr` | dnsaddr resolution with TXT Records |

@@ -144,2 +139,9 @@

[MIT](LICENSE) © 2016 Protocol Labs Inc.
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

@@ -46,4 +46,8 @@ import * as codec from './codec.js'

export interface Resolver { (addr: Multiaddr): Promise<string[]> }
export interface Resolver { (addr: Multiaddr, options?: AbortOptions): Promise<string[]> }
export interface AbortOptions {
signal?: AbortSignal
}
const resolvers = new Map<string, Resolver>()

@@ -425,3 +429,3 @@ const symbol = Symbol.for('@multiformats/js-multiaddr/multiaddr')

*/
async resolve () {
async resolve (options?: AbortOptions) {
const resolvableProto = this.protos().find((p) => p.resolvable)

@@ -439,3 +443,3 @@

const addresses = await resolver(this)
const addresses = await resolver(this, options)
return addresses.map((a) => new Multiaddr(a))

@@ -442,0 +446,0 @@ }

import { getProtocol } from '../protocols-table.js'
import Resolver from './dns.js'
import type { Multiaddr } from '../index.js'
import type { AbortOptions, Multiaddr } from '../index.js'

@@ -10,5 +10,11 @@ const { code: dnsaddrCode } = getProtocol('dnsaddr')

*/
export async function dnsaddrResolver (addr: Multiaddr) {
export async function dnsaddrResolver (addr: Multiaddr, options: AbortOptions = {}) {
const resolver = new Resolver()
if (options.signal != null) {
options.signal.addEventListener('abort', () => {
resolver.cancel()
})
}
const peerId = addr.getPeerId()

@@ -22,2 +28,3 @@ const [, hostname] = addr.stringTuples().find(([proto]) => proto === dnsaddrCode) ?? []

const records = await resolver.resolveTxt(`_dnsaddr.${hostname}`)
let addresses = records.flat().map((a) => a.split('=')[1])

@@ -24,0 +31,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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