pub fn create_program_address(
        seeds: &[&[u8]],
        program_id: &Pubkey,
    ) -> Result<Pubkey, PubkeyError> {
        if seeds.len() > MAX_SEEDS {
            return Err(PubkeyError::MaxSeedLengthExceeded);
        }
        for seed in seeds.iter() {
            if seed.len() > MAX_SEED_LEN {
                return Err(PubkeyError::MaxSeedLengthExceeded);
            }
        }

        // Perform the calculation inline, calling this from within a program is
        // not supported
        #[cfg(not(target_arch = "bpf"))]
        {
            let mut hasher = crate::hash::Hasher::default();
            for seed in seeds.iter() {
                hasher.hash(seed);
            }
            hasher.hashv(&[program_id.as_ref(), PDA_MARKER]);
            let hash = hasher.result();

            if bytes_are_curve_point(hash) {
                return Err(PubkeyError::InvalidSeeds);
            }

            Ok(Pubkey::new(hash.as_ref()))
        }
        // Call via a system call to perform the calculation
        #[cfg(target_arch = "bpf")]
        {
            extern "C" {
                fn sol_create_program_address(
                    seeds_addr: *const u8,
                    seeds_len: u64,
                    program_id_addr: *const u8,
                    address_bytes_addr: *const u8,
                ) -> u64;
            }
            let mut bytes = [0; 32];
            let result = unsafe {
                sol_create_program_address(
                    seeds as *const _ as *const u8,
                    seeds.len() as u64,
                    program_id as *const _ as *const u8,
                    &mut bytes as *mut _ as *mut u8,
                )
            };
            match result {
                crate::entrypoint::SUCCESS => Ok(Pubkey::new(&bytes)),
                _ => Err(result.into()),
            }
        }
    }
/// Create a valid [program derived address][pda] without searching for a bump seed.
///
/// [pda]: https://docs.solana.com/developing/programming-model/calling-between-programs#program-derived-addresses
///
/// Because this function does not create a bump seed, it may unpredictably
/// return an error for any given set of seeds and is not generally suitable
/// for creating program derived addresses.
///
/// However, it can be used for efficiently verifying that a set of seeds plus
/// bump seed generated by [`find_program_address`] derives a particular
/// address as expected. See the example for details.
///
/// See the documentation for [`find_program_address`] for a full description
/// of program derived addresses and bump seeds.
///
/// [`find_program_address`]: Pubkey::find_program_address
///
/// # Examples
///
/// Creating a program derived address involves iteratively searching for a
/// bump seed for which the derived [`Pubkey`] does not lie on the ed25519
/// curve. This search process is generally performed off-chain, with the
/// [`find_program_address`] function, after which the client passes the
/// bump seed to the program as instruction data.
///
/// Depending on the application requirements, a program may wish to verify
/// that the set of seeds, plus the bump seed, do correctly generate an
/// expected address.
///
/// The verification is performed by appending to the other seeds one
/// additional seed slice that contains the single `u8` bump seed, calling
/// `create_program_address`, checking that the return value is `Ok`, and
/// that the returned `Pubkey` has the expected value.
///
/// ```
/// # use solana_program::pubkey::Pubkey;
/// # let program_id = Pubkey::new_unique();
/// let (expected_pda, bump_seed) = Pubkey::find_program_address(&[b"vault"], &program_id);
/// let actual_pda = Pubkey::create_program_address(&[b"vault", &[bump_seed]], &program_id)?;
/// assert_eq!(expected_pda, actual_pda);
/// # Ok::<(), anyhow::Error>(())
/// ```
Create a valid [program derived address][pda] without searching for a bump seed.

Because this function does not create a bump seed, it may unpredictably
return an error for any given set of seeds and is not generally suitable
for creating program derived addresses.

However, it can be used for efficiently verifying that a set of seeds plus
bump seed generated by [`find_program_address`] derives a particular
address as expected. See the example for details.

See the documentation for [`find_program_address`] for a full description
of program derived addresses and bump seeds.


Create a valid [ program derived address ] [ pda ] without searching for a bump seed . Because this function does not create a bump seed it may unpredictably return an error for any given set of seeds and is not generally suitable for creating program derived addresses . However it can be used for efficiently verifying that a set of seeds plus bump seed generated by [ ` find_program_address ` ] derives a particular address as expected . See the example for details . See the documentation for [ ` find_program_address ` ] for a full description of program derived addresses and bump seeds .
pub fn create_program_address(
        seeds: &[&[u8]],
        program_id: &Pubkey,
    ) -> Result<Pubkey, PubkeyError> {
        if seeds.len() > MAX_SEEDS {
            return Err(PubkeyError::MaxSeedLengthExceeded);
        }
        for seed in seeds.iter() {
            if seed.len() > MAX_SEED_LEN {
                return Err(PubkeyError::MaxSeedLengthExceeded);
            }
        }
        // Perform the calculation inline, calling this from within a program is
        // not supported
        #[cfg(not(target_arch = "bpf"))]
        {
            let mut hasher = crate::hash::Hasher::default();
            for seed in seeds.iter() {
                hasher.hash(seed);
            }
            hasher.hashv(&[program_id.as_ref(), PDA_MARKER]);
            let hash = hasher.result();
            if bytes_are_curve_point(hash) {
                return Err(PubkeyError::InvalidSeeds);
            }
            Ok(Pubkey::new(hash.as_ref()))
        }
        // Call via a system call to perform the calculation
        #[cfg(target_arch = "bpf")]
        {
            extern "C" {
                fn sol_create_program_address(
                    seeds_addr: *const u8,
                    seeds_len: u64,
                    program_id_addr: *const u8,
                    address_bytes_addr: *const u8,
                ) -> u64;
            }
            let mut bytes = [0; 32];
            let result = unsafe {
                sol_create_program_address(
                    seeds as *const _ as *const u8,
                    seeds.len() as u64,
                    program_id as *const _ as *const u8,
                    &mut bytes as *mut _ as *mut u8,
                )
            };
            match result {
                crate::entrypoint::SUCCESS => Ok(Pubkey::new(&bytes)),
                _ => Err(result.into()),
            }
        }
    }
pub fn create_program_address ( seeds : & [ & [ u8 ] ] , program_id : & Pubkey , ) -> Result < Pubkey , PubkeyError > { if seeds . len ( ) > MAX_SEEDS { return Err ( PubkeyError :: MaxSeedLengthExceeded ) ; } for seed in seeds . iter ( ) { if seed . len ( ) > MAX_SEED_LEN { return Err ( PubkeyError :: MaxSeedLengthExceeded ) ; } } // Perform the calculation inline, calling this from within a program is // not supported # [ cfg ( not ( target_arch " " ) ) ] { let mut hasher = crate :: hash :: Hasher :: default ( ) ; for seed in seeds . iter ( ) { hasher . hash ( seed ) ; } hasher . hashv ( & [ program_id . as_ref ( ) , PDA_MARKER ] ) ; let hash = hasher . result ( ) ; if bytes_are_curve_point ( hash ) { return Err ( PubkeyError :: InvalidSeeds ) ; } Ok ( Pubkey :: new ( hash . as_ref ( ) ) ) } // Call via a system call to perform the calculation # [ cfg ( target_arch " " ) ] { extern " " { fn sol_create_program_address ( seeds_addr : * const u8 , seeds_len : u64 , program_id_addr : * const u8 , address_bytes_addr : * const u8 , ) -> u64 ; } let mut bytes = [ 0 ; 32 ] ; let result = unsafe { sol_create_program_address ( seeds as * const _ as * const u8 , seeds . len ( ) as u64 , program_id as * const _ as * const u8 , & mut bytes as * mut _ as * mut u8 , ) } ; match result { crate :: entrypoint :: SUCCESS => Ok ( Pubkey :: new ( & bytes ) ) , _ => Err ( result . into ( ) ) , } } }
Create a valid [program derived address][pda] without searching for a bump seed.
Create a valid [ program derived address ] [ pda ] without searching for a bump seed .
seeds
&[&[u8]]
program_id
&Pubkey
examples
Creating a program derived address involves iteratively searching for a
bump seed for which the derived [`Pubkey`] does not lie on the ed25519
curve. This search process is generally performed off-chain, with the
[`find_program_address`] function, after which the client passes the
bump seed to the program as instruction data.

Depending on the application requirements, a program may wish to verify
that the set of seeds, plus the bump seed, do correctly generate an
expected address.

The verification is performed by appending to the other seeds one
additional seed slice that contains the single `u8` bump seed, calling
`create_program_address`, checking that the return value is `Ok`, and
that the returned `Pubkey` has the expected value.


Creating a program derived address involves iteratively searching for a bump seed for which the derived [ ` Pubkey ` ] does not lie on the ed25519 curve . This search process is generally performed off - chain with the [ ` find_program_address ` ] function after which the client passes the bump seed to the program as instruction data . Depending on the application requirements a program may wish to verify that the set of seeds plus the bump seed do correctly generate an expected address . The verification is performed by appending to the other seeds one additional seed slice that contains the single ` u8 ` bump seed calling ` create_program_address ` checking that the return value is ` Ok ` and that the returned ` Pubkey ` has the expected value .
use solana_program::pubkey::pubkey;
None
let program_id = pubkey::new_unique();
let (expected_pda, bump_seed) = Pubkey::find_program_address(&[b"vault"], &program_id);
let actual_pda = Pubkey::create_program_address(&[b"vault", &[bump_seed]], &program_id)?;
assert_eq!(expected_pda, actual_pda).
let ( expected_pda bump_seed ) = Pubkey :: find_program_address ( & [ b " vault " ] &program_id ) ; let actual_pda = Pubkey :: create_program_address ( & [ b " vault " & [ bump_seed ]] &program_id ) ? ; assert_eq! ( expected_pda actual_pda ) .
ok::<(), anyhow::error>(())
None