mirror of
https://github.com/fluencelabs/js-mafmt
synced 2025-04-30 21:22:24 +00:00
Compare commits
No commits in common. "master" and "v6.0.10" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -27,7 +27,6 @@ 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,7 +6,6 @@ stages:
|
|||||||
- cov
|
- cov
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- '12'
|
|
||||||
- '10'
|
- '10'
|
||||||
|
|
||||||
os:
|
os:
|
||||||
@ -21,6 +20,7 @@ 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,85 +1,3 @@
|
|||||||
## [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,12 +1,13 @@
|
|||||||
js-mafmt
|
js-mafmt
|
||||||
========
|
========
|
||||||
|
|
||||||
[](http://protocol.ai)
|
[](http://ipn.io)
|
||||||
[](https://github.com/multiformats/multiformats)
|
[](http://ipfs.io/)
|
||||||
[](https://webchat.freenode.net/?channels=%23ipfs)
|
[](http://webchat.freenode.net/?channels=%23ipfs)
|
||||||
[](https://david-dm.org/multiformats/js-mafmt)
|
[](https://coveralls.io/github/whyrusleeping/js-mafmt?branch=master)
|
||||||
[](https://travis-ci.com/multiformats/js-mafmt)
|
[](https://travis-ci.org/whyrusleeping/js-mafmt)
|
||||||
[](https://codecov.io/gh/multiformats/js-mafmt)
|
[](https://circleci.com/gh/whyrusleeping/js-mafmt)
|
||||||
|
[](https://david-dm.org/whyrusleeping/js-mafmt) [](https://github.com/feross/standard)
|
||||||
|
|
||||||
> Javascript implementation of multiaddr validation
|
> Javascript implementation of multiaddr validation
|
||||||
|
|
||||||
@ -42,17 +43,16 @@ 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` | 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` |
|
| `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` | 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` |
|
| `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` |
|
||||||
| `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` or `QUIC` format multiaddr | `/dnsaddr/ipfs.io/wss` |
|
| `Reliable` | a `WebSockets` or `WebSocketsSecure` or `HTTP` or `HTTPS` or `WebRTCStar` or `WebRTCDirect` or `TCP` or `UTP` format multiaddr | `/dnsaddr/ipfs.io/wss` |
|
||||||
| `Circuit` | | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` |
|
| `Circuit` | | `/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/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": "8.0.4",
|
"version": "6.0.10",
|
||||||
"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,7 +10,6 @@
|
|||||||
"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",
|
||||||
@ -18,7 +17,8 @@
|
|||||||
"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,29 +28,26 @@
|
|||||||
"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": {
|
||||||
"@types/chai": "^4.2.8",
|
"aegir": "^20.0.0",
|
||||||
"@types/mocha": "^8.0.0",
|
"chai": "^4.2.0"
|
||||||
"aegir": "^32.0.2",
|
|
||||||
"uint8arrays": "^2.0.5",
|
|
||||||
"util": "^0.12.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"multiaddr": "^9.0.1"
|
"multiaddr": "^6.1.0"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
|
||||||
"Vasco Santos <vasco.santos@moxy.studio>",
|
|
||||||
"Jacob Heun <jacobheun@gmail.com>",
|
|
||||||
"dmitriy ryajov <dryajov@dmitriys-MBP.HomeNET>",
|
|
||||||
"Maciej Krüger <mkg20001@gmail.com>",
|
|
||||||
"Alan Shaw <alan@tableflip.io>",
|
"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 <jeromyj@gmail.com>",
|
||||||
"dignifiedquire <dignifiedquire@gmail.com>",
|
"Jeromy Johnson <why@ipfs.io>",
|
||||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
|
||||||
"Marcin Rataj <lidel@lidel.org>",
|
|
||||||
"Cayman <caymannava@gmail.com>",
|
|
||||||
"João Antunes <me@jgantunes.com>",
|
"João Antunes <me@jgantunes.com>",
|
||||||
"Alex Potsides <alex@achingbrain.net>",
|
"Maciej Krüger <mkg20001@gmail.com>",
|
||||||
"Hugo Dias <mail@hugodias.me>"
|
"Marcin Rataj <lidel@lidel.org>",
|
||||||
|
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||||
|
"Vasco Santos <vasco.santos@ua.pt>",
|
||||||
|
"dignifiedquire <dignifiedquire@gmail.com>",
|
||||||
|
"dmitriy ryajov <dryajov@dmitriys-MBP.HomeNET>",
|
||||||
|
"victorbjelkholm <victorbjelkholm@gmail.com>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
29
src/index.d.ts
vendored
29
src/index.d.ts
vendored
@ -1,29 +0,0 @@
|
|||||||
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,10 +7,9 @@ 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'),
|
||||||
DNSADDR,
|
base('dnsaddr'),
|
||||||
DNS4,
|
DNS4,
|
||||||
DNS6
|
DNS6
|
||||||
)
|
)
|
||||||
@ -23,8 +22,6 @@ 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'))
|
||||||
@ -48,13 +45,15 @@ 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')),
|
||||||
@ -62,8 +61,6 @@ 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'))
|
||||||
)
|
)
|
||||||
@ -76,21 +73,20 @@ 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('p2p')),
|
and(Reliable, base('p2p-stardust'), base('ipfs')),
|
||||||
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,
|
||||||
WebRTCDirect,
|
base('ipfs'),
|
||||||
base('p2p')
|
base('p2p')
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,11 +117,9 @@ 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
|
||||||
@ -146,9 +140,9 @@ exports.IPFS = P2P
|
|||||||
|
|
||||||
function makeMatchesFunction (partialMatch) {
|
function makeMatchesFunction (partialMatch) {
|
||||||
return function matches (a) {
|
return function matches (a) {
|
||||||
if (!multiaddr.Multiaddr.isMultiaddr(a)) {
|
if (!multiaddr.isMultiaddr(a)) {
|
||||||
try {
|
try {
|
||||||
a = new multiaddr.Multiaddr(a)
|
a = 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
|
||||||
}
|
}
|
||||||
@ -175,7 +169,6 @@ function and () {
|
|||||||
if (a === null) {
|
if (a === null) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return a
|
return a
|
||||||
@ -202,7 +195,6 @@ function or () {
|
|||||||
out = res
|
out = res
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return out
|
return out
|
||||||
@ -224,7 +216,7 @@ function base (n) {
|
|||||||
function matches (a) {
|
function matches (a) {
|
||||||
if (typeof a === 'string') {
|
if (typeof a === 'string') {
|
||||||
try {
|
try {
|
||||||
a = new multiaddr.Multiaddr(a)
|
a = 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,11 +2,9 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { expect } = require('aegir/utils/chai')
|
const expect = require('chai').expect
|
||||||
const multiaddr = require('multiaddr')
|
|
||||||
const uint8ArrayFromString = require('uint8arrays/from-string')
|
|
||||||
|
|
||||||
const mafmt = require('./../src')
|
const mafmt = require('./../src')
|
||||||
|
const multiaddr = require('multiaddr')
|
||||||
|
|
||||||
describe('multiaddr validation', function () {
|
describe('multiaddr validation', function () {
|
||||||
const goodDNS = [
|
const goodDNS = [
|
||||||
@ -55,17 +53,6 @@ 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'
|
||||||
@ -111,9 +98,7 @@ 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'
|
||||||
]
|
]
|
||||||
@ -173,21 +158,14 @@ 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) {
|
||||||
@ -196,9 +174,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 = new multiaddr.Multiaddr(testcase)
|
const ma = 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.bytes), `assertMatches: ${testcase} (multiaddr.bytes)`).to.be.eql(true)
|
expect(p.matches(ma.buffer), `assertMatches: ${testcase} (multiaddr.buffer)`).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
|
||||||
@ -216,15 +194,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 Uint8Array versions
|
// we expect 'p' test to also return false for Multiaddr object and Buffer versions
|
||||||
validMultiaddrObj = new multiaddr.Multiaddr(testcase)
|
validMultiaddrObj = 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 'Uint8Array is invalid' test later below)
|
// (There is a separate 'Buffer 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.bytes), `assertMismatches: ${testcase} (multiaddr.bytes)`).to.be.eql(false)
|
expect(p.matches(validMultiaddrObj.buffer), `assertMismatches: ${testcase} (multiaddr.buffer)`).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
|
||||||
@ -238,8 +216,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 Uint8Array is invalid', function () {
|
it('do not throw if multiaddr Buffer is invalid', function () {
|
||||||
expect(mafmt.HTTP.matches(uint8ArrayFromString('no spoon'))).to.be.eql(false)
|
expect(mafmt.HTTP.matches(Buffer.from('no spoon'))).to.be.eql(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('DNS validation', function () {
|
it('DNS validation', function () {
|
||||||
@ -262,11 +240,6 @@ 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)
|
||||||
@ -309,7 +282,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, badWSS)
|
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWS)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('WebRTCDirect validation', function () {
|
it('WebRTCDirect validation', function () {
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
{
|
|
||||||
"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