web3swift-team / web3swift

Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Apache License 2.0
816 stars 438 forks source link

Problem to understand how to retrieve signature #857

Open luesp15 opened 4 months ago

luesp15 commented 4 months ago

HI, having used web3.js on the web, I'm using these libraries in the hope of finding the same functions. However, I'm having trouble finding the equivalent for this code:

const hash = Web3.utils.soliditySha3(...message)
const signature = Web3.eth.accounts.sign(hash, privateKey).

My message is an array of String and Int.

I've tried with this :

let web3Rinkeby = Web3.InfuraRinkebyWeb3()
// discarded this part since I already have an address

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

let data = message.data(using: .utf8)
let ethAddress = EthereumAddress(from: address)!
let signMsg = web3Rinkeby.wallet.signPersonalMessage(data!, account: ethAddress, password: "");

But the signature I receive at the end is nil. Do you have any idea how I can do it? Considering that I already have a valid address and the privateKey.