Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate secp256k1 private key #483

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

leovct
Copy link
Member

@leovct leovct commented Jan 22, 2025

Description

Main feature

Generate an Secp256k1 nodekey from a private key (in hex format).

polycli nodekey --private-key 2a4ae8c4c250917781d38d95dafbb0abe87ae2c9aea02ed7c7524685358e49c2 --key-type secp256k1 | jq
{
  "address": "99AA9FC116C1E5E741E9EC18BD1FD232130A5C44",
  "pub_key": {
    "type": "comet/PubKeySecp256k1Uncompressed",
    "value": "BBNYN0nMJsgo0Fp3kVW85PRGBNe7Gdz1XBFuTWQ7D8FnKRb2JYO3i3FK2UiA5+gTSxYu1K66KdYjQYP1mOkH09g="
  },
  "priv_key": {
    "type": "comet/PrivKeySecp256k1Uncompressed",
    "value": "OP72E0D7GEi/4VySpolVudLW7uPJm+6PWEtFKJmvp1M="
  }
}

Most of the logic has been copy/pasted from 0xPolygon/cometbft's fork (scep256k1 package). Indeed, it's not possible to import the package yet because go.mod declares its path as github.com/cometbft/cometbft instead of github.com/0xpolygon/cometbft. Unfortunately, the logic will need to be updated to support new versions. For now, we support the latest polygon's cometbft relase.

Minor

Allow passing an hex encoded private key from the command line to generate a node key.

polycli nodekey --private-key 2a4ae8c4c250917781d38d95dafbb0abe87ae2c9aea02ed7c7524685358e49c2 | jq
{
  "PublicKey": "93e8717f46b146ebfb99159eb13a5d044c191998656c8b79007b16051bb1ff762d09884e43783d898dd47f6220af040206cabbd45c9a26bb278a522c3d538a1f",
  "PrivateKey": "2a4ae8c4c250917781d38d95dafbb0abe87ae2c9aea02ed7c7524685358e49c2",
  "ENR": "enode://93e8717f46b146ebfb99159eb13a5d044c191998656c8b79007b16051bb1ff762d09884e43783d898dd47f6220af040206cabbd45c9a26bb278a522c3d538a1f@0.0.0.0:30303?discport=0"
}

Jira / Linear Tickets

x

Testing

x

@leovct leovct changed the title feat: nodekey input file feat: generate heimdall-v2 priv validator key file Jan 22, 2025
@leovct leovct changed the title feat: generate heimdall-v2 priv validator key file feat: generate secp256k1 private key Jan 22, 2025
@leovct leovct marked this pull request as ready for review January 22, 2025 18:04
Copy link

@ARR552 ARR552 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think It would be nice to add unit tests to this functions

go.mod Show resolved Hide resolved
Copy link
Contributor

@rebelArtists rebelArtists left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, looks need to rebase tho

@leovct leovct merged commit df38375 into 0xPolygon:main Jan 28, 2025
6 checks passed
@leovct leovct deleted the feat/nodeKey-input-file branch January 28, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants