Beispiel #1
0
    static void Main()
    {
        //var privKey = EthECKey.GenerateKey();
        var privKey = new EthECKey("97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a");

        byte[] pubKeyCompressed = new ECKey(privKey.GetPrivateKeyAsBytes(), true).GetPubKey(true);
        Console.WriteLine("Private key: {0}", privKey.GetPrivateKey().Substring(4));
        Console.WriteLine("Public key: {0}", privKey.GetPubKey().ToHex().Substring(2));
        Console.WriteLine("Public key (compressed): {0}", pubKeyCompressed.ToHex());

        Console.WriteLine();

        string msg = "Message for signing";

        byte[] msgBytes  = Encoding.UTF8.GetBytes(msg);
        byte[] msgHash   = new Sha3Keccack().CalculateHash(msgBytes);
        var    signature = privKey.SignAndCalculateV(msgHash);

        Console.WriteLine("Msg: {0}", msg);
        Console.WriteLine("Msg hash: {0}", msgHash.ToHex());
        Console.WriteLine("Signature: [v = {0}, r = {1}, s = {2}]",
                          signature.V[0] - 27, signature.R.ToHex(), signature.S.ToHex());

        Console.WriteLine();

        var pubKeyRecovered = EthECKey.RecoverFromSignature(signature, msgHash);

        Console.WriteLine("Recovered pubKey: {0}", pubKeyRecovered.GetPubKey().ToHex().Substring(2));

        bool validSig = pubKeyRecovered.Verify(msgHash, signature);

        Console.WriteLine("Signature valid? {0}", validSig);
    }
Beispiel #2
0
 private void Initialise(EthECKey key)
 {
     PrivateKey = key.GetPrivateKey();
     Address    = key.GetPublicAddress();
     PublicKey  = key.GetPubKey().ToHex();
     InitialiseDefaultTransactionManager();
 }
Beispiel #3
0
        public void SharedSecretECDHImportTest()
        {
            EthECKey ecKey1 = EthECKey.GenerateKey();
            EthECKey ecKey2 = EthECKey.GenerateKey();

            ECDH_Key alice = ECDH_Key.ImportKey(ecKey1.GetPrivateKey());
            ECDH_Key bob   = ECDH_Key.ImportKey(ecKey2.GetPrivateKey());

            var ecPubKey1 = ecKey1.GetPubKey().ToHex(true);
            var ecPubKey2 = ecKey2.GetPubKey().ToHex(true);

            var shared1 = alice.GenerateSharedSecretHex(bob.PublicKey);
            var shared2 = bob.GenerateSharedSecretHex(alice.PublicKey);

            Assert.Equal(shared1, shared2);
        }
        public static JsonWebKey ToJsonWebKey(
            this EthECKey ecKey)
        {
            var privateKey = ecKey.GetPrivateKeyAsBytes();
            var publicKey  = ecKey.GetPubKey();

            var ecParameters = new ECParameters
            {
                Curve = "SECP256K1",
                D     = privateKey,
                X     = publicKey.Slice(1, 33),
                Y     = publicKey.Slice(33, 65)
            };

            return(new JsonWebKey(ecParameters));
        }
Beispiel #5
0
        public void SharedSecretGenerationBasedOnEthKeyImportTest()
        {
            EthECKey  ecKey1 = EthECKey.GenerateKey();
            EthECKey  ecKey2 = EthECKey.GenerateKey();
            X25519Key alice  = X25519Key.ImportKey(ecKey1.GetPrivateKey());
            X25519Key bob    = X25519Key.ImportKey(ecKey2.GetPrivateKey());

            var s1 = alice.GenerateSharedSecretHex(ecKey2.GetPubKey().ToHex(true));
            var s2 = bob.GenerateSharedSecretHex(ecKey1.GetPubKey().ToHex(true));

            var shared1 = alice.GenerateSharedSecretHex(bob.PublicKey);
            var shared2 = bob.GenerateSharedSecretHex(alice.PublicKey);

            Assert.Equal(shared1, shared2);

            testOutputHelper.WriteLine(shared1);
            testOutputHelper.WriteLine(shared2);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            EthECKey keyPair = EthECKey.GenerateKey();

            Console.WriteLine("private key =>" + keyPair.GetPrivateKey());
            Console.WriteLine("public key=>" + keyPair.GetPubKey().ToHex());
            Console.WriteLine("address=>" + keyPair.GetPublicAddress());
            var wordlist = "brass bus same payment express already energy direct type have venture afraid";

            var  privateKey = keyPair.GetPrivateKey();
            var  addresss   = keyPair.GetPublicAddress();
            Web3 web3       = new Web3("http://localhost:7545");
            var  nonce      = web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(addresss).GetAwaiter().GetResult();



            Console.ReadLine();
        }
        public async Task CreateVaspForBank()
        {
            var signature = new EthECKey(Settings.PersonSignaturePrivateKeyHex);
            var handshake = ECDH_Key.ImportKey(Settings.PersonHandshakePrivateKeyHex);

            var signPub      = signature.GetPubKey().ToHex(prefix: true);
            var handshakePub = handshake.PublicKey;

            (VaspInformation vaspInfo, VaspContractInfo vaspContractInfo) = await VaspInformationBuilder.CreateForBankAsync(
                NodeClient.EthereumRpc,
                Settings.VaspSmartContractAddressBank,
                Settings.Bic);

            VaspClient vasp = VaspClient.Create(
                vaspInfo,
                vaspContractInfo,
                Settings.BankHandshakePrivateKeyHex,
                Settings.BankSignaturePrivateKeyHex,
                NodeClient.EthereumRpc,
                NodeClient.WhisperRpc,
                _fakeEnsProvider,
                _signService,
                NodeClient.TransportClient);

            // VASP paramaters must be derived from smart contract
            Assert.NotNull(vasp.VaspInfo.Name);
            Assert.NotNull(vasp.VaspInfo.VaspIdentity);
            Assert.NotNull(vasp.VaspInfo.PostalAddress);

            // VASP natural person parameters should be same what we pass in constructor
            Assert.Equal(vasp.VaspInfo.BIC, Settings.Bic);

            Assert.Null(vasp.VaspInfo.NaturalPersonIds);
            Assert.Null(vasp.VaspInfo.PlaceOfBirth);
            Assert.Null(vasp.VaspInfo.JuridicalPersonIds);
        }
Beispiel #8
0
 private void Initialise(EthECKey key)
 {
     PrivateKey = key.GetPrivateKey();
     PublicKey  = key.GetPubKey().ToHex();
     Address    = Bech32.Encode("io", Hash.Hash160B(key.GetPubKey().Slice(1)));
 }