Signature

class Signature

The Signature object is a wrapper around a raw bytes signature, typically returned by sign_message() or other similar methods.

Parameters:

signature_bytes (bytes) – The raw signature bytes.

LENGTH = 64
static default()

Create a new default signature object.

Returns:

The default signature.

Return type:

Signature

Example

>>> from solders.signature import Signature
>>> Signature.default()
Signature(
    1111111111111111111111111111111111111111111111111111111111111111,
)
static from_bytes(raw_bytes)

Construct from bytes. Equivalent to Signature.__init__ but included for the sake of consistency.

Parameters:

raw_bytes (bytes) – the signature bytes.

Returns:

a Signature object.

Return type:

Signature

static from_json(raw)

Build from a JSON string.

static from_string(s)

Retrieve a signature from a base58-encoded string.

Parameters:

s (str) – base58-encoded signature.

Returns:

The decoded signature.

Return type:

Signature

Example

>>> from solders.signature import Signature
>>> from solders.keypair import Keypair
>>> sig = Keypair().sign_message(bytes([0]))
>>> assert Signature.from_string(str(sig)) == sig
static new_unique()

Create a random siganture.

Returns:

The random signature.

Return type:

Signature

to_bytes_array()

Returns this signature as a byte array.

Returns:

the signature as a list of 64 u8 ints.

Return type:

list[int]

Example

>>> from solders.signature import Signature
>>> assert Signature.default().to_bytes_array() == [0] * 64
to_json()

Convert to a JSON string.

verify(pubkey, message_bytes)

Check if the signature is a valid signature created by the given pubkey on the given message.

Parameters:
  • pubkey – The pubkey that is supposed to have signed the message.

  • message (bytes) – The message in bytes.

Returns:

True if verfiication is successful.

Return type:

bool

Example

>>> from solders.keypair import Keypair
>>> from solders.signature import Signature
>>> kp = Keypair()
>>> msg = b"macaroni"
>>> sig = kp.sign_message(msg)
>>> sig.verify(kp.pubkey(), msg)
True