public static Key?GetPrivateKey(this ISigningRepository repo, KeyId id) { if (!repo.TryGetSecret(id, out var res)) { return(null); } return(res.PrivateKey); }
public void Merge(ISigningRepository other) { if (!(other is FlatSigningRepository)) { throw new NotSupportedException($"{nameof(FlatSigningRepository)} can be merged only with the same type"); } var otherRepo = (FlatSigningRepository)other; MergeDict(Secrets, otherRepo.Secrets); MergeDict(Pubkeys, otherRepo.Pubkeys); MergeDict(Scripts, otherRepo.Scripts); MergeDict(KeyOrigins, otherRepo.KeyOrigins); }
public static bool IsSolvable(this ISigningRepository repo, Script scriptPubKey) { var temp = scriptPubKey.FindTemplate(); if (temp is PayToPubkeyTemplate p2pkT) { var pk = p2pkT.ExtractScriptPubKeyParameters(scriptPubKey) !; if (repo.TryGetPubKey(pk.Hash, out var _)) { return(true); } } if (temp is PayToPubkeyHashTemplate p2pkhT) { var keyId = p2pkhT.ExtractScriptPubKeyParameters(scriptPubKey) !; if (repo.TryGetPubKey(keyId, out var _)) { return(true); } } PubKey[]? pks = null; if (temp is PayToMultiSigTemplate p2multiT) { pks = p2multiT.ExtractScriptPubKeyParameters(scriptPubKey) !.PubKeys; } if (temp is PayToScriptHashTemplate p2shT) { var scriptId = p2shT.ExtractScriptPubKeyParameters(scriptPubKey) !; // This will give us witness script directly in case of p2sh-p2wsh if (repo.TryGetScript(scriptId, out var sc)) { scriptPubKey = sc; pks = sc.GetAllPubKeys(); } } if (temp is PayToWitTemplate) { var witId = PayToWitScriptHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey); if (witId != null) { if (repo.TryGetScript(witId.HashForLookUp, out var sc)) { pks = sc.GetAllPubKeys(); } } var wpkh = PayToWitPubKeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey); if (wpkh != null) { var witKeyId = wpkh.AsKeyId(); if (repo.TryGetPubKey(witKeyId, out var _)) { return(true); } } } if (pks != null) { foreach (var pk in pks) { if (!repo.TryGetPubKey(pk.Hash, out var _)) { return(false); } } return(true); } return(false); }