public string GenerateAddress(Wallet wallet) { if (wallet.Secret == null || wallet.Secret.Length == 0) { wallet.Secret = _secrets.GenerateSecret(wallet); } // Generate next seed based on the first secret or a new secret from the last key pair var lastKeyPair = wallet.KeyPairs.LastOrDefault(); var seed = lastKeyPair == null ? wallet.Secret : PasswordUtil.FastHash( Encoding.UTF8.GetString(lastKeyPair.PrivateKey), Constants.DefaultFixedSalt16); var keyPair = Ed25519.GenerateKeyPairFromSecret(seed); var newKeyPair = new KeyPair( wallet.KeyPairs.Count + 1, keyPair.Item1, keyPair.Item2 ); wallet.KeyPairs.Add(newKeyPair); return(newKeyPair.PublicKey.ToHex()); }
public byte[] GenerateSecret(params object[] args) { var wallet = args.FirstOrDefault() as Wallet; Contract.Assert(wallet != null); Contract.Assert(!string.IsNullOrWhiteSpace(wallet.PasswordHash)); wallet.Secret = PasswordUtil.FastHash(wallet.PasswordHash, "salt"); return(wallet.Secret); }