4

What is the algorithm to produce a bootnode's enode url ?

For example, I have this data:

Node key:  59233b25bfa4c214a8713e07a395a5d11478de10f36c6c80ba5369541f73bc44
IP: 127.0.0.1
Port: 30303

From these 3 fields how do I create the enode url ? What is the process?

10

On a practical front, you can generate the Enode from the node key using Geth's bootnode utility:

> /usr/local/bin/bootnode -nodekeyhex 59233b25bfa4c214a8713e07a395a5d11478de10f36c6c80ba5369541f73bc44 -writeaddress
c636515b084e5dcfb39c0e00e3d0dd5b5c4ba7c04d9a4adc3aad4eea6ab25561f0fa09fce119e2aebdcfa34d02a3c8f551b814e31df6940fa937f16e0624fc40

The enode URL is then constructed like this:

enode://ENODE@IP:PORT

I.e. enode://c636515b084e5dcfb39c0e00e3d0dd5b5c4ba7c04d9a4adc3aad4eea6ab25561f0fa09fce119e2aebdcfa34d02a3c8f551b814e31df6940fa937f16e0624fc40@127.0.0.1:30303


If you want to know the actual calculation, the source code from Geth works as follows.

bootnode executes this line to process the input nodeKeyHex from the command line parameter into nodeKey:

nodeKey, err = crypto.HexToECDSA(*nodeKeyHex)

After this, nodeKey.PublicKey is the Public Key (which is the enode) generated from the Private Key (which is the node key) using this function:

func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
    priv := new(ecdsa.PrivateKey)
    priv.PublicKey.Curve = S256()
    if strict && 8*len(d) != priv.Params().BitSize {
        return nil, fmt.Errorf("invalid length, need %d bits", priv.Params().BitSize)
    }
    priv.D = new(big.Int).SetBytes(d)
    priv.PublicKey.X, priv.PublicKey.Y = priv.PublicKey.Curve.ScalarBaseMult(d)
    return priv, nil
}
  • 1
    never thought the keys of the nodes are private. thanks! – Nulik Oct 21 '17 at 21:48
  • 1
    Yes - if you need to (re)generate the enode, you can read the nodekey in from a file with the -nodekey flag to bootnode. This is a bit more secure (the nodekey won't appear in your shell history). – benjaminion Oct 21 '17 at 21:51
  • If one is curious about the process of creating the public key from the private key (aka nodeKeyHex), its documented here (maximintegrated.com/en/app-notes/index.mvp/id/5767) – shark8me Apr 25 '18 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.