-
-
Notifications
You must be signed in to change notification settings - Fork 246
feat: Add client_info to LSPS1, LSPS7, and Flow requests #3810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { getClientInfo, stripVersionPrefix } from './ClientInfoUtils'; | ||
| import { version as appVersion } from '../package.json'; | ||
|
|
||
| const strippedAppVersion = appVersion.replace(/^[vV]/, ''); | ||
|
|
||
| describe('ClientInfoUtils', () => { | ||
| describe('stripVersionPrefix', () => { | ||
| it('strips lowercase v prefix', () => { | ||
| expect(stripVersionPrefix('v0.18.4-beta')).toBe('0.18.4-beta'); | ||
| }); | ||
|
|
||
| it('strips uppercase V prefix', () => { | ||
| expect(stripVersionPrefix('V25.02')).toBe('25.02'); | ||
| }); | ||
|
|
||
| it('leaves version without prefix unchanged', () => { | ||
| expect(stripVersionPrefix('0.13.0-prealpha')).toBe( | ||
| '0.13.0-prealpha' | ||
| ); | ||
| }); | ||
|
|
||
| it('only strips the first v', () => { | ||
| expect(stripVersionPrefix('v1.2.3-v4')).toBe('1.2.3-v4'); | ||
| }); | ||
|
|
||
| it('handles empty string', () => { | ||
| expect(stripVersionPrefix('')).toBe(''); | ||
| }); | ||
|
|
||
| it('does not strip v from middle of string', () => { | ||
| expect(stripVersionPrefix('24.11-preview')).toBe('24.11-preview'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getClientInfo', () => { | ||
| it('always includes app name and version without v prefix', () => { | ||
| const info = getClientInfo(); | ||
| expect(info.app).toBe('ZEUS'); | ||
| expect(info.app_version).toBe(strippedAppVersion); | ||
| expect(info.app_version).not.toMatch(/^[vV]/); | ||
| }); | ||
|
|
||
| it('omits node fields when no implementation provided', () => { | ||
| const info = getClientInfo(); | ||
| expect(info.node).toBeUndefined(); | ||
| expect(info.node_version).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('maps embedded-lnd to LND', () => { | ||
| const info = getClientInfo('embedded-lnd', '0.18.4-beta'); | ||
| expect(info.node).toBe('LND'); | ||
| expect(info.node_version).toBe('0.18.4-beta'); | ||
| }); | ||
|
|
||
| it('maps lnd to LND', () => { | ||
| const info = getClientInfo('lnd', '0.17.0-beta'); | ||
| expect(info.node).toBe('LND'); | ||
| expect(info.node_version).toBe('0.17.0-beta'); | ||
| }); | ||
|
|
||
| it('maps lightning-node-connect to LND', () => { | ||
| const info = getClientInfo('lightning-node-connect', '0.18.0'); | ||
| expect(info.node).toBe('LND'); | ||
| expect(info.node_version).toBe('0.18.0'); | ||
| }); | ||
|
|
||
| it('maps cln-rest to Core Lightning', () => { | ||
| const info = getClientInfo('cln-rest', '25.02'); | ||
| expect(info.node).toBe('Core Lightning'); | ||
| expect(info.node_version).toBe('25.02'); | ||
| }); | ||
|
|
||
| it('includes node name but omits node_version when version not provided', () => { | ||
| const info = getClientInfo('embedded-lnd'); | ||
| expect(info.node).toBe('LND'); | ||
| expect(info.node_version).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('uses implementation string as fallback for unknown backends', () => { | ||
| const info = getClientInfo('ldk-node' as any, '0.5.0'); | ||
| expect(info.node).toBe('ldk-node'); | ||
| expect(info.node_version).toBe('0.5.0'); | ||
| }); | ||
|
|
||
| it('ignores node_version when no implementation provided', () => { | ||
| const info = getClientInfo(undefined, '0.18.4-beta'); | ||
| expect(info.node).toBeUndefined(); | ||
| expect(info.node_version).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('strips v prefix from node version', () => { | ||
| const info = getClientInfo('cln-rest', 'v24.11.1'); | ||
| expect(info.node_version).toBe('24.11.1'); | ||
| }); | ||
|
|
||
| it('strips V prefix from node version', () => { | ||
| const info = getClientInfo('lnd', 'V0.18.4-beta'); | ||
| expect(info.node_version).toBe('0.18.4-beta'); | ||
| }); | ||
|
|
||
| it('returns correct shape for LSPS1 REST payload', () => { | ||
| const info = getClientInfo('lnd', '0.18.4-beta'); | ||
| const payload = { | ||
| lsp_balance_sat: '5000000', | ||
| client_balance_sat: '0', | ||
| token: 'SUMMER25', | ||
| client_info: info | ||
| }; | ||
| expect(payload.client_info).toEqual({ | ||
| app: 'ZEUS', | ||
| app_version: strippedAppVersion, | ||
| node: 'LND', | ||
| node_version: '0.18.4-beta' | ||
| }); | ||
| }); | ||
|
|
||
| it('returns correct shape for LSPS7 custom message payload', () => { | ||
| const info = getClientInfo('embedded-lnd', '0.18.4-beta'); | ||
| const params = { | ||
| short_channel_id: '832746x1x0', | ||
| channel_extension_expiry_blocks: 4380, | ||
| token: '', | ||
| client_info: info | ||
| }; | ||
| expect(params.client_info.app).toBe('ZEUS'); | ||
| expect(params.client_info.node).toBe('LND'); | ||
| }); | ||
|
|
||
| it('returns correct shape for Flow proposal payload', () => { | ||
| const info = getClientInfo('embedded-lnd', '0.18.4-beta'); | ||
| const body = { | ||
| bolt11: 'lnbc1...', | ||
| fee_id: 'abc123', | ||
| simpleTaproot: false, | ||
| client_info: info | ||
| }; | ||
| expect(body.client_info).toEqual({ | ||
| app: 'ZEUS', | ||
| app_version: strippedAppVersion, | ||
| node: 'LND', | ||
| node_version: '0.18.4-beta' | ||
| }); | ||
| }); | ||
|
|
||
| it('handles cln-rest for LSPS1 REST with v prefix stripped', () => { | ||
| const info = getClientInfo('cln-rest', 'v24.11.1'); | ||
| const payload = { | ||
| lsp_balance_sat: '1000000', | ||
| client_info: info | ||
| }; | ||
| expect(payload.client_info.node).toBe('Core Lightning'); | ||
| expect(payload.client_info.node_version).toBe('24.11.1'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { version as appVersion } from '../package.json'; | ||
| import { Implementations } from '../stores/SettingsStore'; | ||
|
|
||
| // Only backends that support LSP (Flow, LSPS1, or LSPS7) | ||
| const NODE_NAMES: Partial<Record<Implementations, string>> = { | ||
| 'embedded-lnd': 'LND', | ||
| lnd: 'LND', | ||
| 'lightning-node-connect': 'LND', | ||
| 'cln-rest': 'Core Lightning' | ||
| }; | ||
|
|
||
| export interface ClientInfo { | ||
| app: string; | ||
| app_version: string; | ||
| node?: string; | ||
| node_version?: string; | ||
| } | ||
|
|
||
| /** Strips a leading 'v' or 'V' from a version string. */ | ||
| export function stripVersionPrefix(version: string): string { | ||
| return version.replace(/^[vV]/, ''); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a client_info object for LSPS1, LSPS7, and Flow requests. | ||
| */ | ||
| export function getClientInfo( | ||
| implementation?: Implementations, | ||
| nodeVersion?: string | ||
| ): ClientInfo { | ||
| const info: ClientInfo = { | ||
| app: 'ZEUS', | ||
| app_version: stripVersionPrefix(appVersion) | ||
| }; | ||
|
|
||
| if (implementation) { | ||
| info.node = NODE_NAMES[implementation] || implementation; | ||
| if (nodeVersion) { | ||
| info.node_version = stripVersionPrefix(nodeVersion); | ||
| } | ||
| } | ||
|
|
||
| return info; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.