简体   繁体   English

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

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

I'm trying to explore Ethereum and creating a app which let user sign message and validate the message. 我正在尝试探索以太坊并创建一个让用户签名消息并验证消息的应用程序。 I'm using web3swift framework for this and what I have tried so far is as follows - 我正在使用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);

but I'm not sure if this is right and how to validate any message as well. 但我不确定这是否正确以及如何验证任何消息。 Please help. 请帮忙。

Seems, that you didn't specify exact address. 好像,您没有指定确切的地址。 Here is an example: 这是一个例子:

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

Here is an example, how to sign transactions in the tests of the project : 这是一个例子,如何在项目测试中签署事务:

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

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