| 2597 | |
| 2598 | |
| 2599 | def test_signmessagewithkey(node_factory, chainparams): |
| 2600 | l1, l2 = node_factory.get_nodes(2) |
| 2601 | message = "a test message" |
| 2602 | addr_bech32 = l1.rpc.newaddr("bech32")["bech32"] |
| 2603 | addr_other = l2.rpc.newaddr("bech32")["bech32"] |
| 2604 | if TEST_NETWORK != "liquid-regtest": |
| 2605 | # refuse to sign if the address is not a P2WPKH |
| 2606 | addr_p2tr = l1.rpc.newaddr("p2tr")["p2tr"] |
| 2607 | with pytest.raises( |
| 2608 | RpcError, match=r"Address is not p2wpkh and it is not supported" |
| 2609 | ): |
| 2610 | l1.rpc.signmessagewithkey(message, addr_p2tr) |
| 2611 | |
| 2612 | # refuse to sign if the address does not belong to us |
| 2613 | with pytest.raises( |
| 2614 | RpcError, match=r"Address is not found in the wallet\'s database" |
| 2615 | ): |
| 2616 | l1.rpc.signmessagewithkey(message, addr_other) |
| 2617 | response = l1.rpc.signmessagewithkey(message, addr_bech32) |
| 2618 | assert response["address"] == addr_bech32 |
| 2619 | signature = base64.b64decode(response["base64"]) |
| 2620 | assert signature.hex() == response["signature"] |
| 2621 | assert ( |
| 2622 | subprocess.check_output( |
| 2623 | [ |
| 2624 | "devtools/bip137-verifysignature", |
| 2625 | message, |
| 2626 | response["signature"], |
| 2627 | response["address"], |
| 2628 | chainparams["name"], |
| 2629 | ] |
| 2630 | ).decode("utf-8") |
| 2631 | == "Signature is valid!\n" |
| 2632 | ) |
| 2633 | |
| 2634 | |
| 2635 | def test_include(node_factory): |