Struct solders_signature::Signature
source · pub struct Signature(pub Signature);
Expand description
The Signature
object is a wrapper around a raw bytes signature, typically
returned by :meth:~solders.keypair.Keypair.sign_message
or other similar methods.
Args: signature_bytes (bytes): The raw signature bytes.
Tuple Fields§
§0: Signature
Implementations§
source§impl Signature
impl Signature
pub const LENGTH: usize = 64usize
pub fn new(signature_bytes: [u8; 64]) -> Self
sourcepub fn new_unique() -> Self
pub fn new_unique() -> Self
Create a random siganture.
Returns: Signature: The random signature.
sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create a new default signature object.
Returns: Signature: The default signature.
Example: >>> from solders.signature import Signature >>> Signature.default() Signature( 1111111111111111111111111111111111111111111111111111111111111111, )
sourcepub fn new_from_str(s: &str) -> PyResult<Self>
pub fn new_from_str(s: &str) -> PyResult<Self>
Retrieve a signature from a base58-encoded string.
Args: s (str): base58-encoded signature.
Returns: Signature: The decoded 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
sourcepub fn verify(&self, pubkey: Pubkey, message_bytes: &[u8]) -> bool
pub fn verify(&self, pubkey: Pubkey, message_bytes: &[u8]) -> bool
Check if the signature is a valid signature created by the given pubkey on the given message.
Args: pubkey: The pubkey that is supposed to have signed the message. message (bytes): The message in bytes.
Returns: bool: True if verfiication is successful.
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
sourcepub fn to_bytes_array(&self) -> [u8; 64]
pub fn to_bytes_array(&self) -> [u8; 64]
Returns this signature as a byte array.
Returns: list[int]: the signature as a list of 64 u8 ints.
Example: >>> from solders.signature import Signature >>> assert Signature.default().to_bytes_array() == [0] * 64
sourcepub fn from_bytes(raw_bytes: [u8; 64]) -> PyResult<Self>
pub fn from_bytes(raw_bytes: [u8; 64]) -> PyResult<Self>
Construct from bytes
. Equivalent to Signature.__init__
but included for the sake of consistency.
Args: raw_bytes (bytes): the signature bytes.
Returns:
Signature: a Signature
object.
pub fn __hash__(&self) -> u64
pub fn __richcmp__(&self, other: &Self, op: CompareOp) -> bool
pub fn __bytes__<'a>(&self, py: Python<'a>) -> &'a PyBytes
pub fn __str__(&self) -> String
pub fn __repr__(&self) -> String
pub fn __reduce__(&self) -> PyResult<(PyObject, PyObject)>
Trait Implementations§
source§impl AsRef<Signature> for Signature
impl AsRef<Signature> for Signature
source§fn as_ref(&self) -> &SignatureOriginal
fn as_ref(&self) -> &SignatureOriginal
source§impl CommonMethods<'_> for Signature
impl CommonMethods<'_> for Signature
fn py_to_json(&self) -> String
fn py_from_json(raw: &'a str) -> Result<Self, PyErr>
source§impl CommonMethodsCore for Signature
impl CommonMethodsCore for Signature
source§impl<'de> Deserialize<'de> for Signature
impl<'de> Deserialize<'de> for Signature
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<Signature> for Signature
impl From<Signature> for Signature
source§fn from(original: SignatureOriginal) -> Signature
fn from(original: SignatureOriginal) -> Signature
source§impl Ord for Signature
impl Ord for Signature
source§impl PartialEq for Signature
impl PartialEq for Signature
source§impl PartialOrd for Signature
impl PartialOrd for Signature
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PyBytesGeneral for Signature
impl PyBytesGeneral for Signature
fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes
source§impl PyBytesSlice for Signature
impl PyBytesSlice for Signature
fn pybytes_slice<'a>(&self, py: Python<'a>) -> &'a PyBytes
source§impl PyClassImpl for Signature
impl PyClassImpl for Signature
source§const IS_BASETYPE: bool = true
const IS_BASETYPE: bool = true
source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
§type ThreadChecker = ThreadCheckerStub<Signature>
type ThreadChecker = ThreadCheckerStub<Signature>
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
source§impl PyClassNewTextSignature<Signature> for PyClassImplCollector<Signature>
impl PyClassNewTextSignature<Signature> for PyClassImplCollector<Signature>
fn new_text_signature(self) -> Option<&'static str>
source§impl PyFromBytesGeneral for Signature
impl PyFromBytesGeneral for Signature
fn py_from_bytes_general(raw: &[u8]) -> PyResult<Self>
source§impl PyMethods<Signature> for PyClassImplCollector<Signature>
impl PyMethods<Signature> for PyClassImplCollector<Signature>
fn py_methods(self) -> &'static PyClassItems
source§impl PyTypeInfo for Signature
impl PyTypeInfo for Signature
§type AsRefTarget = PyCell<Signature>
type AsRefTarget = PyCell<Signature>
source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object
is an instance of this type or a subclass of this type.source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object
is an instance of this type.