public void TestRecoverAddressTest() { var priKey = "0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65".ToBytes(); var vechainKey = new SimpleWallet(priKey); var msgHash = Keccack256.CalculateHash("hello world"); var signature = Secp256k1.Sign(msgHash, priKey); var recoverAddress = SimpleWallet.RecoverAddress(msgHash, signature); Assert.True(recoverAddress == "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"); }
public void TestSecp256k1() { var priKey = Secp256k1.GeneratePrivateKey(); var pubKey = Secp256k1.DerivePublicKey(priKey); var msgHash = Keccack256.CalculateHash("hello world"); var signature = Secp256k1.Sign(msgHash, priKey); var recoveredPubKey = Secp256k1.RecoverPublickey(Keccack256.CalculateHash("hello world"), signature); Assert.True(pubKey.SequenceEqual(recoveredPubKey)); }
private byte[][] Encode(Dictionary <string, dynamic> args) { List <byte[]> topics = new List <byte[]>(); if (!this._definition.Anonymous) { topics.Add(this._definition.Sha3Signature); } foreach (var input in this._definition.inputs) { if (!input.Indexed) { continue; } if (args.ContainsKey(input.Name) && args[input.Name] == null) { topics.Add(null); } else { var arg = args[input.Name]; if (this.IsDynamicType(input.ABIType)) { if (input.ABIType == "string") { byte[] topic = Keccack256.CalculateHash(arg.ToString()); topics.Add(topic); } else { if ((arg is string) && (arg as string).IsHexString()) { byte[] topic = Keccack256.CalculateHash(arg); topics.Add(topic); } else { throw new ArgumentException(string.Format("invalid {0} value", input.ABIType)); } } } else { byte[] topic = AbiParameterCoder.EncodeParame(new AbiInputParameter(input, arg)); topics.Add(topic); } } } return(topics.ToArray()); }
private byte[][] Encode(Dictionary <string, dynamic> args) { List <byte[]> topics = new List <byte[]>(); if (!this._definition.Anonymous) { topics.Add(this._definition.Sha3Signature); } foreach (var input in this._definition.inputs) { if (!input.Indexed) { continue; } if (args.ContainsKey(input.Name) && args[input.Name] == null) { topics.Add(null); } else { var arg = args[input.Name]; if (IsDynamicType(input.ABIType)) { if (input.ABIType == "string") { byte[] topic = Keccack256.CalculateHash(arg.ToString()); topics.Add(topic); } else { if (arg is string stringArgs && stringArgs.IsHexString()) { byte[] topic = Keccack256.CalculateHash(arg); topics.Add(topic); } else { throw new ArgumentException($"invalid {input.ABIType} value"); } } }