From 0b9e3fc8ef387fc50601872a6cf3fb914d4b45c6 Mon Sep 17 00:00:00 2001 From: crosschainer Date: Sun, 31 Mar 2024 17:38:03 +0000 Subject: [PATCH 1/5] ValidatorUpdate is not json serializable --- src/xian/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xian/utils.py b/src/xian/utils.py index 8e8b85bf..3e6187d1 100644 --- a/src/xian/utils.py +++ b/src/xian/utils.py @@ -229,7 +229,7 @@ def tx_hash_from_tx(tx): def hash_from_validator_updates(validator_updates): h = hashlib.sha3_256() - encoded_validator_updates = encode(validator_updates).encode() + encoded_validator_updates = str(validator_updates).encode() h.update(encoded_validator_updates) return h.hexdigest() From 4f1210a6f4313042fb0ceaf7902e389b418109a4 Mon Sep 17 00:00:00 2001 From: crosschainer Date: Sun, 31 Mar 2024 17:40:28 +0000 Subject: [PATCH 2/5] sorted --- src/xian/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xian/utils.py b/src/xian/utils.py index 3e6187d1..5ff1b435 100644 --- a/src/xian/utils.py +++ b/src/xian/utils.py @@ -229,6 +229,8 @@ def tx_hash_from_tx(tx): def hash_from_validator_updates(validator_updates): h = hashlib.sha3_256() + # Sort the list of validator updates to ensure that the hash is consistent + validator_updates = sorted(validator_updates) encoded_validator_updates = str(validator_updates).encode() h.update(encoded_validator_updates) return h.hexdigest() From 0393c18dada06993e7bdeed2bb09d3dd90de1eaa Mon Sep 17 00:00:00 2001 From: crosschainer Date: Sun, 31 Mar 2024 18:46:37 +0000 Subject: [PATCH 3/5] It was very wrong --- src/xian/tools/validator_file_gen.py | 39 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/xian/tools/validator_file_gen.py b/src/xian/tools/validator_file_gen.py index a60b13e8..caea94a8 100644 --- a/src/xian/tools/validator_file_gen.py +++ b/src/xian/tools/validator_file_gen.py @@ -1,6 +1,6 @@ from argparse import ArgumentParser -from nacl.public import PrivateKey -from base64 import b64encode +from nacl.signing import SigningKey +from nacl.encoding import HexEncoder, Base64Encoder import json import hashlib @@ -15,30 +15,37 @@ def __init__(self): self.args = self.parser.parse_args() def generate_keys(self): - validator_sk_hex = bytes.fromhex(self.args.validator_privkey) - validator_sk = PrivateKey(validator_sk_hex) + pk_hex = self.args.validator_privkey - validator_pub_key = validator_sk.public_key + # Convert hex private key to bytes and generate signing key object + signing_key = SigningKey(pk_hex, encoder=HexEncoder) - validator_pub_key_b64 = b64encode(validator_pub_key._public_key).decode('utf-8') - validator_sk_b64 = b64encode(validator_sk._private_key + validator_pub_key._public_key).decode('utf-8') + # Encode private key in Base64 for the output + private_key_hex = signing_key.encode(encoder=HexEncoder).decode('utf-8') - validator_pub_key_hash = hashlib.sha256(validator_pub_key._public_key).digest()[:20] - validator_address = validator_pub_key_hash.hex().upper() + # Obtain the verify key (public key) from the signing key + verify_key = signing_key.verify_key + # Encode public key in Base64 for the output + public_key_b64 = verify_key.encode(encoder=Base64Encoder).decode('utf-8') - return { - 'address': validator_address, - 'pub_key': { - 'type': 'tendermint/PubKeyEd25519', - 'value': validator_pub_key_b64 + # Hash the public key using SHA-256 and take the first 20 bytes for the address + address_bytes = hashlib.sha256(verify_key.encode()).digest()[:20] + address = address_bytes.hex().upper() + + output = { + "address": address, + "pub_key": { + "type": "tendermint/PubKeyEd25519", + "value": public_key_b64 }, 'priv_key': { 'type': 'tendermint/PrivKeyEd25519', - 'value': validator_sk_b64 + 'value': private_key_hex } } - + return output + def main(self): if len(self.args.validator_privkey) != 64: From 410dd2500d53cf6150b33c4c76599a63ad67510d Mon Sep 17 00:00:00 2001 From: crosschainer Date: Sun, 31 Mar 2024 18:47:36 +0000 Subject: [PATCH 4/5] woops --- src/xian/tools/validator_file_gen.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/xian/tools/validator_file_gen.py b/src/xian/tools/validator_file_gen.py index caea94a8..d3b1b1e7 100644 --- a/src/xian/tools/validator_file_gen.py +++ b/src/xian/tools/validator_file_gen.py @@ -20,8 +20,7 @@ def generate_keys(self): # Convert hex private key to bytes and generate signing key object signing_key = SigningKey(pk_hex, encoder=HexEncoder) - # Encode private key in Base64 for the output - private_key_hex = signing_key.encode(encoder=HexEncoder).decode('utf-8') + private_key_b64 = signing_key.encode(encoder=Base64Encoder).decode('utf-8') # Obtain the verify key (public key) from the signing key verify_key = signing_key.verify_key @@ -41,11 +40,11 @@ def generate_keys(self): }, 'priv_key': { 'type': 'tendermint/PrivKeyEd25519', - 'value': private_key_hex + 'value': private_key_b64 } } return output - + def main(self): if len(self.args.validator_privkey) != 64: From a0edf76b3b9508c6ddb926e77b18af825ec60309 Mon Sep 17 00:00:00 2001 From: crosschainer Date: Sun, 31 Mar 2024 18:52:35 +0000 Subject: [PATCH 5/5] concat bytes --- src/xian/tools/validator_file_gen.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/xian/tools/validator_file_gen.py b/src/xian/tools/validator_file_gen.py index d3b1b1e7..702bdb20 100644 --- a/src/xian/tools/validator_file_gen.py +++ b/src/xian/tools/validator_file_gen.py @@ -17,14 +17,19 @@ def __init__(self): def generate_keys(self): pk_hex = self.args.validator_privkey + # Convert hex private key to bytes and generate signing key object signing_key = SigningKey(pk_hex, encoder=HexEncoder) - private_key_b64 = signing_key.encode(encoder=Base64Encoder).decode('utf-8') - # Obtain the verify key (public key) from the signing key verify_key = signing_key.verify_key + # Concatenate private and public key bytes + priv_key_with_pub = signing_key.encode() + verify_key.encode() + + # Encode concatenated private and public keys in Base64 for the output + priv_key_with_pub_b64 = Base64Encoder.encode(priv_key_with_pub).decode('utf-8') + # Encode public key in Base64 for the output public_key_b64 = verify_key.encode(encoder=Base64Encoder).decode('utf-8') @@ -40,7 +45,7 @@ def generate_keys(self): }, 'priv_key': { 'type': 'tendermint/PrivKeyEd25519', - 'value': private_key_b64 + 'value': priv_key_with_pub_b64 } } return output