docs: @Nullable
      public ECKey getConnectedKey(KeyBag keyBag) throws ScriptException {
          TransactionOutput connectedOutput = getConnectedOutput();
          checkNotNull(connectedOutput, "Input is not connected so cannot retrieve key");
          Script connectedScript = connectedOutput.getScriptPubKey();
          if (ScriptPattern.isP2PKH(connectedScript)) {
              byte[] addressBytes = ScriptPattern.extractHashFromP2PKH(connectedScript);
              return keyBag.findKeyFromPubKeyHash(addressBytes, Script.ScriptType.P2PKH);
          } else if (ScriptPattern.isP2WPKH(connectedScript)) {
              byte[] addressBytes = ScriptPattern.extractHashFromP2WH(connectedScript);
              return keyBag.findKeyFromPubKeyHash(addressBytes, Script.ScriptType.P2WPKH);
          } else if (ScriptPattern.isP2PK(connectedScript)) {
              byte[] pubkeyBytes = ScriptPattern.extractKeyFromP2PK(connectedScript);
              return keyBag.findKeyFromPubKey(pubkeyBytes);
          } else {
              throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Could not understand form of connected output script: " + connectedScript);
          }
      }