Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Public Key format difference between `extractPublicKey` and `encrypt` question

Open
#239 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
typescript
Domain
cryptography

Research direction

Start by comparing the public-key representations returned by extractPublicKey and accepted by encrypt, using the example signatures and MetaMask-exported key in the issue. Done when the compatibility or required encoding conversion is established and documented, with the API behavior explained clearly.

Written by the indexing model from the issue text.

Description

Hi, probably missing something obvious and sorry to bother you but I'm trying to use the extracted public key from a personal_sign'ed message to encrypt a return message to a user... but the public key returned by extractPublicKey is a 130 byte hex-encoded string (starting with 0x4) whereas the encrypt method requires the public key be a 44 character (base64 encoded?) string. Am I missing something terribly obvious? I cannot figure out how to convert the hex-encoded to the 44 character version.

try {
      console.log("Account: ", connector.accounts[0]);
      const msg = `0x${Buffer.from("Hello World", "utf8").toString("hex")}`;
      console.log("MessageHashBytes: ", msg);
      const signature = await connector.signPersonalMessage([
        msg,
        connector.accounts[0],
      ]);
      console.log("Signature: ", signature);
      const result = recoverPersonalSignature({ data: msg, signature });
      console.log("Result: ", result);
      const publicKey = extractPublicKey({
        data: msg,
        signature
      });
      console.log('Public Key: ', publicKey)
      console.log('Public Key Length: ', publicKey.length);
      
      const questionMark = Buffer.from(publicKey).toString('base64');
      console.log('Hmm: ', questionMark, questionMark.length)
      
    } catch (error) {
      if (error instanceof Error) console.log(error.message);
    }

produces the following output:

Account:  0x0C0Bd9c93596F6FC9F7E3dd8F53EF73a6759873b
MessageHashBytes:  0x48656c6c6f20576f726c64
Signature:  0x618ebc96d5a7ea456ecbf3bc938e28a5329e1dc063ef26b94c8a8a11cfca0ff26783259b56921dec86bfa2115765624b58ce4a9799ac43f5321c2ac2b7af7f2a1c
Result:  0x0c0bd9c93596f6fc9f7e3dd8f53ef73a6759873b
Public Key:  0x4d979e20ed15805a4b9aec2d9b8dfe256a174844f20ecd26ca5a571e70907a04bbc9be04b47bdc3a73cfdfe7b5536d4bb15fec07e7d9db076816e7f80cd28200
Public Key Length:  130
Hmm:  MHg0ZDk3OWUyMGVkMTU4MDVhNGI5YWVjMmQ5YjhkZmUyNTZhMTc0ODQ0ZjIwZWNkMjZjYTVhNTcxZTcwOTA3YTA0YmJjOWJlMDRiNDdiZGMzYTczY2ZkZmU3YjU1MzZkNGJiMTVmZWMwN2U3ZDlkYjA3NjgxNmU3ZjgwY2QyODIwMA== 176

When I export my public key from metamask I receive +5ar2xujBQQPv+RTRU2tzO6sjSuTMZSosAx5NAdfkw0=

Thanks in advance anyone who can point me in the right direction! <3

Dominant language
TypeScript
Stars
584
Forks
230
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MetaMask/eth-sig-util

All issues in MetaMask/eth-sig-util

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.