is there in solana web3js any way how to check address ownership?
For example in ETH I sign a message with PK and then recover the address with message and signiture. If the address which I am checking equals to the address from recover function I know that the person who sign the message owns the specific address.
I need to make same functionality in solana.
Thank you for your help.
import Accounts from "web3-eth-accounts";
/**
* Check address ownership by signed message
*
* @param {string} address address to check ownership
* @param {string} message message signed by address private key
* @param {string} sign message sign
* @returns true if message was signed with this address private key, false otherwise
*/
export const checkAddressOwnership = (address, message, sign) => {
const accounts = new Accounts();
const recoveredAddress = accounts.recover(message, sign);
return address.toLowerCase() === recoveredAddress.toLowerCase();
};
/**
* Sign message with address private key
*
* @param {string} message message to sign
* @param {string} privateKey private key
* @returns signed message
*/
export const signMessage = (message, privateKey) => {
const accounts = new Accounts();
return accounts.sign(message, privateKey);
};