@@ -225,9 +225,14 @@ export const verifyOneTimePayment = async (params: {
225225 } ;
226226} ;
227227
228+ const APPROVE_DELEGATE_DISCRIMINATOR = Buffer . from ( [
229+ 68 , 6 , 248 , 64 , 195 , 222 , 182 , 223 ,
230+ ] ) ;
231+
228232export const verifyDelegationTransaction = async ( params : {
229233 txSignature : string ;
230234 expectedPayerWallet : string ;
235+ subscriptionId : string ;
231236} ) : Promise < { valid : boolean ; reason ?: string } > => {
232237 const { connection } = initializeSolana ( ) ;
233238
@@ -242,14 +247,20 @@ export const verifyDelegationTransaction = async (params: {
242247 const programIdStr = PROGRAM_ID . toBase58 ( ) ;
243248 const instructions = tx . transaction . message . instructions ;
244249
245- const programInvoked = instructions . some (
246- ( ix ) => ix . programId . toBase58 ( ) === programIdStr ,
247- ) ;
250+ const approveDelegateInvoked = instructions . some ( ( ix ) => {
251+ if ( ix . programId . toBase58 ( ) !== programIdStr ) return false ;
252+ if ( ! ( "data" in ix ) ) return false ;
253+ const decoded = Buffer . from ( anchor . utils . bytes . bs58 . decode ( ix . data as string ) ) ;
254+ return decoded
255+ . subarray ( 0 , 8 )
256+ . equals ( APPROVE_DELEGATE_DISCRIMINATOR ) ;
257+ } ) ;
248258
249- if ( ! programInvoked ) {
259+ if ( ! approveDelegateInvoked ) {
250260 return {
251261 valid : false ,
252- reason : "Transaction did not invoke the PattPay program" ,
262+ reason :
263+ "Transaction did not invoke the approve_delegate instruction on the PattPay program" ,
253264 } ;
254265 }
255266
@@ -264,6 +275,21 @@ export const verifyDelegationTransaction = async (params: {
264275 } ;
265276 }
266277
278+ const payerPubkey = new PublicKey ( params . expectedPayerWallet ) ;
279+ const { delegateApprovalPDA } = derivePDAs (
280+ params . subscriptionId ,
281+ payerPubkey ,
282+ ) ;
283+ const accountInfo = await connection . getAccountInfo ( delegateApprovalPDA ) ;
284+
285+ if ( accountInfo === null ) {
286+ return {
287+ valid : false ,
288+ reason :
289+ "DelegateApproval PDA does not exist on-chain, delegation not confirmed" ,
290+ } ;
291+ }
292+
267293 return { valid : true } ;
268294} ;
269295
0 commit comments