private static void UpdateResultFromFile(UInt160 hash) { string address = hash.ToAddress(); X509Certificate2 cert; try { cert = new X509Certificate2(Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer")); } catch (CryptographicException) { results[hash].Type = CertificateQueryResultType.Missing; return; } if (cert.PublicKey.Oid.Value != "1.2.840.10045.2.1") { results[hash].Type = CertificateQueryResultType.Missing; return; } if (!hash.Equals(Contract.CreateSignatureRedeemScript(ECPoint.DecodePoint(cert.PublicKey.EncodedKeyValue.RawData, ECCurve.Secp256r1)).ToScriptHash())) { results[hash].Type = CertificateQueryResultType.Missing; return; } using (X509Chain chain = new X509Chain()) { results[hash].Certificate = cert; if (chain.Build(cert)) { results[hash].Type = CertificateQueryResultType.Good; } else if (chain.ChainStatus.Length == 1 && chain.ChainStatus[0].Status == X509ChainStatusFlags.NotTimeValid) { results[hash].Type = CertificateQueryResultType.Expired; } else { results[hash].Type = CertificateQueryResultType.Invalid; } } }
private bool OnImportMultisigAddress(string[] args) { if (NoWallet()) { return(true); } if (args.Length < 4) { Console.WriteLine("Error. Invalid parameters."); return(true); } int m = int.Parse(args[2]); int n = args.Length - 3; if (m < 1 || m > n || n > 1024) { Console.WriteLine("Error. Invalid parameters."); return(true); } ECPoint[] publicKeys = args.Skip(3).Select(p => ECPoint.Parse(p, ECCurve.Secp256r1)).ToArray(); Contract multiSignContract = Contract.CreateMultiSigContract(m, publicKeys); KeyPair keyPair = Program.Wallet.GetAccounts().FirstOrDefault(p => p.HasKey && publicKeys.Contains(p.GetKey().PublicKey))?.GetKey(); WalletAccount account = Program.Wallet.CreateAccount(multiSignContract, keyPair); if (Program.Wallet is NEP6Wallet wallet) { wallet.Save(); } Console.WriteLine("Multisig. Addr.: " + multiSignContract.Address); return(true); }
public void TestSerializeAndDeserializeConsensusContext() { var consensusContext = new ConsensusContext(null, null); consensusContext.PrevHash = UInt256.Parse("0xaa8e1b1c619467a6500cbca4425f76512d1bd0ba2e0aee7e5fd15169325db52e"); consensusContext.BlockIndex = 1; consensusContext.ViewNumber = 2; consensusContext.Validators = new ECPoint[7] { ECPoint.Parse("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", Krona.Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", Krona.Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", Krona.Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", Krona.Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", Krona.Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", Krona.Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", Krona.Cryptography.ECC.ECCurve.Secp256r1) }; consensusContext.MyIndex = -1; consensusContext.PrimaryIndex = 6; consensusContext.Timestamp = 4244941711; consensusContext.Nonce = UInt64.MaxValue; consensusContext.NextConsensus = UInt160.Parse("5555AAAA5555AAAA5555AAAA5555AAAA5555AAAA"); var testTx1 = TestUtils.CreateRandomHashInvocationMockTransaction().Object; var testTx2 = TestUtils.CreateRandomHashInvocationMockTransaction().Object; int txCountToInlcude = 256; consensusContext.TransactionHashes = new UInt256[txCountToInlcude]; Transaction[] txs = new Transaction[txCountToInlcude]; txs[0] = TestUtils.CreateRandomMockBlockReward().Object; consensusContext.TransactionHashes[0] = txs[0].Hash; for (int i = 1; i < txCountToInlcude; i++) { txs[i] = TestUtils.CreateRandomHashInvocationMockTransaction().Object; consensusContext.TransactionHashes[i] = txs[i].Hash; } // consensusContext.TransactionHashes = new UInt256[2] {testTx1.Hash, testTx2.Hash}; consensusContext.Transactions = txs.ToDictionary(p => p.Hash); consensusContext.PreparationPayloads = new ConsensusPayload[consensusContext.Validators.Length]; var prepareRequestMessage = new PrepareRequest { Nonce = consensusContext.Nonce, NextConsensus = consensusContext.NextConsensus, TransactionHashes = consensusContext.TransactionHashes, BlockReward = (BlockReward)consensusContext.Transactions[consensusContext.TransactionHashes[0]], Timestamp = 23, StateRootSignature = new byte[64] }; consensusContext.PreparationPayloads[6] = MakeSignedPayload(consensusContext, prepareRequestMessage, 6, new[] { (byte)'3', (byte)'!' }); consensusContext.PreparationPayloads[0] = MakeSignedPayload(consensusContext, new PrepareResponse { PreparationHash = consensusContext.PreparationPayloads[6].Hash, StateRootSignature = new byte[64] }, 0, new[] { (byte)'t', (byte)'e' }); consensusContext.PreparationPayloads[1] = MakeSignedPayload(consensusContext, new PrepareResponse { PreparationHash = consensusContext.PreparationPayloads[6].Hash, StateRootSignature = new byte[64] }, 1, new[] { (byte)'s', (byte)'t' }); consensusContext.PreparationPayloads[2] = null; consensusContext.PreparationPayloads[3] = MakeSignedPayload(consensusContext, new PrepareResponse { PreparationHash = consensusContext.PreparationPayloads[6].Hash, StateRootSignature = new byte[64] }, 3, new[] { (byte)'1', (byte)'2' }); consensusContext.PreparationPayloads[4] = null; consensusContext.PreparationPayloads[5] = null; consensusContext.CommitPayloads = new ConsensusPayload[consensusContext.Validators.Length]; using (SHA256 sha256 = SHA256.Create()) { consensusContext.CommitPayloads[3] = MakeSignedPayload(consensusContext, new Commit { Signature = sha256.ComputeHash(testTx1.Hash.ToArray()) }, 3, new[] { (byte)'3', (byte)'4' }); consensusContext.CommitPayloads[6] = MakeSignedPayload(consensusContext, new Commit { Signature = sha256.ComputeHash(testTx2.Hash.ToArray()) }, 3, new[] { (byte)'6', (byte)'7' }); } consensusContext.Timestamp = TimeProvider.Current.UtcNow.ToTimestamp(); consensusContext.ChangeViewPayloads = new ConsensusPayload[consensusContext.Validators.Length]; consensusContext.ChangeViewPayloads[0] = MakeSignedPayload(consensusContext, new ChangeView { ViewNumber = 1, Timestamp = 6 }, 0, new[] { (byte)'A' }); consensusContext.ChangeViewPayloads[1] = MakeSignedPayload(consensusContext, new ChangeView { ViewNumber = 1, Timestamp = 5 }, 1, new[] { (byte)'B' }); consensusContext.ChangeViewPayloads[2] = null; consensusContext.ChangeViewPayloads[3] = MakeSignedPayload(consensusContext, new ChangeView { ViewNumber = 1, Timestamp = uint.MaxValue }, 3, new[] { (byte)'C' }); consensusContext.ChangeViewPayloads[4] = null; consensusContext.ChangeViewPayloads[5] = null; consensusContext.ChangeViewPayloads[6] = MakeSignedPayload(consensusContext, new ChangeView { ViewNumber = 1, Timestamp = 1 }, 6, new[] { (byte)'D' }); consensusContext.LastChangeViewPayloads = new ConsensusPayload[consensusContext.Validators.Length]; var copiedContext = TestUtils.CopyMsgBySerialization(consensusContext, new ConsensusContext(null, null)); copiedContext.PrevHash.Should().Be(consensusContext.PrevHash); copiedContext.BlockIndex.Should().Be(consensusContext.BlockIndex); copiedContext.ViewNumber.Should().Be(consensusContext.ViewNumber); copiedContext.Validators.ShouldAllBeEquivalentTo(consensusContext.Validators); copiedContext.MyIndex.Should().Be(consensusContext.MyIndex); copiedContext.PrimaryIndex.Should().Be(consensusContext.PrimaryIndex); copiedContext.Timestamp.Should().Be(consensusContext.Timestamp); copiedContext.Nonce.Should().Be(consensusContext.Nonce); copiedContext.NextConsensus.Should().Be(consensusContext.NextConsensus); copiedContext.TransactionHashes.ShouldAllBeEquivalentTo(consensusContext.TransactionHashes); copiedContext.Transactions.ShouldAllBeEquivalentTo(consensusContext.Transactions); copiedContext.Transactions.Values.ShouldAllBeEquivalentTo(consensusContext.Transactions.Values); copiedContext.PreparationPayloads.ShouldAllBeEquivalentTo(consensusContext.PreparationPayloads); copiedContext.CommitPayloads.ShouldAllBeEquivalentTo(consensusContext.CommitPayloads); copiedContext.ChangeViewPayloads.ShouldAllBeEquivalentTo(consensusContext.ChangeViewPayloads); }
public static CertificateQueryResult Query(ECPoint pubkey) { return(Query(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())); }
public WalletAccount GetAccount(ECPoint pubkey) { return(GetAccount(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())); }