Example #1
0
def get_master_pubkey(root_G1: tuple, chaincode_G1: tuple) -> bytes:
    try:
        root_pubkey = bls_conv.G1_to_pubkey(root_G1)
        public_chaincode_address = bls_conv.G1_to_pubkey(chaincode_G1)
    except:
        raise DerivationErrorBasic('Encoding master public key')

    if not bls_basic.KeyValidate(root_pubkey):
        raise DerivationErrorBasic('Encoding public root key')

    if not bls_basic.KeyValidate(public_chaincode_address):
        raise DerivationErrorBasic('Encoding public root chaincode')

    joint = root_pubkey + public_chaincode_address
    return joint + sha512(joint).digest()[:6]
Example #2
0
def parse_master_pubkey(master_pubkey: bytes) -> Tuple[tuple, tuple]:
    if not len(master_pubkey) == 102:
        raise DerivationErrorBasic(
            f'Wrong length master public key, got {len(master_pubkey)} bytes, should be 102'
        )

    checksum = master_pubkey[96:102]
    if sha512(master_pubkey[:96]).digest()[:6] != checksum:
        raise DerivationErrorBasic(f'Wrong master public key checksum')

    if not bls_basic.KeyValidate(master_pubkey[:48]):
        raise DerivationErrorBasic('Parsing master public key')
    if not bls_basic.KeyValidate(master_pubkey[48:96]):
        raise DerivationErrorBasic('Parsing master public chaincode')

    try:
        root_public_key = bls_conv.pubkey_to_G1(master_pubkey[:48])
        public_chaincode = bls_conv.pubkey_to_G1(master_pubkey[48:96])
    except:
        raise DerivationErrorBasic(
            'Parsing master public to root public key and chaincode')

    return root_public_key, public_chaincode
Example #3
0
def test_key_validate(pubkey, success):
    assert G2Basic.KeyValidate(pubkey) == success