Metamask: Got different Public keys from same Private key. `eth-crypto`’s `recoverPublicKey()` and MetaMask’s `eth_getEncryptionPublicKey`

Metamask: Got different Public keys from same Private key. `eth-crypto`’s `recoverPublicKey()` and MetaMask’s `eth_getEncryptionPublicKey`

Understanding the difference in public keys made of metamask and Ethereum

Metamask: Got different Public keys from same Private key. `eth-crypto`'s `recoverPublicKey()` and MetaMask's `eth_getEncryptionPublicKey`

As Ethereum developers, we are not foreigners for little interactions with Ethereum blockchain. Recently, several users are confused by deviating between public keys shown on their wallet wallet and those retrieved by the eth_getencryptipublic 'RPC Call.

Question: Different public keys from the same private key

Let's dive into the details of what is happening. When we useeth_getencryplpublexy ‘, it requires a public encryption key to the default address of the Ethereum account. However, this public key is calculated on the basis of a private key stored in a metamic. Here’s why:

* Private Key: Private key used to create an Ethereum wallet is unique to each individual.

* Calculation of public key: When you take on your public key using eth_getencryptionpublisckey ', is not directly connected to your private key. Instead, it uses a different calculation method, which generates a new set of keys (public and private) on the basis of a common secret between your wallet Metamascus and Ethereum blockchain.

* Common Secret: This common secret is used to get a public key from a private key.

Solution:Recowcublexy ()Vs.eth_getencryptionPubliscney ‘

To solve this problem, you can use any of the two methods:

  • RECOVEPUBLICKEY ():

* You can call Recowcpubliscney () on your wallet your metamascus wallet to download the public key associated with a particular Ethereum address.

* This method provides a private key that uses metamask and allows you to make a public key from it.

  • eth_getencryplpublisckey (Rpc):

* You can use eth_getencryplpublexy as before to download a public boat key for your Ethereum account address.

* However, keep in mind that this will restore a different set of keys than if you used Recowcublexy ().

Example code: Return of a public key with a metamascus Recowcublexy ()

`Javascript

Const Web3 = required (‘web3’);

Const Metamascus = New Web3 (new web3.Providers.httpprovider (‘

Metamask.getaccounts (). Then (accounts => {

Const Publicky = Accounts [0] .Getpublkyy ();

// Recovery of a private key using a Metamascus reCoublickey method

Return metamask.recoverpublisckey (Publickey);

});

`

Conclusion:

The deviation between public keys shown on your wallet and those retrieved byeth_getencryplpublckeyRPC calls RPC can be resolved by using or Recarpubliscney () `or ‘Eth_getencryplpublyckey’. By understanding how Ethereum addresses, private keys and common secrets work together, you will be better equipped to move in these complex interactions.

If you have any questions or you need a further clarification of this topic, feel free to ask!

Ethereum Undefined Reading

No Comments

Post A Comment