i want to sign message in solana-web3.js but i can't find signMessage function like the one in phantom extension
using phantom extension will give result like this:
{"signature":"5uLfqwr19GdFBUyMTPeeL3HJ9U5f9TjRzAnCkzAaCyxZgNeA3C1i6c37FjPTowZRg8WSYdwANdVVXMMkWx2Hzwoy","address":"2o6AxcaMZqcS3L8oyPhS66keuxA1FrRtrSRcRxRw4U9C"}
i found the code but this code doesn't give the same result as signMessage function of phantom wallet extension
const signMessage = (message, mnemonic) => {
// mnemonic to keypair
const seed = bip39.mnemonicToSeedSync(mnemonic);
const path = 'm/44\'/501\'/0\'/0\'';
const derivedSeed = derivePath(path, seed.toString('hex')).key;
const keyPair = Keypair.fromSeed(derivedSeed);
if (!keyPair) throw new Error('Invalid secret key')
// sign message
const address = keyPair.publicKey.toBase58()
const bufSecretKey = keyPair.secretKey
const serializedData = Buffer.from(message)
const bufSig = tweetnacl.sign(serializedData, bufSecretKey)
const signature = Buffer.from(bufSig).toString('hex')
return { signature, address}
};
the result of the above code is like this:
{"signature":"f53409d847b5eae5ef3bb892b998805d2ea04b699e39bb5c126e757d1f4023488945ba210609fb661f70c10a45fdd55db09741d5e6a8839446a91af39d4fe5044c6f67696e204368616c6c656e67653a2066613666363234342d663863352d343162642d383033372d356333396562653534396366","address":"2o6AxcaMZqcS3L8oyPhS66keuxA1FrRtrSRcRxRw4U9C"}
how do i sign like in phantom wallet extension with solana-web3.js???