Пример #1
0
        static void Main(string[] args)
        {
            KeyVaultClient kvc       = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken));
            var            signer    = new AzureKeyVaultExternalSigner(kvc, URI);
            var            publicKey = signer.GetPublicKeyAsync().Result;

            System.Console.WriteLine(publicKey.ToHex());

            var msgHash           = new Util.Sha3Keccack().CalculateHash("Hello").HexToByteArray();
            var ethExternalSigner = new EthECKeyExternalSigner(signer);

            var signature          = ethExternalSigner.SignAndCalculateVAsync(msgHash).Result;
            var publicKeyRecovered = EthECKey.RecoverFromSignature(signature, msgHash);

            System.Console.WriteLine(publicKeyRecovered.GetPubKey().ToHex());

            var transfer = new TransferFunction();

            transfer.To          = "0x1996a57077877D38e18A1BE44A55100D77b8fA1D";
            transfer.FromAddress = publicKeyRecovered.GetPublicAddress();
            transfer.Value       = 1;
            transfer.Nonce       = 1;
            transfer.GasPrice    = 100;
            transfer.Gas         = 1000;

            var rpcClient        = new RpcClient(new Uri("http://localhost:8545"));
            var transactionInput = transfer.CreateTransactionInput("0x12890d2cce102216644c59daE5baed380d84830c");

            var externalAccount = new ExternalAccount(ethExternalSigner, 1);

            externalAccount.InitialiseAsync().Wait();
            externalAccount.InitialiseDefaultTransactionManager(rpcClient);
            var signature2          = externalAccount.TransactionManager.SignTransactionAsync(transactionInput).Result;
            var transactionSigner   = new TransactionSigner();
            var publicKeyRecovered2 = transactionSigner.GetPublicKey(signature2, 1);

            System.Console.WriteLine(publicKeyRecovered2.ToHex());
            System.Console.ReadLine();
        }