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

Feature/keysend #699

Merged
merged 33 commits into from
Mar 22, 2022
Merged

Feature/keysend #699

merged 33 commits into from
Mar 22, 2022

Conversation

kiwiidb
Copy link
Contributor

@kiwiidb kiwiidb commented Mar 16, 2022

Link this PR to an issue

Fixes #671

Type of change

  • New feature (non-breaking change which adds functionality)

Describe the changes you have made in this PR -

  • Added a new keysend screen that is mostly copied over from the LNurlPay screen. This screen is triggered either by pasting in a pubkey in the send box (by checking for length and starting characters), or by a webln.keysend call.
  • Added more fields to the sendPaymentArgs to allow for keysend and offer payments (later).
  • Implements the keysend method for the LND and LNDhub connectors.
  • Adds a webLN keysend function.

Screenshots of the changes (If any) -

Schermafbeelding 2022-03-16 om 08 55 52

-> 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?

  • webLN tested on https://amboss.space - check out the keysend billboard. Tested with lndhub.go backend.
  • by pasting in random pubkeys and doing payments. Get a pubkey from lnd-2 on rtl.regtest.getalby.com - connect to alby-simnet-lnd-1 in the extension - make payment. Check status on RTL.

Schermafbeelding 2022-03-16 om 09 05 57

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:

  • My code follows the style guidelines of this project and performed a self-review of my own code
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (If Any)

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
@kiwiidb kiwiidb requested review from bumi and dylancom March 16, 2022 08:10
@github-actions
Copy link

Build files:

dest: dest_pubkey_base64,
amt: args.amount,
payment_hash: hash,
dest_custom_records: {
Copy link
Collaborator

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

@AaronDewes
Copy link
Contributor

I'll implement Keysend in Citadel 0.0.2 too, so the Citadel connector can be updated.


setSuccessAction({
tag: "message",
message: `Keysend paid! Preimage: ${payment.preimage}`,
Copy link
Collaborator

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>;
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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;
Copy link
Collaborator

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.

src/extension/background-script/connectors/lnd.ts Outdated Show resolved Hide resolved
@@ -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";
Copy link
Collaborator

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;
}
Copy link
Collaborator

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.
@kiwiidb
Copy link
Contributor Author

kiwiidb commented Mar 17, 2022

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 Map, but this won't serialize into json. How to best do this?

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 (TLV_WHATSAT_MESSAGE)?

@dylancom
Copy link
Contributor

dylancom commented Mar 17, 2022

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 Map, but this won't serialize into json. How to best do this?

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 (TLV_WHATSAT_MESSAGE)?

I would suggest using an object of shape: Record<string, string>.

@bumi
Copy link
Collaborator

bumi commented Mar 17, 2022

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 (TLV_WHATSAT_MESSAGE)?

I think this can be done later. I'd release it without the comment option and add the comment option later.
Imo it's better to release small things fast and thus also reduce complexity

Keysend can now only be triggered from webLN.
@kiwiidb
Copy link
Contributor Author

kiwiidb commented Mar 18, 2022

  • Left out the option of a manual comment.
  • Keysend can now only be triggered from webLN:
await webln.keysend({destination: "025c1d5d1b4c983cc6350fc2d756fbb59b4dc365e45e87f8e3afe07e24013e8220", amount: "100", customRecords: {"test123":"test"}})

@kiwiidb kiwiidb requested a review from bumi March 18, 2022 10:47
}

if (await checkAllowance(message.origin.host, parseInt(amount))) {
return sendPaymentWithAllowance(message, true);
Copy link
Collaborator

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);
Copy link
Collaborator

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
bumi and others added 4 commits March 19, 2022 10:57
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
@kiwiidb kiwiidb requested a review from bumi March 19, 2022 14:14
@kiwiidb
Copy link
Contributor Author

kiwiidb commented Mar 21, 2022

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).

@dylancom dylancom merged commit 2524351 into master Mar 22, 2022
@dylancom dylancom deleted the feature/keysend branch March 22, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keysend
5 participants