Skip to content
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

LNURL-auth support for LNDHub #1254

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backends/CLightningREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ export default class CLightningREST extends LND {
this.getRequest(
`/v1/utility/checkMessage/${data.msg}/${data.signature}`
);
lnurlAuth = (message: string) => this.signMessage(message);

supportsMessageSigning = () => true;
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsKeysend = () => true;
Expand Down
2 changes: 2 additions & 0 deletions backends/Eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ export default class Eclair {
msg: Base64Utils.btoa(data.msg),
sig: data.signature
});
lnurlAuth = (message: string) => this.signMessage(message);

supportsMessageSigning = () => true;
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsKeysend = () => false;
Expand Down
2 changes: 2 additions & 0 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@ export default class LND {
msg: Base64Utils.btoa(data.msg),
signature: data.signature
});
lnurlAuth = (r_hash: string) => this.signMessage(r_hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love what you've done here, wrapping up the signMessage method for the new call

subscribeInvoice = (r_hash: string) =>
this.getRequest(`/v2/invoices/subscribe/${r_hash}`);

supportsMessageSigning = () => true;
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsKeysend = () => true;
Expand Down
2 changes: 2 additions & 0 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export default class LightningNodeConnect {
signature: req.signature
})
.then((data: lnrpc.VerifyMessageResponse) => snakeize(data));
lnurlAuth = async (message: string) => await this.signMessage(message);
subscribeInvoice = (r_hash: string) =>
this.lnc.lnd.invoices.subscribeSingleInvoice({ r_hash });
subscribeInvoices = () => this.lnc.lnd.lightning.subscribeInvoices();
Expand All @@ -285,6 +286,7 @@ export default class LightningNodeConnect {
};

supportsMessageSigning = () => true;
supportsLnurlAuth = () => true;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsKeysend = () => true;
Expand Down
5 changes: 5 additions & 0 deletions backends/LndHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ export default class LndHub extends LND {
invoice: data.payment_request,
amount: Number(data.amt && data.amt * 1000)
});
lnurlAuth = () =>
Promise.resolve({
signature: `lndhub://${stores.settingsStore.username}:${stores.settingsStore.password}`
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was an actual /auth endpoint we could use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That endpoint was for actual LNDHub auth (fetching an auth token) - didn’t actually do any message signing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected!


supportsMessageSigning = () => false;
supportsLnurlAuth = () => true;
supportsOnchainSends = () => false;
supportsOnchainReceiving = () =>
!(
Expand Down
1 change: 1 addition & 0 deletions backends/Spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export default class Spark {
};

supportsMessageSigning = () => false;
supportsLnurlAuth = () => false;
supportsOnchainSends = () => true;
supportsOnchainReceiving = () => true;
supportsKeysend = () => false;
Expand Down
2 changes: 2 additions & 0 deletions utils/BackendUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BackendUtils {
importAccount = (...args: any[]) => this.call('importAccount', args);
signMessage = (...args: any[]) => this.call('signMessage', args);
verifyMessage = (...args: any[]) => this.call('verifyMessage', args);
lnurlAuth = (...args: any[]) => this.call('lnurlAuth', args);

fundPsbt = (...args: any[]) => this.call('fundPsbt', args);
finalizePsbt = (...args: any[]) => this.call('finalizePsbt', args);
Expand All @@ -104,6 +105,7 @@ class BackendUtils {
login = (...args: any[]) => this.call('login', args);

supportsMessageSigning = () => this.call('supportsMessageSigning');
supportsLnurlAuth = () => this.call('supportsLnurlAuth');
supportsOnchainSends = () => this.call('supportsOnchainSends');
supportsOnchainReceiving = () => this.call('supportsOnchainReceiving');
supportsKeysend = () => this.call('supportsKeysend');
Expand Down
2 changes: 1 addition & 1 deletion utils/handleAnything.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const handleAnything = async (
];
break;
case 'login':
if (BackendUtils.supportsMessageSigning()) {
if (BackendUtils.supportsLnurlAuth()) {
if (isClipboardValue) return true;
return [
'LnurlAuth',
Expand Down
5 changes: 3 additions & 2 deletions views/LnurlAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class LnurlAuth extends React.Component<

const body = LNURLAUTH_CANONICAL_PHRASE;

BackendUtils.signMessage(body)
BackendUtils.lnurlAuth(body)
.then((signature: any) => {
// got the signed message, now build linkingkey

Expand Down Expand Up @@ -252,7 +252,8 @@ export default class LnurlAuth extends React.Component<
padding: 20,
fontSize: 22,
color: themeColor('text'),
fontFamily: 'Lato-Bold'
fontFamily: 'Lato-Bold',
textAlign: 'center'
}}
>
{domain}
Expand Down