Esempio n. 1
0
        public void Can_sign()
        {
            EthereumSigner signer = new EthereumSigner(new SingleReleaseSpecProvider(LatestRelease.Instance, 99), NullLogManager.Instance);
            DevWallet      wallet = new DevWallet(NullLogManager.Instance);

            for (int i = 1; i <= 10; i++)
            {
                Address   signerAddress = wallet.GetAccounts()[0];
                Signature sig           = wallet.Sign(signerAddress, TestObject.KeccakA);
                Address   recovered     = signer.RecoverAddress(sig, TestObject.KeccakA);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
            }
        }
Esempio n. 2
0
        public Task <UInt256> ExecuteAsync(ExpressWalletAccount account, Neo.VM.Script script, decimal additionalGas = 0)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(OfflineNode));
            }

            var devAccount = DevWalletAccount.FromExpressWalletAccount(account);
            var devWallet  = new DevWallet(string.Empty, devAccount);
            var signer     = new Signer()
            {
                Account = devAccount.ScriptHash, Scopes = WitnessScope.CalledByEntry
            };
            var tx = devWallet.MakeTransaction(script, devAccount.ScriptHash, new[] { signer });

            if (additionalGas > 0.0m)
            {
                tx.SystemFee += (long)additionalGas.ToBigInteger(NativeContract.GAS.Decimals);
            }
            var context = new ContractParametersContext(tx);

            if (devAccount.IsMultiSigContract())
            {
                var wallets = chain.GetMultiSigWallets(account);

                foreach (var wallet in wallets)
                {
                    if (context.Completed)
                    {
                        break;
                    }

                    wallet.Sign(context);
                }
            }
            else
            {
                devWallet.Sign(context);
            }

            if (!context.Completed)
            {
                throw new Exception();
            }

            tx.Witnesses = context.GetWitnesses();

            return(SubmitTransactionAsync(tx));
        }
Esempio n. 3
0
        public void Can_sign_on_networks_with_chain_id()
        {
            const int      networkId = 40000;
            EthereumSigner signer    = new EthereumSigner(new SingleReleaseSpecProvider(LatestRelease.Instance, networkId), NullLogManager.Instance);
            DevWallet      wallet    = new DevWallet(NullLogManager.Instance);

            for (int i = 1; i <= 10; i++)
            {
                Address     signerAddress = wallet.GetAccounts()[0];
                Transaction tx            = new Transaction();
                tx.SenderAddress = signerAddress;

                wallet.Sign(tx, networkId);
                Address recovered = signer.RecoverAddress(tx, networkId);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
                Assert.AreEqual(networkId, tx.Signature.GetChainId, "chainId");
            }
        }