What I want to do is use a rust crate in solana program. and a function of the rust crate will do a CPI to another program. how can I sign that CPI with the signer from the main program. Can i pass the signer as argument, can I pass signature separately, or make the crate function return transaction to the solana program and sign that transaction there?
1 Answer
When you're on-chain, signer status is propagated automatically into CPI programs as long as the instruction defines the account as a signer. For example,
- program A takes in account 1 as a signer
- create an instruction into program B in which account 1 is signer
- perform the CPI, and pass in the account info for account 1
- program B gets account 1 as a signer
You can read more about permission and CPIs in the documentation at https://docs.solana.com/developing/programming-model/calling-between-programs#instructions-that-require-privileges
To do a CPI using a dependent crate, you only need a way to create an instruction, the program, and nothing else.