protection against replay attack

This commit is contained in:
Jincheng Lu 2025-12-03 03:19:58 +08:00
parent bca2b75ed4
commit 582312e727
2 changed files with 25 additions and 11 deletions

View File

@ -24,8 +24,6 @@ export const signMessage = async (message: string,provider: EIP1193Provider,user
params: [msg, userAccount], params: [msg, userAccount],
}) })
console.log("Encoded Public Key: ", msg);
return sig; return sig;
} catch (err) { } catch (err) {
console.error(err) console.error(err)

View File

@ -20,23 +20,39 @@ interface Node {
} }
function NodeItem({node}: {node: Node}) { function NodeItem({node}: {node: Node}) {
const port = 8080;
const { auth } = useAuth(); const { auth } = useAuth();
const [ratingOpen, setRatingOpen] = React.useState(false); const [ratingOpen, setRatingOpen] = React.useState(false);
const [ratingValue, setRatingValue] = React.useState<number | null>(null); const [ratingValue, setRatingValue] = React.useState<number | null>(null);
const [submittingRating, setSubmittingRating] = React.useState(false); const [submittingRating, setSubmittingRating] = React.useState(false);
const connect = async ({ip}: {ip: string}) => { const getUrl = () => `http://${node.ip}:${port}`;
const publicKey = await getPublicKey(auth.providerWithInfo.provider, auth.accounts[0]); const connect = async () => {
const sig = await signMessage("H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=",auth.providerWithInfo.provider, auth.accounts[0]); // const publicKey = await getPublicKey(auth.providerWithInfo.provider, auth.accounts[0]);
try { try {
const res_string = publicKey + '\n' + sig; const iv = await axios.get(getUrl() + "/connect");
let response = await axios.post('http://' + ip + ":8080/connect", res_string); console.log(iv.data);
console.log(response.data); // Log the response from the server
const sig = await signMessage(iv.data + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=",auth.providerWithInfo.provider, auth.accounts[0]);
const res_string = iv.data + '\n' + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=" + '\n' + sig;
let response = await axios.post(getUrl() + "/connect", res_string);
console.log(response.data);
} catch (error) { } catch (error) {
console.error('Error:', error); console.error('Error:', error);
} }
} }
const disconnect = ({ip}: {ip: string}) => { const disconnect = async () => {
try{
const iv = await axios.get(getUrl() + "/disconnect");
console.log(iv.data);
const sig = await signMessage(iv.data,auth.providerWithInfo.provider, auth.accounts[0]);
const res_string = iv.data + '\n' + sig;
let response = await axios.post(getUrl() + "/disconnect", res_string);
console.log(response.data);
} catch (error) {
console.error('Error:', error);
}
setRatingOpen(true); setRatingOpen(true);
} }
@ -124,14 +140,14 @@ function NodeItem({node}: {node: Node}) {
size="small" size="small"
> >
<Button <Button
onClick={() => disconnect({ip: node.ip})} onClick={() => disconnect()}
color="error" color="error"
variant="outlined" variant="outlined"
> >
Disconnect Disconnect
</Button> </Button>
<Button <Button
onClick={() => connect({ip: node.ip})} onClick={() => connect()}
color="primary" color="primary"
> >
Connect Connect