From 93584d0c95f6062a29e980daff6edadd13bbbc95 Mon Sep 17 00:00:00 2001 From: xueyanli Date: Fri, 5 Jan 2024 15:50:56 +0800 Subject: [PATCH] support unisat wallet --- framework/helper/ckb_auth_cli.py | 4 +++ framework/utils.py | 2 -- prepare.sh | 2 +- testcases/test_bitcoin.py | 51 +++++++++++++++++++++++++++++--- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/framework/helper/ckb_auth_cli.py b/framework/helper/ckb_auth_cli.py index 9e6a9d5..8077156 100644 --- a/framework/helper/ckb_auth_cli.py +++ b/framework/helper/ckb_auth_cli.py @@ -96,4 +96,8 @@ def verify_tron_signature(account, signature, message="00112233445566778899aabbc def verify_dogecoin_signature(address, signMessage, message): cmd = f"{ckb_auth_cli_path} dogecoin verify -a {address} -s {signMessage} -m {message}" + return run_command(cmd) + +def verify_bitcoin_signature_byUnisat(address, signMessage, message): + cmd = f"{ckb_auth_cli_path} unisat verify -a {address} -s {signMessage} -m {message}" return run_command(cmd) \ No newline at end of file diff --git a/framework/utils.py b/framework/utils.py index bc65cad..b6d4499 100644 --- a/framework/utils.py +++ b/framework/utils.py @@ -7,7 +7,6 @@ import string import random import base58 -from base64 import b64decode def get_project_root(): current_path = os.path.dirname(os.path.abspath(__file__)) @@ -78,7 +77,6 @@ def process_solana_output(output): return None - def check_container_status(container_name): cmd = f"docker ps -a | grep {container_name}" try: diff --git a/prepare.sh b/prepare.sh index 59f8051..a218e3b 100644 --- a/prepare.sh +++ b/prepare.sh @@ -7,7 +7,7 @@ cargo install ckb-capsule --git https://github.com/nervosnetwork/capsule.git --t echo "download ckb-auth" git clone https://github.com/joii2020/ckb-auth.git cd ckb-auth -git checkout dogecoin +git checkout unisat3 echo "build contract" git submodule update --init diff --git a/testcases/test_bitcoin.py b/testcases/test_bitcoin.py index 34050f6..f8a4404 100644 --- a/testcases/test_bitcoin.py +++ b/testcases/test_bitcoin.py @@ -3,6 +3,7 @@ from framework.helper.bitcoin_cli import * import pytest + # @pytest.mark.skip("debug") class TestBitcoin: @classmethod @@ -11,8 +12,8 @@ def setup_class(cls): @classmethod def teardown_class(cls): - stopBitcoind() - + stopBitcoind() + def test_signMessageAndVerify(self): address, walletName = createWalletAndAddress(self.cli, generate_random_string(5)) print(f"address: {address}, walletName: {walletName}") @@ -20,6 +21,48 @@ def test_signMessageAndVerify(self): print(f"signMessage:{signMessage}") assert signMessage is not None result = verify_bitcoin_signature(address, signMessage, message) - assert "Signature verification succeeded!" in result + assert "Signature verification succeeded!" in result - \ No newline at end of file + def test_verifyMessageByUnisat(self): + """ + verify message by unisat wallet + """ + verify_cases = [ + { + "address": "bc1ql9ju4rwv20k4ly7yxzev4und09wwexn9wspeta", + "signature": "HClKAE+iHiZMJN9WgJCSwT88JslZ0CsU2dbongWqSzVpFRfGTV7uy36gTn82PIvNmFpguAYtRFuBY87CLbNghX4=", + "message": "0011223344556677889900112233445500112233445566778899001122334455" + }, + { + "address": "tb1ql9ju4rwv20k4ly7yxzev4und09wwexn9yk62sw", + "signature": "HAcDpCzFUF9+2WE3cUeNhX0HUCRQ3xf0p61gDZ4rjvYSePxF6zYlE5hfQob+PdClohJLV5JBwuTcjyIgOb4ZK+M=", + "message": "0011223344556677889900112233445500112233445566778899001122334455" + }, + { + "address": "3HsqUZPg8BKi9q242W5fyFGGqzquPDBpWB", + "signature": "HAcDpCzFUF9+2WE3cUeNhX0HUCRQ3xf0p61gDZ4rjvYSePxF6zYlE5hfQob+PdClohJLV5JBwuTcjyIgOb4ZK+M=", + "message": "0011223344556677889900112233445500112233445566778899001122334455" + }, + { + "address": "2N9S3YJKhjdq4McebhdhYbCFY4M45DqGsW5", + "signature": "HGnj9mK62Kl9l6RwnKuDZdItqDGp2VRJL0Hlv8JfMSwaewkwM1TJgZNCeJrkWEAArVo2pzihLrY/1jsELN1gDBE=", + "message": "0011223344556677889900112233445500112233445566778899001122334455" + }, + { + "address": "n1rY3ZQi9YB5pMtdBvk79eyYEUsdv5K24b", + "signature": "Gz1enxNMu/IBUTuHj3PQsVCixzen/Im6mRW8tfrfFKn/MTOyPuXyAhSrHYKtmB34yGgqZnixCh6IfimbyT7gD7E=", + "message": "0011223344556677889900112233445500112233445566778899001122334455" + }, + { + "address": "1MLakWKjLWjq3FR1UMmjKjmDNVGvyLk6Tc", + "signature": "G0c+GB5p6a9Dnrz/U3BzWnnAHAI5Bn2tjqG+Bm35UBQHDRHukng4n90exqSda4cEVcBbIAkEEEFikb0OIIpBPtY=", + "message": "0011223344556677889900112233445500112233445566778899001122334455" + } + ] + for verify_case in verify_cases: + result = verify_bitcoin_signature_byUnisat( + verify_case["address"], + verify_case["signature"], + verify_case["message"] + ) + assert "Signature verification succeeded!" in result