Module libra.auth_key

Provides AuthKey class for holding Libra authentication key and generating account address, prefix from it.

Expand source code
# Copyright (c) The Libra Core Contributors
# SPDX-License-Identifier: Apache-2.0

"""Provides AuthKey class for holding Libra authentication key and generating account address, prefix from it."""

from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from . import utils, libra_types


class AuthKey:
    """Libra Authentication Key

    Wraps authentication key bytes, derives account address and authentication key prefix.
    """

    data: bytes

    @staticmethod
    def from_public_key(public_key: Ed25519PublicKey) -> "AuthKey":
        single_key_scheme = b"\x00"
        return AuthKey(utils.hash(utils.public_key_bytes(public_key), single_key_scheme))

    def __init__(self, data: bytes) -> None:
        self.data = data

    def account_address(self) -> libra_types.AccountAddress:
        return utils.account_address(self.data[-utils.ACCOUNT_ADDRESS_LEN :])

    def prefix(self) -> bytes:
        return self.data[: -utils.ACCOUNT_ADDRESS_LEN]

    def hex(self) -> str:
        return self.data.hex()

Classes

class AuthKey (data: bytes)

Libra Authentication Key

Wraps authentication key bytes, derives account address and authentication key prefix.

Expand source code
class AuthKey:
    """Libra Authentication Key

    Wraps authentication key bytes, derives account address and authentication key prefix.
    """

    data: bytes

    @staticmethod
    def from_public_key(public_key: Ed25519PublicKey) -> "AuthKey":
        single_key_scheme = b"\x00"
        return AuthKey(utils.hash(utils.public_key_bytes(public_key), single_key_scheme))

    def __init__(self, data: bytes) -> None:
        self.data = data

    def account_address(self) -> libra_types.AccountAddress:
        return utils.account_address(self.data[-utils.ACCOUNT_ADDRESS_LEN :])

    def prefix(self) -> bytes:
        return self.data[: -utils.ACCOUNT_ADDRESS_LEN]

    def hex(self) -> str:
        return self.data.hex()

Class variables

var data : bytes

Static methods

def from_public_key(public_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey) ‑> AuthKey
Expand source code
@staticmethod
def from_public_key(public_key: Ed25519PublicKey) -> "AuthKey":
    single_key_scheme = b"\x00"
    return AuthKey(utils.hash(utils.public_key_bytes(public_key), single_key_scheme))

Methods

def account_address(self) ‑> AccountAddress
Expand source code
def account_address(self) -> libra_types.AccountAddress:
    return utils.account_address(self.data[-utils.ACCOUNT_ADDRESS_LEN :])
def hex(self) ‑> str
Expand source code
def hex(self) -> str:
    return self.data.hex()
def prefix(self) ‑> bytes
Expand source code
def prefix(self) -> bytes:
    return self.data[: -utils.ACCOUNT_ADDRESS_LEN]