public HDNode(ExtKey masterKey) { this._masterKey = masterKey; this.PrivateKey = masterKey.PrivateKey.ToBytes(); this.PublicKey = Secp256k1.DerivePublicKey(this.PrivateKey); this.ChainCode = masterKey.ChainCode; this.NodeType = HDNodeType.PrivateKey; }
public static string EncryptToJson(byte[] privateKey, string password) { byte[] publicKey = Secp256k1.DerivePublicKey(privateKey); string address = SimpleWallet.PublicKeyToAddress(publicKey); KeyStoreService keyStore = new KeyStoreService(); string jsonString = keyStore.EncryptAndGenerateDefaultKeyStoreAsJson(password, privateKey, address); JObject json = JObject.Parse(jsonString); json["address"] = json["address"].ToString().Replace("0x", ""); return(json.ToString()); }
public static byte[] Sign(byte[] msgHash, byte[] privatekey) { ECKey ecKey = new ECKey(privatekey, true); var sign = ecKey.Sign(msgHash); var recId = Secp256k1.CalculateRecId(ecKey, sign, msgHash); sign.V = new byte[1] { Convert.ToByte(recId) }; List <byte> signature = new List <byte>(); signature.AddRange(sign.R.ToByteArrayUnsigned()); signature.AddRange(sign.S.ToByteArrayUnsigned()); signature.AddRange(sign.V); return(signature.ToArray()); }
public static string RecoverAddress(byte[] msgHash, byte[] signature) { byte[] publickey = Secp256k1.RecoverPublickey(msgHash, signature); return(SimpleWallet.PublicKeyToAddress(publickey)); }
public byte[] Sign(byte[] msgHash) { return(Secp256k1.Sign(msgHash, this._privateKey)); }
/// <summary> /// return address starts with '0x'. /// </summary> /// <param name="priKey"></param> /// <returns></returns> public static string PrivateKeyToAddress(byte[] priKey) { byte[] pubKey = Secp256k1.DerivePublicKey(priKey); return(SimpleWallet.PublicKeyToAddress(pubKey)); }
public SimpleWallet(byte[] priKey) { this._privateKey = priKey; this._publicKey = Secp256k1.DerivePublicKey(this._privateKey); this.address = SimpleWallet.PublicKeyToAddress(this._publicKey); }