11import { SolMethod } from '@metamask/keyring-api' ;
2- import { assert , literal , object } from '@metamask/superstruct' ;
3- import type { Json , JsonRpcRequest } from '@metamask/utils' ;
2+ import { assert , object } from '@metamask/superstruct' ;
3+ import type { Json } from '@metamask/utils' ;
44
55import { Network } from '../../constants/solana' ;
66import type { WalletService } from '../../services/wallet/WalletService' ;
77import type { ILogger } from '../../utils/logger' ;
88import type { SolanaKeyring } from '../onKeyringRequest/Keyring' ;
9- import type { ClientRequestUseCase } from './types' ;
10- import {
11- ClientRequestMethod ,
12- SignAndSendTransactionWithIntentParamsStruct ,
9+ import type {
10+ ClientRequestUseCase ,
11+ SignAndSendTransactionWithIntentParams ,
1312} from './types' ;
1413
1514export class SignAndSendTransactionWithIntentUseCase
16- implements ClientRequestUseCase
15+ implements ClientRequestUseCase < SignAndSendTransactionWithIntentParams >
1716{
1817 #keyring: SolanaKeyring ;
1918
@@ -36,27 +35,18 @@ export class SignAndSendTransactionWithIntentUseCase
3635 * This allows swap/bridge transactions to be executed without user confirmation
3736 * when they match a verified intent from the backend.
3837 *
39- * @param request - The JSON-RPC request containing the intent, transaction, and signature.
38+ * @param params - The validated parameters containing intent, transaction, and signature.
4039 * @returns The transaction signature if successful.
4140 */
42- async execute ( request : JsonRpcRequest ) : Promise < Json > {
41+ async execute ( params : SignAndSendTransactionWithIntentParams ) : Promise < Json > {
4342 this . #logger. log (
4443 '[SignAndSendTransactionWithIntentUseCase] execute' ,
45- request ,
44+ params ,
4645 ) ;
4746
48- const { method, params } = request ;
49-
50- assert (
51- method ,
52- literal ( ClientRequestMethod . SignAndSendTransactionWithIntent ) ,
53- ) ;
54- assert ( params , SignAndSendTransactionWithIntentParamsStruct ) ;
55-
5647 const { intent, tx, signature } = params ;
5748
58- // TODO: Implement signature verification
59- // This should verify that the backend signed the intent and transaction
49+ // Verify that the backend signed the intent (and transaction?)
6050 // to ensure the transaction came from our backend and matches the user's intent
6151 const isValidSignature = await this . #verifyBackendSignature(
6252 intent ,
@@ -68,8 +58,7 @@ export class SignAndSendTransactionWithIntentUseCase
6858 throw new Error ( 'Invalid backend signature' ) ;
6959 }
7060
71- // TODO: Implement transaction vs intent verification
72- // This should verify that the transaction actually performs the swap/bridge
61+ // Verify that the transaction actually performs the swap/bridge
7362 // described in the intent (correct amounts, assets, etc.)
7463 const transactionMatchesIntent = await this . #verifyTransactionMatchesIntent(
7564 intent ,
@@ -81,12 +70,11 @@ export class SignAndSendTransactionWithIntentUseCase
8170 }
8271
8372 // Get the user's account
84- // For now, we'll use the first account, but this should be determined
85- // based on the intent's from address
86- const account = ( await this . #keyring. listAccounts ( ) ) [ 0 ] ;
73+ // TODO: How do we know which account to use? For now, we'll use the first account
74+ const account = ( await this . #keyring. listAccounts ( ) ) [ 0 ] ; // TODO: We should move account CRUDs to an AccountService
8775 assert ( account , object ( ) ) ;
8876
89- // TODO: Determine the correct network from the intent
77+ // TODO: How do we know the correct network?
9078 // For now, defaulting to mainnet
9179 const scope : Network = Network . Mainnet ;
9280
0 commit comments