Compare commits

...

41 Commits

Author SHA1 Message Date
Pavel Murygin
3d47c8d9be bump dependencies 2021-04-09 18:23:24 +03:00
Vasco Santos
5c177cddd9 chore: add util dev dep 2021-03-15 14:34:53 +01:00
dependabot-preview[bot]
1d9532a83f chore(deps-dev): bump aegir from 31.0.4 to 32.0.2
Bumps [aegir](https://github.com/ipfs/aegir) from 31.0.4 to 32.0.2.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v31.0.4...v32.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-15 14:34:53 +01:00
dependabot-preview[bot]
2524351ebc
chore(deps-dev): bump aegir from 30.3.0 to 31.0.3 (#74)
Bumps [aegir](https://github.com/ipfs/aegir) from 30.3.0 to 31.0.3.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v30.3.0...v31.0.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2021-03-05 10:00:53 +01:00
Vasco Santos
6a8b586003 chore: fix lint 2021-02-15 09:57:56 +01:00
dependabot-preview[bot]
175e1661a7 chore(deps-dev): bump aegir from 29.2.2 to 30.3.0
Bumps [aegir](https://github.com/ipfs/aegir) from 29.2.2 to 30.3.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v29.2.2...v30.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-15 09:57:56 +01:00
Vasco Santos
e1dedc8139 chore: release version v8.0.4 2021-01-13 16:03:08 +01:00
Vasco Santos
edc37b4306 chore: update contributors 2021-01-13 16:03:08 +01:00
wqsz7xn
ac7d10c646
feat: add QUIC support (#70) 2021-01-13 15:31:49 +01:00
Vasco Santos
38a1f1f171 chore: release version v8.0.3 2021-01-11 10:20:36 +01:00
Vasco Santos
ce180cc04a chore: update contributors 2021-01-11 10:20:35 +01:00
Vasco Santos
c8430c1556
fix: add webrtc direct with p2p as valid P2P multiaddr (#71) 2021-01-11 10:16:51 +01:00
Vasco Santos
f5beeee47c chore: release version v8.0.2 2020-12-28 10:19:22 +00:00
Vasco Santos
a4ee2a9449 chore: update contributors 2020-12-28 10:19:22 +00:00
Vasco Santos
10e131dade
chore: fix json format ts config (#68) 2020-12-28 10:18:37 +00:00
dependabot-preview[bot]
810466c0f2
chore(deps-dev): bump uint8arrays from 1.1.0 to 2.0.5 (#66)
Bumps [uint8arrays](https://github.com/achingbrain/uint8arrays) from 1.1.0 to 2.0.5.
- [Release notes](https://github.com/achingbrain/uint8arrays/releases)
- [Changelog](https://github.com/achingbrain/uint8arrays/blob/master/CHANGELOG.md)
- [Commits](https://github.com/achingbrain/uint8arrays/compare/v1.1.0...v2.0.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-12-22 13:05:19 +00:00
dependabot-preview[bot]
161aa30b7b
chore(deps-dev): bump aegir from 28.2.0 to 29.0.1 (#64)
Bumps [aegir](https://github.com/ipfs/aegir) from 28.2.0 to 29.0.1.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v28.2.0...v29.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-11-24 14:15:56 +01:00
Vasco Santos
b02922eb1b chore: release version v8.0.1 2020-10-27 12:01:37 +00:00
Vasco Santos
85d5045ee6 chore: update contributors 2020-10-27 12:01:37 +00:00
Vasco Santos
86928d49c2 chore: add support for dns4 and dns6 2020-10-27 11:58:49 +00:00
Vasco Santos
95d5178a2a feat: add dnsnaddr p2p 2020-10-27 11:58:49 +00:00
dependabot-preview[bot]
79b1b53f3d
chore(deps-dev): bump aegir from 27.0.0 to 28.0.2 (#63)
Bumps [aegir](https://github.com/ipfs/aegir) from 27.0.0 to 28.0.2.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v27.0.0...v28.0.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-10-26 09:40:52 +00:00
dependabot-preview[bot]
9da7f66990
chore(deps-dev): bump aegir from 26.0.0 to 27.0.0 (#61)
Bumps [aegir](https://github.com/ipfs/aegir) from 26.0.0 to 27.0.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v26.0.0...v27.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-10-06 10:46:01 +02:00
dependabot-preview[bot]
c95bd9d91c
chore(deps-dev): bump aegir from 25.1.0 to 26.0.0 (#60)
Bumps [aegir](https://github.com/ipfs/aegir) from 25.1.0 to 26.0.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v25.1.0...v26.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-08-16 19:06:12 +02:00
Jacob Heun
1c92da635d
chore: release version v8.0.0 2020-08-10 15:37:39 +02:00
Jacob Heun
48eaa4bf59
chore: update contributors 2020-08-10 15:37:39 +02:00
Alex Potsides
022ab870fc
fix: replace node buffers with uint8arrays (#59)
BREAKING CHANGES:

- Now uses a version of `multiaddr` than has a `.bytes` property instead of `.buffer`
2020-08-10 15:34:58 +02:00
dependabot-preview[bot]
af85d97a3f
chore(deps-dev): bump @types/mocha from 7.0.2 to 8.0.0 (#57)
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 7.0.2 to 8.0.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-07-21 14:20:22 +02:00
dependabot-preview[bot]
d0e0631857
chore(deps-dev): bump aegir from 22.1.0 to 25.0.0 (#55)
Bumps [aegir](https://github.com/ipfs/aegir) from 22.1.0 to 25.0.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v22.1.0...v25.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-07-13 11:36:51 +02:00
Vasco Santos
6d86efaeb7
chore: add buffer to tests (#56) 2020-07-13 10:43:51 +02:00
dependabot-preview[bot]
f1b20b032b
chore(deps-dev): bump aegir from 21.10.2 to 22.0.0 (#52)
Bumps [aegir](https://github.com/ipfs/aegir) from 21.10.2 to 22.0.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v21.10.2...v22.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-05-25 18:16:20 +02:00
dependabot-preview[bot]
02dba170bf
chore(deps-dev): bump aegir from 20.6.1 to 21.3.0 (#51)
Bumps [aegir](https://github.com/ipfs/aegir) from 20.6.1 to 21.3.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v20.6.1...v21.3.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-21 06:51:21 -05:00
Jacob Heun
571d381385
chore: release version v7.1.0 2020-02-06 13:58:45 +01:00
Jacob Heun
f5c7da8ddb
chore: update contributors 2020-02-06 13:58:45 +01:00
Cayman
74830fa5d9
feat: add typescript types + type tests (#48)
* feat: add typescript types

* feat: add typescript type tests

* chore: bump deps

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-02-06 13:57:16 +01:00
Jacob Heun
52d9dfc062
chore: release version v7.0.1 2020-01-23 16:49:07 +01:00
Jacob Heun
ecaababa40
chore: update contributors 2020-01-23 16:49:07 +01:00
Jacob Heun
7112ab7898
fix: webrtc-star should not require the p2p codec (#47)
* fix: webrtc-star should not require the p2p codec

* docs: update readme ipfs -> p2p

* docs: fix badges
2020-01-23 16:47:25 +01:00
Vasco Santos
48a6c9f5bd chore: release version v7.0.0 2019-09-11 19:53:47 +02:00
Vasco Santos
decf40cfbe chore: update contributors 2019-09-11 19:53:47 +02:00
Vasco Santos
1479f6ad2c
chore: update deps (#46)
As multiaddr now defaults to using /p2p over /ipfs
we no longer need the logic for both. /ipfs is still supported
as demonstrated in the tests.
2019-09-11 19:47:54 +02:00
9 changed files with 242 additions and 54 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ coverage
.lock-wscript
build
docs
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git

View File

@ -6,6 +6,7 @@ stages:
- cov
node_js:
- '12'
- '10'
os:
@ -20,7 +21,6 @@ jobs:
include:
- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check -- -i wrtc -i electron-webrtc
- npm run lint

View File

@ -1,3 +1,85 @@
## [8.0.4](https://github.com/multiformats/js-mafmt/compare/v8.0.3...v8.0.4) (2021-01-13)
### Features
* add QUIC support ([#70](https://github.com/multiformats/js-mafmt/issues/70)) ([ac7d10c](https://github.com/multiformats/js-mafmt/commit/ac7d10c646f343edd3154bae504bc9a2dcd0d506))
## [8.0.3](https://github.com/multiformats/js-mafmt/compare/v8.0.2...v8.0.3) (2021-01-11)
### Bug Fixes
* add webrtc direct with p2p as valid P2P multiaddr ([#71](https://github.com/multiformats/js-mafmt/issues/71)) ([c8430c1](https://github.com/multiformats/js-mafmt/commit/c8430c1556edf687d22f2c00eb3b6ff96b580aa5))
## [8.0.2](https://github.com/multiformats/js-mafmt/compare/v8.0.1...v8.0.2) (2020-12-28)
<a name="8.0.1"></a>
## [8.0.1](https://github.com/multiformats/js-mafmt/compare/v7.1.0...v8.0.1) (2020-10-27)
### Bug Fixes
* replace node buffers with uint8arrays ([#59](https://github.com/multiformats/js-mafmt/issues/59)) ([022ab87](https://github.com/multiformats/js-mafmt/commit/022ab87))
### Features
* add dnsnaddr p2p ([95d5178](https://github.com/multiformats/js-mafmt/commit/95d5178))
### BREAKING CHANGES
* - Now uses a version of `multiaddr` than has a `.bytes` property instead of `.buffer`
<a name="8.0.0"></a>
# [8.0.0](https://github.com/multiformats/js-mafmt/compare/v7.1.0...v8.0.0) (2020-08-10)
### Bug Fixes
* replace node buffers with uint8arrays ([#59](https://github.com/multiformats/js-mafmt/issues/59)) ([022ab87](https://github.com/multiformats/js-mafmt/commit/022ab87))
### BREAKING CHANGES
* - Now uses a version of `multiaddr` than has a `.bytes` property instead of `.buffer`
<a name="7.1.0"></a>
# [7.1.0](https://github.com/multiformats/js-mafmt/compare/v7.0.1...v7.1.0) (2020-02-06)
### Features
* add typescript types + type tests ([#48](https://github.com/multiformats/js-mafmt/issues/48)) ([74830fa](https://github.com/multiformats/js-mafmt/commit/74830fa))
<a name="7.0.1"></a>
## [7.0.1](https://github.com/multiformats/js-mafmt/compare/v7.0.0...v7.0.1) (2020-01-23)
### Bug Fixes
* webrtc-star should not require the p2p codec ([#47](https://github.com/multiformats/js-mafmt/issues/47)) ([7112ab7](https://github.com/multiformats/js-mafmt/commit/7112ab7))
<a name="7.0.0"></a>
# [7.0.0](https://github.com/multiformats/js-mafmt/compare/v6.0.10...v7.0.0) (2019-09-11)
<a name="6.0.10"></a>
## [6.0.10](https://github.com/multiformats/js-mafmt/compare/v6.0.9...v6.0.10) (2019-09-11)

View File

@ -1,13 +1,12 @@
js-mafmt
========
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/whyrusleeping/js-mafmt/badge.svg?branch=master)](https://coveralls.io/github/whyrusleeping/js-mafmt?branch=master)
[![Travis CI](https://travis-ci.org/whyrusleeping/js-mafmt.svg?branch=master)](https://travis-ci.org/whyrusleeping/js-mafmt)
[![Circle CI](https://circleci.com/gh/whyrusleeping/js-mafmt.svg?style=svg)](https://circleci.com/gh/whyrusleeping/js-mafmt)
[![Dependency Status](https://david-dm.org/whyrusleeping/js-mafmt.svg?style=flat-square)](https://david-dm.org/whyrusleeping/js-mafmt) [![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/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](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-mafmt.svg?style=flat-square)](https://david-dm.org/multiformats/js-mafmt)
[![](https://img.shields.io/travis/multiformats/js-mafmt.svg?style=flat-square)](https://travis-ci.com/multiformats/js-mafmt)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-mafmt.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-mafmt)
> Javascript implementation of multiaddr validation
@ -43,16 +42,17 @@ Where `<FORMAT>` may be:
| `IP` | an "ip4" or "ip6" format multiaddr | `/ip4/127.0.0.1` <br> `/ip6/fc00::` |
| `TCP` | a "tcp" over `IP` format multiaddr | `/ip4/0.0.7.6/tcp/1234` |
| `UDP` | a "udp" over `IP` format multiaddr | `/ip4/0.0.7.6/udp/1234` |
| `QUIC` | a "quic" over `UDP` format multiaddr | `/ip4/1.2.3.4/udp/1234/quic` |
| `UTP` | a "utp" over `UDP` format multiaddr | `/ip4/1.2.3.4/udp/3456/utp` |
| `Websockets` | a "ws" over `TCP` or "ws" over `DNS` format multiaddr | `/ip4/1.2.3.4/tcp/3456/ws` <br> `/dnsaddr/ipfs.io/ws` |
| `WebSocketsSecure` | a "wss" over `TCP` or "wss" over `DNS` format multiaddr | `/ip6/::/tcp/0/wss` <br> `/dnsaddr/ipfs.io/wss` |
| `HTTP` | a "http" over `TCP` or `DNS` or "http" over `DNS` format multiaddr | `/ip4/127.0.0.1/tcp/90/http` <br> `/dnsaddr/ipfs.io/http` |
| `HTTPS` | a "https" over `TCP` or `DNS` or "https" over `DNS` format multiaddr | `/ip4/127.0.0.1/tcp/90/https` <br> `/dnsaddr/ipfs.io/https` |
| `WebRTCStar` | an "ipfs" over "p2p-webrtc-star" over `Websockets` or "ipfs" over "p2p-webrtc-star" over `WebSocketsSecure` format multiaddr | `/dnsaddr/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` |
| `WebSocketStar` | an "ipfs" over "p2p-websocket-star" over `Websockets` or "ipfs" over "p2p-websocket-star" over `WebSocketsSecure` or "p2p-websocket-star" over `Websockets` or "p2p-websocket-star" over `WebSocketsSecure` format multiaddr | `/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star` <br> `/dnsaddr/localhost/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` |
| `WebRTCStar` | a "p2p" over "p2p-webrtc-star" over `Websockets` or "p2p" over "p2p-webrtc-star" over `WebSocketsSecure` format multiaddr | `/dnsaddr/ipfs.io/wss/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` |
| `WebSocketStar` | a "p2p" over "p2p-websocket-star" over `Websockets` or "p2p" over "p2p-websocket-star" over `WebSocketsSecure` or "p2p-websocket-star" over `Websockets` or "p2p-websocket-star" over `WebSocketsSecure` format multiaddr | `/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star` <br> `/dnsaddr/localhost/ws/p2p-websocket-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` |
| `WebRTCDirect` | a "p2p-webrtc-direct" over `HTTP` or "p2p-webrtc-direct" over `HTTPS` format multiaddr | `/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct` |
| `Reliable` | a `WebSockets` or `WebSocketsSecure` or `HTTP` or `HTTPS` or `WebRTCStar` or `WebRTCDirect` or `TCP` or `UTP` format multiaddr | `/dnsaddr/ipfs.io/wss` |
| `Circuit` | | `/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
| `Reliable` | a `WebSockets` or `WebSocketsSecure` or `HTTP` or `HTTPS` or `WebRTCStar` or `WebRTCDirect` or `TCP` or `UTP` or `QUIC` format multiaddr | `/dnsaddr/ipfs.io/wss` |
| `Circuit` | | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
| `P2P` | "p2p", aka "ipfs", over `Reliable` or `WebRTCStar` or "p2p" format multiaddr | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` <br> `/ip4/127.0.0.1/tcp/20008/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
Where `multiaddr` may be:

View File

@ -1,6 +1,6 @@
{
"name": "mafmt",
"version": "6.0.10",
"version": "8.0.4",
"description": "A multiaddr validator",
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
"main": "src/index.js",
@ -10,6 +10,7 @@
"test": "aegir test",
"test:node": "aegir test --target node",
"test:browser": "aegir test --target browser",
"test:types": "npx tsc",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
@ -17,8 +18,7 @@
"coverage-publish": "aegir coverage publish"
},
"pre-push": [
"lint",
"test"
"lint"
],
"repository": "github:multiformats/js-mafmt",
"keywords": [
@ -28,26 +28,29 @@
"bugs": "https://github.com/multiformats/js-mafmt/issues",
"homepage": "https://github.com/multiformats/js-mafmt#readme",
"devDependencies": {
"aegir": "^20.0.0",
"chai": "^4.2.0"
"@types/chai": "^4.2.8",
"@types/mocha": "^8.0.0",
"aegir": "^32.0.2",
"uint8arrays": "^2.0.5",
"util": "^0.12.3"
},
"dependencies": {
"multiaddr": "^6.1.0"
"multiaddr": "^9.0.1"
},
"contributors": [
"Alan Shaw <alan@tableflip.io>",
"David Dias <daviddias.p@gmail.com>",
"Hugo Dias <mail@hugodias.me>",
"Jacob Heun <jacobheun@gmail.com>",
"Jeromy <jeromyj@gmail.com>",
"Jeromy Johnson <why@ipfs.io>",
"João Antunes <me@jgantunes.com>",
"Maciej Krüger <mkg20001@gmail.com>",
"Marcin Rataj <lidel@lidel.org>",
"Vasco Santos <vasco.santos@moxy.studio>",
"Vasco Santos <vasco.santos@ua.pt>",
"dignifiedquire <dignifiedquire@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"dmitriy ryajov <dryajov@dmitriys-MBP.HomeNET>",
"victorbjelkholm <victorbjelkholm@gmail.com>"
"Maciej Krüger <mkg20001@gmail.com>",
"Alan Shaw <alan@tableflip.io>",
"Jeromy <jeromyj@gmail.com>",
"dignifiedquire <dignifiedquire@gmail.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Marcin Rataj <lidel@lidel.org>",
"Cayman <caymannava@gmail.com>",
"João Antunes <me@jgantunes.com>",
"Alex Potsides <alex@achingbrain.net>",
"Hugo Dias <mail@hugodias.me>"
]
}

29
src/index.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
import Multiaddr = require('multiaddr');
export declare interface Mafmt {
toString(): string;
input?: (Mafmt | (() => Mafmt))[];
matches: (a: string | Uint8Array | Multiaddr) => boolean;
partialMatch: (protos: string[]) => boolean;
}
export const DNS: Mafmt;
export const DNS4: Mafmt;
export const DNS6: Mafmt;
export const IP: Mafmt;
export const TCP: Mafmt;
export const UDP: Mafmt;
export const QUIC: Mafmt;
export const UTP: Mafmt;
export const HTTP: Mafmt;
export const HTTPS: Mafmt;
export const WebSockets: Mafmt;
export const WebSocketsSecure: Mafmt;
export const WebSocketStar: Mafmt;
export const WebRTCStar: Mafmt;
export const WebRTCDirect: Mafmt;
export const Reliable: Mafmt;
export const Stardust: Mafmt;
export const Circuit: Mafmt;
export const P2P: Mafmt;
export const IPFS: Mafmt;

View File

@ -7,9 +7,10 @@ const multiaddr = require('multiaddr')
*/
const DNS4 = base('dns4')
const DNS6 = base('dns6')
const DNSADDR = base('dnsaddr')
const DNS = or(
base('dns'),
base('dnsaddr'),
DNSADDR,
DNS4,
DNS6
)
@ -22,6 +23,8 @@ const TCP = or(
const UDP = and(IP, base('udp'))
const UTP = and(UDP, base('utp'))
const QUIC = and(UDP, base('quic'))
const WebSockets = or(
and(TCP, base('ws')),
and(DNS, base('ws'))
@ -45,15 +48,13 @@ const HTTPS = or(
)
const WebRTCStar = or(
and(WebSockets, base('p2p-webrtc-star'), base('ipfs')),
and(WebSocketsSecure, base('p2p-webrtc-star'), base('ipfs')),
and(WebSockets, base('p2p-webrtc-star'), base('p2p')),
and(WebSocketsSecure, base('p2p-webrtc-star'), base('p2p'))
and(WebSocketsSecure, base('p2p-webrtc-star'), base('p2p')),
and(WebSockets, base('p2p-webrtc-star')),
and(WebSocketsSecure, base('p2p-webrtc-star'))
)
const WebSocketStar = or(
and(WebSockets, base('p2p-websocket-star'), base('ipfs')),
and(WebSocketsSecure, base('p2p-websocket-star'), base('ipfs')),
and(WebSockets, base('p2p-websocket-star'), base('p2p')),
and(WebSocketsSecure, base('p2p-websocket-star'), base('p2p')),
and(WebSockets, base('p2p-websocket-star')),
@ -61,6 +62,8 @@ const WebSocketStar = or(
)
const WebRTCDirect = or(
and(HTTP, base('p2p-webrtc-direct'), base('p2p')),
and(HTTPS, base('p2p-webrtc-direct'), base('p2p')),
and(HTTP, base('p2p-webrtc-direct')),
and(HTTPS, base('p2p-webrtc-direct'))
)
@ -73,20 +76,21 @@ const Reliable = or(
WebRTCStar,
WebRTCDirect,
TCP,
UTP
UTP,
QUIC,
DNS
)
// Unlike ws-star, stardust can run over any transport thus removing the requirement for websockets (but don't even think about running a stardust server over webrtc-star ;) )
const Stardust = or(
and(Reliable, base('p2p-stardust'), base('ipfs')),
and(Reliable, base('p2p-stardust'), base('p2p')),
and(Reliable, base('p2p-stardust'))
)
const _P2P = or(
and(Reliable, base('ipfs')),
and(Reliable, base('p2p')),
WebRTCStar,
base('ipfs'),
WebRTCDirect,
base('p2p')
)
@ -117,9 +121,11 @@ const P2P = or(
exports.DNS = DNS
exports.DNS4 = DNS4
exports.DNS6 = DNS6
exports.DNSADDR = DNSADDR
exports.IP = IP
exports.TCP = TCP
exports.UDP = UDP
exports.QUIC = QUIC
exports.UTP = UTP
exports.HTTP = HTTP
exports.HTTPS = HTTPS
@ -140,9 +146,9 @@ exports.IPFS = P2P
function makeMatchesFunction (partialMatch) {
return function matches (a) {
if (!multiaddr.isMultiaddr(a)) {
if (!multiaddr.Multiaddr.isMultiaddr(a)) {
try {
a = multiaddr(a)
a = new multiaddr.Multiaddr(a)
} catch (err) { // catch error
return false // also if it's invalid it's propably not matching as well so return false
}
@ -169,6 +175,7 @@ function and () {
if (a === null) {
return true
}
return false
})
return a
@ -195,6 +202,7 @@ function or () {
out = res
return true
}
return false
})
return out
@ -216,7 +224,7 @@ function base (n) {
function matches (a) {
if (typeof a === 'string') {
try {
a = multiaddr(a)
a = new multiaddr.Multiaddr(a)
} catch (err) { // catch error
return false // also if it's invalid it's propably not matching as well so return false
}

View File

@ -2,9 +2,11 @@
'use strict'
const expect = require('chai').expect
const mafmt = require('./../src')
const { expect } = require('aegir/utils/chai')
const multiaddr = require('multiaddr')
const uint8ArrayFromString = require('uint8arrays/from-string')
const mafmt = require('./../src')
describe('multiaddr validation', function () {
const goodDNS = [
@ -53,6 +55,17 @@ describe('multiaddr validation', function () {
'/ip6/fc00::/tcp/5523/udp/9543'
]
const goodQUIC = [
'/ip4/1.2.3.4/udp/1234/quic',
'/ip6/::/udp/1234/quic'
]
const badQUIC = [
'/ip4/0.0.0.0/tcp/12345/quic',
'/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic',
'/quic'
]
const goodUTP = [
'/ip4/1.2.3.4/udp/3456/utp',
'/ip6/::/udp/0/utp'
@ -98,7 +111,9 @@ describe('multiaddr validation', function () {
'/dnsaddr/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/dnsaddr/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip6/::/tcp/0/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5',
'/ip6/::/tcp/0/ws/p2p-webrtc-star',
'/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79',
'/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star',
'/dns/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79',
'/dns/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79'
]
@ -158,14 +173,21 @@ describe('multiaddr validation', function () {
const goodIPFS = [
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct/p2p/QmPj9ZZ6notLfV9khV1FtxH1Goe5sVaUyqgoXrTYQWp382',
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/ip4/127.0.0.1/tcp/20008/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/tcp/3456/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/udp/1234/quic/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj'
'/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/dns6/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
].concat(goodCircuit)
function assertMatches (p) {
@ -174,9 +196,9 @@ describe('multiaddr validation', function () {
test.forEach(function (testcase) {
try {
expect(p.matches(testcase), `assertMatches: ${testcase} (string)`).to.be.eql(true)
const ma = multiaddr(testcase)
const ma = new multiaddr.Multiaddr(testcase)
expect(p.matches(ma), `assertMatches: ${testcase} (multiaddr object)`).to.be.eql(true)
expect(p.matches(ma.buffer), `assertMatches: ${testcase} (multiaddr.buffer)`).to.be.eql(true)
expect(p.matches(ma.bytes), `assertMatches: ${testcase} (multiaddr.bytes)`).to.be.eql(true)
} catch (err) {
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=true] ' + err.stack
throw err
@ -194,15 +216,15 @@ describe('multiaddr validation', function () {
let validMultiaddrObj
try {
// if testcase string happens to be a valid multiaddr,
// we expect 'p' test to also return false for Multiaddr object and Buffer versions
validMultiaddrObj = multiaddr(testcase)
// we expect 'p' test to also return false for Multiaddr object and Uint8Array versions
validMultiaddrObj = new multiaddr.Multiaddr(testcase)
} catch (e) {
// Ignoring testcase as the string is not a multiaddr
// (There is a separate 'Buffer is invalid' test later below)
// (There is a separate 'Uint8Array is invalid' test later below)
}
if (validMultiaddrObj) {
expect(p.matches(validMultiaddrObj), `assertMismatches: ${testcase} (multiaddr object)`).to.be.eql(false)
expect(p.matches(validMultiaddrObj.buffer), `assertMismatches: ${testcase} (multiaddr.buffer)`).to.be.eql(false)
expect(p.matches(validMultiaddrObj.bytes), `assertMismatches: ${testcase} (multiaddr.bytes)`).to.be.eql(false)
}
} catch (err) {
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=false] ' + err.stack
@ -216,8 +238,8 @@ describe('multiaddr validation', function () {
expect(mafmt.HTTP.matches('/http-google-com')).to.be.eql(false)
})
it('do not throw if multiaddr Buffer is invalid', function () {
expect(mafmt.HTTP.matches(Buffer.from('no spoon'))).to.be.eql(false)
it('do not throw if multiaddr Uint8Array is invalid', function () {
expect(mafmt.HTTP.matches(uint8ArrayFromString('no spoon'))).to.be.eql(false)
})
it('DNS validation', function () {
@ -240,6 +262,11 @@ describe('multiaddr validation', function () {
assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP)
})
it('QUIC validation', function () {
assertMatches(mafmt.QUIC, goodQUIC)
assertMismatches(mafmt.QUIC, badQUIC)
})
it('UTP validation', function () {
assertMatches(mafmt.UTP, goodUTP)
assertMismatches(mafmt.UTP, badUTP, goodIP, goodTCP, goodUDP)
@ -282,7 +309,7 @@ describe('multiaddr validation', function () {
it('WebRTCStar validation', function () {
assertMatches(mafmt.WebRTCStar, goodWebRTCStar)
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWS)
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWSS)
})
it('WebRTCDirect validation', function () {

38
tsconfig.json Normal file
View File

@ -0,0 +1,38 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"target": "ES5",
"noImplicitAny": false,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
"baseUrl": ".",
"paths": {
"mafmt": [
"./src",
"../src"
]
},
"types": [
"node",
"mocha",
"chai"
],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"./src/index.d.ts"
],
"include": [
"./test/**/*.spec.js"
]
}