Browse Source

pylightning: wrap signmessage/checkmessage.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
ab48ecf07c
  1. 21
      contrib/pylightning/lightning/lightning.py
  2. 12
      tests/test_misc.py

21
contrib/pylightning/lightning/lightning.py

@ -991,3 +991,24 @@ class LightningRpc(UnixDomainSocketRpc):
"txid": txid
}
return self.call("txsend", payload)
def signmessage(self, message):
"""
Sign a message with this node's secret key.
"""
payload = {
"message": message
}
return self.call("signmessage", payload)
def checkmessage(self, message, zbase, pubkey=None):
"""
Check if a message was signed (with a specific key).
Use returned field ['verified'] to get result.
"""
payload = {
"message": message,
"zbase": zbase,
"pubkey": pubkey,
}
return self.call("checkmessage", payload)

12
tests/test_misc.py

@ -1653,7 +1653,7 @@ def test_signmessage(node_factory):
corpus = [[None,
"this is a test!",
l1.rpc.call('signmessage', ["this is a test!"])['zbase'],
l1.rpc.signmessage("this is a test!")['zbase'],
l1.info['id']]]
# Other contributions from LND users!
@ -1683,9 +1683,9 @@ def test_signmessage(node_factory):
subprocess.run(['devtools/lightning-checkmessage',
c[1] + "modified", c[2], c[3]], check=True)
assert l1.rpc.call('checkmessage', [c[1], c[2], c[3]])['verified']
assert not l1.rpc.call('checkmessage', [c[1] + "modified", c[2], c[3]])['verified']
checknokey = l1.rpc.call('checkmessage', [c[1], c[2]])
assert l1.rpc.checkmessage(c[1], c[2], c[3])['verified']
assert not l1.rpc.checkmessage(c[1] + "modified", c[2], c[3])['verified']
checknokey = l1.rpc.checkmessage(c[1], c[2])
# Of course, we know our own pubkey
if c[3] == l1.info['id']:
assert checknokey['verified']
@ -1694,7 +1694,7 @@ def test_signmessage(node_factory):
assert checknokey['pubkey'] == c[3]
# l2 knows about l1, so it can validate it.
zm = l1.rpc.call('signmessage', ["message for you"])['zbase']
checknokey = l2.rpc.call('checkmessage', ["message for you", zm])
zm = l1.rpc.signmessage(message="message for you")['zbase']
checknokey = l2.rpc.checkmessage(message="message for you", zbase=zm)
assert checknokey['pubkey'] == l1.info['id']
assert checknokey['verified']

Loading…
Cancel
Save