簡體   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