pub struct Pubkey(pub Pubkey);
Expand description
A public key.
Args: pubkey_bytes (bytes): The pubkey in bytes.
Example: >>> from solders.pubkey import Pubkey >>> pubkey = Pubkey(bytes([1] * 32)) >>> str(pubkey) ‘4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi’ >>> bytes(pubkey).hex() ‘0101010101010101010101010101010101010101010101010101010101010101’
Tuple Fields§
§0: Pubkey
Implementations§
Source§impl Pubkey
impl Pubkey
pub const LENGTH: usize = 32usize
pub fn new(pubkey_bytes: [u8; 32]) -> Self
Sourcepub fn new_unique() -> Self
pub fn new_unique() -> Self
Unique pubkey for tests and benchmarks.
Returns: Pubkey: Randomly generated pubkey.
Sourcepub fn new_from_str(s: &str) -> PyResult<Self>
pub fn new_from_str(s: &str) -> PyResult<Self>
Retrieve a pubkey from a base58 string.
Returns: Pubkey: the pubkey obtained from the base58 string.
Example:
>>> from solders.pubkey import Pubkey
>>> Pubkey.from_string("BPFLoader1111111111111111111111111111111111")
Pubkey(
BPFLoader1111111111111111111111111111111111,
)
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create a new default pubkey.
Returns: Pubkey: The default pubkey.
Example: >>> from solders.pubkey import Pubkey >>> Pubkey.default() Pubkey( 11111111111111111111111111111111, )
Sourcepub fn create_with_seed(
base: &Self,
seed: &str,
program_id: &Self,
) -> PyResult<Self>
pub fn create_with_seed( base: &Self, seed: &str, program_id: &Self, ) -> PyResult<Self>
Derive a pubkey from another key, a seed, and a program ID.
Args: base (Pubkey): The other pubkey to use. seed (str): The seed string program_id (Pubkey): The program ID.
Returns: Pubkey: The derived pubkey.
Example: >>> from solders.pubkey import Pubkey >>> default_public_key = Pubkey.default() >>> Pubkey.create_with_seed(default_public_key, “limber chicken: 4/45”, default_public_key) Pubkey( 9h1HyLCW5dZnBVap8C5egQ9Z6pHyjsh5MNy83iPqqRuq, )
Sourcepub fn create_program_address(seeds: Vec<&[u8]>, program_id: &Self) -> Self
pub fn create_program_address(seeds: Vec<&[u8]>, program_id: &Self) -> Self
Derive a program address from seeds and a program ID.
Args: seeds (Sequence[bytes]): The seeds to use. program_id (Pubkey): The program ID.
Returns: Pubkey: The derived program address.
Example:
>>> from solders.pubkey import Pubkey
>>> program_id = Pubkey.from_string("BPFLoader1111111111111111111111111111111111")
>>> Pubkey.create_program_address([b"", bytes([1])], program_id)
Pubkey(
3gF2KMe9KiC6FNVBmfg9i267aMPvK37FewCip4eGBFcT,
)
Sourcepub fn find_program_address(seeds: Vec<&[u8]>, program_id: &Self) -> (Self, u8)
pub fn find_program_address(seeds: Vec<&[u8]>, program_id: &Self) -> (Self, u8)
Find a valid program derived address <https://docs.solana.com/developing/programming-model/calling-between-programs#program-derived-addresses>
_ and its corresponding bump seed.
Program derived addresses (PDAs) are account keys that only the program,
program_id
, has the authority to sign. The address is of the same form
as a Solana Pubkey
, except they are ensured to not be on the ed25519
curve and thus have no associated private key. When performing
cross-program invocations the program can “sign” for the key by calling
invoke_signed
and passing the same seeds used to generate the
address, along with the calculated bump seed, which this function
returns as the second tuple element. The runtime will verify that the
program associated with this address is the caller and thus authorized
to be the signer.
The seeds
are application-specific, and must be carefully selected to
uniquely derive accounts per application requirements. It is common to
use static strings and other pubkeys as seeds.
Because the program address must not lie on the ed25519 curve, there may
be seed and program id combinations that are invalid. For this reason,
an extra seed (the bump seed) is calculated that results in a
point off the curve. The bump seed must be passed as an additional seed
when calling invoke_signed
.
Warning: Because of the way the seeds are hashed there is a potential for program address collisions for the same program id. The seeds are hashed sequentially which means that seeds {“abcdef”}, {“abc”, “def”}, and {“ab”, “cd”, “ef”} will all result in the same program address given the same program id. Since the chance of collision is local to a given program id, the developer of that program must take care to choose seeds that do not collide with each other. For seed schemes that are susceptible to this type of hash collision, a common remedy is to insert separators between seeds, e.g. transforming {“abc”, “def”} into {“abc”, “-”, “def”}.
Args: seeds (Sequence[bytes]): The seeds to use. program_id (Pubkey): The program ID.
Returns: Pubkey: The PDA.
Example:
>>> from solders.pubkey import Pubkey
>>> program_id = Pubkey.from_string("BPFLoader1111111111111111111111111111111111")
>>> program_address, nonce = Pubkey.find_program_address([b""], program_id)
>>> program_address
Pubkey(
EXWkUCz3YJU9TDVk39ogA4TwoVsUi75ZDhH6yT7acPgQ,
)
>>> nonce
255
Sourcepub fn is_on_curve(&self) -> bool
pub fn is_on_curve(&self) -> bool
Check that the pubkey is on the ed25519 curve.
Returns:
bool: True
if the pubkey is on the curve.
Sourcepub fn from_bytes(raw: &[u8]) -> PyResult<Self>
pub fn from_bytes(raw: &[u8]) -> PyResult<Self>
Construct from bytes
. Equivalent to Pubkey.__init__
but included for the sake of consistency.
Args: raw (bytes): the pubkey bytes.
Returns:
Pubkey: a Pubkey
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<Pubkey> for Pubkey
impl AsRef<Pubkey> for Pubkey
Source§fn as_ref(&self) -> &PubkeyOriginal
fn as_ref(&self) -> &PubkeyOriginal
Source§impl CommonMethods<'_> for Pubkey
impl CommonMethods<'_> for Pubkey
fn py_to_json(&self) -> String
fn py_from_json(raw: &'a str) -> Result<Self, PyErr>
Source§impl CommonMethodsCore for Pubkey
impl CommonMethodsCore for Pubkey
Source§impl<'de> Deserialize<'de> for Pubkey
impl<'de> Deserialize<'de> for Pubkey
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<&Pubkey> for Pubkey
impl From<&Pubkey> for Pubkey
Source§fn from(pubkey: &PubkeyOriginal) -> Self
fn from(pubkey: &PubkeyOriginal) -> Self
Source§impl From<Pubkey> for Pubkey
impl From<Pubkey> for Pubkey
Source§fn from(original: PubkeyOriginal) -> Pubkey
fn from(original: PubkeyOriginal) -> Pubkey
Source§impl Ord for Pubkey
impl Ord for Pubkey
Source§impl PartialOrd for Pubkey
impl PartialOrd for Pubkey
Source§impl PyBytesGeneral for Pubkey
impl PyBytesGeneral for Pubkey
fn pybytes_general<'a>(&self, py: Python<'a>) -> &'a PyBytes
Source§impl PyBytesSlice for Pubkey
impl PyBytesSlice for Pubkey
fn pybytes_slice<'a>(&self, py: Python<'a>) -> &'a PyBytes
Source§impl PyClassImpl for Pubkey
impl PyClassImpl for Pubkey
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
Source§type ThreadChecker = SendablePyClass<Pubkey>
type ThreadChecker = SendablePyClass<Pubkey>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§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<Pubkey> for PyClassImplCollector<Pubkey>
impl PyClassNewTextSignature<Pubkey> for PyClassImplCollector<Pubkey>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyFromBytesGeneral for Pubkey
impl PyFromBytesGeneral for Pubkey
fn py_from_bytes_general(raw: &[u8]) -> PyResult<Self>
Source§impl PyMethods<Pubkey> for PyClassImplCollector<Pubkey>
impl PyMethods<Pubkey> for PyClassImplCollector<Pubkey>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Pubkey
impl PyTypeInfo for Pubkey
Source§type AsRefTarget = PyCell<Pubkey>
type AsRefTarget = PyCell<Pubkey>
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.impl Copy for Pubkey
impl Eq for Pubkey
impl StructuralPartialEq for Pubkey
Auto Trait Implementations§
impl Freeze for Pubkey
impl RefUnwindSafe for Pubkey
impl Send for Pubkey
impl Sync for Pubkey
impl Unpin for Pubkey
impl UnwindSafe for Pubkey
Blanket Implementations§
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<'a, T> FromPyObject<'a> for T
impl<'a, T> FromPyObject<'a> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more