diff --git a/.env.example b/.env.example index 15ccd7f..81378e1 100644 --- a/.env.example +++ b/.env.example @@ -9,10 +9,8 @@ NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS=71Jvq4Epe2FCJ7JFSF7jLXdNk1Wy4Bhqd9iL6bEFEL NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY NEXT_PUBLIC_SOLANA_TOKEN_SYMBOL=GOR NEXT_PUBLIC_MIN_SOLANA_PAYMENT_AMOUNT=400000000 # Approx. 5 USD -NEXT_PUBLIC_MIN -# UI Configuration (optional) -NEXT_PUBLIC_DOMAIN_SUFFIX=apps.vaasl.io +# UI Configuration NEXT_PUBLIC_EXAMPLE_URL=https://git.vdb.to/cerc-io/test-progressive-web-app # Server-side environment variables @@ -28,3 +26,4 @@ REGISTRY_GAS_PRICE=0.001 # Application Configuration DEPLOYER_LRN= +NEXT_PUBLIC_DOMAIN_SUFFIX= diff --git a/src/services/solana.ts b/src/services/solana.ts index 00bcfd9..90509d4 100644 --- a/src/services/solana.ts +++ b/src/services/solana.ts @@ -7,6 +7,7 @@ import { createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token'; + import { SolanaPaymentResult, SolanaWalletType, SolanaWalletState } from '../types'; assert(process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS, 'SOLANA_TOKEN_MINT_ADDRESS is required'); diff --git a/src/types/index.ts b/src/types/index.ts index 240b7c3..84d9d34 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -69,4 +69,4 @@ export interface LaconicTransferResult { success: boolean; transactionHash?: string; error?: string; -} \ No newline at end of file +} diff --git a/src/utils/solanaVerify.ts b/src/utils/solanaVerify.ts index 5f8da42..92821d7 100644 --- a/src/utils/solanaVerify.ts +++ b/src/utils/solanaVerify.ts @@ -1,8 +1,8 @@ import assert from 'assert'; import BN from 'bn.js'; -import { Connection } from '@solana/web3.js'; -import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; +import { Connection, PublicKey } from '@solana/web3.js'; +import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from '@solana/spl-token'; // Simplified transaction info extraction following reference implementation const extractTxInfo = async (connection: Connection, transactionSignature: string): Promise<{ authority: string; amount: string }> => { @@ -87,6 +87,11 @@ export const verifyUnusedSolanaPayment = async ( }; } + const expectedTokenAccount = getAssociatedTokenAddressSync( + new PublicKey(process.env.NEXT_PUBLIC_SOLANA_TOKEN_MINT_ADDRESS!), + new PublicKey(process.env.NEXT_PUBLIC_SOLANA_TOKEN_RECIPIENT_ADDRESS!) + ); + // Verify recipient address by checking the transaction instructions let foundValidTransfer = false; @@ -94,9 +99,8 @@ export const verifyUnusedSolanaPayment = async ( if ('parsed' in instruction && instruction.programId.equals(TOKEN_PROGRAM_ID)) { const parsed = instruction.parsed; if (parsed.type === 'transferChecked' || parsed.type === 'transfer') { - // TODO: Check recipient address - // Verify amount - if (parsed.info.amount === amount ) { + // Verify amount and recipient's associated token address + if (parsed.info.amount === amount && parsed.info.destination === expectedTokenAccount.toBase58() ) { foundValidTransfer = true; break; }