*/
constructor (url: string | URL, auth?: { header: string, value: string })
constructor (url: unknown, auth: unknown) {
- if ((typeof url === 'string' || url instanceof URL) && URL.canParse(url)) {
- this.#url = new URL(url)
- this.#url.protocol = 'https:'
- } else {
- throw new RpcError('Invalid URL', { cause: url })
+ if (typeof url !== 'string' && !(url instanceof URL)) {
+ throw new RpcError('Invalid RPC URL', { cause: url })
}
+ if (!(URL.canParse(url))) {
+ throw new RpcError('Failed to parse RPC URL', { cause: url })
+ }
+
+ const u = new URL(url)
+ if (u.protocol === 'http:') {
+ u.protocol = 'https:'
+ }
+ if (u.protocol !== 'https:') {
+ throw new RpcError('RPC requires HTTPS')
+ }
+ this.#url = u
if (typeof auth === 'string') {
(auth as string) = auth.trim()