diff --git a/src/client.ts b/src/client.ts deleted file mode 100644 index 8ffc4765..00000000 --- a/src/client.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Buffer } from 'node:buffer'; -import { sign } from '@noble/ed25519'; -import { Connection, Keypair, PublicKey, SystemProgram, Transaction, TransactionInstruction, sendAndConfirmTransaction } from '@solana/web3.js'; - -export async function createCustodialTransfer( - connection: Connection, - payer: Keypair, - programId: PublicKey, - custodialAccount: PublicKey, - recipient: PublicKey, - amount: number, - signerKeypair: Keypair, -) { - // Message to sign - const message = Buffer.from(`Transfer ${amount} lamports to ${recipient.toBase58()}`); - - // Sign the message with Ed25519 - const signatureBytes = await sign(message, signerKeypair.secretKey.slice(0, 32)); - - // Create instruction data - const instructionData = Buffer.concat([Buffer.from(signatureBytes), Buffer.from(signerKeypair.publicKey.toBytes()), message]); - - const instruction = new TransactionInstruction({ - keys: [ - { pubkey: custodialAccount, isSigner: false, isWritable: true }, - { pubkey: recipient, isSigner: false, isWritable: true }, - { pubkey: signerKeypair.publicKey, isSigner: true, isWritable: false }, - { - pubkey: new PublicKey('Ed25519SigVerify111111111111111111111111111'), - isSigner: false, - isWritable: false, - }, - ], - programId, - data: instructionData, - }); - - const transaction = new Transaction().add(instruction); - - const txSignature = await sendAndConfirmTransaction(connection, transaction, [payer, signerKeypair]); - - return txSignature; -} - -// Example usage -async function main() { - const connection = new Connection('http://localhost:8899', 'confirmed'); - const payer = Keypair.generate(); - const programId = new PublicKey('Your_Program_ID'); - const custodialAccount = new PublicKey('Custodial_Account_Address'); - const recipient = new PublicKey('Recipient_Address'); - const amount = 1000000; // lamports - const signerKeypair = Keypair.generate(); - - try { - const signature = await createCustodialTransfer(connection, payer, programId, custodialAccount, recipient, amount, signerKeypair); - console.log('Transaction signature:', signature); - } catch (error) { - console.error('Error:', error); - } -} diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index d9335d61..00000000 --- a/src/lib.rs +++ /dev/null @@ -1,66 +0,0 @@ -use solana_program::{ - account_info::{next_account_info, AccountInfo}, - entrypoint, - entrypoint::ProgramResult, - msg, - program_error::ProgramError, - pubkey::Pubkey, - ed25519_program, -}; - -entrypoint!(process_instruction); - -pub fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], - instruction_data: &[u8], -) -> ProgramResult { - let accounts_iter = &mut accounts.iter(); - - // Get account info - let custodial_account = next_account_info(accounts_iter)?; - let recipient = next_account_info(accounts_iter)?; - let signer = next_account_info(accounts_iter)?; - let ed25519_program_id = next_account_info(accounts_iter)?; - - // Verify this is the expected Ed25519 program - if ed25519_program_id.key != &ed25519_program::id() { - return Err(ProgramError::InvalidArgument); - } - - // First 64 bytes are the signature - let signature = &instruction_data[..64]; - // Next 32 bytes are the public key - let public_key = &instruction_data[64..96]; - // Remaining data is the message to verify - let message = &instruction_data[96..]; - - // Verify the Ed25519 signature - let verification_instruction = ed25519_program::instruction::new_ed25519_instruction( - public_key, - message, - signature, - ); - - // Invoke the Ed25519 program to verify the signature - solana_program::program::invoke( - &verification_instruction, - &[ed25519_program_id.clone()], - )?; - - // If we get here, the signature was verified successfully - msg!("Signature verification successful!"); - - // Transfer funds from custodial account to recipient - **custodial_account.try_borrow_mut_lamports()? = custodial_account - .lamports() - .checked_sub(amount) - .ok_or(ProgramError::InsufficientFunds)?; - - **recipient.try_borrow_mut_lamports()? = recipient - .lamports() - .checked_add(amount) - .ok_or(ProgramError::Overflow)?; - - Ok(()) -} \ No newline at end of file