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

Add support for loading private key from hex string #118

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

saurabh-router
Copy link
Contributor

  • Resolves: #

Summary

This PR introduces a new function NewPrivateKeyFromHex in the private_key.go file. This function allows creating a PrivateKey instance from a hexadecimal string representation of the key.

Key changes:

  1. Added a new function NewPrivateKeyFromHex that takes a hex string and a key algorithm as input.
  2. Implemented support for both ED25519 and SECP256K1 algorithms.
  3. Improved error handling with more descriptive error messages.
  4. Ensured consistency with existing code style and patterns in the file.

Details:

  • The function uses a switch statement to handle different key algorithms.
  • It calls newly implemented NewPrivateKeyFromHex functions in the ed25519 and secp256k1 packages (added in the same commit).
  • Proper error handling is implemented for unsupported algorithms and key creation failures.
  • The public key is derived from the private key and combined with the algorithm byte.
  • The function returns a PrivateKey struct with the algorithm, public key, and private key information.

This addition enhances the flexibility of the keypair package by allowing users to create private keys from hexadecimal strings, which is a common format for storing and transmitting cryptographic keys.

Checklist

  • Code is properly formatted
  • All commits are signed
  • Tests included
  • Documentation (manuals or wiki) has been updated or is not required

@saurabh-router
Copy link
Contributor Author

@ihor could you please review this PR?

Signed-off-by: Saurabh Singh <[email protected]>
@ZhmakAS ZhmakAS merged commit ed9af41 into make-software:master Oct 4, 2024
1 check passed
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.

2 participants