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

Extra Zeroes In Private Key In Nethereum.Hd Wallet Class #563

Open
nathangang opened this issue Jun 25, 2019 · 5 comments
Open

Extra Zeroes In Private Key In Nethereum.Hd Wallet Class #563

nathangang opened this issue Jun 25, 2019 · 5 comments

Comments

@nathangang
Copy link

Issue tracker is ONLY used for reporting bugs. New features, questions and support should be discussed on our gitter channel first. Gitter

Expected Behavior

Private Key should always be 0x followed by 64 hex characters.

Current Behavior

Private Key is usually 64 hex characters, but for some new wallet addresses or imported seed phrases, there are 66 characters and the private key string starts with '00'. In this case, the extra 00 characters cause private key to not import in Metamask.

Possible Solution

My workaround has been to remove the extra start characters if present so that the resulting substring is 64 characters long. Not sure what is causing this within the Wallet class.

Steps to Reproduce

public string GenerateSeedPhrase()
{
var mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve);
return mnemonic.IsValidChecksum ? mnemonic.ToString() : string.Empty;
}

string seedPhrase = GenerateSeedPhrase();
var wallet = new Wallet(seedPhrase, null);
var newAccount = wallet.GetAccount(0);
string privateKeyString = newAccount.PrivateKey.Substring(2); // Sometimes this is the correct length, sometimes it starts with two extraneous 0's.

Context (Environment)

Writing a Xamarin Forms app for a crypto collectible game.

Detailed Description

Possible Implementation

@knight2008
Copy link

same issue here.
Generate new address and private key, but sometimes the private key is invalid starting with two zero.
I have new 10 address, but 4 of them are invalid.

string seeds = "scrub response inhale chuckle inhale olympic noise dismiss net tray grant come";
var wallet = new Wallet(seeds, "");
Console.WriteLine("generate private key with seeds:");
Console.WriteLine("index length private key");
for (int index = 0; index < 10; index++)
{
var account_tmp = wallet.GetAccount(index);
Console.WriteLine("{0}, {1}, {2}", index, account_tmp.PrivateKey.Length, account_tmp.PrivateKey);
}

generate private key with seeds:
index length private key
0, 66, 0x050514b9f15d9d1cebb553e34283218b3f62da8a03e8f063fd846e21cdfc8143
1, 68, 0x00dcfdc9273f78eae4551ac15343f20a2e3b713c51791ae1a0a7462085b541a662
2, 68, 0x00b2e4fc20085c2912acd50444cd9b314cc31930786837b9bc5cba17bebb9167b3
3, 66, 0x2debef3ba63d83d7eb5c1e44b5be310502476263244e10d5e0b2dae104f640f2
4, 68, 0x00ff1e7eff1340f7c6f2baa1535e4f1bc13784a36f390308f219c3dfa3ab64a302
5, 66, 0x785fb22f31f03d0a1f477f8eec537b5d4c09d01dafccc6e74bddaca1c9fdd046
6, 68, 0x009132a6ad6df016014cc9763d55cf2d79f8603486b12c861236ef219fb3fa2bcf
7, 66, 0x3007ea1589fd3f4b2e7e765c0afd402ea952b38f11841f158b572e7a7c45ec8d
8, 66, 0x2fbf69f11c42493f1508e468df65f1d2dccd2cd9601172a985f1afb6e2ed9fc6
9, 66, 0x2dc81a6054ad0cf678e578552d8b6f41b21f96ca31b6ad9bfbf3db35e47b29a1

@juanfranblanco
Copy link
Member

Hi, private keys are big integers so sometimes the byte array equivalent will include the prefix zero to indicate the sign, or in another scenarios will be prefixed with 00s as it is a smaller number.

@knight2008
Copy link

sometimes the private key is invalid due to missing two zero.
604, 64, 0x1e6263c7ff3b6dacd489c094f1a92a06db5a4b352703e10e629a1263275ac8
should be
604, 64, 0x001e6263c7ff3b6dacd489c094f1a92a06db5a4b352703e10e629a1263275ac8

so how can we get the exact valid private key from the seed?

index length private key
600, 66, 0x1756400e0bc44ef94590d4179a849a90b2a7c426b55a7979fede6cd467e43eca
601, 66, 0x25f7c9827682201f28775330a5839f78bb7648ec0d2a0a433e140d8099bc66bd
602, 66, 0x59dd483cc66b6d4c914cb5737eeec247cd7af50f25aa06f62c96fe189e7a9b44
603, 68, 0x0093dd5b691b1c467869d4ff6783366c563d07d76e6ffa3e99142970f0bebe0253
604, 64, 0x1e6263c7ff3b6dacd489c094f1a92a06db5a4b352703e10e629a1263275ac8
605, 68, 0x00a58d0c33c76883ce36d9dee862c781cbb83afc48482d138d59e83d054b222c4b
606, 68, 0x00faca66040b521d221ac722745b0f2ab9d4dea2240acd88eae4290a355efc43b5
607, 66, 0x05a6e5f727f6b0ef1fd193ae7217c0d09c8873f4132b82c70eb3ada491d6f861
608, 66, 0x37e9c1bad7acc9bff01ea4722eda4bb37e41ce4dba6cb987e3354cac8efb10a8
609, 66, 0x06e3d6fdaaab788ab1a08ab81e8db867e37fa460cc8310f8bf14cf8c2d1ab7da

@juanfranblanco
Copy link
Member

What do yo mean by invalid? When you use the private key can you get the same address and sign? Or you mean for external usage.

@knight2008
Copy link

i.e.: I use this private key and import it to MetaMask or MEW online. but it does not work, the MM report invalid private key.

603, 68, 0x0093dd5b691b1c467869d4ff6783366c563d07d76e6ffa3e99142970f0bebe0253

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

No branches or pull requests

3 participants