0

solana web3js 中是否有任何方法可以检查地址所有权?

例如,在 ETH 中,我使用 PK 签署消息,然后使用消息和签名恢复地址。如果我正在检查的地址等于恢复功能的地址,我知道签署消息的人拥有特定地址。

我需要在 solana 中实现相同的功能。

谢谢您的帮助。

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

4

1 回答 1

1

Solana 使用 Ed25519 曲线进行加密,基于快速搜索,不能保证具有此公钥恢复属性。这是我能找到的最好的解释:https ://crypto.stackexchange.com/questions/9936/what-signature-schemes-allow-recovering-the-public-key-from-a-signature#9939

也许密码学专家可以提供更多信息!

于 2022-01-24T23:00:32.163 回答