0

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);
};

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
Hancs
  • 83
  • 4

1 Answers1

1

Solana uses the Ed25519 curve for its crypto, which, based on a quick search, is not guaranteed to have this public key recovery property. This is the best explanation I've been able to find: https://crypto.stackexchange.com/questions/9936/what-signature-schemes-allow-recovering-the-public-key-from-a-signature#9939

Perhaps a cryptography expert can give more information!

Jon C
  • 7,019
  • 10
  • 17