Presigner

class Presigner

A signer that represents a Signature that has been constructed externally. Performs a signature verification against the expected message upon sign() requests to affirm its relationship to the message bytes.

Parameters:
  • pubkey (Pubkey) – The pubkey of the signer.

  • signature (Signature) – The signature created by signing the message.

static default()

Create a new default presigner.

Returns:

The default presigner.

Return type:

Presigner

pubkey()

Get this signer’s Pubkey.

Returns:

The pubkey of the presigner.

Return type:

Pubkey

Example

>>> from solders.keypair import Keypair
>>> from solders.pubkey import Pubkey
>>> seed_bytes = bytes([0] * 32)
>>> pubkey_bytes = b";j'\xbc\xce\xb6\xa4-b\xa3\xa8\xd0*o\rse2\x15w\x1d\xe2C\xa6:\xc0H\xa1\x8bY\xda)"
>>> kp = Keypair.from_bytes(seed_bytes + pubkey_bytes)
>>> assert kp.pubkey() == Pubkey(pubkey_bytes)
sign_message(message)

Verifies the signature of the presigner and returns it if valid.

Returns:

The signature assigned to this object.

Return type:

Signature

Raises:

SignerError – if the signature is invalid.

Example

>>> from solders.keypair import Keypair
>>> from solders.presigner import Presigner
>>> keypair = Keypair.from_seed(bytes([0] * 32))
>>> pubkey = keypair.pubkey()
>>> data = bytes([1])
>>> sig = keypair.sign_message(data)
>>> presigner = Presigner(pubkey, sig)
>>> assert presigner.pubkey() == pubkey
>>> assert presigner.sign_message(data) == sig