-
Notifications
You must be signed in to change notification settings - Fork 26
Adding support for compact offers #840
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,6 +236,9 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v | |
| /** This function verifies that the offer provided was generated by us. */ | ||
| private fun isOurOffer(offer: OfferTypes.Offer, pathId: ByteVector?, blindedPrivateKey: PrivateKey): Boolean = when { | ||
| pathId != null && pathId.size() != 32 -> false | ||
| // Compact offers are randomly generated, but they don't store the nonce in the path_id to save space. | ||
| // It is instead the wallet's responsibility to store the corresponding blinded public key(s). | ||
| pathId == null && nodeParams.compactOfferKeys.value.contains(blindedPrivateKey.publicKey()) -> true | ||
|
Comment on lines
+239
to
+241
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "compact offers" are not real offers in the sense that we won't accept invoice requests for them, so they don't need to be handled here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually they are real offers, we do want to accept payments for them (for example when merchant does a refund or cashback). It's also handy to use that card simply to provide our offer that anyone can pay, so I think it's worth handling them here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, then we should at least check that it has only a blinded route and no other field (no description that we would commit to).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By tapping the card, we give permission to the other party to collect a (small) payment. It seems weird and unsafe to reuse this interaction to also mean "pay me". |
||
| else -> { | ||
| val expected = deterministicOffer(nodeParams.chainHash, nodeParams.nodePrivateKey, walletParams.trampolineNode.id, offer.amount, offer.description, pathId?.let { ByteVector32(it) }) | ||
| expected == OfferTypes.OfferAndKey(offer, blindedPrivateKey) | ||
|
|
@@ -272,5 +275,22 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v | |
| val sessionKey = PrivateKey(Crypto.sha256(tweak + trampolineNodeId.value + nodePrivateKey.value).byteVector32()) | ||
| return OfferTypes.Offer.createBlindedOffer(chainHash, nodePrivateKey, trampolineNodeId, amount, description, Features.empty, sessionKey, pathId) | ||
| } | ||
|
|
||
| fun deterministicCompactOffer( | ||
| chainHash: BlockHash, | ||
| nodePrivateKey: PrivateKey, | ||
| trampolineNodeId: PublicKey, | ||
| nonce: ByteVector32 | ||
| ): OfferTypes.OfferAndKey { | ||
| // We generate a deterministic session key based on: | ||
| // - a custom tag indicating that this is used in the Bolt 12 context | ||
| // - the compact offer parameters (nonce) | ||
| // - our trampoline node, which is used as an introduction node for the offer's blinded path | ||
| // - our private key, which ensures that nobody else can generate the same path key secret | ||
| val tweak = "bolt 12 compact offer".encodeToByteArray().byteVector() + | ||
| Crypto.sha256("offer nonce".encodeToByteArray().byteVector() + nonce) | ||
| val sessionKey = PrivateKey(Crypto.sha256(tweak + trampolineNodeId.value + nodePrivateKey.value).byteVector32()) | ||
| return OfferTypes.Offer.createBlindedOffer(chainHash, nodePrivateKey, trampolineNodeId, null, null, Features.empty, sessionKey, null, allowCompactFormat = 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.
The compact format should still be disallowed for payments and for standard offers. We should enable it explicitly only when we need it.