3

I want to create an anchor PDA using the following logic:

seeds = [
    b"some-text",
    user.key().as_ref(),
    Vec<Pubkey>,
    bool
]

Is this possible? The array of pubkeys are variable in length.

If it doesn't work outright for the vector of pubkeys, one idea I had was to hash the vector of pubkeys together to produce a string in a deterministic manner.

e.g. something like:

function hashSortedConcatenatedPublicKeys(publicKeys):
    sortedKeys = sort(publicKeys)
    concatenatedKeys = ''.join(sortedKeys)
    hashOfConcatenatedKeys = sha256(concatenatedKeys)
    return hashOfConcatenatedKeys

The goal is to create a unique PDA for a group of addresses so if you think there are other methods of doing this let me know!

1 Answer 1

1

Yes, you could use a hash for that like so:

#[derive(Accounts)]
#[instruction(level_seed: String)]
pub struct InitPlayer<'info> {   
    #[account(
        init_if_needed,
        payer = signer,
        space = 10240, // 8 + all the tiles a game config
        seeds = [level_seed.as_ref()],
        bump,
    )]

But you would need to make sure somehow that only the correct people can change your PDA. Adding a signer help only to a certain degree:

signer.key().as_ref(),

because if you pass in the string for the seeds the client could just put any seed and change other accounts. Another solution could be you create an account and add all the authorities there as a vector and then check in the program if the signer is within these authorities.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.