github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/protocol/mediator/util.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package mediator
     8  
     9  import (
    10  	"errors"
    11  	"fmt"
    12  )
    13  
    14  // GetRouterConfig util to get the router configuration. The endpoint is overridden with routers endpoint,
    15  // if router is registered. Returns endpoint, routingKeys and error.
    16  func GetRouterConfig(routeSvc ProtocolService, connID, endpoint string) (string, []string, error) {
    17  	routeConf, err := routeSvc.Config(connID)
    18  	if err != nil && !errors.Is(err, ErrRouterNotRegistered) {
    19  		return "", nil, fmt.Errorf("fetch router config: %w", err)
    20  	}
    21  
    22  	if routeConf != nil {
    23  		return routeConf.Endpoint(), routeConf.Keys(), nil
    24  	}
    25  
    26  	return endpoint, nil, nil
    27  }
    28  
    29  // AddKeyToRouter util to add the recipient keys to the router.
    30  func AddKeyToRouter(routeSvc ProtocolService, connID, recKey string) error {
    31  	if err := routeSvc.AddKey(connID, recKey); err != nil && !errors.Is(err, ErrRouterNotRegistered) {
    32  		return fmt.Errorf("addKey: %w", err)
    33  	}
    34  
    35  	return nil
    36  }