Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wallyv1/backend/src/controllers/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const login = async (req: Request, res: Response) => {

// You can use result.fid or result.data as the user identifier
const user = { id: result.fid, username: result.data?.username || '' };
if (!user.id) {
return res.status(401).json({ message: 'Invalid credentials' });
}

Expand Down
3 changes: 3 additions & 0 deletions wallyv1/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import transferRoutes from './routes/transfers';
import sessionRoutes from './routes/sessions';
import walletRoutes from './routes/walletRoutes';
import tokenRoutes from './routes/token';
import eipRoutes from './routes/eipRoutes';
import { startEventListeners } from './services/eventListenerService';
import { connectRedis } from './db/redisClient';
import { sequelize } from './db/index';
Expand Down Expand Up @@ -62,6 +63,8 @@ app.use('/api/transfers', transferRoutes);
app.use('/api/sessions', sessionRoutes);
app.use('/api/wallet', walletRoutes);
app.use('/api/token', tokenRoutes);
app.use('/api/eip7702', eipRoutes);
app.use('/api/eip5792', eipRoutes);
app.use('/sessions', sessionsRoutes);

// Start contract event listeners
Expand Down
229 changes: 229 additions & 0 deletions wallyv1/backend/src/routes/eipRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import express from 'express';
import { WallyService } from '../services/wallyService';

const router = express.Router();
const wallyService = new WallyService();

// --- EIP-7702: Temporary Contract Code Routes ---

/**
* Set temporary contract code for an EOA
* POST /api/eip7702/setTemporaryCode
*/
router.post('/setTemporaryCode', async (req, res) => {
try {
const { account, codeHash, expiresAt, nonce, signature } = req.body;

if (!account || !codeHash || !expiresAt || !nonce || !signature) {
return res.status(400).json({ error: 'Missing required parameters' });
}

const result = await wallyService.setTemporaryCode(account, codeHash, expiresAt, nonce, signature);

if (result.success) {
res.json({ success: true, transactionHash: result.transactionHash });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Reset temporary contract code
* POST /api/eip7702/resetTemporaryCode
*/
router.post('/resetTemporaryCode', async (req, res) => {
try {
const { account } = req.body;

if (!account) {
return res.status(400).json({ error: 'Missing account parameter' });
}

const result = await wallyService.resetTemporaryCode(account);

if (result.success) {
res.json({ success: true, transactionHash: result.transactionHash });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Execute with temporary contract code
* POST /api/eip7702/executeWithTemporaryCode
*/
router.post('/executeWithTemporaryCode', async (req, res) => {
try {
const { account, target, data, value } = req.body;

if (!account || !target || !data) {
return res.status(400).json({ error: 'Missing required parameters' });
}

const result = await wallyService.executeWithTemporaryCode(account, target, data, value || '0');

if (result.success) {
res.json({ success: true, transactionHash: result.transactionHash, result: result.result });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Get temporary code information
* GET /api/eip7702/getTemporaryCode/:account
*/
router.get('/getTemporaryCode/:account', async (req, res) => {
try {
const { account } = req.params;

const result = await wallyService.getTemporaryCode(account);

if (result.success) {
res.json({
success: true,
active: result.active,
codeHash: result.codeHash,
expiresAt: result.expiresAt
});
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

// --- EIP-5792: Wallet API Routes ---

/**
* Request wallet permissions (EIP-5792)
* POST /api/eip5792/wallet_requestPermissions
*/
router.post('/wallet_requestPermissions', async (req, res) => {
try {
const { account, methods, expiresAt, nonce, signature } = req.body;

if (!account || !methods || !expiresAt || !nonce || !signature) {
return res.status(400).json({ error: 'Missing required parameters' });
}

const result = await wallyService.wallet_requestPermissions(account, methods, expiresAt, nonce, signature);

if (result.success) {
res.json({ success: true, transactionHash: result.transactionHash });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Get wallet permissions (EIP-5792)
* GET /api/eip5792/wallet_getPermissions/:account
*/
router.get('/wallet_getPermissions/:account', async (req, res) => {
try {
const { account } = req.params;

const result = await wallyService.wallet_getPermissions(account);

if (result.success) {
res.json({
success: true,
methods: result.methods,
expiresAt: result.expiresAt,
active: result.active
});
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Execute transaction (EIP-5792: eth_sendTransaction)
* POST /api/eip5792/eth_sendTransaction
*/
router.post('/eth_sendTransaction', async (req, res) => {
try {
const { account, to, value, data } = req.body;

if (!account || !to) {
return res.status(400).json({ error: 'Missing required parameters' });
}

const result = await wallyService.eth_sendTransaction(account, to, value || '0', data || '0x');

if (result.success) {
res.json({ success: true, transactionHash: result.transactionHash, result: result.result });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Sign data (EIP-5792: eth_sign)
* POST /api/eip5792/eth_sign
*/
router.post('/eth_sign', async (req, res) => {
try {
const { account, dataHash } = req.body;

if (!account || !dataHash) {
return res.status(400).json({ error: 'Missing required parameters' });
}

const result = await wallyService.eth_sign(account, dataHash);

if (result.success) {
res.json({ success: true, signature: result.signature });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

/**
* Revoke wallet permissions
* POST /api/eip5792/wallet_revokePermissions
*/
router.post('/wallet_revokePermissions', async (req, res) => {
try {
const { account } = req.body;

if (!account) {
return res.status(400).json({ error: 'Missing account parameter' });
}

const result = await wallyService.wallet_revokePermissions(account);

if (result.success) {
res.json({ success: true, transactionHash: result.transactionHash });
} else {
res.status(400).json({ error: result.error });
}
} catch (err: any) {
res.status(500).json({ error: 'Internal server error', details: err.message });
}
});

export default router;
2 changes: 1 addition & 1 deletion wallyv1/backend/src/services/eventListenerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import WallyV1 from '../artifacts/WallyV1.json';
import { sessionService } from './sessionService';
import { TransferPerformedEvent, PermissionGrantedEvent, PermissionRevokedEvent, MiniAppSessionGrantedEvent, MiniAppSessionRevokedEvent } from '../db/models';
import redisClient from '../db/redisClient';
import { logInfo, logError } from '../infra/monitoring/logger
import { logInfo, logError } from '../infra/monitoring/logger';

const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const contract = new ethers.Contract(wallyv1Address, WallyV1.abi, provider);
Expand Down
2 changes: 1 addition & 1 deletion wallyv1/backend/src/services/tokenListService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { Token } from '../db/index'; // PostgreSQL Token model
import { logError } from '../infra/monitoring/logger
import { logError } from '../infra/monitoring/logger';
import { levenshtein } from '../utils/levenshtein';
import { getTokenFromPostgres } from './postgresService';

Expand Down
Loading