offers: make them always unsigned.

This is in preparation for the spec update where the signature field
does not even exist.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-11-09 13:02:00 +10:30 committed by Christian Decker
parent 9a0d2040d3
commit 3afa5077fe
10 changed files with 10 additions and 75 deletions

View file

@ -41,7 +41,6 @@ On success, an object is returned, containing:
- **active** (boolean): Whether the offer can produce invoices/payments (always *false*)
- **single\_use** (boolean): Whether the offer is disabled after first successful use
- **bolt12** (string): The bolt12 string representing this offer
- **bolt12\_unsigned** (string): The bolt12 string representing this offer, without signature
- **used** (boolean): Whether the offer has had an invoice paid / payment made
- **label** (string, optional): The label provided when offer was created
@ -75,4 +74,4 @@ RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:27200ba49d493cbbb1ea84736ccfaeb05a92c69dab34f48cd3d5bbf46ffc2d64)
[comment]: # ( SHA256STAMP:b471374a7c160373b328c2171953225b7fa27d26314a270e95320c1b6ef57307)

View file

@ -36,7 +36,6 @@ On success, an object containing **offers** is returned. It is an array of obje
- **active** (boolean): whether this can still be used
- **single\_use** (boolean): whether this expires as soon as it's paid
- **bolt12** (string): the bolt12 encoding of the offer
- **bolt12\_unsigned** (string): the bolt12 encoding of the offer, without signature
- **used** (boolean): True if an associated invoice has been paid
- **label** (string, optional): the (optional) user-specified label
@ -81,4 +80,4 @@ RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:ac5b79c1f9b76add7eb08b9940180f2200049509df627cccc1dc892efa488778)
[comment]: # ( SHA256STAMP:985a6bae4b0a1702cd02998859c8072eee44b219c15294af4f4078465531c8c9)

View file

@ -101,7 +101,6 @@ On success, an object is returned, containing:
- **active** (boolean): whether this can still be used (always *true*)
- **single\_use** (boolean): whether this expires as soon as it's paid (reflects the *single_use* parameter)
- **bolt12** (string): the bolt12 encoding of the offer
- **bolt12\_unsigned** (string): the bolt12 encoding of the offer, without a signature
- **used** (boolean): True if an associated invoice has been paid
- **created** (boolean): false if the offer already existed
- **label** (string, optional): the (optional) user-specified label
@ -135,4 +134,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:aa7544c07d3d84963e43500a367ceb62ebab8f5ae26de1dd39bb087f928dcaee)
[comment]: # ( SHA256STAMP:217af2aae777229992e2ee07c6f8040d4ca5b75ee2064590584de13162974fe2)

View file

@ -60,7 +60,6 @@ On success, an object is returned, containing:
- **active** (boolean): whether this will pay a matching incoming invoice (always *true*)
- **single\_use** (boolean): whether this expires as soon as it's paid out (always *true*)
- **bolt12** (string): the bolt12 encoding of the offer
- **bolt12\_unsigned** (string): the bolt12 encoding of the offer, without a signature
- **used** (boolean): True if an incoming invoice has been paid (always *false*)
- **created** (boolean): false if the offer already existed
- **label** (string, optional): the (optional) user-specified label
@ -100,4 +99,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:7c0f75ca64bdcce2467f42d7671caccf5f7bf6eb97fb3edef1e39f2fdb87b4d8)
[comment]: # ( SHA256STAMP:903e40a51c806613da956ce1b4021e9aac964c11d0d0c2714aeb68a12f083265)

View file

@ -6,7 +6,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used"
],
"additionalProperties": false,
@ -32,10 +31,6 @@
"type": "string",
"description": "The bolt12 string representing this offer"
},
"bolt12_unsigned": {
"type": "string",
"description": "The bolt12 string representing this offer, without signature"
},
"used": {
"type": "boolean",
"description": "Whether the offer has had an invoice paid / payment made"

View file

@ -16,7 +16,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used"
],
"properties": {
@ -38,10 +37,6 @@
"type": "string",
"description": "the bolt12 encoding of the offer"
},
"bolt12_unsigned": {
"type": "string",
"description": "the bolt12 encoding of the offer, without signature"
},
"used": {
"type": "boolean",
"description": "True if an associated invoice has been paid"

View file

@ -7,7 +7,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used",
"created"
],
@ -33,10 +32,6 @@
"type": "string",
"description": "the bolt12 encoding of the offer"
},
"bolt12_unsigned": {
"type": "string",
"description": "the bolt12 encoding of the offer, without a signature"
},
"used": {
"type": "boolean",
"description": "True if an associated invoice has been paid"

View file

@ -7,7 +7,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used",
"created"
],
@ -36,10 +35,6 @@
"type": "string",
"description": "the bolt12 encoding of the offer"
},
"bolt12_unsigned": {
"type": "string",
"description": "the bolt12 encoding of the offer, without a signature"
},
"used": {
"type": "boolean",
"enum": [

View file

@ -19,7 +19,6 @@
static void json_populate_offer(struct json_stream *response,
const struct sha256 *offer_id,
const char *b12,
const char *b12_nosig,
const struct json_escape *label,
enum offer_status status)
{
@ -27,8 +26,6 @@ static void json_populate_offer(struct json_stream *response,
json_add_bool(response, "active", offer_status_active(status));
json_add_bool(response, "single_use", offer_status_single(status));
json_add_string(response, "bolt12", b12);
if (b12_nosig)
json_add_string(response, "bolt12_unsigned", b12_nosig);
json_add_bool(response, "used", offer_status_used(status));
if (label)
json_add_escaped_string(response, "label", label);
@ -90,10 +87,9 @@ static struct command_result *json_createoffer(struct command *cmd,
struct json_escape *label;
struct tlv_offer *offer;
struct sha256 merkle;
const char *b12str, *b12str_nosig;
const char *b12str;
bool *single_use;
enum offer_status status;
struct pubkey key;
bool created;
if (!param(cmd, buffer, params,
@ -108,11 +104,7 @@ static struct command_result *json_createoffer(struct command *cmd,
else
status = OFFER_MULTIPLE_USE_UNUSED;
merkle_tlv(offer->fields, &merkle);
offer->signature = tal(offer, struct bip340sig);
if (!pubkey_from_node_id(&key, &cmd->ld->id))
fatal("invalid own node_id?");
hsm_sign_b12(cmd->ld, "offer", "signature", &merkle, NULL, &key,
offer->signature);
offer->signature = NULL;
b12str = offer_encode(cmd, offer);
/* If it already exists, we use that one instead (and then
@ -131,10 +123,9 @@ static struct command_result *json_createoffer(struct command *cmd,
created = true;
offer->signature = tal_free(offer->signature);
b12str_nosig = offer_encode(cmd, offer);
response = json_stream_success(cmd);
json_populate_offer(response, &merkle, b12str, b12str_nosig, label, status);
json_populate_offer(response, &merkle, b12str, label, status);
json_add_bool(response, "created", created);
return command_success(cmd, response);
}
@ -147,25 +138,6 @@ static const struct json_command createoffer_command = {
};
AUTODATA(json_command, &createoffer_command);
/* We store strings in the db, so removing signatures is easiest by conversion */
static const char *offer_str_nosig(const tal_t *ctx,
struct lightningd *ld,
const char *b12str)
{
char *fail;
struct tlv_offer *offer = offer_decode(tmpctx, b12str, strlen(b12str),
ld->our_features, chainparams,
&fail);
if (!offer) {
log_broken(ld->log, "Cannot reparse offerstr from db %s: %s",
b12str, fail);
return NULL;
}
offer->signature = tal_free(offer->signature);
return offer_encode(ctx, offer);
}
static struct command_result *json_listoffers(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
@ -194,7 +166,6 @@ static struct command_result *json_listoffers(struct command *cmd,
json_object_start(response, NULL);
json_populate_offer(response,
offer_id, b12,
offer_str_nosig(tmpctx, cmd->ld, b12),
label, status);
json_object_end(response);
}
@ -211,8 +182,6 @@ static struct command_result *json_listoffers(struct command *cmd,
json_object_start(response, NULL);
json_populate_offer(response,
&id, b12,
offer_str_nosig(tmpctx,
cmd->ld, b12),
label, status);
json_object_end(response);
}
@ -258,10 +227,7 @@ static struct command_result *json_disableoffer(struct command *cmd,
status = wallet_offer_disable(wallet, offer_id, status);
response = json_stream_success(cmd);
json_populate_offer(response, offer_id, b12,
offer_str_nosig(tmpctx,
cmd->ld, b12),
label, status);
json_populate_offer(response, offer_id, b12, label, status);
return command_success(cmd, response);
}

View file

@ -4405,7 +4405,6 @@ def test_offer(node_factory, bitcoind):
offer = only_one(l1.rpc.call('listoffers', [ret['offer_id']])['offers'])
assert offer['bolt12'] == ret['bolt12']
assert offer['bolt12_unsigned'] == ret['bolt12_unsigned']
assert offer['offer_id'] == ret['offer_id']
output = subprocess.check_output([bolt12tool, 'decode',
@ -4414,12 +4413,6 @@ def test_offer(node_factory, bitcoind):
assert 'amount' not in output
else:
assert 'amount' in output
output = subprocess.check_output([bolt12tool, 'decode',
offer['bolt12_unsigned']]).decode('ASCII')
if amount == 'any':
assert 'amount' not in output
else:
assert 'amount' in output
# Try wrong amount precision:
with pytest.raises(RpcError, match='Currency AUD requires 2 minor units'):
@ -4608,7 +4601,7 @@ def test_fetchinvoice(node_factory, bitcoind):
assert offer1['created'] is True
inv1 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})
inv2 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12_unsigned'],
inv2 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'],
'payer_note': 'Thanks for the fish!'})
assert inv1 != inv2
assert 'next_period' not in inv1
@ -4908,7 +4901,7 @@ def test_sendinvoice(node_factory, bitcoind):
assert only_one(l1.rpc.call('listoffers', [offer['offer_id']])['offers'])['used'] is False
# sendinvoice should work.
out = l2.rpc.call('sendinvoice', {'offer': offer['bolt12_unsigned'],
out = l2.rpc.call('sendinvoice', {'offer': offer['bolt12'],
'label': 'test sendinvoice 1'})
assert out['label'] == 'test sendinvoice 1'
assert out['description'] == 'simple test'