public Task <IEnumerable <string> > Sign(string chainId, IEnumerable <string> requiredKeys, byte[] signBytes, IEnumerable <string> abiNames = null) { var data = new List <byte[]>() { Hex.HexToBytes(chainId), signBytes, new byte[32] }; var hash = Sha256Manager.GetHash(SerializationHelper.Combine(data)); return(Task.FromResult(requiredKeys.Select(key => { var sign = Secp256K1Manager.SignCompressedCompact(hash, Keys[key]); var check = new List <byte[]>() { sign, KeyTypeBytes }; var checksum = Ripemd160Manager.GetHash(SerializationHelper.Combine(check)).Take(4).ToArray(); var signAndChecksum = new List <byte[]>() { sign, checksum }; return "SIG_K1_" + Base58.Encode(SerializationHelper.Combine(signAndChecksum)); }))); }
/// <summary> /// Calculate request unique hash key /// </summary> /// <param name="url">Url to send the request</param> /// <param name="data">data sent in the body</param> /// <returns></returns> public string GetRequestHashKey(string url, object data) { var keyBytes = new List <byte[]>() { Encoding.UTF8.GetBytes(url), SerializationHelper.ObjectToByteArray(data) }; return(Encoding.Default.GetString(Sha256Manager.GetHash(SerializationHelper.Combine(keyBytes)))); }
public void VerifyKeyTypes() { var key = CryptoHelper.GenerateKeyPair(); CryptoHelper.PrivKeyStringToBytes(key.PrivateKey); CryptoHelper.PubKeyStringToBytes(key.PublicKey); var helloBytes = Encoding.UTF8.GetBytes("Hello world!"); var hash = Sha256Manager.GetHash(helloBytes); var sign = Secp256K1Manager.SignCompressedCompact(hash, CryptoHelper.GetPrivateKeyBytesWithoutCheckSum(key.PrivateKey)); var check = new List <byte[]>() { sign, Encoding.UTF8.GetBytes("K1") }; var checksum = Ripemd160Manager.GetHash(SerializationHelper.Combine(check)).Take(4).ToArray(); var signAndChecksum = new List <byte[]>() { sign, checksum }; CryptoHelper.SignStringToBytes("SIG_K1_" + Base58.Encode(SerializationHelper.Combine(signAndChecksum))); }