public void Setup() { ClientFactory factory = new ProoflessClientFactory(Chain.Mainnet); IN3 in3 = factory.CreateIn3(new string[][] { }); _wallet = (SimpleWallet)in3.Signer; }
public void TestGenerateVeChainKey() { var priKey = "0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65".ToBytes(); var vechainKey = new SimpleWallet(priKey); Assert.True(vechainKey.address == "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"); }
public void Setup() { ClientBuilder builder = new ClientBuilder(Chain.Mainnet); IN3 in3 = builder.ConstructClient(new string[][] { }); _wallet = (SimpleWallet)in3.Signer; }
private string GetDelegator() { if (!this.GetDelegated()) { return(""); } if (!this.GetSignatureValid()) { return(""); } try { byte[] signingHash = this.SigningHash(this.Origin); byte[] delegatorSignature = new byte[65]; Array.Copy(this.Signature, 65, delegatorSignature, 0, 65); byte[] delegatorpubKey = Secp256k1.RecoverPublickey(signingHash, delegatorSignature); return(SimpleWallet.PublicKeyToAddress(delegatorpubKey)); } catch { return(""); } }
public void TestPublicKeyToAddress() { var pubKey = "0x0465e790f6065164e2f610297b5358b6c474f999fb5b4d2574fcaffccb59342c1f6f28f0b684ec97946da65cd08a1b9fc276f79d90caed80e56456cebbc165938e".ToBytes(); var address = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"; Assert.True(SimpleWallet.PublicKeyToAddress(pubKey) == address); }
public async Task SendTransaction() { string[][] mockedResponses = { new[] { "eth_gasPrice", "eth_gasPrice.json" }, new[] { "eth_estimateGas", "eth_estimateGas.json" }, new[] { "eth_getTransactionCount", "eth_getTransactionCount.json" }, new[] { "eth_sendRawTransaction", "eth_sendRawTransaction.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); string expectedHash = "0xd5651b7c0b396c16ad9dc44ef0770aa215ca795702158395713facfbc9b55f38"; string pk = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; SimpleWallet sw = (SimpleWallet)in3.Signer; string from = sw.AddRawKey(pk); TransactionRequest request = new TransactionRequest { From = @from, To = "0x3940256B93c4BE0B1d5931A6A036608c25706B0c", Gas = 21000, Value = 100000000 }; object txHash = await in3.Eth1.SendTransaction(request); Assert.That(txHash, Is.EqualTo(expectedHash)); }
public void Subtract_From_Empty_Wallet() { SimpleWallet wallet = new SimpleWallet(); var exception = Assert.Throws <SubtractionFromLesserQuantityException>(() => { wallet.Subtract(10); }); Assert.That(exception.GetType() == typeof(SubtractionFromLesserQuantityException)); }
public void TestToChecksumAddress() { var address = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"; var checksumAddress = SimpleWallet.ToChecksumAddress(address); Assert.True(checksumAddress == "0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed"); }
public async Task SendTransactionAndWait() { string[][] mockedResponses = { new[] { "eth_gasPrice", "eth_gasPrice.json" }, new[] { "eth_estimateGas", "eth_estimateGas.json" }, new[] { "eth_getTransactionCount", "eth_getTransactionCount.json" }, new[] { "eth_sendRawTransaction", "eth_sendRawTransaction.json" }, new[] { "eth_getTransactionReceipt", "eth_getTransactionReceipt.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); string pk = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; SimpleWallet sw = (SimpleWallet)in3.Signer; string from = sw.AddRawKey(pk); TransactionRequest request = new TransactionRequest { From = @from, To = "0x3940256B93c4BE0B1d5931A6A036608c25706B0c", Gas = 21000, Value = 100000000 }; TransactionReceipt receipt = await in3.Eth1.SendTransactionAndWait(request); Assert.That(receipt.To, Is.EqualTo("0x5b8174e20996ec743f01d3b55a35dd376429c596")); Assert.That(receipt.Status); Assert.That(receipt.Logs[0].Address, Is.EqualTo("0x5b8174e20996ec743f01d3b55a35dd376429c596")); }
public void Subtract_From_Wallet_Result_Is_Correct(decimal initialValue, decimal finalValue, decimal result) { SimpleWallet wallet = new SimpleWallet(); wallet.Add(initialValue); wallet.Subtract(finalValue); Assert.That(result.Equals(wallet.GetBalance())); }
public void Subtract_From_Filled_Wallet_Result_Is_0() { SimpleWallet wallet = new SimpleWallet(); wallet.Add(20); wallet.Subtract(20); Assert.That(wallet.GetBalance().Equals(0)); }
public void Subtract_From_Filled_Wallet_Result_Is_Remainder() { SimpleWallet wallet = new SimpleWallet(); wallet.Add(20); wallet.Subtract(10); Assert.IsTrue(wallet.GetBalance() > 0); }
public void Negative_Add_To_Wallet() { IWallet wallet = new SimpleWallet(); var exception = Assert.Throws <NegativeAdditionException>(() => { wallet.Add(-1); }); Assert.That(exception.GetType() == typeof(NegativeAdditionException)); }
public void TestIsChecksumAddress() { var checksumAddress1 = "0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed"; var checksumAddress2 = "0x7567d83b7b8d80ADdCb281a71d54FC7B3364ffeD"; var checksumAddress3 = "hello world"; Assert.True(SimpleWallet.IsChecksumAddress(checksumAddress1)); Assert.False(SimpleWallet.IsChecksumAddress(checksumAddress2)); Assert.False(SimpleWallet.IsChecksumAddress(checksumAddress3)); }
public void TestIsValidAddress() { var address1 = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"; var address2 = "0x7567d83b7b8d80addcb2"; var address3 = "hello world"; Assert.True(SimpleWallet.IsValidAddress(address1)); Assert.False(SimpleWallet.IsValidAddress(address2)); Assert.False(SimpleWallet.IsValidAddress(address3)); }
public void OpenWallet(string path, string password) { CurrentWallet?.Dispose(); //clean up the current one, if any var simpleWallet = new SimpleWallet(LocalNode); simpleWallet.Open(path, password); _logger.LogMessage("Index Height is :" + WalletIndexer.IndexHeight); Transaction = new TransactionExecutionEngine(LocalNode); Contracts = new ContractEngine(Transaction); CurrentWallet = simpleWallet; }
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 Add_To_Wallet(decimal initialBalance, decimal additionBalance) { SimpleWallet wallet = new SimpleWallet(); wallet.Add(initialBalance); decimal walletContentsPrevious = wallet.GetBalance(); wallet.Add(additionBalance); decimal walletContentNext = wallet.GetBalance(); decimal difference = walletContentNext - walletContentsPrevious; Assert.That(difference.Equals(additionBalance)); }
public string CalculateIDWithUnsigned(string origin) { if (!SimpleWallet.IsValidAddress(origin)) { throw new ArgumentException("origin expected address"); } byte[] signingHash = this.SigningHash(); MemoryStream stream = new MemoryStream(); stream.Append(signingHash); stream.Append(origin.ToBytes()); return(Blake2b.CalculateHash(stream.ToArray()).ToHexString()); }
public void Subtract_From_Balance_Raises_Event() { SimpleWallet wallet = new SimpleWallet(); decimal walletBalance = 0; wallet.Add(10); IVendingMachineInternal machineInternal = new FakeVendingMachineInternal(); wallet.Init(machineInternal); ((IVendingMachineExternal)machineInternal).WalletValueChanged += balance => { walletBalance = balance; }; wallet.Subtract(5); Assert.That(walletBalance.Equals(5)); }
public void CreateNewWallet() { var wlt = SimpleWallet.CreateNewSimpleWallet("one", new Password("testtest"), NetworkType.Types.MAIN_NET); Assert.AreEqual("", wlt.WalletObj.PrivateKey); Assert.AreEqual("one", wlt.WalletObj.Name); Assert.AreEqual((byte)104, wlt.Network.GetNetwork()); Assert.AreEqual("one", wlt.Name); Assert.IsNotNull(wlt.WalletObj.Accounts.Account[0].Address); Assert.IsNotNull(wlt.WalletObj.Accounts.Account[0].Encrypted); Assert.IsNotNull(wlt.WalletObj.Accounts.Account[0].Iv); Assert.AreEqual("pass:bip32", wlt.WalletObj.Accounts.Account[0].Algo); Assert.AreEqual("", wlt.WalletObj.Accounts.Account[0].Child); Assert.AreEqual("Primary", wlt.WalletObj.Accounts.Account[0].Label); }
public void Add_In_Balance_Raises_Event() { //Arrange IWallet wallet = new SimpleWallet(); //Act decimal walletBalance = 0; IVendingMachineInternal machineInternal = new FakeVendingMachineInternal(); wallet.Init(machineInternal); ((IVendingMachineExternal)machineInternal).WalletValueChanged += balance => { walletBalance = balance; }; wallet.Add(10); //Assert Assert.That(walletBalance.Equals(10)); }
public void CreateNewWalletWithKey() { var wlt = SimpleWallet.CreateNewSimpleWallet("two", new Password("testtest"), "9822cf9571a5551ec19720b87a567a20797b75ec4b6711387643fc352fef704e", NetworkType.Types.MAIN_NET); Assert.AreEqual("", wlt.WalletObj.PrivateKey); Assert.AreEqual("two", wlt.WalletObj.Name); Assert.AreEqual(wlt.EncryptedPrivateKey.Decrypt(new Password("testtest")), "9822cf9571a5551ec19720b87a567a20797b75ec4b6711387643fc352fef704e"); Assert.AreEqual((byte)104, wlt.Network.GetNetwork()); Assert.AreEqual("two", wlt.Name); Assert.IsNotNull(wlt.WalletObj.Accounts.Account[0].Address); Assert.IsNotNull(wlt.WalletObj.Accounts.Account[0].Encrypted); Assert.IsNotNull(wlt.WalletObj.Accounts.Account[0].Iv); Assert.AreEqual("pass:bip32", wlt.WalletObj.Accounts.Account[0].Algo); Assert.AreEqual("", wlt.WalletObj.Accounts.Account[0].Child); Assert.AreEqual("Primary", wlt.WalletObj.Accounts.Account[0].Label); }
public void ImportWallet() { var wlt = SimpleWallet.ImportFromNanoWalletFile("eyJwcml2YXRlS2V5IjoiIiwibmFtZSI6InNpbXBsZXdhbGxldCIsImFjY291bnRzIjp7IjAiOnsiYnJhaW4iOnRydWUsImFsZ28iOiJwYXNzOmJpcDMyIiwiZW5jcnlwdGVkIjoiNTkwYzY3NWJlMzBkYzg1ZDI1MTI2MjBiMDUyNmM1ZGRiNjc1NmFkZjk4ZWJmODI3ZjdjMTI0ZTlmMTE1YTgxOTQzYjc0MWQ3MWRlNDM5NzkwMWNkYjFiOTE3YmYxZDY1IiwiaXYiOiJkNTkwYWIxNTUzNTFhYmRkOWM1MTFlOGZiNDZlZTdhOSIsImFkZHJlc3MiOiJOQ0RET1E1SDI0U1Q0NVA1SEwzSk1aSzRITlJXUFhWRkJBNVRXN0FGIiwibGFiZWwiOiJQcmltYXJ5IiwibmV0d29yayI6MTA0LCJjaGlsZCI6ImQxYWMyN2Y4NTc0Y2IxNTcxNzFmMTRiNWZkMjZlYmMxMjRlMzgzN2I0ODZkOTcyMTdjOWQ4NWFjOGFjNjMwOTkifX19", NetworkType.Types.MAIN_NET); Assert.AreEqual("", wlt.WalletObj.PrivateKey); Assert.AreEqual("simplewallet", wlt.WalletObj.Name); Assert.AreEqual("590c675be30dc85d2512620b0526c5ddb6756adf98ebf827f7c124e9f115a81943b741d71de4397901cdb1b917bf1d65", wlt.EncryptedPrivateKey.EncryptedKey); Assert.AreEqual("d590ab155351abdd9c511e8fb46ee7a9", wlt.EncryptedPrivateKey.Iv); Assert.AreEqual("9b4ed1b56be9e8106da2ef4fc681db0f9f4c22ccbad5f9bb9d3fbe68a1b20007", wlt.EncryptedPrivateKey.Decrypt(new Password("simplewallet"))); Assert.AreEqual((byte)104, wlt.Network.GetNetwork()); Assert.AreEqual("simplewallet", wlt.Name); Assert.AreEqual("NCDDOQ5H24ST45P5HL3JMZK4HNRWPXVFBA5TW7AF", wlt.WalletObj.Accounts.Account[0].Address); Assert.AreEqual("590c675be30dc85d2512620b0526c5ddb6756adf98ebf827f7c124e9f115a81943b741d71de4397901cdb1b917bf1d65", wlt.WalletObj.Accounts.Account[0].Encrypted); Assert.AreEqual("d590ab155351abdd9c511e8fb46ee7a9", wlt.WalletObj.Accounts.Account[0].Iv); Assert.AreEqual("pass:bip32", wlt.WalletObj.Accounts.Account[0].Algo); Assert.AreEqual("d1ac27f8574cb157171f14b5fd26ebc124e3837b486d97217c9d85ac8ac63099", wlt.WalletObj.Accounts.Account[0].Child); Assert.AreEqual("Primary", wlt.WalletObj.Accounts.Account[0].Label); }
private string GetOrigin() { if (!this.GetSignatureValid()) { return(""); } try { byte[] signingHash = this.SigningHash(); byte[] originSigh = new byte[65]; Array.Copy(this.Signature, 0, originSigh, 0, 65); byte[] pubKey = Secp256k1.RecoverPublickey(signingHash, originSigh); return(SimpleWallet.PublicKeyToAddress(pubKey)); } catch { return(""); } }
/// <summary> /// verify certificate signture /// </summary> /// <param name="certificate"></param> /// <returns></returns> public static bool Verify(ICertificate certificate) { const bool result = false; if (certificate.Signer == null || certificate.Signature.Length != 65) { throw new ArgumentException("invalid signature"); } try { byte[] msgHash = SigningHash(certificate); byte[] publicKey = Secp256k1.RecoverPublickey(msgHash, certificate.Signature); return(certificate.Signer.Equals(SimpleWallet.PublicKeyToAddress(publicKey))); } catch { } return(result); }
public byte[] SigningHash(string delegateFor = "") { byte[] encode = RlpCode.Encode(Transaction.UnsignedRlpDefinition(), this.Body); byte[] hash = Blake2b.CalculateHash(encode); if (delegateFor.Length != 0) { if (SimpleWallet.IsValidAddress(delegateFor)) { MemoryStream stream = new MemoryStream(); stream.Append(hash); stream.Append(delegateFor.ToBytes()); return(Blake2b.CalculateHash(stream.ToArray())); } else { throw new ArgumentException("delegateFor expected address"); } } return(hash); }
public async Task EstimateGas() { string[][] mockedResponses = { new[] { "eth_estimateGas", "eth_estimateGas.json" } }; IN3 in3 = _factory.CreateIn3(mockedResponses); string pk = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; SimpleWallet wallet = (SimpleWallet)in3.Signer; string from = wallet.AddRawKey(pk); long expectedGasEstimate = 21000; TransactionRequest tx = new TransactionRequest { GasPrice = 1, From = @from, To = "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8" }; long gasEstimate = await in3.Eth1.EstimateGas(tx, BlockParameter.Latest); Assert.That(gasEstimate, Is.EqualTo(expectedGasEstimate)); }
static async Task Main() { IN3 goerliClient = IN3.ForChain(Chain.Goerli); string myPrivateKey = "0x0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1"; string receivingAddress = "0x6FA33809667A99A805b610C49EE2042863b1bb83"; // Get the wallet, which is the default signer. SimpleWallet myAccountWallet = (SimpleWallet)goerliClient.Signer; string myAccount = myAccountWallet.AddRawKey(myPrivateKey); // Create the transaction request TransactionRequest transferWei = new TransactionRequest(); transferWei.To = receivingAddress; transferWei.From = myAccount; transferWei.Value = 300; // Get the current gas prices long currentGasPrice = await goerliClient.Eth1.GetGasPrice(); transferWei.GasPrice = currentGasPrice; long estimatedSpentGas = await goerliClient.Eth1.EstimateGas(transferWei, BlockParameter.Latest); Console.Out.WriteLine($"Estimated gas to spend: {estimatedSpentGas}"); string transactionHash = await goerliClient.Eth1.SendTransaction(transferWei); Console.Out.WriteLine($"Transaction {transactionHash} sent."); Thread.Sleep(30000); TransactionReceipt receipt = await goerliClient.Eth1.GetTransactionReceipt(transactionHash); Console.Out.WriteLine($"Transaction {transactionHash} mined on block {receipt.BlockNumber}."); }
public void TestPrivateKeyToAddress() { var priKey = "0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65".ToBytes(); Assert.True(SimpleWallet.PrivateKeyToAddress(priKey) == "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"); }