diff --git a/common/jsonrpc_errors.h b/common/jsonrpc_errors.h index 47a56e69e8a8..10127f6e217c 100644 --- a/common/jsonrpc_errors.h +++ b/common/jsonrpc_errors.h @@ -99,6 +99,9 @@ static const errcode_t DATASTORE_UPDATE_WRONG_GENERATION = 1204; static const errcode_t DATASTORE_UPDATE_HAS_CHILDREN = 1205; static const errcode_t DATASTORE_UPDATE_NO_CHILDREN = 1206; +/* Errors from signmessage command */ +static const errcode_t SIGNMESSAGE_PUBKEY_NOT_FOUND = 1301; + /* Errors from wait* commands */ static const errcode_t WAIT_TIMEOUT = 2000; diff --git a/doc/lightning-checkmessage.7.md b/doc/lightning-checkmessage.7.md index 9ccf3c13e23a..6bbc48341f56 100644 --- a/doc/lightning-checkmessage.7.md +++ b/doc/lightning-checkmessage.7.md @@ -20,6 +20,10 @@ known node key (as per *listnodes*), and verification succeeds if it matches for any one of them. Note: this is implemented far more efficiently than trying each one, so performance is not a concern. +On failure, an error is returned and core lightning exit with the following error code: +- -32602: Parameter missed or malformed; +- 1301: *pubkey* not found in the graph. + RETURN VALUE ------------ diff --git a/lightningd/signmessage.c b/lightningd/signmessage.c index 44dfe52bfae7..199dd04fa67e 100644 --- a/lightningd/signmessage.c +++ b/lightningd/signmessage.c @@ -1,5 +1,6 @@ #include "config.h" #include +#include #include #include #include @@ -137,6 +138,12 @@ static void listnodes_done(const char *buffer, if (t) t = json_get_member(buffer, t, "nodes"); + if (!deprecated_apis && (!t || t->size == 0)) { + was_pending(command_fail(can->cmd, SIGNMESSAGE_PUBKEY_NOT_FOUND, + "pub key not found in the graph, expected pubkey is %s", + node_id_to_hexstr(tmpctx, &can->id))); + return; + } response = json_stream_success(can->cmd); json_add_node_id(response, "pubkey", &can->id); json_add_bool(response, "verified", t && t->size == 1); @@ -235,4 +242,3 @@ static const struct json_command json_checkmessage_cmd = { "Verify a digital signature {zbase} of {message} signed with {pubkey}", }; AUTODATA(json_command, &json_checkmessage_cmd); - diff --git a/tests/test_misc.py b/tests/test_misc.py index 84d2836efb8f..2be5f76d94da 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2606,3 +2606,18 @@ def test_datastore_keylist(node_factory): 'string': 'ab2val2', 'generation': 1, 'hex': b'ab2val2'.hex()}]} + + +def test_checkmessage_pubkey_not_found(node_factory): + l1 = node_factory.get_node() + + msg = "testcase to check new rpc error" + pubkey = "03be3b0e9992153b1d5a6e1623670b6c3663f72ce6cf2e0dd39c0a373a7de5a3b7" + zbase = "d66bqz3qsku5fxtqsi37j11pci47ydxa95iusphutggz9ezaxt56neh77kxe5hyr41kwgkncgiu94p9ecxiexgpgsz8daoq4tw8kj8yx" + + with pytest.raises(RpcError): + l1.rpc.checkmessage(msg, zbase) + + check_result = l1.rpc.checkmessage(msg, zbase, pubkey=pubkey) + assert check_result["pubkey"] == pubkey + assert check_result["verified"] == True