GetScatter / eos-sharp

C# client library for EOS blockchains
MIT License
75 stars 48 forks source link

Error on using generated private key #28

Closed bjornomsland closed 5 years ago

bjornomsland commented 5 years ago

Hi, I generate a keypair using

eosKeyPair = EosSharp.Core.Helpers.CryptoHelper.GenerateKeyPair();

and then create a new EOS account with the public key. This works fine.

But when I try to sign a transaction in eos-sharp I get a check-sum-error-exception. When I try to import the private key to Scatter I get "Private key not long enough".

This is an example of a private key generated that don't work: 2jTY92qynZetndq69sPif3Yp4hyBd3wduwaar7BafNUKx7K5vp

What am I doing wrong?

bjornomsland commented 5 years ago

I think I found the problem. If I use

eosKeyPair = EosSharp.Core.Helpers.CryptoHelper.GenerateKeyPair("sha256x2");

the private key is ok but the public key is wrong.

By using the code below (skipping the 'sha256x2' parameter on the public key), both private and public code are correct and can be used when creating an EOS account and import to Scatter.

var key = Secp256K1Manager.GenerateRandomKey(); var pubKey = Secp256K1Manager.GetPublicKey(key, true); string privateKey = KeyToString(key, "sha256x2"); string publicKey = KeyToString(pubKey, null, "EOS");

mmcs85 commented 5 years ago

Thanks for the bug report. fixed here: https://github.com/GetScatter/eos-sharp/commit/9ca6f4b7b30898210aa8a6e456cfd0642f9b464a