improved signing

This commit is contained in:
Jincheng Lu
2025-11-21 19:39:15 +08:00
parent afbb627c89
commit 4bfd6781aa
3 changed files with 21 additions and 21 deletions
+4 -3
View File
@@ -11,9 +11,10 @@ export const signMessage = async (provider: EIP1193Provider,userAccount: string)
method: 'eth_getEncryptionPublicKey',
params: [userAccount],
})
const bytes = new TextEncoder().encode(String(publicKey));
const msg = '0x' + Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
// const bytes = new TextEncoder().encode(String(publicKey));
// const msg = '0x' + Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
const msg = `0x${Buffer.from(String(publicKey), "utf8").toString("hex")}`
const sign = await provider.request({
method: "personal_sign",
params: [msg, userAccount],
+2 -3
View File
@@ -22,10 +22,9 @@ function NodeItem({node}: {node: Node}) {
const connect = async ({ip}: {ip: string}) => {
const res = await signMessage(auth.providerWithInfo.provider, auth.accounts[0]);
try {
let response = await axios.post('http://' + ip + ":8080/connect", res?.publicKey);
const res_string = res?.publicKey + '\n' + res?.sign;
let response = await axios.post('http://' + ip + ":8080/connect", res_string);
console.log(response.data); // Log the response from the server
// response = await axios.post('http://' + ip + ":8080/connect", res?.sign);
// console.log(response.data); // Log the response from the server
} catch (error) {
console.error('Error:', error);
}