crypto¶
- class ED25519PublicKey¶
- LENGTH = 32¶
- static empty()¶
Create an empty pubkey.
- Returns:
ED25519PublicKey
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_json(raw)¶
Build from a JSON string.
- static from_seed(seed)¶
Build from seed.
- Parameters:
seed (str) –
- Returns:
ED25519PublicKey
- static from_str(s)¶
Parse from a string.
s (str): The string to parse
- Returns:
ED25519PublicKey
- to_json()¶
Convert to a JSON string.
- class Secp256K1PublicKey¶
- LENGTH = 64¶
- static empty()¶
Create an empty pubkey.
- Returns:
Secp256K1PublicKey
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_json(raw)¶
Build from a JSON string.
- static from_str(s)¶
Parse from a string.
s (str): The string to parse
- Returns:
Secp256K1PublicKey
- to_json()¶
Convert to a JSON string.
- class ED25519SecretKey¶
- LENGTH = 64¶
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_json(raw)¶
Build from a JSON string.
- static from_random()¶
Randomly generate the key.
- Returns:
ED25519SecretKey
- static from_seed(seed)¶
Build from seed.
- Parameters:
seed (str) –
- Returns:
ED25519SecretKey
- static from_str(s)¶
Parse from a string.
s (str): The string to parse
- Returns:
ED25519SecretKey
- public_key()¶
Retrieve the public key of this secret key.
- Returns:
The public key.
- Return type:
- sign(data)¶
Sign a message with this secret key.
- Parameters:
data (bytes | Sequence[int]) – The message to sign.
- Returns
ED25519Signature: the message signature.
- to_json()¶
Convert to a JSON string.
- class Secp256K1SecretKey¶
- LENGTH = 32¶
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_json(raw)¶
Build from a JSON string.
- static from_random()¶
Randomly generate the key.
- Returns:
Secp256K1SecretKey
- static from_seed(seed)¶
Build from seed.
- Parameters:
seed (str) –
- Returns:
Secp256K1SecretKey
- static from_str(s)¶
Parse from a string.
s (str): The string to parse
- Returns:
Secp256K1SecretKey
- public_key()¶
Retrieve the public key of this secret key.
- Returns:
The public key.
- Return type:
- sign(data)¶
Sign a message with this secret key.
- Parameters:
data (bytes | Sequence[int]) – The message to sign.
- Returns
Secp256K1Signature: the message signature.
- to_json()¶
Convert to a JSON string.
- class ED25519Signature¶
- LENGTH = 64¶
- static empty()¶
Create an empty signature.
- Returns:
ED25519Signature
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_json(raw)¶
Build from a JSON string.
- static from_str(s)¶
Parse from a string.
s (str): The string to parse
- Returns:
ED25519Signature
- to_json()¶
Convert to a JSON string.
- verify(data, public_key)¶
Verifies that this signature comes from signing the data with given public key. Also if public key isn’t on the curve returns false.
- Parameters:
data (Sequence[int] | bytes) – the unsigned message.
public_key (ED25519PublicKey) – The public key of the signer.
- Returns:
Signature verification result
- Return type:
bool
- class Secp256K1Signature¶
- LENGTH = 65¶
- check_signature_values(reject_upper)¶
- Parameters:
reject_upper – bool
- Returns:
bool
- static empty()¶
Create an empty signature.
- Returns:
Secp256K1Signature
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_json(raw)¶
Build from a JSON string.
- static from_str(s)¶
Parse from a string.
s (str): The string to parse
- Returns:
Secp256K1Signature
- recover(msg)¶
Recover the pubkey of the given message’s signer.
- Parameters:
msg (bytes | Sequence[int]) – the unsigned message.
- Returns:
The signer’s pubkey.
- Return type:
- to_json()¶
Convert to a JSON string.
- verify(data, public_key)¶
Verifies that this signature comes from signing the data with given public key. Also if public key isn’t on the curve returns false.
- Parameters:
data (Sequence[int] | bytes) – the unsigned message.
public_key (Secp256K1PublicKey) – The public key of the signer.
- Returns:
Signature verification result
- Return type:
bool
- class EmptySigner¶
- static public_key()¶
Returns an empty public key.
- Returns:
empty pubkey.
- Return type:
- static sign()¶
Returns an empty signature.
- Returns:
empty signature.
- Return type:
- static verify(data, signature)¶
Verifies that this signature comes from signing the data with this signer’s public key. Also if public key isn’t on the curve returns false.
- Parameters:
data (Sequence[int] | bytes) – the unsigned message.
signature (Signature) – The signature.
- Returns:
Signature verification result
- Return type:
bool
- class InMemorySigner¶
-
- compute_vrf_with_proof(data)¶
See https://docs.rs/near-crypto/latest/near_crypto/trait.Signer.html#tymethod.compute_vrf_with_proof
- Parameters:
data (bytes | Sequence[int]) –
- Returns:
tuple[list[int], list[int]]
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_file(path)¶
Read the signer from a file.
- Parameters:
path (pathlib.Path) – The file to read.
- Returns:
InMemorySigner
- static from_json(raw)¶
Build from a JSON string.
- static from_random(account_id, key_type)¶
Randomly generate the key.
- Returns:
InMemorySigner
- static from_secret_key(account_id, secret_key)¶
Build the signer from a secret key.
- Parameters:
account_id (AccountId) – The signer’s account ID.
secret_key (SecretKey) – The signer’s secret key.
- static from_seed(account_id, key_type, seed)¶
Build from seed.
- public_key¶
the signer’s public key.
- Type:
PublicKey
- secret_key¶
the signer’s secret key.
- Type:
SecretKey
- sign(data)¶
Sign a message with this signer’s secret key.
- Parameters:
data (bytes | Sequence[int]) – The message to sign.
- Returns
Signature: the message signature.
- to_json()¶
Convert to a JSON string.
- verify(data, signature)¶
Verifies that this signature comes from signing the data with this signer’s public key. Also if public key isn’t on the curve returns false.
- Parameters:
data (Sequence[int] | bytes) – the unsigned message.
signature (Signature) – The signature.
- Returns:
Signature verification result
- Return type:
bool
- write_to_file(path)¶
Save to a file.
- Parameters:
path (pathlib.Path) –
- Returns:
None
- class KeyFile¶
A file for storing keys in.
- static from_bytes(data)¶
Deserialize from bytes.
- Parameters:
data (bytes) – the serialized object.
Returns: the deserialized object.
- static from_file(path)¶
Read from a file.
- Parameters:
path (pathlib.Path) – The file to read.
- Returns:
KeyFile
- static from_json(raw)¶
Build from a JSON string.
- public_key¶
the public key.
- Type:
PublicKey
- secret_key¶
the secret key.
- Type:
SecretKey
- to_json()¶
Convert to a JSON string.
- write_to_file(path)¶
Write to a file.
- Parameters:
path (pathlib.Path) – The file to write.