-
Notifications
You must be signed in to change notification settings - Fork 194
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
Feature/keysend #699
Feature/keysend #699
Conversation
Implement keysend for lndhub-based accounts.
Initial work on keysend for lnd connector
Keysend working with LND.
WebLN keysend PoC working
Save payments and allowances. Allow automated payments.
Use an object as the webln argument
dest: dest_pubkey_base64, | ||
amt: args.amount, | ||
payment_hash: hash, | ||
dest_custom_records: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we allow passing in of this custom records? that developers can decide what records to set?
e.g. I think the podcasting uses a special one: https://github.com/lightning/blips/blob/master/blip-0010.md
I'll implement Keysend in Citadel 0.0.2 too, so the Citadel connector can be updated. |
src/app/screens/Keysend.tsx
Outdated
|
||
setSuccessAction({ | ||
tag: "message", | ||
message: `Keysend paid! Preimage: ${payment.preimage}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just Payment sent!
? people don't need to know it's a keysend.
@@ -88,6 +92,7 @@ export default interface Connector { | |||
getBalance(): Promise<GetBalanceResponse>; | |||
makeInvoice(args: MakeInvoiceArgs): Promise<MakeInvoiceResponse>; | |||
sendPayment(args: SendPaymentArgs): Promise<SendPaymentResponse>; | |||
sendPaymentKeySend(args: SendPaymentArgs): Promise<SendPaymentResponse>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this keysend
? why add sendPayment
?
@@ -92,6 +92,11 @@ class Eclair implements Connector { | |||
}; | |||
} | |||
|
|||
async sendPaymentKeySend( | |||
args: SendPaymentArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those should be KeysendArgs
- it's different to what sendpayment accepts
@@ -81,7 +83,58 @@ class Lnd implements Connector { | |||
}; | |||
}); | |||
} | |||
async sendPaymentKeySend( | |||
args: SendPaymentArgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those should be KeysendArgs - it's different to what sendpayment accepts
@@ -43,6 +43,10 @@ export type SendPaymentResponse = | |||
|
|||
export interface SendPaymentArgs { | |||
paymentRequest: string; | |||
offer: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SendPaymentArgs are very different to what is passed to keysend. We should create a new interface for that.
@@ -1,5 +1,7 @@ | |||
import Base64 from "crypto-js/enc-base64"; | |||
import UTF8 from "crypto-js/enc-utf8"; | |||
import CryptoJS from "crypto-js"; | |||
import _ from "lodash"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we load only the module we need.
import random from "lodash/random";
for (let i = 0; i < 32; i++) { | ||
const randomNumber = _.random(0, 255); | ||
byteArray[i] = randomNumber; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should move this into a utils function: utils.randomHex(32)
or something.
@dylancom do you know a nicer way on how to get a random hex string?
This currently won't work, need to serialize the custom record map to json somehow.
I've fixed @bumi 's comments. However the code currently does not work, I'm not sure on how to pass in a map all the way to the network call. I used a TypeScript Also, would we only allow this to be called by webln, or would we also allow people just pasting in a pubkey? Would we allow custom records in the latter case? Or just a comment ( |
I would suggest using an object of shape: Record<string, string>. |
I think this can be done later. I'd release it without the comment option and add the comment option later. |
Keysend can now only be triggered from webLN.
|
} | ||
|
||
if (await checkAllowance(message.origin.host, parseInt(amount))) { | ||
return sendPaymentWithAllowance(message, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of magic boolean flags. When I read this code here it is unclear what this true
means.
looking into sendPaymentWithAllowance
this function basically now does two things based on the boolean flag.
I would split this up and use here a new keySendWithAllowance
method. it is more descriptive and we don't need to add some if
in those methods sendPayment methods
} | ||
|
||
if (await checkAllowance(message.origin.host, parseInt(amount))) { | ||
return sendPaymentWithAllowance(message, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of magic boolean flags. When I read this code here it is unclear what this true
means.
looking into sendPaymentWithAllowance
this function basically now does two things based on the boolean flag.
I would split this up and use here a new keySendWithAllowance
method. it is more descriptive and we don't need to add some if
in those methods sendPayment methods
This tries to follow the exact same structure as the webln.sendPayment call. With that it also introduces a new "confirmKeysend" screen that is used in the prompt to confirm the keysend payment. This is only to confirm webln payments and thus for example the amount can also not be changed. When doing manual keysend payments we should use a new screen that allows the user to set the amount and potentially also other fields as a comment/message.
this allows users to do keysend payments from the send screen
repy before showing the success message. this typically closes the prompt but just in case the component is used somewhere else we still show the success message
Some keysend suggestions
I've added some commits that handle the encoding of the custom records. The custom record values passed in through webln should now be plain strings (these strings can be serialized json). Depending on the connector used, they are either encoded as base64 (LND connector) or as hex (LNDhub connector). |
* master: refactor: revert makeinvoice changes refactor: revert makeinvoice changes refactor: get rid of union type refactor: add error response type Revert "refactor: throw instead of succeeding with an error" refactor: throw instead of succeeding with an error
import only needed lib
Link this PR to an issue
Fixes #671
Type of change
Describe the changes you have made in this PR -
webln.keysend
call.sendPaymentArgs
to allow for keysend and offer payments (later).LND
andLNDhub
connectors.Screenshots of the changes (If any) -
-> Be aware that the pubkey might not be associated with the website. It could be another user of the website, or a pubkey associated with a podcast feed.
How Has This Been Tested?
I don't have any tests and also the code could use some refactoring since I have copy-pasted quite a bit. I think it would be more opportune if someone else picks this up.
Checklist: