pub struct Address(/* private fields */);Expand description
The address of a Solana account.
Some account addresses are ed25519 public keys, with corresponding secret
keys that are managed off-chain. Often, though, account addresses do not
have corresponding secret keys — as with program derived
addresses — or the secret key is not relevant to the operation
of a program, and may have even been disposed of. As running Solana programs
can not safely create or manage secret keys, the full Keypair is not
defined in solana-program but in solana-sdk.
Implementations§
Source§impl Address
impl Address
Sourcepub fn derive_address<const N: usize>(
seeds: &[&[u8]; N],
bump: Option<u8>,
program_id: &Address,
) -> Address
pub fn derive_address<const N: usize>( seeds: &[&[u8]; N], bump: Option<u8>, program_id: &Address, ) -> Address
Derive a program address from the given seeds, optional bump and program id.
In general, the derivation uses an optional bump (byte) value to ensure a
valid PDA (off-curve) is generated. Even when a program stores a bump to
derive a program address, it is necessary to use the
[Address::create_program_address] to validate the derivation. In
most cases, the program has the correct seeds for the derivation, so it would
be sufficient to just perform the derivation and compare it against the
expected resulting address.
This function avoids the cost of the create_program_address syscall
(1500 compute units) by directly computing the derived address
calculating the hash of the seeds, bump and program id using the
sol_sha256 syscall.
§Important
This function differs from [Address::create_program_address] in that
it does not perform a validation to ensure that the derived address is a valid
(off-curve) program derived address. It is intended for use in cases where the
seeds, bump, and program id are known to be valid, and the caller wants to derive
the address without incurring the cost of the create_program_address syscall.
Sourcepub const fn derive_address_const<const N: usize>(
seeds: &[&[u8]; N],
bump: Option<u8>,
program_id: &Address,
) -> Address
pub const fn derive_address_const<const N: usize>( seeds: &[&[u8]; N], bump: Option<u8>, program_id: &Address, ) -> Address
Derive a program address from the given seeds, optional bump and program id.
In general, the derivation uses an optional bump (byte) value to ensure a valid PDA (off-curve) is generated.
This function is intended for use in const contexts - i.e., the seeds and
bump are known at compile time and the program id is also a constant. It avoids
the cost of the create_program_address syscall (1500 compute units) by
directly computing the derived address using the SHA-256 hash of the seeds,
bump and program id.
§Important
This function differs from [Address::create_program_address] in that
it does not perform a validation to ensure that the derived address is a valid
(off-curve) program derived address. It is intended for use in cases where the
seeds, bump, and program id are known to be valid, and the caller wants to derive
the address without incurring the cost of the create_program_address syscall.
This function is a compile-time constant version of Address::derive_address.
It has worse performance than derive_address, so only use this function in
const contexts, where all parameters are known at compile-time.
Source§impl Address
impl Address
pub const fn new_from_array(address_array: [u8; 32]) -> Address
Sourcepub const fn from_str_const(s: &str) -> Address
Available on crate feature decode only.
pub const fn from_str_const(s: &str) -> Address
decode only.Decode a string into an Address, usable in a const context
Sourcepub fn new_unique() -> Address
Available on crate feature atomic only.
pub fn new_unique() -> Address
atomic only.Create a unique Address for tests and benchmarks.
pub fn create_with_seed( base: &Address, seed: &str, owner: &Address, ) -> Result<Address, AddressError>
sha2 only.pub const fn to_bytes(&self) -> [u8; 32]
Sourcepub fn is_on_curve(&self) -> bool
Available on crate features curve25519 or syscalls only.
pub fn is_on_curve(&self) -> bool
curve25519 or syscalls only.Checks whether the given address lies on the Ed25519 curve.
On-curve addresses correspond to valid Ed25519 public keys (and therefore can have associated private keys). Off-curve addresses are typically used for program-derived addresses (PDAs).
Trait Implementations§
Source§impl Hash for Address
Custom impl of Hash for Address.
impl Hash for Address
Custom impl of Hash for Address.
This allows us to skip hashing the length of the address which is always the same anyway.