Skip to content

pngfi/metamask-sign-recover-pubkey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

metamask-sign-recover-pubkey

How to recover pubkey by metamask signature,

Metamask eth_getEncryptionPublicKey function cannot use

ethereum
  .request({
    method: 'eth_getEncryptionPublicKey',
    params: [accounts[0]], // you must have access to the specified account
  })

So we need get pubkey from signature

img_1.png

  const {ethereum}: any = window;
 
  // message hex
  let message = arrayify(hashMessage('generate_pubkey'));
  let 0xhex = "0x" + ua2hex(message)
  const sign = await ethereum.request({method: "eth_sign", params: [address, 0xhex]});
  const pk = signatureToPubkey(
    sign,
    Buffer.from(message)
  )

  console.log('pubkey:', pk)
  
  //pubkey : AiJbGH7xjbW7PoDClLDb3On9YgiWXQMq2cHIA1v4lfPj
  return pk;

About

how to recover pubkey by metamask signature

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published