github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/profile/author.go (about)

     1  package profile
     2  
     3  import (
     4  	"github.com/libp2p/go-libp2p-core/crypto"
     5  )
     6  
     7  // Author uses keypair cryptography to distinguish between different log sources
     8  // (authors)
     9  //
    10  // Deprecated - don't rely on this interface, refactor to use profile.Profiles
    11  // and public keys instead
    12  type Author interface {
    13  	AuthorID() string
    14  	AuthorPubKey() crypto.PubKey
    15  	Username() string
    16  }
    17  
    18  type author struct {
    19  	id       string
    20  	pubKey   crypto.PubKey
    21  	username string
    22  }
    23  
    24  // NewAuthor creates an Author interface implementation, allowing outside
    25  // packages needing to satisfy the Author interface
    26  //
    27  // Deprecated - use profile.Profile instead
    28  func NewAuthor(id string, pubKey crypto.PubKey, username string) Author {
    29  	return author{
    30  		id:       id,
    31  		pubKey:   pubKey,
    32  		username: username,
    33  	}
    34  }
    35  
    36  // NewAuthorFromProfile creates an Author interface implementation from a
    37  // profile
    38  //
    39  // Deprecated - use profile.Profile instead
    40  func NewAuthorFromProfile(p *Profile) Author {
    41  	pub := p.PubKey
    42  	if pub == nil && p.PrivKey != nil {
    43  		pub = p.PrivKey.GetPublic()
    44  	}
    45  	return author{
    46  		id:       p.ID.Encode(),
    47  		pubKey:   pub,
    48  		username: p.Peername,
    49  	}
    50  }
    51  
    52  func (a author) AuthorID() string {
    53  	return a.id
    54  }
    55  
    56  func (a author) AuthorPubKey() crypto.PubKey {
    57  	return a.pubKey
    58  }
    59  
    60  func (a author) Username() string {
    61  	return a.username
    62  }