(urlString: string)
| 267 | // Throws an error if `urlString` is not a valid exchange URL, i.e. it must not |
| 268 | // have credentials (user:password@) or hash (#fragment). |
| 269 | function validateExchangeURL(urlString: string): void { |
| 270 | // `urlString` can be relative, so try parsing it with a dummy base URL. |
| 271 | const url = new URL(urlString, 'https://webbundle.example/'); |
| 272 | if (url.username !== '' || url.password !== '') { |
| 273 | throw new Error('Exchange URL must not have credentials: ' + urlString); |
| 274 | } |
| 275 | if (url.hash !== '') { |
| 276 | throw new Error('Exchange URL must not have a hash: ' + urlString); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | function byteString(s: string): Uint8Array { |
| 281 | return new TextEncoder().encode(s); |
no outgoing calls
no test coverage detected