Skip to content

Commit

Permalink
0.2.2-0.0.1 - Fix: DNS Validation (#36)
Browse files Browse the repository at this point in the history
* Update dns regex

* Inc version
  • Loading branch information
lnbc1QWFyb24 authored Jul 21, 2023
1 parent 81dfe87 commit f7cdc70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lnmessage",
"version": "0.2.2",
"version": "0.2.2-0.0.1",
"description": "Talk to Lightning nodes from your browser",
"main": "dist/index.js",
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export function validateInit(options: LnWebSocketOptions): void {

const ipRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/

const domainRegex =
/^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$/
const dnsRegex =
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/

if (!ip || (!ip.match(ipRegex) && !ip.match(domainRegex) && ip !== 'localhost')) {
if (!ip || (!ip.match(ipRegex) && !ip.match(dnsRegex) && ip !== 'localhost')) {
throw new Error(`${ip} is not a valid IP or DNS address`)
}

Expand Down

0 comments on commit f7cdc70

Please sign in to comment.