mirror of
https://github.com/fluencelabs/js-mafmt
synced 2025-04-29 11:02:22 +00:00
Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3d47c8d9be | ||
|
5c177cddd9 | ||
|
1d9532a83f | ||
|
2524351ebc | ||
|
6a8b586003 | ||
|
175e1661a7 | ||
|
e1dedc8139 | ||
|
edc37b4306 | ||
|
ac7d10c646 | ||
|
38a1f1f171 | ||
|
ce180cc04a | ||
|
c8430c1556 | ||
|
f5beeee47c | ||
|
a4ee2a9449 | ||
|
10e131dade | ||
|
810466c0f2 | ||
|
161aa30b7b | ||
|
b02922eb1b | ||
|
85d5045ee6 | ||
|
86928d49c2 | ||
|
95d5178a2a | ||
|
79b1b53f3d | ||
|
9da7f66990 | ||
|
c95bd9d91c | ||
|
1c92da635d | ||
|
48eaa4bf59 | ||
|
022ab870fc | ||
|
af85d97a3f | ||
|
d0e0631857 | ||
|
6d86efaeb7 | ||
|
f1b20b032b | ||
|
02dba170bf | ||
|
571d381385 | ||
|
f5c7da8ddb | ||
|
74830fa5d9 | ||
|
52d9dfc062 | ||
|
ecaababa40 | ||
|
7112ab7898 | ||
|
48a6c9f5bd | ||
|
decf40cfbe | ||
|
1479f6ad2c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -27,6 +27,7 @@ coverage
|
|||||||
.lock-wscript
|
.lock-wscript
|
||||||
|
|
||||||
build
|
build
|
||||||
|
docs
|
||||||
|
|
||||||
# Dependency directory
|
# Dependency directory
|
||||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||||
|
@ -6,6 +6,7 @@ stages:
|
|||||||
- cov
|
- cov
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
|
- '12'
|
||||||
- '10'
|
- '10'
|
||||||
|
|
||||||
os:
|
os:
|
||||||
@ -20,7 +21,6 @@ jobs:
|
|||||||
include:
|
include:
|
||||||
- stage: check
|
- stage: check
|
||||||
script:
|
script:
|
||||||
- npx aegir commitlint --travis
|
|
||||||
- npx aegir dep-check -- -i wrtc -i electron-webrtc
|
- npx aegir dep-check -- -i wrtc -i electron-webrtc
|
||||||
- npm run lint
|
- npm run lint
|
||||||
|
|
||||||
|
82
CHANGELOG.md
82
CHANGELOG.md
@ -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>
|
<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)
|
## [6.0.10](https://github.com/multiformats/js-mafmt/compare/v6.0.9...v6.0.10) (2019-09-11)
|
||||||
|
|
||||||
|
22
README.md
22
README.md
@ -1,13 +1,12 @@
|
|||||||
js-mafmt
|
js-mafmt
|
||||||
========
|
========
|
||||||
|
|
||||||
[](http://ipn.io)
|
[](http://protocol.ai)
|
||||||
[](http://ipfs.io/)
|
[](https://github.com/multiformats/multiformats)
|
||||||
[](http://webchat.freenode.net/?channels=%23ipfs)
|
[](https://webchat.freenode.net/?channels=%23ipfs)
|
||||||
[](https://coveralls.io/github/whyrusleeping/js-mafmt?branch=master)
|
[](https://david-dm.org/multiformats/js-mafmt)
|
||||||
[](https://travis-ci.org/whyrusleeping/js-mafmt)
|
[](https://travis-ci.com/multiformats/js-mafmt)
|
||||||
[](https://circleci.com/gh/whyrusleeping/js-mafmt)
|
[](https://codecov.io/gh/multiformats/js-mafmt)
|
||||||
[](https://david-dm.org/whyrusleeping/js-mafmt) [](https://github.com/feross/standard)
|
|
||||||
|
|
||||||
> Javascript implementation of multiaddr validation
|
> 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::` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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` | 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` |
|
| `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` |
|
| `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` |
|
| `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` | | `/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
|
| `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` |
|
| `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:
|
Where `multiaddr` may be:
|
||||||
|
37
package.json
37
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mafmt",
|
"name": "mafmt",
|
||||||
"version": "6.0.10",
|
"version": "8.0.4",
|
||||||
"description": "A multiaddr validator",
|
"description": "A multiaddr validator",
|
||||||
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
|
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
@ -10,6 +10,7 @@
|
|||||||
"test": "aegir test",
|
"test": "aegir test",
|
||||||
"test:node": "aegir test --target node",
|
"test:node": "aegir test --target node",
|
||||||
"test:browser": "aegir test --target browser",
|
"test:browser": "aegir test --target browser",
|
||||||
|
"test:types": "npx tsc",
|
||||||
"release": "aegir release",
|
"release": "aegir release",
|
||||||
"release-minor": "aegir release --type minor",
|
"release-minor": "aegir release --type minor",
|
||||||
"release-major": "aegir release --type major",
|
"release-major": "aegir release --type major",
|
||||||
@ -17,8 +18,7 @@
|
|||||||
"coverage-publish": "aegir coverage publish"
|
"coverage-publish": "aegir coverage publish"
|
||||||
},
|
},
|
||||||
"pre-push": [
|
"pre-push": [
|
||||||
"lint",
|
"lint"
|
||||||
"test"
|
|
||||||
],
|
],
|
||||||
"repository": "github:multiformats/js-mafmt",
|
"repository": "github:multiformats/js-mafmt",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -28,26 +28,29 @@
|
|||||||
"bugs": "https://github.com/multiformats/js-mafmt/issues",
|
"bugs": "https://github.com/multiformats/js-mafmt/issues",
|
||||||
"homepage": "https://github.com/multiformats/js-mafmt#readme",
|
"homepage": "https://github.com/multiformats/js-mafmt#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^20.0.0",
|
"@types/chai": "^4.2.8",
|
||||||
"chai": "^4.2.0"
|
"@types/mocha": "^8.0.0",
|
||||||
|
"aegir": "^32.0.2",
|
||||||
|
"uint8arrays": "^2.0.5",
|
||||||
|
"util": "^0.12.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"multiaddr": "^6.1.0"
|
"multiaddr": "^9.0.1"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Alan Shaw <alan@tableflip.io>",
|
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"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@moxy.studio>",
|
||||||
"Vasco Santos <vasco.santos@ua.pt>",
|
"Jacob Heun <jacobheun@gmail.com>",
|
||||||
"dignifiedquire <dignifiedquire@gmail.com>",
|
|
||||||
"dmitriy ryajov <dryajov@dmitriys-MBP.HomeNET>",
|
"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
29
src/index.d.ts
vendored
Normal 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;
|
34
src/index.js
34
src/index.js
@ -7,9 +7,10 @@ const multiaddr = require('multiaddr')
|
|||||||
*/
|
*/
|
||||||
const DNS4 = base('dns4')
|
const DNS4 = base('dns4')
|
||||||
const DNS6 = base('dns6')
|
const DNS6 = base('dns6')
|
||||||
|
const DNSADDR = base('dnsaddr')
|
||||||
const DNS = or(
|
const DNS = or(
|
||||||
base('dns'),
|
base('dns'),
|
||||||
base('dnsaddr'),
|
DNSADDR,
|
||||||
DNS4,
|
DNS4,
|
||||||
DNS6
|
DNS6
|
||||||
)
|
)
|
||||||
@ -22,6 +23,8 @@ const TCP = or(
|
|||||||
const UDP = and(IP, base('udp'))
|
const UDP = and(IP, base('udp'))
|
||||||
const UTP = and(UDP, base('utp'))
|
const UTP = and(UDP, base('utp'))
|
||||||
|
|
||||||
|
const QUIC = and(UDP, base('quic'))
|
||||||
|
|
||||||
const WebSockets = or(
|
const WebSockets = or(
|
||||||
and(TCP, base('ws')),
|
and(TCP, base('ws')),
|
||||||
and(DNS, base('ws'))
|
and(DNS, base('ws'))
|
||||||
@ -45,15 +48,13 @@ const HTTPS = or(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const WebRTCStar = 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(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(
|
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(WebSockets, base('p2p-websocket-star'), base('p2p')),
|
||||||
and(WebSocketsSecure, base('p2p-websocket-star'), base('p2p')),
|
and(WebSocketsSecure, base('p2p-websocket-star'), base('p2p')),
|
||||||
and(WebSockets, base('p2p-websocket-star')),
|
and(WebSockets, base('p2p-websocket-star')),
|
||||||
@ -61,6 +62,8 @@ const WebSocketStar = or(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const WebRTCDirect = 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(HTTP, base('p2p-webrtc-direct')),
|
||||||
and(HTTPS, base('p2p-webrtc-direct'))
|
and(HTTPS, base('p2p-webrtc-direct'))
|
||||||
)
|
)
|
||||||
@ -73,20 +76,21 @@ const Reliable = or(
|
|||||||
WebRTCStar,
|
WebRTCStar,
|
||||||
WebRTCDirect,
|
WebRTCDirect,
|
||||||
TCP,
|
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 ;) )
|
// 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(
|
const Stardust = or(
|
||||||
and(Reliable, base('p2p-stardust'), base('ipfs')),
|
and(Reliable, base('p2p-stardust'), base('p2p')),
|
||||||
and(Reliable, base('p2p-stardust'))
|
and(Reliable, base('p2p-stardust'))
|
||||||
)
|
)
|
||||||
|
|
||||||
const _P2P = or(
|
const _P2P = or(
|
||||||
and(Reliable, base('ipfs')),
|
|
||||||
and(Reliable, base('p2p')),
|
and(Reliable, base('p2p')),
|
||||||
WebRTCStar,
|
WebRTCStar,
|
||||||
base('ipfs'),
|
WebRTCDirect,
|
||||||
base('p2p')
|
base('p2p')
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -117,9 +121,11 @@ const P2P = or(
|
|||||||
exports.DNS = DNS
|
exports.DNS = DNS
|
||||||
exports.DNS4 = DNS4
|
exports.DNS4 = DNS4
|
||||||
exports.DNS6 = DNS6
|
exports.DNS6 = DNS6
|
||||||
|
exports.DNSADDR = DNSADDR
|
||||||
exports.IP = IP
|
exports.IP = IP
|
||||||
exports.TCP = TCP
|
exports.TCP = TCP
|
||||||
exports.UDP = UDP
|
exports.UDP = UDP
|
||||||
|
exports.QUIC = QUIC
|
||||||
exports.UTP = UTP
|
exports.UTP = UTP
|
||||||
exports.HTTP = HTTP
|
exports.HTTP = HTTP
|
||||||
exports.HTTPS = HTTPS
|
exports.HTTPS = HTTPS
|
||||||
@ -140,9 +146,9 @@ exports.IPFS = P2P
|
|||||||
|
|
||||||
function makeMatchesFunction (partialMatch) {
|
function makeMatchesFunction (partialMatch) {
|
||||||
return function matches (a) {
|
return function matches (a) {
|
||||||
if (!multiaddr.isMultiaddr(a)) {
|
if (!multiaddr.Multiaddr.isMultiaddr(a)) {
|
||||||
try {
|
try {
|
||||||
a = multiaddr(a)
|
a = new multiaddr.Multiaddr(a)
|
||||||
} catch (err) { // catch error
|
} catch (err) { // catch error
|
||||||
return false // also if it's invalid it's propably not matching as well so return false
|
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) {
|
if (a === null) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
return a
|
return a
|
||||||
@ -195,6 +202,7 @@ function or () {
|
|||||||
out = res
|
out = res
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
return out
|
return out
|
||||||
@ -216,7 +224,7 @@ function base (n) {
|
|||||||
function matches (a) {
|
function matches (a) {
|
||||||
if (typeof a === 'string') {
|
if (typeof a === 'string') {
|
||||||
try {
|
try {
|
||||||
a = multiaddr(a)
|
a = new multiaddr.Multiaddr(a)
|
||||||
} catch (err) { // catch error
|
} catch (err) { // catch error
|
||||||
return false // also if it's invalid it's propably not matching as well so return false
|
return false // also if it's invalid it's propably not matching as well so return false
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const expect = require('chai').expect
|
const { expect } = require('aegir/utils/chai')
|
||||||
const mafmt = require('./../src')
|
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
|
const uint8ArrayFromString = require('uint8arrays/from-string')
|
||||||
|
|
||||||
|
const mafmt = require('./../src')
|
||||||
|
|
||||||
describe('multiaddr validation', function () {
|
describe('multiaddr validation', function () {
|
||||||
const goodDNS = [
|
const goodDNS = [
|
||||||
@ -53,6 +55,17 @@ describe('multiaddr validation', function () {
|
|||||||
'/ip6/fc00::/tcp/5523/udp/9543'
|
'/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 = [
|
const goodUTP = [
|
||||||
'/ip4/1.2.3.4/udp/3456/utp',
|
'/ip4/1.2.3.4/udp/3456/utp',
|
||||||
'/ip6/::/udp/0/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/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||||
'/dnsaddr/ipfs.io/wss/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/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/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/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79',
|
||||||
'/dns/wrtc-star.discovery.libp2p.io/tcp/443/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 = [
|
const goodIPFS = [
|
||||||
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
||||||
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
'/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',
|
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||||
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
|
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
|
||||||
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
||||||
'/ip4/127.0.0.1/tcp/20008/ws/p2p/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/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
||||||
'/ip4/1.2.3.4/tcp/3456/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/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)
|
].concat(goodCircuit)
|
||||||
|
|
||||||
function assertMatches (p) {
|
function assertMatches (p) {
|
||||||
@ -174,9 +196,9 @@ describe('multiaddr validation', function () {
|
|||||||
test.forEach(function (testcase) {
|
test.forEach(function (testcase) {
|
||||||
try {
|
try {
|
||||||
expect(p.matches(testcase), `assertMatches: ${testcase} (string)`).to.be.eql(true)
|
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), `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) {
|
} catch (err) {
|
||||||
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=true] ' + err.stack
|
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=true] ' + err.stack
|
||||||
throw err
|
throw err
|
||||||
@ -194,15 +216,15 @@ describe('multiaddr validation', function () {
|
|||||||
let validMultiaddrObj
|
let validMultiaddrObj
|
||||||
try {
|
try {
|
||||||
// if testcase string happens to be a valid multiaddr,
|
// if testcase string happens to be a valid multiaddr,
|
||||||
// we expect 'p' test to also return false for Multiaddr object and Buffer versions
|
// we expect 'p' test to also return false for Multiaddr object and Uint8Array versions
|
||||||
validMultiaddrObj = multiaddr(testcase)
|
validMultiaddrObj = new multiaddr.Multiaddr(testcase)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignoring testcase as the string is not a multiaddr
|
// 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) {
|
if (validMultiaddrObj) {
|
||||||
expect(p.matches(validMultiaddrObj), `assertMismatches: ${testcase} (multiaddr object)`).to.be.eql(false)
|
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) {
|
} catch (err) {
|
||||||
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=false] ' + err.stack
|
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)
|
expect(mafmt.HTTP.matches('/http-google-com')).to.be.eql(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('do not throw if multiaddr Buffer is invalid', function () {
|
it('do not throw if multiaddr Uint8Array is invalid', function () {
|
||||||
expect(mafmt.HTTP.matches(Buffer.from('no spoon'))).to.be.eql(false)
|
expect(mafmt.HTTP.matches(uint8ArrayFromString('no spoon'))).to.be.eql(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('DNS validation', function () {
|
it('DNS validation', function () {
|
||||||
@ -240,6 +262,11 @@ describe('multiaddr validation', function () {
|
|||||||
assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP)
|
assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('QUIC validation', function () {
|
||||||
|
assertMatches(mafmt.QUIC, goodQUIC)
|
||||||
|
assertMismatches(mafmt.QUIC, badQUIC)
|
||||||
|
})
|
||||||
|
|
||||||
it('UTP validation', function () {
|
it('UTP validation', function () {
|
||||||
assertMatches(mafmt.UTP, goodUTP)
|
assertMatches(mafmt.UTP, goodUTP)
|
||||||
assertMismatches(mafmt.UTP, badUTP, goodIP, goodTCP, goodUDP)
|
assertMismatches(mafmt.UTP, badUTP, goodIP, goodTCP, goodUDP)
|
||||||
@ -282,7 +309,7 @@ describe('multiaddr validation', function () {
|
|||||||
|
|
||||||
it('WebRTCStar validation', function () {
|
it('WebRTCStar validation', function () {
|
||||||
assertMatches(mafmt.WebRTCStar, goodWebRTCStar)
|
assertMatches(mafmt.WebRTCStar, goodWebRTCStar)
|
||||||
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWS)
|
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWSS)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('WebRTCDirect validation', function () {
|
it('WebRTCDirect validation', function () {
|
||||||
|
38
tsconfig.json
Normal file
38
tsconfig.json
Normal 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"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user