Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/sinon-19.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Nov 21, 2024
2 parents fda78fc + d0d8db4 commit f4f8a5f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 67 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [12.3.2](https://github.com/multiformats/js-multiaddr/compare/v12.3.1...v12.3.2) (2024-11-21)

### Bug Fixes

* do not allow modifying tuples ([#391](https://github.com/multiformats/js-multiaddr/issues/391)) ([77f15d2](https://github.com/multiformats/js-multiaddr/commit/77f15d29b07e7b7e2fb9e3ef39cd0e1da0982388))

### Documentation

* fix dnsaddrResolver name ([#392](https://github.com/multiformats/js-multiaddr/issues/392)) ([823b45f](https://github.com/multiformats/js-multiaddr/commit/823b45fc786d0603f3260b9de4c7694dbe91533a)), closes [#388](https://github.com/multiformats/js-multiaddr/issues/388)

## [12.3.1](https://github.com/multiformats/js-multiaddr/compare/v12.3.0...v12.3.1) (2024-09-09)

### Bug Fixes
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ A standard way to represent addresses that

```TypeScript
import { multiaddr } from '@multiformats/multiaddr'
const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
// Multiaddr(/ip4/127.0.0.1/udp/1234)

const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
const addr = multiaddr('/ip4/127.0.0.1/udp/1234')
// Multiaddr(/ip4/127.0.0.1/udp/1234)

addr.bytes
Expand Down Expand Up @@ -77,9 +75,9 @@ DNSADDR addresses can resolve to multiple multiaddrs, since there is no limit to

```TypeScript
import { multiaddr, resolvers } from '@multiformats/multiaddr'
import { dnsaddr } from '@multiformats/multiaddr/resolvers'
import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'

resolvers.set('dnsaddr', dnsaddr)
resolvers.set('dnsaddr', dnsaddrResolver)

const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io')

Expand All @@ -88,7 +86,7 @@ const resolved = await ma.resolve({
signal: AbortSignal.timeout(5000)
})

console.info(await ma.resolve(resolved)
console.info(resolved)
// [Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...')...]
```

Expand All @@ -102,7 +100,9 @@ import { dns } from '@multiformats/dns'
import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'

const resolver = dns({
'.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query')
resolvers: {
'.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query')
}
})

const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io')
Expand Down
29 changes: 0 additions & 29 deletions examples/try.js

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiformats/multiaddr",
"version": "12.3.1",
"version": "12.3.2",
"description": "multiaddr implementation (binary + string representation of network addresses)",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/multiformats/js-multiaddr#readme",
Expand Down Expand Up @@ -154,6 +154,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"doc-check": "aegir doc-check",
"build": "aegir build",
"test": "aegir test -f",
"test:chrome": "aegir test -t browser --cov",
Expand All @@ -175,7 +176,7 @@
},
"devDependencies": {
"@types/sinon": "^17.0.2",
"aegir": "^44.1.1",
"aegir": "^45.0.2",
"sinon": "^19.0.2",
"sinon-ts": "^2.0.0"
},
Expand Down
6 changes: 0 additions & 6 deletions src/convert.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* @packageDocumentation
*
* Provides methods for converting
*/

import { IpNet } from '@chainsafe/netmask'
import { base32 } from 'multiformats/bases/base32'
import { base58btc } from 'multiformats/bases/base58'
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
*
* ```TypeScript
* import { multiaddr } from '@multiformats/multiaddr'
* const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
* // Multiaddr(/ip4/127.0.0.1/udp/1234)
*
* const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
* const addr = multiaddr('/ip4/127.0.0.1/udp/1234')
* // Multiaddr(/ip4/127.0.0.1/udp/1234)
*
* addr.bytes
Expand Down Expand Up @@ -55,9 +53,9 @@
*
* ```TypeScript
* import { multiaddr, resolvers } from '@multiformats/multiaddr'
* import { dnsaddr } from '@multiformats/multiaddr/resolvers'
* import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers'
*
* resolvers.set('dnsaddr', dnsaddr)
* resolvers.set('dnsaddr', dnsaddrResolver)
*
* const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io')
*
Expand All @@ -66,7 +64,7 @@
* signal: AbortSignal.timeout(5000)
* })
*
* console.info(await ma.resolve(resolved)
* console.info(resolved)
* // [Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...'), Multiaddr('/ip4/147.75...')...]
* ```
*
Expand All @@ -80,7 +78,9 @@
* import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
*
* const resolver = dns({
* '.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query')
* resolvers: {
* '.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query')
* }
* })
*
* const ma = multiaddr('/dnsaddr/bootstrap.libp2p.io')
Expand Down
30 changes: 14 additions & 16 deletions src/multiaddr.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/**
* @packageDocumentation
*
* An implementation of a Multiaddr in JavaScript
*
* @example
*
* ```js
* import { multiaddr } from '@multiformats/multiaddr'
*
* const ma = multiaddr('/ip4/127.0.0.1/tcp/1234')
* ```
*/

import { base58btc } from 'multiformats/bases/base58'
import { CID } from 'multiformats/cid'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
Expand Down Expand Up @@ -151,11 +137,23 @@ export class Multiaddr implements MultiaddrInterface {
}

tuples (): Array<[number, Uint8Array?]> {
return this.#tuples
return this.#tuples.map(([code, value]) => {
if (value == null) {
return [code]
}

return [code, value]
})
}

stringTuples (): Array<[number, string?]> {
return this.#stringTuples
return this.#stringTuples.map(([code, value]) => {
if (value == null) {
return [code]
}

return [code, value]
})
}

encapsulate (addr: MultiaddrInput): Multiaddr {
Expand Down
1 change: 1 addition & 0 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export interface Resolver<ResolveOptions extends AbortOptions = AbortOptions> {
}

export { dnsaddrResolver } from './dnsaddr.js'
export type { DNSADDROptions } from './dnsaddr.js'
16 changes: 16 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,14 @@ describe('helpers', () => {
[302]
])
})

it('does not allow modifying parts', () => {
const ma = multiaddr('/ip4/0.0.0.0/tcp/1234')
const tuples = ma.tuples()
tuples[0][0] = 41

expect(ma.toOptions()).to.have.property('family', 4)
})
})

describe('.stringTuples', () => {
Expand All @@ -741,6 +749,14 @@ describe('helpers', () => {
[302]
])
})

it('does not allow modifying string parts', () => {
const ma = multiaddr('/ip4/0.0.0.0/tcp/1234')
const tuples = ma.stringTuples()
tuples[0][0] = 41

expect(ma.toOptions()).to.have.property('family', 4)
})
})

describe('.decapsulate', () => {
Expand Down

0 comments on commit f4f8a5f

Please sign in to comment.