github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/libkb/social_assertion.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package libkb
     5  
     6  import (
     7  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     8  )
     9  
    10  // IsSocialAssertion returns true for strings that are valid
    11  // social assertions.  They do not need to be normalized, so
    12  // user@twitter and twitter:user will work, as will
    13  // USER@Twitter.
    14  func IsSocialAssertion(ctx AssertionContext, s string) bool {
    15  	_, ok := NormalizeSocialAssertion(ctx, s)
    16  	return ok
    17  }
    18  
    19  // NormalizeSocialAssertion creates a SocialAssertion from its
    20  // input and normalizes it.  The service name will be lowercased.
    21  // If the service is case-insensitive, then the username will also
    22  // be lowercased.  Colon assertions (twitter:user) will be
    23  // transformed to the user@twitter format.
    24  func NormalizeSocialAssertion(ctx AssertionContext, s string) (keybase1.SocialAssertion, bool) {
    25  	url, err := ParseAssertionURL(ctx, s, true)
    26  	if err != nil || !url.IsRemote() {
    27  		return keybase1.SocialAssertion{}, false
    28  	}
    29  	return keybase1.SocialAssertion{
    30  		User:    url.GetValue(),
    31  		Service: keybase1.SocialAssertionService(url.GetKey()),
    32  	}, true
    33  }