Skip to content

Commit

Permalink
invoice: output payment_secret in JSON.
Browse files Browse the repository at this point in the history
This makes it easier to access (rather than decoding bolt11).

Changelog-Added: JSON-RPC: `invoice` now outputs explicit `payment_secret` it its own field.
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Jul 14, 2021
1 parent 246d230 commit 3f5d5a1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion doc/lightning-invoice.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion doc/lightning-invoice.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RETURN VALUE
On success, an object is returned, containing:
- **bolt11** (string): the bolt11 string
- **payment_hash** (hex): the hash of the *payment_preimage* which will prove payment (always 64 characters)
- **payment_secret** (hex): the *payment_secret* to place in the onion (always 64 characters)
- **expires_at** (u64): UNIX timestamp of when invoice expires

The following warnings may also be returned:
Expand Down Expand Up @@ -111,4 +112,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:e63e87b91a14b8ae823ae67fc25315bc31b15a14378c05f4c972830bf3515af1)
[comment]: # ( SHA256STAMP:cba838098a7f95ab74906f387b2d67777b33ccc40349cb9a8ef1f7c9cc28c6ef)
8 changes: 7 additions & 1 deletion doc/schemas/invoice.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [ "payment_hash", "expires_at", "bolt11" ],
"required": [ "payment_hash", "expires_at", "bolt11", "payment_secret" ],
"properties": {
"bolt11": {
"type": "string",
Expand All @@ -14,6 +14,12 @@
"maxLength": 64,
"minLength": 64
},
"payment_secret": {
"type": "hex",
"description": "the *payment_secret* to place in the onion",
"maxLength": 64,
"minLength": 64
},
"expires_at": {
"type": "u64",
"description": "UNIX timestamp of when invoice expires"
Expand Down
3 changes: 3 additions & 0 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ invoice_complete(struct invoice_info *info,
struct invoice invoice;
char *b11enc;
const struct invoice_details *details;
struct secret payment_secret;
struct wallet *wallet = info->cmd->ld->wallet;

b11enc = bolt11_encode(info, info->b11, false,
Expand Down Expand Up @@ -904,6 +905,8 @@ invoice_complete(struct invoice_info *info,
json_add_sha256(response, "payment_hash", &details->rhash);
json_add_u64(response, "expires_at", details->expiry_time);
json_add_string(response, "bolt11", details->invstring);
invoice_secret(&details->r, &payment_secret);
json_add_secret(response, "payment_secret", &payment_secret);

notify_invoice_creation(info->cmd->ld, info->b11->msat,
info->payment_preimage, info->label);
Expand Down
5 changes: 5 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ void json_add_node_id(struct json_stream *response UNNEEDED,
void json_add_preimage(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct preimage *preimage UNNEEDED)
{ fprintf(stderr, "json_add_preimage called!\n"); abort(); }
/* Generated stub for json_add_secret */
void json_add_secret(struct json_stream *response UNNEEDED,
const char *fieldname UNNEEDED,
const struct secret *secret UNNEEDED)
{ fprintf(stderr, "json_add_secret called!\n"); abort(); }
/* Generated stub for json_add_sha256 */
void json_add_sha256(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct sha256 *hash UNNEEDED)
Expand Down

0 comments on commit 3f5d5a1

Please sign in to comment.