In transactions/computeAddress, why do you drop the first byte after 0x? #3382
Replies: 2 comments 7 replies
-
I finally incanted the correct google search terms and came up with a stackexchange answer. The |
Beta Was this translation helpful? Give feedback.
-
Public keys come in several flavours. Raw, compressed and uncompressed. Raw are 64 bytes long and represent the padded x and y values for the public key. Uncompressed begin with a An important observation when looking at compressed keys, is that for any x, there are only two possible (canonical) y values (to simplify things, we will make some simplifying nomenclature), which means for an x the two keys are (x, y) and (x, -y), where y is dependant on x. Because of this, we can instead store just the x and a single extra bit to indicate whether to take the y or -y; so we use the All these prefixes were decided back in the day of bitcoin, so a given prefix can indicate whether something is an address, compressed public key, uncompressed public key, private key, encrypted private key, xpub, xpriv, etc. Ethereum tends to (internally) use raw keys when computing ecrecover-based things, but ethers prefers to keep keys in the standard formats (externally), which simplifies interacting with other libraries and the prefix makes it easier to detect what type of key is being used during debugging and logging. It also makes several situations non-ambiguous which would otherwise have no safe way to automatically detect what the input is. Does that make sense? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why is it necessary to drop the first byte? After retrieving the
publicKey
value fromcomputePublicKey
, I get a value of0x04f77....
. Next, you perform ahexDataSlice
to drop the04
, passing on a new0xf77....
to the keccak call.transactions/src.ts/index.ts
Where can I learn the meaning and impact of the differing lengths of a public key? I understand that all ethereum addresses are 20 bytes in length, padded to 32 bytes. But when would it be compressed or uncompressed (a re? When would it be 65 or 33?
signing-key/src.ts/index.ts
Etherjs has been a fun entrypoint into the world of cryptography, thanks alot! I'm learning OCaml and some basic cryptography + eth workings by porting ethers over to OCaml.
Beta Was this translation helpful? Give feedback.
All reactions