common/identity/identity.go

33 lines
694 B
Go
Raw Permalink Normal View History

2025-01-12 09:17:29 +01:00
package identity
import (
"fmt"
"git.grassecon.net/grassrootseconomics/common/phone"
)
2025-01-13 18:47:03 +01:00
// Identity contains all flavors of identifiers used across stream, api and
// client for a single agent.
type Identity struct {
NormalAddress string
ChecksumAddress string
SessionId string
}
2025-01-12 09:17:29 +01:00
// CheckRecipient validates the recipient format based on the criteria
func CheckRecipient(recipient string) (string, error) {
if phone.IsValidPhoneNumber(recipient) {
return "phone number", nil
}
if IsValidAddress(recipient) {
return "address", nil
}
if IsValidAlias(recipient) {
return "alias", nil
}
return "", fmt.Errorf("invalid recipient: must be a phone number, address or alias")
}