Skip to content

Keys

Generate new keys

from_seed(sign_algo: SignAlgo = <SignAlgo.ECDSA_P256: 2>, hash_algo: HashAlgo = <HashAlgo.SHA3_256: 3>, *, seed: str = None) -> tuple[AccountKey, in_memory_signer.InMemorySigner] classmethod

from_seed provide a way for user to create a public and private key for an account using, seed string.

Parameters

sign_algo : int Signature algorithm associate with account. hash_algo : str Hash algorithm associate with account. seed : str The seed associate with account.

Returns

AccountKey Return Account Key contain public and hash algorithm and signature algorithm. it also create a InMemorySigner, it can be use signing messages and transactions.

Source code in flow_py_sdk/account_key.py
@classmethod
def from_seed(
    cls,
    sign_algo: SignAlgo = SignAlgo.ECDSA_P256,
    hash_algo: HashAlgo = HashAlgo.SHA3_256,
    *,
    seed: str = None
) -> tuple[AccountKey, in_memory_signer.InMemorySigner]:
    """
    from_seed provide a way for user to create a public and private key for an account using, seed string.

    Parameters
    ----------
    sign_algo : int
        Signature algorithm associate with account.
    hash_algo : str
        Hash algorithm associate with account.
    seed : str
        The seed associate with account.

    Returns
    -------
    AccountKey
        Return Account Key contain public and hash algorithm and signature algorithm.
        it also create a InMemorySigner, it can be use signing messages and transactions.

    """

    # Generate private key using provided Seed.
    if seed == None:
        sk = SigningKey.generate()
        private_key = sk.to_string()
    else:
        secexp = randrange_from_seed__trytryagain(
            seed, sign_algo.get_signing_curve().order
        )
        sk = SigningKey.from_secret_exponent(
            secexp, curve=sign_algo.get_signing_curve()
        )
        private_key = sk.to_string()

    # Extract public Key (verifying Key) of generated private key.
    vk = sk.get_verifying_key()
    public_key = vk.to_string()
    # Create Account Key.
    ak = AccountKey(public_key=public_key, hash_algo=hash_algo, sign_algo=sign_algo)

    # Save generated private key in in_memory_signer for further messages or transaction Signing.

    signer = in_memory_signer.InMemorySigner(
        hash_algo=hash_algo, sign_algo=sign_algo, private_key_hex=private_key.hex()
    )

    return ak, signer