public void TestCreateMultiSigRedeemScriptFee() { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); Neo.Cryptography.ECC.ECPoint[] publicKeys = new Neo.Cryptography.ECC.ECPoint[2]; publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); byte[] verification = Contract.CreateMultiSigRedeemScript(2, publicKeys); byte[] invocation = new ScriptBuilder().EmitPush(UInt160.Zero).EmitPush(UInt160.Zero).ToArray(); long fee = PolicyContract.DefaultExecFeeFactor * (ApplicationEngine.OpCodePrices[OpCode.PUSHDATA1] * (2 + 2) + ApplicationEngine.OpCodePrices[OpCode.PUSHINT8] * 2 + ApplicationEngine.OpCodePrices[OpCode.SYSCALL] + ApplicationEngine.CheckSigPrice * 2); using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, new Transaction { Signers = Array.Empty <Signer>(), Attributes = Array.Empty <TransactionAttribute>() }, null, settings: TestBlockchain.TheNeoSystem.Settings)) { engine.LoadScript(invocation.Concat(verification).ToArray(), configureState: p => p.CallFlags = CallFlags.None); engine.Execute(); engine.GasConsumed.Should().Be(fee); } }
/// <summary> /// Decrypts a NEP2 key using a passphrase and the ScryptParameters, returning a private key /// </summary> /// <param name="nep2"></param> /// <param name="passphrase"></param> /// <param name="scryptParameters"></param> /// <returns>private key</returns> public static byte[] DecryptKey(string nep2, string passphrase, ScryptParameters scryptParameters) { if (nep2 == null) { throw new ArgumentNullException(nameof(nep2)); } if (passphrase == null) { throw new ArgumentNullException(nameof(passphrase)); } byte[] data = nep2.Base58CheckDecode(); if (data.Length != 39 || data[0] != 0x01 || data[1] != 0x42 || data[2] != 0xe0) { throw new FormatException(); } byte[] addresshash = new byte[4]; Buffer.BlockCopy(data, 3, addresshash, 0, 4); byte[] derivedkey = SCrypt.DeriveKey(Encoding.UTF8.GetBytes(passphrase), addresshash, scryptParameters.N, scryptParameters.R, scryptParameters.P, 64); byte[] derivedhalf1 = derivedkey.Take(32).ToArray(); byte[] derivedhalf2 = derivedkey.Skip(32).ToArray(); byte[] encryptedkey = new byte[32]; Buffer.BlockCopy(data, 7, encryptedkey, 0, 32); byte[] prikey = Xor(encryptedkey.Aes256Decrypt(derivedhalf2), derivedhalf1); ECPoint pubkey = ECCurve.Secp256r1.G * prikey; UInt160 scriptHash = Neo.SmartContract.Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash(); string address = Wallet.ToAddress(scriptHash); if (!Encoding.ASCII.GetBytes(address).Sha256().Sha256().Take(4).SequenceEqual(addresshash)) { throw new FormatException(); } return(prikey); }
public void TestCreateMultiSigRedeemScript() { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); Neo.Cryptography.ECC.ECPoint[] publicKeys = new Neo.Cryptography.ECC.ECPoint[2]; publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); Action action = () => Contract.CreateMultiSigRedeemScript(0, publicKeys); action.Should().Throw <ArgumentException>(); byte[] script = Contract.CreateMultiSigRedeemScript(2, publicKeys); byte[] expectedArray = new byte[75]; expectedArray[0] = 0x52; expectedArray[1] = 0x21; Array.Copy(publicKeys[0].EncodePoint(true), 0, expectedArray, 2, 33); expectedArray[35] = 0x21; Array.Copy(publicKeys[1].EncodePoint(true), 0, expectedArray, 36, 33); expectedArray[69] = 0x52; expectedArray[70] = 0x68; Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckMultiSig), 0, expectedArray, 71, 4); Assert.AreEqual(Encoding.Default.GetString(expectedArray), Encoding.Default.GetString(script)); }
/// <summary> /// create new multi address /// </summary> /// <returns></returns> public async Task <object> CreateMultiAddress(int limit, string[] publicKeys) { if (CurrentWallet == null) { return(Error(ErrorCode.WalletNotOpen)); } var points = publicKeys.Select(p => ECPoint.DecodePoint(Helper.HexToBytes(p), ECCurve.Secp256r1)).ToArray(); Contract contract = Contract.CreateMultiSigContract(limit, points); if (contract == null) { return(Error(ErrorCode.CreateMultiContractFail)); } var hashSet = new HashSet <ECPoint>(points); var key = CurrentWallet.GetAccounts().FirstOrDefault(p => p.HasKey && hashSet.Contains(p.GetKey().PublicKey))?.GetKey(); var newAccount = CurrentWallet.CreateAccount(contract, key); if (CurrentWallet is NEP6Wallet wallet) { wallet.Save(); } return(new AccountModel() { AccountType = AccountType.MultiSignature, Address = newAccount.Address, ScriptHash = newAccount.ScriptHash, }); }
public void TestCreateMultiSigContract() { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); Neo.Cryptography.ECC.ECPoint[] publicKeys = new Neo.Cryptography.ECC.ECPoint[2]; publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); Contract contract = Contract.CreateMultiSigContract(2, publicKeys); byte[] expectedArray = new byte[75]; expectedArray[0] = 0x52; expectedArray[1] = 0x21; Array.Copy(publicKeys[0].EncodePoint(true), 0, expectedArray, 2, 33); expectedArray[35] = 0x21; Array.Copy(publicKeys[1].EncodePoint(true), 0, expectedArray, 36, 33); expectedArray[69] = 0x52; expectedArray[70] = 0x68; Array.Copy(BitConverter.GetBytes(InteropService.Neo_Crypto_CheckMultiSig), 0, expectedArray, 71, 4); Assert.AreEqual(Encoding.Default.GetString(expectedArray), Encoding.Default.GetString(contract.Script)); Assert.AreEqual(2, contract.ParameterList.Length); Assert.AreEqual(ContractParameterType.Signature, contract.ParameterList[0]); Assert.AreEqual(ContractParameterType.Signature, contract.ParameterList[1]); }
public void TestCreateMultiSigRedeemScript() { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); Neo.Cryptography.ECC.ECPoint[] publicKeys = new Neo.Cryptography.ECC.ECPoint[2]; publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); Action action = () => Contract.CreateMultiSigRedeemScript(0, publicKeys); action.Should().Throw <ArgumentException>(); byte[] script = Contract.CreateMultiSigRedeemScript(2, publicKeys); byte[] expectedArray = new byte[77]; expectedArray[0] = (byte)OpCode.PUSH2; expectedArray[1] = (byte)OpCode.PUSHDATA1; expectedArray[2] = 0x21; Array.Copy(publicKeys[0].EncodePoint(true), 0, expectedArray, 3, 33); expectedArray[36] = (byte)OpCode.PUSHDATA1; expectedArray[37] = 0x21; Array.Copy(publicKeys[1].EncodePoint(true), 0, expectedArray, 38, 33); expectedArray[71] = (byte)OpCode.PUSH2; expectedArray[72] = (byte)OpCode.SYSCALL; Array.Copy(BitConverter.GetBytes(ApplicationEngine.System_Crypto_CheckMultisig), 0, expectedArray, 73, 4); CollectionAssert.AreEqual(expectedArray, script); }
public static byte[] CreateSignatureRedeemScript(ECPoint publicKey) { using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitPush(publicKey.EncodePoint(true)); sb.Emit(OpCode.CHECKSIG); return(sb.ToArray()); } }
public void TestIsMultiSigContract() { ECPoint[] publicKeys1 = new ECPoint[20]; for (int i = 0; i < 20; i++) { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); publicKeys1[i] = key1.PublicKey; } byte[] script1 = Contract.CreateMultiSigRedeemScript(20, publicKeys1); Assert.AreEqual(true, Neo.SmartContract.Helper.IsMultiSigContract(script1, out _, out ECPoint[] p1)); CollectionAssert.AreEqual(publicKeys1.OrderBy(p => p).ToArray(), p1); Neo.Cryptography.ECC.ECPoint[] publicKeys2 = new Neo.Cryptography.ECC.ECPoint[256]; for (int i = 0; i < 256; i++) { byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); publicKeys2[i] = key2.PublicKey; } byte[] script2 = Contract.CreateMultiSigRedeemScript(256, publicKeys2); Assert.AreEqual(true, Neo.SmartContract.Helper.IsMultiSigContract(script2, out _, out ECPoint[] p2)); CollectionAssert.AreEqual(publicKeys2.OrderBy(p => p).ToArray(), p2); Neo.Cryptography.ECC.ECPoint[] publicKeys3 = new Neo.Cryptography.ECC.ECPoint[3]; for (int i = 0; i < 3; i++) { byte[] privateKey3 = new byte[32]; RandomNumberGenerator rng3 = RandomNumberGenerator.Create(); rng3.GetBytes(privateKey3); KeyPair key3 = new KeyPair(privateKey3); publicKeys3[i] = key3.PublicKey; } byte[] script3 = Contract.CreateMultiSigRedeemScript(3, publicKeys3); Assert.AreEqual(true, Neo.SmartContract.Helper.IsMultiSigContract(script3, out _, out ECPoint[] p3)); CollectionAssert.AreEqual(publicKeys3.OrderBy(p => p).ToArray(), p3); Neo.Cryptography.ECC.ECPoint[] publicKeys4 = new Neo.Cryptography.ECC.ECPoint[3]; for (int i = 0; i < 3; i++) { byte[] privateKey4 = new byte[32]; RandomNumberGenerator rng4 = RandomNumberGenerator.Create(); rng4.GetBytes(privateKey4); KeyPair key4 = new KeyPair(privateKey4); publicKeys4[i] = key4.PublicKey; } byte[] script4 = Contract.CreateMultiSigRedeemScript(3, publicKeys4); script4[script4.Length - 1] = 0x00; Assert.AreEqual(false, Neo.SmartContract.Helper.IsMultiSigContract(script4, out _, out ECPoint[] p4)); Assert.IsNull(p4); }
public InvocationTransaction MakeAssetCreationTransaction( AssetType?assetType, string assetName, Fixed8 amount, byte precision, ECPoint assetOwner, UInt160 assetAdmin, UInt160 assetIssuer) { return(TransactionHelper.MakeAssetCreationTransaction( assetType, assetName, amount, precision, assetOwner, assetAdmin, assetIssuer)); }
private void UpdateResultFromFile(UInt160 hash) { var path = this.GetCachedCertificatePathFromScriptHash(hash); X509Certificate2 cert; try { cert = new X509Certificate2(path); } 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; } // Compare hash with cached value var decodedPublicKey = ECPoint.DecodePoint(cert.PublicKey.EncodedKeyValue.RawData, ECCurve.Secp256r1); var decodedHash = GetRedeemScriptHashFromPublicKey(decodedPublicKey); if (!hash.Equals(decodedHash)) { results[hash].Type = CertificateQueryResultType.Missing; return; } using (var 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; } } }
public string GetCachedCertificatePath(ECPoint publicKey) { if (!this.initialized) { throw new Exception("Service has not been initialized!"); } var hash = GetRedeemScriptHashFromPublicKey(publicKey); var path = this.GetCachedCertificatePathFromScriptHash(hash); if (!this.fileManager.FileExists(path)) { return(null); } return(path); }
public bool ViewCertificate(ECPoint publicKey) { if (!this.initialized) { throw new Exception("Service has not been initialized!"); } var hash = GetRedeemScriptHashFromPublicKey(publicKey); var path = this.GetCachedCertificatePathFromScriptHash(hash); if (!this.fileManager.FileExists(path)) { return(false); } this.processHelper.Run(path); return(true); }
private bool OnImportMultisigAddress(string[] args) { if (NoWallet()) { return(true); } if (args.Length < 5) { Console.WriteLine("Error. Use at least 2 public keys to create a multisig address."); 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); } if (WalletLocked()) { 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); }
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 CertificateQueryResult GetCertificateQueryResult(ECPoint publicKey) { // Check if certificate has been cached from a previous query if (this.certificateQueryResultCache.ContainsKey(publicKey)) { return(this.certificateQueryResultCache[publicKey]); } // Query for certificate var result = this.certificateService.Query(publicKey); if (result == null) { return(null); } // Cache certificate query result this.certificateQueryResultCache.Add(publicKey, result); return(result); }
public CertificateQueryResult Query(ECPoint publickey) { if (!this.initialized) { throw new Exception("Service has not been initialized!"); } var hash = GetRedeemScriptHashFromPublicKey(publickey); lock (results) { if (results.ContainsKey(hash)) { return(results[hash]); } results[hash] = new CertificateQueryResult { Type = CertificateQueryResultType.Querying }; } var path = this.GetCachedCertificatePathFromScriptHash(hash); var address = Wallet.ToAddress(hash); if (this.fileManager.FileExists(path)) { lock (results) { UpdateResultFromFile(hash); } } else { var url = $"http://cert.onchain.com/antshares/{address}.cer"; var web = new WebClient(); web.DownloadDataCompleted += this.Web_DownloadDataCompleted; web.DownloadDataAsync(new Uri(url), hash); } return(results[hash]); }
public void TestIsStandardContract() { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); byte[] script1 = Contract.CreateSignatureRedeemScript(key1.PublicKey); Assert.AreEqual(true, Neo.SmartContract.Helper.IsStandardContract(script1)); Neo.Cryptography.ECC.ECPoint[] publicKeys2 = new Neo.Cryptography.ECC.ECPoint[3]; for (int i = 0; i < 3; i++) { byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); publicKeys2[i] = key2.PublicKey; } byte[] script2 = Contract.CreateMultiSigRedeemScript(3, publicKeys2); Assert.AreEqual(true, Neo.SmartContract.Helper.IsStandardContract(script2)); }
public void TestCreateMultiSigContract() { byte[] privateKey1 = new byte[32]; RandomNumberGenerator rng1 = RandomNumberGenerator.Create(); rng1.GetBytes(privateKey1); KeyPair key1 = new KeyPair(privateKey1); byte[] privateKey2 = new byte[32]; RandomNumberGenerator rng2 = RandomNumberGenerator.Create(); rng2.GetBytes(privateKey2); KeyPair key2 = new KeyPair(privateKey2); Neo.Cryptography.ECC.ECPoint[] publicKeys = new Neo.Cryptography.ECC.ECPoint[2]; publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); Contract contract = Contract.CreateMultiSigContract(2, publicKeys); byte[] expectedArray = new byte[78]; expectedArray[0] = (byte)OpCode.PUSH2; expectedArray[1] = (byte)OpCode.PUSHDATA1; expectedArray[2] = 0x21; Array.Copy(publicKeys[0].EncodePoint(true), 0, expectedArray, 3, 33); expectedArray[36] = (byte)OpCode.PUSHDATA1; expectedArray[37] = 0x21; Array.Copy(publicKeys[1].EncodePoint(true), 0, expectedArray, 38, 33); expectedArray[71] = (byte)OpCode.PUSH2; expectedArray[72] = (byte)OpCode.PUSHNULL; expectedArray[73] = (byte)OpCode.SYSCALL; Array.Copy(BitConverter.GetBytes(ApplicationEngine.Neo_Crypto_CheckMultisigWithECDsaSecp256r1), 0, expectedArray, 74, 4); CollectionAssert.AreEqual(expectedArray, contract.Script); Assert.AreEqual(2, contract.ParameterList.Length); Assert.AreEqual(ContractParameterType.Signature, contract.ParameterList[0]); Assert.AreEqual(ContractParameterType.Signature, contract.ParameterList[1]); }
public InvocationTransaction MakeValidatorRegistrationTransaction(ECPoint publicKey) { return(TransactionHelper.MakeValidatorRegistrationTransaction(publicKey)); }
public void TestSerializeAndDeserializeConsensusContext() { var consensusContext = new ConsensusContext(null, null) { Block = new Block { PrevHash = Blockchain.GenesisBlock.Hash, Index = 1, Timestamp = 4244941711, NextConsensus = UInt160.Parse("5555AAAA5555AAAA5555AAAA5555AAAA5555AAAA"), ConsensusData = new ConsensusData { PrimaryIndex = 6 } }, ViewNumber = 2, Validators = new ECPoint[7] { ECPoint.Parse("02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70", Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d", Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e", Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554", Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", Cryptography.ECC.ECCurve.Secp256r1), ECPoint.Parse("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", Cryptography.ECC.ECCurve.Secp256r1) }, MyIndex = -1 }; var testTx1 = TestUtils.CreateRandomHashTransaction(); var testTx2 = TestUtils.CreateRandomHashTransaction(); int txCountToInlcude = 256; consensusContext.TransactionHashes = new UInt256[txCountToInlcude]; Transaction[] txs = new Transaction[txCountToInlcude]; for (int i = 0; i < txCountToInlcude; i++) { txs[i] = TestUtils.CreateRandomHashTransaction(); 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 { TransactionHashes = consensusContext.TransactionHashes, Timestamp = 23 }; consensusContext.PreparationPayloads[6] = MakeSignedPayload(consensusContext, prepareRequestMessage, 6, new[] { (byte)'3', (byte)'!' }); consensusContext.PreparationPayloads[0] = MakeSignedPayload(consensusContext, new PrepareResponse { PreparationHash = consensusContext.PreparationPayloads[6].Hash }, 0, new[] { (byte)'t', (byte)'e' }); consensusContext.PreparationPayloads[1] = MakeSignedPayload(consensusContext, new PrepareResponse { PreparationHash = consensusContext.PreparationPayloads[6].Hash }, 1, new[] { (byte)'s', (byte)'t' }); consensusContext.PreparationPayloads[2] = null; consensusContext.PreparationPayloads[3] = MakeSignedPayload(consensusContext, new PrepareResponse { PreparationHash = consensusContext.PreparationPayloads[6].Hash }, 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.Block.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.Block.PrevHash.Should().Be(consensusContext.Block.PrevHash); copiedContext.Block.Index.Should().Be(consensusContext.Block.Index); copiedContext.ViewNumber.Should().Be(consensusContext.ViewNumber); copiedContext.Validators.ShouldAllBeEquivalentTo(consensusContext.Validators); copiedContext.MyIndex.Should().Be(consensusContext.MyIndex); copiedContext.Block.ConsensusData.PrimaryIndex.Should().Be(consensusContext.Block.ConsensusData.PrimaryIndex); copiedContext.Block.Timestamp.Should().Be(consensusContext.Block.Timestamp); copiedContext.Block.NextConsensus.Should().Be(consensusContext.Block.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); }
private static UInt160 GetRedeemScriptHashFromPublicKey(ECPoint publicKey) { return(Contract.CreateSignatureRedeemScript(publicKey).ToScriptHash()); }
public WalletAccount GetAccount(ECPoint pubkey) { return(GetAccount(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())); }
public static CertificateQueryResult Query(ECPoint pubkey) { return(Query(Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())); }