繁体   English   中英

使用用户的私钥对任何消息进行签名,并验证以太坊上的签名

[英]Sign any message with the user’s private key and verify the signature on Ethereum

我正在尝试探索以太坊并创建一个让用户签名消息并验证消息的应用程序。 我正在使用web3swift框架,到目前为止我尝试的内容如下 -

    let web3Rinkeby = Web3.InfuraRinkebyWeb3()
    let msgStr = "This is my first Ethereum App";
    let data = msgStr.data(using: .utf8)
    let signMsg = web3Rinkeby.wallet.signPersonalMessage(data!, account: address);

    print(signMsg);

但我不确定这是否正确以及如何验证任何消息。 请帮忙。

好像,您没有指定确切的地址。 这是一个例子:

let web3Rinkeby = Web3.InfuraRinkebyWeb3()

/// 
    let keystore = try! EthereumKeystoreV3(password: "")
    let keystoreManager = KeystoreManager([keystore!])
    web3Rinkeby.addKeystoreManager(keystoreManager)
    let address = keystoreManager.addresses![0]
///

let msgStr = "This is my first Ethereum App";
let data = msgStr.data(using: .utf8)
let signMsg = web3Rinkeby.wallet.signPersonalMessage(data!, account: address);

print(signMsg);

这是一个例子,如何在项目测试中签署事务:

暂无
暂无

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

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