├── .DS_Store ├── .aegir.cjs ├── .github ├── dependabot.yml └── workflows │ ├── generated-pr.yml │ ├── js-test-and-release.yml │ └── stale.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── package.json ├── src └── index.ts ├── test └── index.spec.ts └── tsconfig.json /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiformats/js-mafmt/71aa1038ab06a59c33f125a318af001ca52dd171/.DS_Store -------------------------------------------------------------------------------- /.aegir.cjs: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** @type {import('aegir').PartialOptions} */ 4 | module.exports = { 5 | build: { 6 | bundlesizeMax: '12KB' 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "10:00" 8 | open-pull-requests-limit: 10 9 | commit-message: 10 | prefix: "deps" 11 | prefix-development: "deps(dev)" 12 | -------------------------------------------------------------------------------- /.github/workflows/generated-pr.yml: -------------------------------------------------------------------------------- 1 | name: Close Generated PRs 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | 12 | jobs: 13 | stale: 14 | uses: ipdxco/unified-github-workflows/.github/workflows/reusable-generated-pr.yml@v1 15 | -------------------------------------------------------------------------------- /.github/workflows/js-test-and-release.yml: -------------------------------------------------------------------------------- 1 | name: test & maybe release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | permissions: 11 | contents: write 12 | id-token: write 13 | packages: write 14 | pull-requests: write 15 | 16 | concurrency: 17 | group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} 18 | cancel-in-progress: true 19 | 20 | jobs: 21 | js-test-and-release: 22 | uses: ipdxco/unified-github-workflows/.github/workflows/js-test-and-release.yml@v1.0 23 | secrets: 24 | DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} 25 | DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} 26 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 27 | UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }} 28 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 29 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Close Stale Issues 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | permissions: 9 | issues: write 10 | pull-requests: write 11 | 12 | jobs: 13 | stale: 14 | uses: ipdxco/unified-github-workflows/.github/workflows/reusable-stale-issue.yml@v1 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | .vscode 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [12.1.6](https://github.com/multiformats/js-mafmt/compare/v12.1.5...v12.1.6) (2023-08-02) 2 | 3 | 4 | ### Dependencies 5 | 6 | * **dev:** bump aegir from 39.0.13 to 40.0.8 ([#160](https://github.com/multiformats/js-mafmt/issues/160)) ([46d0b71](https://github.com/multiformats/js-mafmt/commit/46d0b71ad7f7c8d46a04feb5f926a7af7c39ab29)) 7 | 8 | ## [12.1.5](https://github.com/multiformats/js-mafmt/compare/v12.1.4...v12.1.5) (2023-06-01) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * add test cases for [#156](https://github.com/multiformats/js-mafmt/issues/156) ([d780138](https://github.com/multiformats/js-mafmt/commit/d7801389ad8deb9ea263fe3603730429c2722afb)) 14 | 15 | ## [12.1.4](https://github.com/multiformats/js-mafmt/compare/v12.1.3...v12.1.4) (2023-06-01) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * match websocket addresses that include a peer id ([#156](https://github.com/multiformats/js-mafmt/issues/156)) ([080936f](https://github.com/multiformats/js-mafmt/commit/080936f3d44f13b948d14c9fb3b234b036f563ce)) 21 | 22 | ## [12.1.3](https://github.com/multiformats/js-mafmt/compare/v12.1.2...v12.1.3) (2023-05-17) 23 | 24 | 25 | ### Bug Fixes 26 | 27 | * remove engines field ([#155](https://github.com/multiformats/js-mafmt/issues/155)) ([a464023](https://github.com/multiformats/js-mafmt/commit/a464023d87610f5c079c0b5ba234d0b373503a0b)) 28 | 29 | ## [12.1.2](https://github.com/multiformats/js-mafmt/compare/v12.1.1...v12.1.2) (2023-05-15) 30 | 31 | 32 | ### Dependencies 33 | 34 | * **dev:** bump aegir from 38.1.8 to 39.0.6 ([#152](https://github.com/multiformats/js-mafmt/issues/152)) ([72bdf8e](https://github.com/multiformats/js-mafmt/commit/72bdf8e0d1456236c8e1c17ce01b21592f628dcb)) 35 | 36 | ## [12.1.1](https://github.com/multiformats/js-mafmt/compare/v12.1.0...v12.1.1) (2023-05-15) 37 | 38 | 39 | ### Bug Fixes 40 | 41 | * match complete webRTC address ([#153](https://github.com/multiformats/js-mafmt/issues/153)) ([9335539](https://github.com/multiformats/js-mafmt/commit/9335539d675f568f3f043b150c07f21b815430c7)) 42 | 43 | ## [12.1.0](https://github.com/multiformats/js-mafmt/compare/v12.0.0...v12.1.0) (2023-04-03) 44 | 45 | 46 | ### Features 47 | 48 | * support webtransport multiaddrs ([#148](https://github.com/multiformats/js-mafmt/issues/148)) ([20076b1](https://github.com/multiformats/js-mafmt/commit/20076b1e4e0e81249aaab72d63bbc7422c3a9b9e)) 49 | 50 | ## [12.0.0](https://github.com/multiformats/js-mafmt/compare/v11.1.2...v12.0.0) (2023-03-20) 51 | 52 | 53 | ### ⚠ BREAKING CHANGES 54 | 55 | * the existing WebRTCDirect multicodec name has been deprecated and renamed P2PWebRTCDirect. The new WebRTCDirect codec has been added but is not the same, please check your code before upgrading! Integer codes are unchanged. 56 | 57 | ### Bug Fixes 58 | 59 | * Rename WebRTCDirect to P2PWebRTCDirect and deprecate ([#146](https://github.com/multiformats/js-mafmt/issues/146)) ([92f92d7](https://github.com/multiformats/js-mafmt/commit/92f92d7841c26c149bce2b6b3c0026507fd318ed)) 60 | 61 | ## [11.1.2](https://github.com/multiformats/js-mafmt/compare/v11.1.1...v11.1.2) (2023-03-17) 62 | 63 | 64 | ### Dependencies 65 | 66 | * bump @multiformats/multiaddr from 11.6.1 to 12.0.0 ([#145](https://github.com/multiformats/js-mafmt/issues/145)) ([cb5c927](https://github.com/multiformats/js-mafmt/commit/cb5c92712bcd1f75139e68d91286bd4e820e6ec1)) 67 | * **dev:** bump uint8arrays from 3.1.1 to 4.0.3 ([#131](https://github.com/multiformats/js-mafmt/issues/131)) ([60146ce](https://github.com/multiformats/js-mafmt/commit/60146ce3af87aaa159a35a1d7632c887e9d982eb)) 68 | 69 | ## [11.1.1](https://github.com/multiformats/js-mafmt/compare/v11.1.0...v11.1.1) (2023-03-17) 70 | 71 | 72 | ### Dependencies 73 | 74 | * **dev:** bump aegir from 37.12.1 to 38.1.7 ([#142](https://github.com/multiformats/js-mafmt/issues/142)) ([83f55a9](https://github.com/multiformats/js-mafmt/commit/83f55a9cc15615dc06fc4be754fbcbf6014b8d9e)) 75 | 76 | ## [11.1.0](https://github.com/multiformats/js-mafmt/compare/v11.0.4...v11.1.0) (2023-02-28) 77 | 78 | 79 | ### Features 80 | 81 | * add webrtc addresses ([#130](https://github.com/multiformats/js-mafmt/issues/130)) ([d0ce7d7](https://github.com/multiformats/js-mafmt/commit/d0ce7d70283d6deaa074e2623eb751f4b12f15f5)) 82 | 83 | ## [11.0.4](https://github.com/multiformats/js-mafmt/compare/v11.0.3...v11.0.4) (2023-02-27) 84 | 85 | 86 | ### Bug Fixes 87 | 88 | * add /tls/ws as alias for /wss ([#141](https://github.com/multiformats/js-mafmt/issues/141)) ([05e0323](https://github.com/multiformats/js-mafmt/commit/05e03230a1518cb791271296160107ea9ba863d5)) 89 | 90 | ## [11.0.3](https://github.com/multiformats/js-mafmt/compare/v11.0.2...v11.0.3) (2022-09-21) 91 | 92 | 93 | ### Trivial Changes 94 | 95 | * update project config ([#121](https://github.com/multiformats/js-mafmt/issues/121)) ([ceef343](https://github.com/multiformats/js-mafmt/commit/ceef343568d30080cdedf35edaa6365b1d031cd9)) 96 | 97 | 98 | ### Dependencies 99 | 100 | * update @multiformats/multiaddr to 11.0.0 ([#123](https://github.com/multiformats/js-mafmt/issues/123)) ([dc5a87f](https://github.com/multiformats/js-mafmt/commit/dc5a87f54c0e2a8e5857f9e0a5715b289cfe45d8)) 101 | 102 | ### [11.0.2](https://github.com/multiformats/js-mafmt/compare/v11.0.1...v11.0.2) (2022-01-08) 103 | 104 | 105 | ### Trivial Changes 106 | 107 | * add semantic release config ([#97](https://github.com/multiformats/js-mafmt/issues/97)) ([af1a100](https://github.com/multiformats/js-mafmt/commit/af1a10075462c11004bebd2b133aee4ea96d0ba4)) 108 | 109 | # [10.0.0](https://github.com/multiformats/js-mafmt/compare/v9.0.0...v10.0.0) (2021-07-07) 110 | 111 | 112 | ### chore 113 | 114 | * upgrade multiaddr ([#81](https://github.com/multiformats/js-mafmt/issues/81)) ([2785b23](https://github.com/multiformats/js-mafmt/commit/2785b23d42fee537907ce3811ddce4ae107fc781)) 115 | 116 | 117 | ### BREAKING CHANGES 118 | 119 | * uses new major of multiaddr module 120 | 121 | 122 | 123 | # [9.0.0](https://github.com/multiformats/js-mafmt/compare/v8.0.4...v9.0.0) (2021-04-11) 124 | 125 | 126 | 127 | ## [8.0.4](https://github.com/multiformats/js-mafmt/compare/v8.0.3...v8.0.4) (2021-01-13) 128 | 129 | 130 | ### Features 131 | 132 | * add QUIC support ([#70](https://github.com/multiformats/js-mafmt/issues/70)) ([ac7d10c](https://github.com/multiformats/js-mafmt/commit/ac7d10c646f343edd3154bae504bc9a2dcd0d506)) 133 | 134 | 135 | 136 | ## [8.0.3](https://github.com/multiformats/js-mafmt/compare/v8.0.2...v8.0.3) (2021-01-11) 137 | 138 | 139 | ### Bug Fixes 140 | 141 | * 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)) 142 | 143 | 144 | 145 | ## [8.0.2](https://github.com/multiformats/js-mafmt/compare/v8.0.1...v8.0.2) (2020-12-28) 146 | 147 | 148 | 149 | 150 | ## [8.0.1](https://github.com/multiformats/js-mafmt/compare/v7.1.0...v8.0.1) (2020-10-27) 151 | 152 | 153 | ### Bug Fixes 154 | 155 | * replace node buffers with uint8arrays ([#59](https://github.com/multiformats/js-mafmt/issues/59)) ([022ab87](https://github.com/multiformats/js-mafmt/commit/022ab87)) 156 | 157 | 158 | ### Features 159 | 160 | * add dnsnaddr p2p ([95d5178](https://github.com/multiformats/js-mafmt/commit/95d5178)) 161 | 162 | 163 | ### BREAKING CHANGES 164 | 165 | * - Now uses a version of `multiaddr` than has a `.bytes` property instead of `.buffer` 166 | 167 | 168 | 169 | 170 | # [8.0.0](https://github.com/multiformats/js-mafmt/compare/v7.1.0...v8.0.0) (2020-08-10) 171 | 172 | 173 | ### Bug Fixes 174 | 175 | * replace node buffers with uint8arrays ([#59](https://github.com/multiformats/js-mafmt/issues/59)) ([022ab87](https://github.com/multiformats/js-mafmt/commit/022ab87)) 176 | 177 | 178 | ### BREAKING CHANGES 179 | 180 | * - Now uses a version of `multiaddr` than has a `.bytes` property instead of `.buffer` 181 | 182 | 183 | 184 | 185 | # [7.1.0](https://github.com/multiformats/js-mafmt/compare/v7.0.1...v7.1.0) (2020-02-06) 186 | 187 | 188 | ### Features 189 | 190 | * add typescript types + type tests ([#48](https://github.com/multiformats/js-mafmt/issues/48)) ([74830fa](https://github.com/multiformats/js-mafmt/commit/74830fa)) 191 | 192 | 193 | 194 | 195 | ## [7.0.1](https://github.com/multiformats/js-mafmt/compare/v7.0.0...v7.0.1) (2020-01-23) 196 | 197 | 198 | ### Bug Fixes 199 | 200 | * 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)) 201 | 202 | 203 | 204 | 205 | # [7.0.0](https://github.com/multiformats/js-mafmt/compare/v6.0.10...v7.0.0) (2019-09-11) 206 | 207 | 208 | 209 | 210 | ## [6.0.10](https://github.com/multiformats/js-mafmt/compare/v6.0.9...v6.0.10) (2019-09-11) 211 | 212 | 213 | 214 | 215 | ## [6.0.9](https://github.com/multiformats/js-mafmt/compare/v6.0.8...v6.0.9) (2019-09-10) 216 | 217 | 218 | 219 | 220 | ## [6.0.8](https://github.com/multiformats/js-mafmt/compare/v6.0.7...v6.0.8) (2019-08-08) 221 | 222 | 223 | ### Features 224 | 225 | * p2p and dns support ([#42](https://github.com/multiformats/js-mafmt/issues/42)) ([09160b5](https://github.com/multiformats/js-mafmt/commit/09160b5)) 226 | 227 | 228 | 229 | 230 | ## [6.0.7](https://github.com/multiformats/js-mafmt/compare/v6.0.6...v6.0.7) (2019-02-26) 231 | 232 | 233 | ### Features 234 | 235 | * accept Buffer input ([#39](https://github.com/multiformats/js-mafmt/issues/39)) ([c2adc27](https://github.com/multiformats/js-mafmt/commit/c2adc27)), closes [/github.com/multiformats/js-mafmt/blob/v6.0.6/src/index.js#L148](https://github.com//github.com/multiformats/js-mafmt/blob/v6.0.6/src/index.js/issues/L148) 236 | 237 | 238 | 239 | 240 | ## [6.0.6](https://github.com/multiformats/js-mafmt/compare/v6.0.5...v6.0.6) (2019-02-07) 241 | 242 | 243 | ### Features 244 | 245 | * add /p2p-stardust ([#35](https://github.com/multiformats/js-mafmt/issues/35)) ([9b0c199](https://github.com/multiformats/js-mafmt/commit/9b0c199)), closes [libp2p/js-libp2p-websocket-star#70](https://github.com/libp2p/js-libp2p-websocket-star/issues/70) 246 | 247 | 248 | 249 | 250 | ## [6.0.5](https://github.com/multiformats/js-mafmt/compare/v6.0.4...v6.0.5) (2019-01-25) 251 | 252 | 253 | ### Bug Fixes 254 | 255 | * do not throw if multiaddr str is invalid, fixes [#25](https://github.com/multiformats/js-mafmt/issues/25) ([#36](https://github.com/multiformats/js-mafmt/issues/36)) ([5187d59](https://github.com/multiformats/js-mafmt/commit/5187d59)) 256 | 257 | 258 | 259 | 260 | ## [6.0.4](https://github.com/multiformats/js-mafmt/compare/v6.0.3...v6.0.4) (2019-01-08) 261 | 262 | 263 | ### Bug Fixes 264 | 265 | * reduce bundle size ([#34](https://github.com/multiformats/js-mafmt/issues/34)) ([8a2eb6b](https://github.com/multiformats/js-mafmt/commit/8a2eb6b)) 266 | 267 | 268 | 269 | 270 | ## [6.0.3](https://github.com/multiformats/js-mafmt/compare/v6.0.2...v6.0.3) (2018-12-05) 271 | 272 | 273 | 274 | 275 | ## [6.0.2](https://github.com/whyrusleeping/js-mafmt/compare/v6.0.1...v6.0.2) (2018-09-12) 276 | 277 | 278 | ### Features 279 | 280 | * add tcp over dns ([#31](https://github.com/whyrusleeping/js-mafmt/issues/31)) ([acc9295](https://github.com/whyrusleeping/js-mafmt/commit/acc9295)) 281 | 282 | 283 | 284 | 285 | ## [6.0.1](https://github.com/whyrusleeping/js-mafmt/compare/v6.0.0...v6.0.1) (2018-08-28) 286 | 287 | 288 | ### Features 289 | 290 | * adds HTTPS validation and HTTP(s) tests ([87c4202](https://github.com/whyrusleeping/js-mafmt/commit/87c4202)) 291 | 292 | 293 | 294 | 295 | # [6.0.0](https://github.com/whyrusleeping/js-mafmt/compare/v4.0.0...v6.0.0) (2018-04-05) 296 | 297 | 298 | 299 | 300 | # [5.0.0](https://github.com/whyrusleeping/js-mafmt/compare/v4.0.0...v5.0.0) (2018-04-05) 301 | 302 | 303 | 304 | 305 | # [4.0.0](https://github.com/whyrusleeping/js-mafmt/compare/v3.1.0...v4.0.0) (2018-02-12) 306 | 307 | 308 | 309 | 310 | # [3.1.0](https://github.com/whyrusleeping/js-mafmt/compare/v3.0.2...v3.1.0) (2018-02-12) 311 | 312 | 313 | ### Features 314 | 315 | * /dns => /dnsaddr ([#21](https://github.com/whyrusleeping/js-mafmt/issues/21)) ([ecef5f4](https://github.com/whyrusleeping/js-mafmt/commit/ecef5f4)) 316 | 317 | 318 | 319 | 320 | ## [3.0.2](https://github.com/whyrusleeping/js-mafmt/compare/v3.0.1...v3.0.2) (2017-10-24) 321 | 322 | 323 | 324 | 325 | ## [3.0.1](https://github.com/whyrusleeping/js-mafmt/compare/v3.0.0...v3.0.1) (2017-09-06) 326 | 327 | 328 | ### Features 329 | 330 | * Update to multiaddr v3.0.1 - refactor: websocket{s => }-star ([#19](https://github.com/whyrusleeping/js-mafmt/issues/19)) ([2f336e3](https://github.com/whyrusleeping/js-mafmt/commit/2f336e3)) 331 | 332 | 333 | 334 | 335 | # [3.0.0](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.8...v3.0.0) (2017-09-03) 336 | 337 | 338 | ### Features 339 | 340 | * fix p2p addrs situation ([5fbb424](https://github.com/whyrusleeping/js-mafmt/commit/5fbb424)) 341 | 342 | 343 | 344 | 345 | ## [2.1.8](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.7...v2.1.8) (2017-03-27) 346 | 347 | 348 | ### Features 349 | 350 | * add support for recursive addresses ([2e28d27](https://github.com/whyrusleeping/js-mafmt/commit/2e28d27)) 351 | * adding support for ports in resolvable addresses ([a1f9ccd](https://github.com/whyrusleeping/js-mafmt/commit/a1f9ccd)) 352 | 353 | 354 | 355 | 356 | ## [2.1.7](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.6...v2.1.7) (2017-03-22) 357 | 358 | 359 | ### Bug Fixes 360 | 361 | * p2p-circuit validation ([14db530](https://github.com/whyrusleeping/js-mafmt/commit/14db530)) 362 | 363 | 364 | ### Features 365 | 366 | * adding circuit addresses ([c05c1af](https://github.com/whyrusleeping/js-mafmt/commit/c05c1af)) 367 | * adding support for ports in resolvable addresses ([8c188dd](https://github.com/whyrusleeping/js-mafmt/commit/8c188dd)) 368 | * allow p2p-circuit to come as an additional transport ([2f604c3](https://github.com/whyrusleeping/js-mafmt/commit/2f604c3)) 369 | 370 | 371 | 372 | 373 | ## [2.1.6](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.5...v2.1.6) (2017-01-22) 374 | 375 | 376 | ### Features 377 | 378 | * add support for dns validation, make IPFS validation much nicer, es6ify ([ade442f](https://github.com/whyrusleeping/js-mafmt/commit/ade442f)) 379 | * rules for dns4 and dns6 ([1d4aa10](https://github.com/whyrusleeping/js-mafmt/commit/1d4aa10)) 380 | * WebSocketsSecure ([3b99a73](https://github.com/whyrusleeping/js-mafmt/commit/3b99a73)) 381 | 382 | 383 | 384 | 385 | ## [2.1.5](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.4...v2.1.5) (2017-01-16) 386 | 387 | 388 | ### Bug Fixes 389 | 390 | * point to the right entry point, change due to aegir 9 ([bd81b68](https://github.com/whyrusleeping/js-mafmt/commit/bd81b68)) 391 | 392 | 393 | 394 | 395 | ## [2.1.4](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.3...v2.1.4) (2017-01-16) 396 | 397 | 398 | ### Features 399 | 400 | * add WebRTC Direct support for filtering ([db00d97](https://github.com/whyrusleeping/js-mafmt/commit/db00d97)) 401 | 402 | 403 | 404 | 405 | ## [2.1.3](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.2...v2.1.3) (2017-01-16) 406 | 407 | 408 | 409 | 410 | ## [2.1.2](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.1...v2.1.2) (2016-08-22) 411 | 412 | 413 | ### Features 414 | 415 | * **deps:** update aegir ([8fd2972](https://github.com/whyrusleeping/js-mafmt/commit/8fd2972)) 416 | 417 | 418 | 419 | 420 | ## [2.1.1](https://github.com/whyrusleeping/js-mafmt/compare/v2.1.0...v2.1.1) (2016-05-28) 421 | 422 | 423 | 424 | 425 | # [2.1.0](https://github.com/whyrusleeping/js-mafmt/compare/v2.0.2...v2.1.0) (2016-05-22) 426 | 427 | 428 | 429 | 430 | ## [2.0.2](https://github.com/whyrusleeping/js-mafmt/compare/v2.0.1...v2.0.2) (2016-05-21) 431 | 432 | 433 | 434 | 435 | ## [2.0.1](https://github.com/whyrusleeping/js-mafmt/compare/v2.0.0...v2.0.1) (2016-05-21) 436 | 437 | 438 | 439 | 440 | # 2.0.0 (2016-05-17) 441 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This project is dual licensed under MIT and Apache-2.0. 2 | 3 | MIT: https://www.opensource.org/licenses/mit 4 | Apache-2.0: https://www.apache.org/licenses/license-2.0 5 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 2 | 3 | http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 6 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @multiformats/mafmt 2 | 3 | [![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io) 4 | [![codecov](https://img.shields.io/codecov/c/github/multiformats/js-mafmt.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-mafmt) 5 | [![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-mafmt/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-mafmt/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) 6 | 7 | > A multiaddr validator 8 | 9 | ## Table of contents 10 | 11 | - [Install](#install) 12 | - [Browser ` 32 | ``` 33 | 34 | ## Usage 35 | 36 | ```js 37 | import * as mafmt from '@multiformats/mafmt' 38 | 39 | mafmt.DNS.matches('/dns4/ipfs.io') // true 40 | ``` 41 | 42 | ## API 43 | 44 | #### `mafmt..matches(multiaddr)` 45 | 46 | Where `` may be: 47 | 48 | | `` | Description | Example(s) | 49 | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | 50 | | `DNS` | a "dns4" or "dns6" format multiaddr | `/dnsaddr/ipfs.io` | 51 | | `DNS4` | a "dns4" format multiaddr | `/dns4/ipfs.io` | 52 | | `DNS6` | a "dns6" format multiaddr | `/dns6/protocol.ai/tcp/80` | 53 | | `IP` | an "ip4" or "ip6" format multiaddr | `/ip4/127.0.0.1`
`/ip6/fc00::` | 54 | | `TCP` | a "tcp" over `IP` format multiaddr | `/ip4/0.0.7.6/tcp/1234` | 55 | | `UDP` | a "udp" over `IP` format multiaddr | `/ip4/0.0.7.6/udp/1234` | 56 | | `QUIC` | a "quic" over `UDP` format multiaddr | `/ip4/1.2.3.4/udp/1234/quic` | 57 | | `UTP` | a "utp" over `UDP` format multiaddr | `/ip4/1.2.3.4/udp/3456/utp` | 58 | | `Websockets` | a "ws" over `TCP` or "ws" over `DNS` format multiaddr | `/ip4/1.2.3.4/tcp/3456/ws`
`/dnsaddr/ipfs.io/ws` | 59 | | `WebSocketsSecure` | a "wss" over `TCP` or "wss" over `DNS` format multiaddr | `/ip6/::/tcp/0/wss`
`/dnsaddr/ipfs.io/wss` | 60 | | `HTTP` | a "http" over `TCP` or `DNS` or "http" over `DNS` format multiaddr | `/ip4/127.0.0.1/tcp/90/http`
`/dnsaddr/ipfs.io/http` | 61 | | `HTTPS` | a "https" over `TCP` or `DNS` or "https" over `DNS` format multiaddr | `/ip4/127.0.0.1/tcp/90/https`
`/dnsaddr/ipfs.io/https` | 62 | | `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` | 63 | | `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`
`/dnsaddr/localhost/ws/p2p-websocket-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4` | 64 | | `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` | 65 | | `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` | 66 | | `Circuit` | | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` | 67 | | `P2P` | "p2p", aka "ipfs", over `Reliable` or `WebRTCStar` or "p2p" format multiaddr | `/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4`
`/ip4/127.0.0.1/tcp/20008/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj` | 68 | 69 | Where `multiaddr` may be: 70 | 71 | - a [Multiaddr](https://www.npmjs.com/package/@multiformats/multiaddr) 72 | - a String 73 | - a [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) 74 | 75 | Returns `true`/`false` 76 | 77 | ## API Docs 78 | 79 | - 80 | 81 | ## License 82 | 83 | Licensed under either of 84 | 85 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) 86 | - MIT ([LICENSE-MIT](LICENSE-MIT) / ) 87 | 88 | ## Contribution 89 | 90 | Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. 91 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@multiformats/mafmt", 3 | "version": "12.1.6", 4 | "description": "A multiaddr validator", 5 | "license": "Apache-2.0 OR MIT", 6 | "homepage": "https://github.com/multiformats/js-mafmt#readme", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/multiformats/js-mafmt.git" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/multiformats/js-mafmt/issues" 13 | }, 14 | "keywords": [ 15 | "multiaddr" 16 | ], 17 | "type": "module", 18 | "types": "./dist/src/index.d.ts", 19 | "files": [ 20 | "src", 21 | "dist", 22 | "!dist/test", 23 | "!**/*.tsbuildinfo" 24 | ], 25 | "exports": { 26 | ".": { 27 | "types": "./dist/src/index.d.ts", 28 | "import": "./dist/src/index.js" 29 | } 30 | }, 31 | "eslintConfig": { 32 | "extends": "ipfs", 33 | "parserOptions": { 34 | "sourceType": "module" 35 | } 36 | }, 37 | "release": { 38 | "branches": [ 39 | "master" 40 | ], 41 | "plugins": [ 42 | [ 43 | "@semantic-release/commit-analyzer", 44 | { 45 | "preset": "conventionalcommits", 46 | "releaseRules": [ 47 | { 48 | "breaking": true, 49 | "release": "major" 50 | }, 51 | { 52 | "revert": true, 53 | "release": "patch" 54 | }, 55 | { 56 | "type": "feat", 57 | "release": "minor" 58 | }, 59 | { 60 | "type": "fix", 61 | "release": "patch" 62 | }, 63 | { 64 | "type": "docs", 65 | "release": "patch" 66 | }, 67 | { 68 | "type": "test", 69 | "release": "patch" 70 | }, 71 | { 72 | "type": "deps", 73 | "release": "patch" 74 | }, 75 | { 76 | "scope": "no-release", 77 | "release": false 78 | } 79 | ] 80 | } 81 | ], 82 | [ 83 | "@semantic-release/release-notes-generator", 84 | { 85 | "preset": "conventionalcommits", 86 | "presetConfig": { 87 | "types": [ 88 | { 89 | "type": "feat", 90 | "section": "Features" 91 | }, 92 | { 93 | "type": "fix", 94 | "section": "Bug Fixes" 95 | }, 96 | { 97 | "type": "chore", 98 | "section": "Trivial Changes" 99 | }, 100 | { 101 | "type": "docs", 102 | "section": "Documentation" 103 | }, 104 | { 105 | "type": "deps", 106 | "section": "Dependencies" 107 | }, 108 | { 109 | "type": "test", 110 | "section": "Tests" 111 | } 112 | ] 113 | } 114 | } 115 | ], 116 | "@semantic-release/changelog", 117 | "@semantic-release/npm", 118 | "@semantic-release/github", 119 | "@semantic-release/git" 120 | ] 121 | }, 122 | "scripts": { 123 | "clean": "aegir clean", 124 | "lint": "aegir lint", 125 | "dep-check": "aegir dep-check", 126 | "build": "aegir build", 127 | "test": "aegir test", 128 | "test:chrome": "aegir test -t browser", 129 | "test:chrome-webworker": "aegir test -t webworker", 130 | "test:firefox": "aegir test -t browser -- --browser firefox", 131 | "test:firefox-webworker": "aegir test -t webworker -- --browser firefox", 132 | "test:node": "aegir test -t node", 133 | "test:electron-main": "aegir test -t electron-main", 134 | "release": "aegir release", 135 | "docs": "aegir docs" 136 | }, 137 | "dependencies": { 138 | "@multiformats/multiaddr": "^12.0.0" 139 | }, 140 | "devDependencies": { 141 | "aegir": "^40.0.8", 142 | "uint8arrays": "^4.0.3" 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { multiaddr } from '@multiformats/multiaddr' 2 | import type { Multiaddr } from '@multiformats/multiaddr' 3 | 4 | export interface MatchesFunction { (a: string | Uint8Array | Multiaddr): boolean } 5 | export interface PartialMatchesFunction { (protos: string[]): boolean | string[] | null } 6 | 7 | export interface Mafmt { 8 | toString: () => string 9 | input?: Array<(Mafmt | (() => Mafmt))> 10 | matches: MatchesFunction 11 | partialMatch: PartialMatchesFunction 12 | } 13 | 14 | /* 15 | * Valid combinations 16 | */ 17 | export const DNS4 = base('dns4') 18 | export const DNS6 = base('dns6') 19 | export const DNSADDR = base('dnsaddr') 20 | export const DNS = or( 21 | base('dns'), 22 | DNSADDR, 23 | DNS4, 24 | DNS6 25 | ) 26 | 27 | export const IP = or(base('ip4'), base('ip6')) 28 | export const TCP = or( 29 | and(IP, base('tcp')), 30 | and(DNS, base('tcp')) 31 | ) 32 | export const UDP = and(IP, base('udp')) 33 | export const UTP = and(UDP, base('utp')) 34 | 35 | export const QUIC = and(UDP, base('quic')) 36 | export const QUICV1 = and(UDP, base('quic-v1')) 37 | 38 | const _WebSockets = or( 39 | and(TCP, base('ws')), 40 | and(DNS, base('ws')) 41 | ) 42 | 43 | export const WebSockets = or( 44 | and(_WebSockets, base('p2p')), 45 | _WebSockets 46 | ) 47 | 48 | const _WebSocketsSecure = or( 49 | and(TCP, base('wss')), 50 | and(DNS, base('wss')), 51 | and(TCP, base('tls'), base('ws')), 52 | and(DNS, base('tls'), base('ws')) 53 | ) 54 | 55 | export const WebSocketsSecure = or( 56 | and(_WebSocketsSecure, base('p2p')), 57 | _WebSocketsSecure 58 | ) 59 | 60 | export const HTTP = or( 61 | and(TCP, base('http')), 62 | and(IP, base('http')), 63 | and(DNS, base('http')) 64 | ) 65 | 66 | export const HTTPS = or( 67 | and(TCP, base('https')), 68 | and(IP, base('https')), 69 | and(DNS, base('https')) 70 | ) 71 | 72 | const _WebRTCDirect = and(UDP, base('webrtc-direct'), base('certhash')) 73 | export const WebRTCDirect = or( 74 | and(_WebRTCDirect, base('p2p')), 75 | _WebRTCDirect 76 | ) 77 | 78 | const _WebTransport = and(QUICV1, base('webtransport'), base('certhash'), base('certhash')) 79 | export const WebTransport = or( 80 | and(_WebTransport, base('p2p')), 81 | _WebTransport 82 | ) 83 | 84 | /** 85 | * @deprecated 86 | */ 87 | export const P2PWebRTCStar = or( 88 | and(WebSockets, base('p2p-webrtc-star'), base('p2p')), 89 | and(WebSocketsSecure, base('p2p-webrtc-star'), base('p2p')), 90 | and(WebSockets, base('p2p-webrtc-star')), 91 | and(WebSocketsSecure, base('p2p-webrtc-star')) 92 | ) 93 | 94 | export const WebSocketStar = or( 95 | and(WebSockets, base('p2p-websocket-star'), base('p2p')), 96 | and(WebSocketsSecure, base('p2p-websocket-star'), base('p2p')), 97 | and(WebSockets, base('p2p-websocket-star')), 98 | and(WebSocketsSecure, base('p2p-websocket-star')) 99 | ) 100 | 101 | /** 102 | * @deprecated 103 | */ 104 | export const P2PWebRTCDirect = or( 105 | and(HTTP, base('p2p-webrtc-direct'), base('p2p')), 106 | and(HTTPS, base('p2p-webrtc-direct'), base('p2p')), 107 | and(HTTP, base('p2p-webrtc-direct')), 108 | and(HTTPS, base('p2p-webrtc-direct')) 109 | ) 110 | 111 | export const Reliable = or( 112 | _WebSockets, 113 | _WebSocketsSecure, 114 | HTTP, 115 | HTTPS, 116 | P2PWebRTCStar, 117 | P2PWebRTCDirect, 118 | TCP, 119 | UTP, 120 | QUIC, 121 | DNS, 122 | WebRTCDirect, 123 | WebTransport 124 | ) 125 | 126 | // 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 ;) ) 127 | export const Stardust = or( 128 | and(Reliable, base('p2p-stardust'), base('p2p')), 129 | and(Reliable, base('p2p-stardust')) 130 | ) 131 | 132 | const _P2P = or( 133 | and(Reliable, base('p2p')), 134 | P2PWebRTCStar, 135 | P2PWebRTCDirect, 136 | WebRTCDirect, 137 | WebTransport, 138 | base('p2p') 139 | ) 140 | 141 | const _Circuit = or( 142 | and(_P2P, base('p2p-circuit'), _P2P), 143 | and(_P2P, base('p2p-circuit')), 144 | and(base('p2p-circuit'), _P2P), 145 | and(Reliable, base('p2p-circuit')), 146 | and(base('p2p-circuit'), Reliable), 147 | base('p2p-circuit') 148 | ) 149 | 150 | const CircuitRecursive = (): Mafmt => or( 151 | and(_Circuit, CircuitRecursive), 152 | _Circuit 153 | ) 154 | 155 | export const Circuit = CircuitRecursive() 156 | 157 | export const P2P = or( 158 | and(Circuit, _P2P, Circuit), 159 | and(_P2P, Circuit), 160 | and(Circuit, _P2P), 161 | Circuit, 162 | _P2P 163 | ) 164 | 165 | export const IPFS = P2P 166 | 167 | export const WebRTC = or( 168 | and(Circuit, base('webrtc'), base('p2p')), 169 | and(Circuit, base('webrtc')), 170 | and(Reliable, base('webrtc'), base('p2p')), 171 | and(Reliable, base('webrtc')), 172 | base('webrtc') 173 | ) 174 | 175 | /* 176 | * Validation funcs 177 | */ 178 | 179 | function makeMatchesFunction (partialMatch: PartialMatchesFunction): (a: string | Uint8Array | Multiaddr) => boolean { 180 | function matches (a: string | Uint8Array | Multiaddr): boolean { 181 | let ma 182 | 183 | try { 184 | ma = multiaddr(a) 185 | } catch (err: any) { // catch error 186 | return false // also if it's invalid it's probably not matching as well so return false 187 | } 188 | 189 | const out = partialMatch(ma.protoNames()) 190 | if (out === null) { 191 | return false 192 | } 193 | 194 | if (out === true || out === false) { 195 | return out 196 | } 197 | 198 | return out.length === 0 199 | } 200 | 201 | return matches 202 | } 203 | 204 | function and (...args: Array Mafmt)>): Mafmt { 205 | function partialMatch (a: string[]): boolean | string[] | null { 206 | if (a.length < args.length) { 207 | return null 208 | } 209 | 210 | let out: boolean | string[] | null = a 211 | 212 | args.some((arg) => { 213 | out = typeof arg === 'function' 214 | ? arg().partialMatch(a) 215 | : arg.partialMatch(a) 216 | 217 | if (Array.isArray(out)) { 218 | a = out 219 | } 220 | 221 | if (out === null) { 222 | return true 223 | } 224 | 225 | return false 226 | }) 227 | 228 | return out 229 | } 230 | 231 | return { 232 | toString: function () { return '{ ' + args.join(' ') + ' }' }, 233 | input: args, 234 | matches: makeMatchesFunction(partialMatch), 235 | partialMatch 236 | } 237 | } 238 | 239 | function or (...args: Array Mafmt)>): Mafmt { 240 | function partialMatch (a: string[]): boolean | string[] | null { 241 | let out = null 242 | args.some((arg) => { 243 | const res = typeof arg === 'function' 244 | ? arg().partialMatch(a) 245 | : arg.partialMatch(a) 246 | if (res != null) { 247 | out = res 248 | return true 249 | } 250 | return false 251 | }) 252 | 253 | return out 254 | } 255 | 256 | const result = { 257 | toString: function () { return '{ ' + args.join(' ') + ' }' }, 258 | input: args, 259 | matches: makeMatchesFunction(partialMatch), 260 | partialMatch 261 | } 262 | 263 | return result 264 | } 265 | 266 | function base (n: string): Mafmt { 267 | const name = n 268 | 269 | function matches (a: string | Uint8Array | Multiaddr): boolean { 270 | let ma: Multiaddr 271 | 272 | try { 273 | ma = multiaddr(a) 274 | } catch (err: any) { // catch error 275 | return false // also if it's invalid it's probably not matching as well so return false 276 | } 277 | 278 | const pnames = ma.protoNames() 279 | if (pnames.length === 1 && pnames[0] === name) { 280 | return true 281 | } 282 | return false 283 | } 284 | 285 | function partialMatch (protos: string[]): boolean | string[] | null { 286 | if (protos.length === 0) { 287 | return null 288 | } 289 | 290 | if (protos[0] === name) { 291 | return protos.slice(1) 292 | } 293 | return null 294 | } 295 | 296 | return { 297 | toString: function () { return name }, 298 | matches, 299 | partialMatch 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /test/index.spec.ts: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | import { multiaddr } from '@multiformats/multiaddr' 3 | import { expect } from 'aegir/chai' 4 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' 5 | import * as mafmt from '../src/index.js' 6 | import type { Mafmt } from '../src/index.js' 7 | 8 | describe('multiaddr validation', function () { 9 | const goodDNS = [ 10 | '/dns/ipfs.io', 11 | '/dnsaddr/ipfs.io', 12 | '/dns4/ipfs.io', 13 | '/dns4/libp2p.io', 14 | '/dns6/protocol.ai' 15 | ] 16 | 17 | const badDNS = [ 18 | '/ip4/127.0.0.1' 19 | ] 20 | 21 | const goodIP = [ 22 | '/ip4/0.0.0.0', 23 | '/ip6/fc00::' 24 | ] 25 | 26 | const badIP = [ 27 | '/ip4/0.0.0.0/tcp/555', 28 | '/udp/789/ip6/fc00::' 29 | ] 30 | 31 | const goodTCP = [ 32 | '/ip4/0.0.7.6/tcp/1234', 33 | '/ip6/::/tcp/0', 34 | '/dns4/protocol.ai/tcp/80', 35 | '/dns6/protocol.ai/tcp/80', 36 | '/dnsaddr/protocol.ai/tcp/80' 37 | ] 38 | 39 | const badTCP = [ 40 | '/tcp/12345', 41 | '/ip6/fc00::/udp/5523/tcp/9543', 42 | '/dns4/protocol.ai' 43 | ] 44 | 45 | const goodUDP = [ 46 | '/ip4/0.0.7.6/udp/1234', 47 | '/ip6/::/udp/0' 48 | ] 49 | 50 | const badUDP = [ 51 | '/udp/12345', 52 | '/ip6/fc00::/tcp/5523/udp/9543' 53 | ] 54 | 55 | const goodQUIC = [ 56 | '/ip4/1.2.3.4/udp/1234/quic', 57 | '/ip6/::/udp/1234/quic' 58 | ] 59 | 60 | const badQUIC = [ 61 | '/ip4/0.0.0.0/tcp/12345/quic', 62 | '/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic', 63 | '/quic' 64 | ] 65 | 66 | const goodUTP = [ 67 | '/ip4/1.2.3.4/udp/3456/utp', 68 | '/ip6/::/udp/0/utp' 69 | ] 70 | 71 | const badUTP = [ 72 | '/ip4/0.0.0.0/tcp/12345/utp', 73 | '/ip6/::/ip4/0.0.0.0/udp/1234/utp' 74 | ] 75 | 76 | const goodHTTP = [ 77 | '/dnsaddr/ipfs.io/http', 78 | '/dnsaddr/ipfs.io/tcp/3456/http', 79 | '/ip4/0.0.0.0/http', 80 | '/ip4/0.0.0.0/tcp/12345/http', 81 | '/ip6/::/http', 82 | '/ip6/::/tcp/12345/http' 83 | ] 84 | 85 | const goodHTTPS = [ 86 | '/dnsaddr/ipfs.io/https', 87 | '/dnsaddr/ipfs.io/tcp/3456/https', 88 | '/ip4/0.0.0.0/https', 89 | '/ip4/0.0.0.0/tcp/12345/https', 90 | '/ip6/::/https', 91 | '/ip6/::/tcp/12345/https' 92 | ] 93 | 94 | const goodWS = [ 95 | '/dnsaddr/ipfs.io/ws', 96 | '/dns4/ipfs.io/ws', 97 | '/dns6/ipfs.io/ws', 98 | '/ip4/1.2.3.4/tcp/3456/ws', 99 | '/ip6/::/tcp/0/ws', 100 | '/dnsaddr/ipfs.io/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 101 | '/dns4/ipfs.io/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 102 | '/dns6/ipfs.io/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 103 | '/ip4/1.2.3.4/tcp/3456/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 104 | '/ip6/::/tcp/3456/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79' 105 | ] 106 | 107 | const goodWSS = [ 108 | '/dnsaddr/ipfs.io/wss', 109 | '/dns4/ipfs.io/wss', 110 | '/dns6/ipfs.io/wss', 111 | '/ip4/1.2.3.4/tcp/3456/wss', 112 | '/ip6/::/tcp/0/wss', 113 | '/dnsaddr/ipfs.io/tls/ws', 114 | '/dns4/ipfs.io/tls/ws', 115 | '/dns6/ipfs.io/tls/ws', 116 | '/ip4/1.2.3.4/tcp/3456/tls/ws', 117 | '/ip6/::/tcp/0/tls/ws', 118 | '/dnsaddr/ipfs.io/wss/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 119 | '/dns4/ipfs.io/wss/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 120 | '/dns6/ipfs.io/wss/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 121 | '/ip4/1.2.3.4/tcp/3456/wss/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 122 | '/ip6/::/tcp/3456/wss/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 123 | '/dnsaddr/ipfs.io/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 124 | '/dns4/ipfs.io/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 125 | '/dns6/ipfs.io/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 126 | '/ip4/1.2.3.4/tcp/3456/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 127 | '/ip6/::/tcp/3456/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79' 128 | ] 129 | 130 | const goodP2PWebRTCStar = [ 131 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 132 | '/dnsaddr/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 133 | '/dnsaddr/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 134 | '/ip6/::/tcp/0/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5', 135 | '/ip6/::/tcp/0/ws/p2p-webrtc-star', 136 | '/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 137 | '/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star', 138 | '/dns/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', 139 | '/dns/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/ipfs/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79' 140 | ] 141 | 142 | const goodP2PWebRTCDirect = [ 143 | '/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct', 144 | '/ip6/::/tcp/0/http/p2p-webrtc-direct' 145 | ] 146 | 147 | const goodWebSocketStar = [ 148 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star', 149 | '/ip6/::/tcp/0/ws/p2p-websocket-star', 150 | '/dnsaddr/localhost/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 151 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 152 | '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star/ipfs/Qma3uqwymdqwXtC4uvmqqwwMhTDHD7xp9FzM75tQB5qRM3' 153 | ] 154 | 155 | const goodStardust = [ 156 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-stardust', 157 | '/ip6/::/tcp/0/ws/p2p-stardust', 158 | '/dnsaddr/localhost/ws/p2p-stardust/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 159 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-stardust/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 160 | '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-stardust/ipfs/Qma3uqwymdqwXtC4uvmqqwwMhTDHD7xp9FzM75tQB5qRM3' 161 | ] 162 | 163 | const badWS = [ 164 | '/ip4/0.0.0.0/tcp/12345/udp/2222/ws', 165 | '/ip6/::/ip4/0.0.0.0/udp/1234/ws', 166 | '/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star' 167 | ] 168 | 169 | const badWSS = [ 170 | '/ip4/0.0.0.0/tcp/12345/udp/2222/wss', 171 | '/ip6/::/ip4/0.0.0.0/udp/1234/wss' 172 | ] 173 | 174 | const goodCircuit = [ 175 | '/p2p-circuit', 176 | '/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 177 | '/p2p-circuit/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 178 | '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 179 | '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 180 | '/p2p-circuit/ip4/127.0.0.1/tcp/4002/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA', 181 | '/p2p-circuit/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA', 182 | '/p2p-circuit/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj/' + 183 | 'p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj' 184 | ] 185 | 186 | const badCircuit = [ 187 | '/ip4/0.0.0.0/tcp/12345/udp/2222/wss', 188 | '/ip4/0.0.7.6/udp/1234', 189 | '/ip6/::/udp/0/utp', 190 | '/dnsaddr/ipfs.io/ws', 191 | '/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-star' 192 | ] 193 | 194 | const goodIPFS = [ 195 | '/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 196 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 197 | '/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct/p2p/QmPj9ZZ6notLfV9khV1FtxH1Goe5sVaUyqgoXrTYQWp382', 198 | '/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 199 | '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit', 200 | '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 201 | '/ip4/127.0.0.1/tcp/20008/ws/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 202 | '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 203 | '/ip4/1.2.3.4/tcp/3456/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 204 | '/ip4/1.2.3.4/udp/1234/quic/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 205 | '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 206 | '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', 207 | '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit', 208 | '/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/p2p/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', 209 | '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', 210 | '/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', 211 | '/dns6/nyc-2.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' 212 | ].concat(goodCircuit) 213 | 214 | const goodWebRTCDirect = [ 215 | '/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw', 216 | '/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' 217 | ] 218 | 219 | const badWebRTCDirect = [ 220 | '/ip4/0.0.0.0/udp/4004/webrtc-direct', 221 | '/ip4/0.0.0.0/tcp/4004/webrtc-direct', 222 | '/ip4/0.0.0.0/udp/4004/webrtc-direct/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' 223 | ] 224 | 225 | const goodWebRTC = [ 226 | '/ip4/127.0.0.1/tcp/59119/ws/p2p/12D3KooWAzabxK2xhwGQuTUYjbcFT9SZcNvPS1cvj7bPMe2Rh9qF/p2p-circuit/webrtc/p2p/12D3KooWA6L4J1yRwqLwdXPZBxz3UL4E8pEE6AEhFkqDH5LTQyfq', 227 | '/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/webrtc', 228 | '/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/webrtc', 229 | '/webrtc' 230 | ] 231 | 232 | const badWebRTC = [ 233 | '/ip4/0.0.0.0/udp/webrtc', 234 | '/ip4/0.0.0.0/tcp/12345/udp/2222/wss/webrtc' 235 | ] 236 | 237 | const goodWebTransport = [ 238 | '/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v', 239 | '/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v', 240 | '/ip4/97.126.16.119/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v', 241 | '/ip6/::1/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v' 242 | ] 243 | 244 | const badWebTransport = [ 245 | // quic instead of quic-v1 246 | '/ip4/10.5.0.2/udp/4001/quic/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/uEiCoik2HBeT5oc9Jib3SQJzNjn9AnznMDpQWcOeKSuEc9A/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v', 247 | // missing second certhash value 248 | '/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/certhash/uEiDWmsTxXe55Mbwnvd1qrPZAcE5Jtc0tE9WtGXD_NpMERg/certhash/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v', 249 | // missing webtransport/certhash base 250 | '/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v', 251 | // missing value for base 'webtransport/certhash' `${value}/certhash/${value}` 252 | '/ip4/10.5.0.2/udp/4001/quic-v1/webtransport/certhash/p2p/12D3KooWQF6Q3i1QkziJQ9mkNNcyFD8GPQz6R6oEvT75wgsVXm4v' 253 | ] 254 | 255 | function assertMatches (p: Mafmt, ...tests: string[][]): void { 256 | tests.forEach(function (test) { 257 | test.forEach(function (testcase) { 258 | try { 259 | expect(p.matches(testcase), `assertMatches: ${testcase} (string)`).to.be.eql(true) 260 | const ma = multiaddr(testcase) 261 | expect(p.matches(ma), `assertMatches: ${testcase} (multiaddr object)`).to.be.eql(true) 262 | expect(p.matches(ma.bytes), `assertMatches: ${testcase} (multiaddr.bytes)`).to.be.eql(true) 263 | } catch (err: any) { 264 | err.stack = `[testcase=${JSON.stringify(testcase)}, shouldMatch=true] ${err.stack}` // eslint-disable-line @typescript-eslint/restrict-template-expressions 265 | throw err 266 | } 267 | }) 268 | }) 269 | } 270 | 271 | function assertMismatches (p: Mafmt, ...tests: string[][]): void { 272 | tests.forEach(function (test) { 273 | test.forEach(function (testcase) { 274 | try { 275 | expect(p.matches(testcase), `assertMismatches: ${testcase} (string)`).to.be.eql(false) 276 | let validMultiaddrObj 277 | try { 278 | // if testcase string happens to be a valid multiaddr, 279 | // we expect 'p' test to also return false for Multiaddr object and Uint8Array versions 280 | validMultiaddrObj = multiaddr(testcase) 281 | } catch (e) { 282 | // Ignoring testcase as the string is not a multiaddr 283 | // (There is a separate 'Uint8Array is invalid' test later below) 284 | } 285 | if (validMultiaddrObj != null) { 286 | expect(p.matches(validMultiaddrObj), `assertMismatches: ${testcase} (multiaddr object)`).to.be.eql(false) 287 | expect(p.matches(validMultiaddrObj.bytes), `assertMismatches: ${testcase} (multiaddr.bytes)`).to.be.eql(false) 288 | } 289 | } catch (err: any) { 290 | err.stack = `[testcase=${JSON.stringify(testcase)}, shouldMatch=false] ${err.stack}` // eslint-disable-line @typescript-eslint/restrict-template-expressions 291 | throw err 292 | } 293 | }) 294 | }) 295 | } 296 | 297 | it('do not throw if multiaddr str is invalid', function () { 298 | expect(mafmt.HTTP.matches('/http-google-com')).to.be.eql(false) 299 | }) 300 | 301 | it('do not throw if multiaddr Uint8Array is invalid', function () { 302 | expect(mafmt.HTTP.matches(uint8ArrayFromString('no spoon'))).to.be.eql(false) 303 | }) 304 | 305 | it('DNS validation', function () { 306 | assertMatches(mafmt.DNS, goodDNS) 307 | assertMismatches(mafmt.DNS, badDNS, badIP) 308 | }) 309 | 310 | it('IP validation', function () { 311 | assertMatches(mafmt.IP, goodIP) 312 | assertMismatches(mafmt.IP, badIP, goodTCP) 313 | }) 314 | 315 | it('TCP validation', function () { 316 | assertMatches(mafmt.TCP, goodTCP) 317 | assertMismatches(mafmt.TCP, badTCP, goodIP) 318 | }) 319 | 320 | it('UDP validation', function () { 321 | assertMatches(mafmt.UDP, goodUDP) 322 | assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP) 323 | }) 324 | 325 | it('QUIC validation', function () { 326 | assertMatches(mafmt.QUIC, goodQUIC) 327 | assertMismatches(mafmt.QUIC, badQUIC) 328 | }) 329 | 330 | it('UTP validation', function () { 331 | assertMatches(mafmt.UTP, goodUTP) 332 | assertMismatches(mafmt.UTP, badUTP, goodIP, goodTCP, goodUDP) 333 | }) 334 | 335 | it('HTTP validation', function () { 336 | assertMatches(mafmt.HTTP, goodHTTP) 337 | assertMismatches(mafmt.HTTP, goodIP, goodUDP) 338 | }) 339 | 340 | it('HTTPS validation', function () { 341 | assertMatches(mafmt.HTTPS, goodHTTPS) 342 | assertMismatches(mafmt.HTTPS, goodHTTP, goodIP, goodTCP, goodUDP) 343 | }) 344 | 345 | it('Reliable validation', function () { 346 | assertMatches(mafmt.Reliable, goodUTP, goodTCP) 347 | assertMismatches(mafmt.Reliable, goodIP, goodUDP) 348 | }) 349 | 350 | it('WebSockets validation', function () { 351 | assertMatches(mafmt.WebSockets, goodWS) 352 | assertMismatches(mafmt.WebSockets, goodIP, goodUDP, badWS) 353 | }) 354 | 355 | it('WebSocketsSecure validation', function () { 356 | assertMatches(mafmt.WebSocketsSecure, goodWSS) 357 | assertMismatches(mafmt.WebSocketsSecure, goodIP, badWSS, goodUDP, badWS) 358 | }) 359 | 360 | it('WebSocketStar validation', function () { 361 | assertMatches(mafmt.WebSocketStar, goodWebSocketStar) 362 | assertMismatches(mafmt.WebSocketStar, goodIP, goodUDP, badWS) 363 | }) 364 | 365 | it('Stardust validation', function () { 366 | assertMatches(mafmt.Stardust, goodStardust) 367 | assertMismatches(mafmt.Stardust, goodIP, goodUDP, badWS) 368 | }) 369 | 370 | it('P2PWebRTCStar validation', function () { 371 | assertMatches(mafmt.P2PWebRTCStar, goodP2PWebRTCStar) 372 | assertMismatches(mafmt.P2PWebRTCStar, goodIP, goodUDP, badWSS) 373 | }) 374 | 375 | it('P2PWebRTCDirect validation', function () { 376 | assertMatches(mafmt.P2PWebRTCDirect, goodP2PWebRTCDirect) 377 | assertMismatches(mafmt.P2PWebRTCDirect, goodIP, goodUDP, badWS) 378 | }) 379 | 380 | it('Circuit validation', function () { 381 | assertMatches(mafmt.Circuit, goodCircuit) 382 | assertMismatches(mafmt.Circuit, badCircuit) 383 | }) 384 | 385 | it('IPFS validation', function () { 386 | assertMatches(mafmt.IPFS, goodIPFS) 387 | }) 388 | 389 | it('WebRTCDirect validation', function () { 390 | assertMatches(mafmt.WebRTCDirect, goodWebRTCDirect) 391 | assertMismatches(mafmt.WebRTCDirect, badWebRTCDirect) 392 | }) 393 | 394 | it('WebRTC validation', function () { 395 | assertMatches(mafmt.WebRTC, goodWebRTC) 396 | assertMismatches(mafmt.WebRTC, badWebRTC) 397 | }) 398 | 399 | it('WebTransport validation', function () { 400 | assertMatches(mafmt.WebTransport, goodWebTransport) 401 | assertMismatches(mafmt.WebTransport, badWebTransport) 402 | }) 403 | }) 404 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "emitDeclarationOnly": false, 6 | "module": "ES2020" 7 | }, 8 | "include": [ 9 | "src", 10 | "test" 11 | ] 12 | } 13 | --------------------------------------------------------------------------------