繁体   English   中英

Solana 检查地址所有权

[英]Solana check address ownership

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

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

我需要在 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);
};

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM