suiet / wallet-kit

The first choice to connect all wallets on Sui blockchain
https://kit.suiet.app
MIT License
159 stars 57 forks source link

How to verify signMessage in golang?please give me a suggestion #257

Closed noterrible closed 6 months ago

noterrible commented 12 months ago
import {useWallet} from '@suiet/wallet-kit'
import * as tweetnacl from 'tweetnacl'

function App() {
  const wallet = useWallet();

  async function handleSignMsg() {
    try {
      const msg = 'Hello world!'
      // convert string to Uint8Array 
      const msgBytes = new TextEncoder().encode(msg)

      // call wallet's signMessage function
      const result = await wallet.signMessage({
        message: msgBytes
      })
            // verify signature with publicKey and SignedMessage (params are all included in result)
      const verifyResult = await wallet.verifySignedMessage(result, wallet.account.publicKey)
      if (!verifyResult) {
        console.log('signMessage succeed, but verify signedMessage failed')
      } else {
        console.log('signMessage succeed, and verify signedMessage succeed!')
      }
    } catch (e) {
      console.error('signMessage failed', e)
    }
  }

  return (
    <button onClick={handleSignMsg}> Sign Message </button>
  )
}

前端可以使用 wallet.signMessage签名消息,再使用wallet.verifySignedMessage进行验证。那么我在go中,如何验证wallet.signMessage的结果。其中前端使用了wallet.signMessage给我的result,result包含如下:

"message": "Hello world!",
"signature":"ACgj38Kr1bJU74jxiHPTDIIcxr9UG6WftgWol9iF6I3ai1NRWuob603NazIdJJ0qhP8U5yA67FbYbZb59dbqygK1rQTxoTF1RH+j0mc5ILiRdAW2jX2OKecqYuDbBFN0NQ=="
noterrible commented 12 months ago

The Front-end Developmentcan use wallet.signMessage to sign a message and then use wallet.verifySignedMessage to verify it. So, how can I verify the result of wallet.signMessage in Go?The message and signature are the content returned by calling the wallet.signMessage function.

bruceeewong commented 8 months ago

So basically you could re-implement the logic of verifySignedMessage in Go for verifying signatures from mnemonic or privatekey-based wallets. For zk signatures, we have to rely on on-chain verifications for its complexity.

bruceeewong commented 6 months ago

Closed due to a long period of inactivity