From 3f5d5a1de510377601ee26173ee7732185060c52 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 12 Jul 2021 08:34:33 +0930 Subject: [PATCH] invoice: output payment_secret in JSON. 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 --- doc/lightning-invoice.7 | 4 +++- doc/lightning-invoice.7.md | 3 ++- doc/schemas/invoice.schema.json | 8 +++++++- lightningd/invoice.c | 3 +++ lightningd/test/run-invoice-select-inchan.c | 5 +++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/lightning-invoice.7 b/doc/lightning-invoice.7 index 703771736..891ff658b 100644 --- a/doc/lightning-invoice.7 +++ b/doc/lightning-invoice.7 @@ -85,6 +85,8 @@ On success, an object is returned, containing: .IP \[bu] \fBpayment_hash\fR (hex): the hash of the \fIpayment_preimage\fR which will prove payment (always 64 characters) .IP \[bu] +\fBpayment_secret\fR (hex): the \fIpayment_secret\fR to place in the onion (always 64 characters) +.IP \[bu] \fBexpires_at\fR (u64): UNIX timestamp of when invoice expires .RE @@ -136,4 +138,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:f27f015d8d612d280a8abca6930dbd42ef37fdac00bff1b114d1fd9138b15097 +\" SHA256STAMP:1617a52d2c9c5adbee4b410d15889a5f1c32e0a2fb2982dac82c5e74fb028ff3 diff --git a/doc/lightning-invoice.7.md b/doc/lightning-invoice.7.md index 6ffab01ac..3bd8502a1 100644 --- a/doc/lightning-invoice.7.md +++ b/doc/lightning-invoice.7.md @@ -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: @@ -111,4 +112,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:e63e87b91a14b8ae823ae67fc25315bc31b15a14378c05f4c972830bf3515af1) +[comment]: # ( SHA256STAMP:cba838098a7f95ab74906f387b2d67777b33ccc40349cb9a8ef1f7c9cc28c6ef) diff --git a/doc/schemas/invoice.schema.json b/doc/schemas/invoice.schema.json index b4f628495..4e7976555 100644 --- a/doc/schemas/invoice.schema.json +++ b/doc/schemas/invoice.schema.json @@ -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", @@ -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" diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 67d335154..b4434fe89 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -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, @@ -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); diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 1fd3a3dfa..e5ccd4c75 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -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)