public static byte[] PublicKeyToAddressBytes(byte[] bytes) { var sha = Encoders.SHA256(bytes); var ripemd = Hash160(sha); var versioned = new byte[] { 0 }.Concat(ripemd).ToArray(); var checksum = DoubleSHA256(versioned).Take(4).ToArray(); var address = versioned.Concat(checksum).ToArray(); return(address); }
public static Wallet FromMiniKey(string miniKey) { switch (miniKey.Length) { case 22: case 30: ValidateMiniKey(miniKey); var privateKeyBytes = Encoders.SHA256(miniKey); return(new Wallet(privateKeyBytes)); default: throw new System.ArgumentException("Key must be 22 or 30 chars for minikeys"); } }
static void ValidateMiniKey(string minikey) { if (!minikey.StartsWith("S")) { throw new System.ArgumentException("Missing S Prefix"); } if (!(minikey.Length == 30 || minikey.Length == 22)) { throw new System.ArgumentException("Invalid length, must be 30 or 22 chars"); } if (Encoders.SHA256(minikey + "?")[0] != 0) { throw new System.ArgumentException("Failed to pass typo check"); } }
public static Wallet FromPassphrase(string passphrase) { var privateKeyBytes = Encoders.SHA256(Encoding.ASCII.GetBytes(passphrase)); return(new Wallet(privateKeyBytes)); }
public string Hash160(bool compressed) { return(Encoders.BytesToHex(Encoders.Hash160(Encoders.SHA256(PublicKeyBytes(compressed))))); }