/// <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, }); }
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; } } }
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; } } }