使用用户的私钥对任何消息签名,然后在以太坊上验证签名

时间:2018-09-22 09:11:32

标签: ios swift ethereum web3swift

我正在尝试探索以太坊,并创建一个允许用户签名消息并验证消息的应用程序。 我为此使用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);

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

1 个答案:

答案 0 :(得分:0)

似乎您未指定确切地址。 这是一个示例:

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

下面是一个示例,说明如何在tests of the project中签署交易: