Skip to content

Commit

Permalink
offers: make them always unsigned.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rustyrussell authored and cdecker committed Nov 9, 2022
1 parent 9a0d204 commit 3afa507
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 75 deletions.
3 changes: 1 addition & 2 deletions doc/lightning-disableoffer.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -75,4 +74,4 @@ RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:27200ba49d493cbbb1ea84736ccfaeb05a92c69dab34f48cd3d5bbf46ffc2d64)
[comment]: # ( SHA256STAMP:b471374a7c160373b328c2171953225b7fa27d26314a270e95320c1b6ef57307)
3 changes: 1 addition & 2 deletions doc/lightning-listoffers.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -81,4 +80,4 @@ RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:ac5b79c1f9b76add7eb08b9940180f2200049509df627cccc1dc892efa488778)
[comment]: # ( SHA256STAMP:985a6bae4b0a1702cd02998859c8072eee44b219c15294af4f4078465531c8c9)
3 changes: 1 addition & 2 deletions doc/lightning-offer.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,4 +134,4 @@ RESOURCES

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

[comment]: # ( SHA256STAMP:aa7544c07d3d84963e43500a367ceb62ebab8f5ae26de1dd39bb087f928dcaee)
[comment]: # ( SHA256STAMP:217af2aae777229992e2ee07c6f8040d4ca5b75ee2064590584de13162974fe2)
3 changes: 1 addition & 2 deletions doc/lightning-offerout.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,4 +99,4 @@ RESOURCES

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

[comment]: # ( SHA256STAMP:7c0f75ca64bdcce2467f42d7671caccf5f7bf6eb97fb3edef1e39f2fdb87b4d8)
[comment]: # ( SHA256STAMP:903e40a51c806613da956ce1b4021e9aac964c11d0d0c2714aeb68a12f083265)
5 changes: 0 additions & 5 deletions doc/schemas/disableoffer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used"
],
"additionalProperties": false,
Expand All @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions doc/schemas/listoffers.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used"
],
"properties": {
Expand All @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions doc/schemas/offer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used",
"created"
],
Expand All @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions doc/schemas/offerout.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"active",
"single_use",
"bolt12",
"bolt12_unsigned",
"used",
"created"
],
Expand Down Expand Up @@ -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": [
Expand Down
42 changes: 4 additions & 38 deletions lightningd/offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
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)
{
json_add_sha256(response, "offer_id", offer_id);
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);
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
11 changes: 2 additions & 9 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 3afa507

Please sign in to comment.