Hancs
Hancs

Reputation: 83

Solana check address ownership

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

Upvotes: 0

Views: 1037

Answers (2)

DPM
DPM

Reputation: 1

To verify you control the private key of a paper wallet address, use solana-keygen verify:

solana-keygen verify prompt://

where is replaced with the wallet address and the keyword prompt:// tells the command to prompt you for the keypair's seed phrase; key and full-path query-strings accepted. Note that for security reasons, your seed phrase will not be displayed as you type. After entering your seed phrase, the command will output "Success" if the given public key matches the keypair generated from your seed phrase, and "Failed" otherwise.

Upvotes: 0

Jon C
Jon C

Reputation: 8462

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!

Upvotes: 1

Related Questions