/// <summary> /// Privates the key to address. /// </summary> /// <returns>The key to address.</returns> /// <param name="privateKey">Private key.</param> private string privateKeyToAddress(byte[] privateKey) { var pubKeyInBytes = Crypto.Default.ComputePublicKey(privateKey, true); var pubkey = new ECPoint(pubKeyInBytes); var accountContract = ContractFactory.CreateSinglePublicKeyRedeemContract(pubkey); return(accountContract.ScriptHash.ToAddress()); }
/// <summary> /// Creates the NEP6Account with private key. /// </summary> /// <returns>The NEP6Account</returns> /// <param name="privateKey">Private key.</param> private NEP6Account CreateAccountWithPrivateKey(byte[] privateKey, SecureString passphrase, string label = null) { var publicKeyInBytes = Crypto.Default.ComputePublicKey(privateKey, true); var publicKeyInEcPoint = new ECPoint(publicKeyInBytes); var contract = ContractFactory.CreateSinglePublicKeyRedeemContract(publicKeyInEcPoint); var account = new NEP6Account(contract) { Label = label }; account.Key = _walletHelper.EncryptWif(privateKey, passphrase); UnlockAccount(account.Key, publicKeyInEcPoint, privateKey); return(account); }
public void TestCreateSinglePublicKeyRedeemContract() { var privateKey = new byte[] { 103, 53, 97, 56, 98, 18, 129, 236, 104, 172, 110, 254, 31, 5, 142, 188, 116, 114, 216, 54, 247, 77, 151, 243, 131, 155, 198, 39, 22, 111, 56, 126 }; var publicKey = Crypto.Default.ComputePublicKey(privateKey, true); var publicKeyInEcPoint = new ECPoint(publicKey); var result = ContractFactory.CreateSinglePublicKeyRedeemContract(publicKeyInEcPoint); Assert.IsNotNull(result); Assert.AreEqual(1, result.Parameters.Length); Assert.AreEqual(ContractParameterType.Signature, result.Parameters[0]); Assert.AreEqual(ContractParameterType.Void, result.ReturnType); Assert.AreEqual(UInt160.Parse("0x0d7c041c584acea51d66f1e9bf144477ad6dca25"), result.ScriptHash); }
public void Init() { _defaultPassword = new SecureString(); _defaultPassword.AppendChar('1'); _defaultPassword.AppendChar('2'); _defaultPassword.AppendChar('3'); _defaultPassword.AppendChar('4'); _defaultPassword.AppendChar('5'); _defaultPassword.AppendChar('6'); _defaultPassword.AppendChar('7'); _defaultPassword.AppendChar('8'); _defaultPassword.AppendChar('9'); _defaultPassword.AppendChar('0'); var privateKey = Crypto.Default.GenerateRandomBytes(32); var publicKey = Crypto.Default.ComputePublicKey(privateKey, true); var publicKeyInEcPoint = new ECPoint(publicKey); _testContract = ContractFactory.CreateSinglePublicKeyRedeemContract(publicKeyInEcPoint); }
/// <summary> /// Script hash from public key. /// </summary> /// <returns>The script hash.</returns> /// <param name="publicKey">Public key.</param> public UInt160 ScriptHashFromPublicKey(ECPoint publicKey) { return(ContractFactory.CreateSinglePublicKeyRedeemContract(publicKey).ScriptHash); }