#[repr(C)]pub struct Pubkey(pub [u8; 32]);Expand description
A public key used to identify accounts, programs, and other entities in the Arch VM.
The Pubkey is a 32-byte value that uniquely identifies an entity within the Arch system.
It can be used as an account identifier, a program ID, or for other identification purposes.
The struct provides methods for serialization, creation, and verification of program-derived
addresses (PDAs).
Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl Pubkey
impl Pubkey
pub const fn new_from_array(data: [u8; 32]) -> Self
Sourcepub fn serialize(&self) -> [u8; 32]
pub fn serialize(&self) -> [u8; 32]
Serializes the public key to a 32-byte array.
§Returns
A 32-byte array containing the public key bytes
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Sourcepub const fn system_program() -> Self
pub const fn system_program() -> Self
Sourcepub fn is_system_program(&self) -> bool
pub fn is_system_program(&self) -> bool
Checks if the Pubkey represents the system program.
§Returns
true if the Pubkey is the system program’s Pubkey, false otherwise
Sourcepub fn new_unique() -> Self
pub fn new_unique() -> Self
Creates a unique Pubkey for tests and benchmarks.
This method generates a deterministic unique pubkey by incrementing an atomic counter. It is useful for creating distinct keys in test and benchmark environments.
§Returns
A new unique Pubkey instance
Sourcepub fn log(&self)
pub fn log(&self)
Logs the Pubkey to the program log.
This method is used within programs to output the public key to the program’s log, which can be useful for debugging and monitoring program execution.
§Safety
This method makes a direct system call and should only be used within a program context.
Sourcepub fn is_on_curve(pubkey: &[u8]) -> bool
pub fn is_on_curve(pubkey: &[u8]) -> bool
Checks if a public key represents a point on the secp256k1 curve.
This is used in program address derivation to ensure that derived addresses cannot be used to sign transactions (as they don’t map to valid private keys).
§Arguments
pubkey- The public key bytes to check
§Returns
true if the pubkey is on the curve, false otherwise
Sourcepub fn find_program_address(
seeds: &[&[u8]],
program_id: &Pubkey,
) -> (Pubkey, u8)
pub fn find_program_address( seeds: &[&[u8]], program_id: &Pubkey, ) -> (Pubkey, u8)
Finds a valid program address and bump seed for the given seeds and program ID.
This method searches for a program-derived address (PDA) by trying different bump seeds until it finds one that produces a valid PDA (one that is not on the curve).
§Arguments
seeds- The seeds to use in the address derivationprogram_id- The program ID to derive the address from
§Returns
A tuple containing the derived program address and the bump seed used
§Panics
Panics if no valid program address could be found with any bump seed
Sourcepub fn try_find_program_address(
seeds: &[&[u8]],
program_id: &Pubkey,
) -> Option<(Pubkey, u8)>
pub fn try_find_program_address( seeds: &[&[u8]], program_id: &Pubkey, ) -> Option<(Pubkey, u8)>
Attempts to find a valid program address and bump seed for the given seeds and program ID.
Similar to find_program_address, but returns None instead of panicking if no valid
address can be found.
§Arguments
seeds- The seeds to use in the address derivationprogram_id- The program ID to derive the address from
§Returns
An Option containing a tuple of the derived program address and bump seed if found, or None if no valid program address could be derived
Sourcepub fn create_program_address(
seeds: &[&[u8]],
program_id: &Pubkey,
) -> Result<Pubkey, ProgramError>
pub fn create_program_address( seeds: &[&[u8]], program_id: &Pubkey, ) -> Result<Pubkey, ProgramError>
Creates a program address (PDA) deterministically from a set of seeds and a program ID.
Program addresses are deterministically derived from seeds and a program ID, but unlike normal public keys, they do not lie on the ed25519 curve and thus have no associated private key.
§Arguments
seeds- The seeds to use in the address derivation, maximum of 16 seeds with each seed having a maximum length of 32 bytesprogram_id- The program ID to derive the address from
§Returns
The derived program address if successful
§Errors
Returns an error if:
- There are more than MAX_SEEDS seeds
- Any seed is longer than MAX_SEED_LEN bytes
- The resulting address would lie on the ed25519 curve (invalid for a PDA)
Sourcepub fn create_with_seed(
base: &Pubkey,
seed: &str,
owner: &Pubkey,
) -> Result<Pubkey, ProgramError>
pub fn create_with_seed( base: &Pubkey, seed: &str, owner: &Pubkey, ) -> Result<Pubkey, ProgramError>
Creates a derived address based on a base public key, string seed and owner program id.
Mirrors the behaviour of Solana’s Pubkey::create_with_seed helper and is
required by higher-level crates (e.g. Anchor) when working with
SystemProgram instructions such as CreateAccountWithSeed.
The resulting address is simply sha256(base || seed || owner) and can be
on-curve – it is not restricted to PDAs.
§Arguments
base– Base public key that must sign any transaction creating the accountseed– Arbitrary UTF-8 seed text (≤MAX_SEED_LENbytes)owner– Program id that will own the created account
§Errors
ProgramError::MaxSeedLengthExceeded– if the seed is longer thanMAX_SEED_LEN
Trait Implementations§
Source§impl BorshDeserialize for Pubkey
impl BorshDeserialize for Pubkey
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for Pubkey
impl BorshSerialize 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 Display for Pubkey
TODO:
Change this in future according to the correct base implementation
impl Display for Pubkey
TODO: Change this in future according to the correct base implementation
Source§impl Ord for Pubkey
impl Ord for Pubkey
Source§impl PartialOrd for Pubkey
impl PartialOrd for Pubkey
impl Copy for Pubkey
impl<'__de> Decode<'__de> for Pubkeywhere
'__de:,
impl Encode for Pubkey
impl Eq for Pubkey
impl Pod 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> 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> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)