Pubkey

Struct Pubkey 

Source
#[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

Source

pub const fn new_from_array(data: [u8; 32]) -> Self

Source

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

Source

pub fn from_slice(data: &[u8]) -> Self

Creates a new Pubkey from a slice of bytes.

If the slice is shorter than 32 bytes, the remaining bytes will be padded with zeros.

§Arguments
  • data - The byte slice to create the Pubkey from
§Returns

A new Pubkey instance

Source

pub const fn system_program() -> Self

Returns the system program’s public key.

§Returns

The system program’s Pubkey

Source

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

Source

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

Source

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.

Source

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

Source

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 derivation
  • program_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

Source

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 derivation
  • program_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

Source

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 bytes
  • program_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)
Source

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 account
  • seed – Arbitrary UTF-8 seed text (≤ MAX_SEED_LEN bytes)
  • owner – Program id that will own the created account
§Errors

Trait Implementations§

Source§

impl AsMut<[u8]> for Pubkey

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[u8]> for Pubkey

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl BorshDeserialize for Pubkey

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for Pubkey

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Clone for Pubkey

Source§

fn clone(&self) -> Pubkey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pubkey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Pubkey

Source§

fn default() -> Pubkey

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Pubkey

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Pubkey

TODO: Change this in future according to the correct base implementation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<[u8; 32]> for Pubkey

Source§

fn from(value: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Pubkey

Source§

type Err = &'static str

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Pubkey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for Pubkey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Pubkey

Source§

fn cmp(&self, other: &Pubkey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Pubkey

Source§

fn eq(&self, other: &Pubkey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Pubkey

Source§

fn partial_cmp(&self, other: &Pubkey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Pubkey

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Zeroable for Pubkey

Source§

fn zeroed() -> Self

Source§

impl Copy for Pubkey

Source§

impl<'__de> Decode<'__de> for Pubkey
where '__de:,

Source§

impl Encode for Pubkey

Source§

impl Eq for Pubkey

Source§

impl Pod for Pubkey

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

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

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> DecodeOwned for T
where T: for<'de> Decode<'de>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> NoUninit for T
where T: Pod,