{"id":21561738,"url":"https://github.com/synonymdev/ln-constr-parser","last_synced_at":"2026-03-03T20:33:29.478Z","repository":{"id":175737528,"uuid":"653973608","full_name":"synonymdev/ln-constr-parser","owner":"synonymdev","description":"Lightning Connection String Parser","archived":false,"fork":false,"pushed_at":"2023-06-26T05:23:18.000Z","size":102,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-16T07:48:57.077Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/synonymdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-15T06:17:19.000Z","updated_at":"2023-06-30T19:10:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cf1f310-a087-48bf-bc96-cfb911d10e09","html_url":"https://github.com/synonymdev/ln-constr-parser","commit_stats":null,"previous_names":["synonymdev/ln-constr-parser"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/synonymdev/ln-constr-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synonymdev%2Fln-constr-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synonymdev%2Fln-constr-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synonymdev%2Fln-constr-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synonymdev%2Fln-constr-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synonymdev","download_url":"https://codeload.github.com/synonymdev/ln-constr-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synonymdev%2Fln-constr-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30058302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T09:27:49.275Z","updated_at":"2026-03-03T20:33:29.437Z","avatar_url":"https://github.com/synonymdev.png","language":"TypeScript","readme":"# ln-constr-parser\n\n[![NPM version](https://img.shields.io/npm/v/@synonymdev/ln-constr-parser?color=%23FFAE00\u0026style=flat-square)](https://www.npmjs.com/package/@synonymdev/ln-constr-parser)\n\nConvenient, dependency-free Lightning connection string parser for front- and backend.\n\n## Usage\n\n```typescript\nimport {parseConnectionString} from '@synonymdev/ln-constr-parser';\n\nconst connectionString = '0200000000a3eff613189ca6c4070c89206ad658e286751eca1f29262948247a5f@127.0.0.1:9735';\nconst {host, hostType, port, pubKey} = parseConnectionString(connectionString);\n\nconsole.log(host); // 127.0.0.1\nconsole.log(hostType); // ipv4. Depending on the address provided, it could also be ipv6, torv3 or domain.\nconsole.log(port); // 9735\nconsole.log(pubKey); // 0200000000a3eff613189ca6c4070c89206ad658e286751eca1f29262948247a5f\n```\n\nThe `port` is optional. You can make the port mandatory so the parser will throw an error. This also avoids the\nipv6 ambiguity problem (see below).\n\n```typescript\nparseConnectionString(connectionString, {portMandatory: true})\n```\n\n### Parse Errors\n\nIn case of an invalid connection string, the parser will throw a detailed error of what is wrong.\n\n```typescript\nimport {parseConnectionString, ParseFailureCode, ParseError} from '@synonymdev/ln-constr-parser';\n\ntry {\n    const connectionString = 'pubkey@host:port';\n    parseConnectionString(connectionString);\n} catch (e) {\n    if (e instanceof ParseError) {\n        console.log('Parse failed. Reason:', e.code)\n        if (e.code === ParseFailureCode.INVALID_HOST) {\n            console.log('Host value is invalid.')\n        } else if (e.codee === ParseFailureCode.INVALID_IPV6) {\n            console.log('IPv6 host is invalid.')\n        } else if (e.codee === ParseFailureCode.AMBIGUOUS_IPV6) {\n            console.log('IPv6 host is ambiguous. Use square brackets [] like pubkey@[ipv6]:port.')\n        } else if (e.code === ParseFailureCode.INVALID_PORT) {\n            console.log('Invalid port.')\n        } else if (e.code === ParseFailureCode.INVALID_PUBKEY) {\n            console.log('Invalid lightning pubkey.')\n        } else if (e.code === ParseFailureCode.INVALID_ATS) {\n            console.log('The connection string must contain one single @ symbol.')\n        }\n    }\n}\n```\n\n## Supported Address Formats\n\nThe library supports all commonly used address formats in the form of \n- `pubkey@host:port`\n- `pubkey@host`\n- `pubkey@[host]:port`\n- `pubkey@[host]`\n\n**ipv4**\n- Regular `pubkey@127.0.0.1:port`.\n- No port `pubkey@127.0.0.1`.\n- Square brackets `pubkey@[127.0.0.1]:port`.\n- Square brackets no port `pubkey@[127.0.0.1]`.\n\n**ipv6**\n- Square brackets `pubkey@[2001:db8:3333:4444:5555:6666:7777:8888]:port`.\n- Square brackets compressed `pubkey@[2001:db8::8888]:port`.\n- Square brackets no port `pubkey@[2001:db8:3333:4444:5555:6666:7777:8888]`.\n- Square brackets compressed no port `pubkey@[2001:db8::8888]`.\n- Regular uncompressed `pubkey@2001:db8:3333:4444:5555:6666:7777:8888:port`.\n- No port uncompressed `pubkey@2001:db8:3333:4444:5555:6666:7777:8888`.\n\n\u003e **⚠️ Ambiguity problem** If you don't make the port mandatory, it is adviced to use square brackets `[]` with IPv6. It is impossible to separate a compressed IPv6 from the port. Example:\n\u003e `2001:db8::8888:9735` may as well be a IPv6 (`2001:db8::8888:9735`) OR a IPv6:port (`2001:db8::8888` and port `9735`).\n\u003e The library will do its best to parse it correctly but will throw an error in case of ambiguity.\n\n**torv3**\n- Regular `pubkey@giexynrrloc2fewstcybenljdksidtglfydecbellzkl63din6w73eid.onion:port`.\n- No port `pubkey@giexynrrloc2fewstcybenljdksidtglfydecbellzkl63din6w73eid.onion`.\n- Square brackets `pubkey@[giexynrrloc2fewstcybenljdksidtglfydecbellzkl63din6w73eid.onion]:port`.\n- Square brackets no port `pubkey@[giexynrrloc2fewstcybenljdksidtglfydecbellzkl63din6w73eid.onion]`.\n\n**domain**\n- Regular `pubkey@synonym.to:port`.\n- No port `pubkey@synonym.to`.\n- Square brackets `pubkey@[synonym.to]:port`.\n- Square brackets no port `pubkey@[synonym.to]`.\n\n\n\n\n## Parse Subcomponents\n\nThe library also provides functions to parse the individual components of a connection string.\n\n```typescript\nimport {parseAddress, parseHost, parsePort, parsePubkey} from '@synonymdev/ln-constr-parser';\n\nconst {host, hostType, port} = parseAddress('127.0.0.1:9000')\nconst {host, hostType} = parseHost('127.0.0.1')\nconst port = parsePort('900')\nconst pubkey = parsePubkey('0200000000a3eff613189ca6c4070c89206ad658e286751eca1f29262948247a5f')\n```\n\n\n---\n\nMay the ⚡ be with you.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynonymdev%2Fln-constr-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynonymdev%2Fln-constr-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynonymdev%2Fln-constr-parser/lists"}