2021-09-10 08:52:44 +02:00
|
|
|
package lightning
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/mail"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// IsInvoice is used to check if a string matches lnbc invoide pattern.
|
|
|
|
|
// todo -- probably should add regex and validate length
|
2021-09-13 22:44:43 +02:00
|
|
|
func IsInvoice(message string) bool {
|
|
|
|
|
message = strings.ToLower(message)
|
2021-09-10 08:52:44 +02:00
|
|
|
// invoice string must start with lnbc or lightning:lnbc
|
2021-09-13 22:44:43 +02:00
|
|
|
if strings.HasPrefix(message, "lnbc") || strings.HasPrefix(message, "lightning:lnbc") {
|
2021-09-10 08:52:44 +02:00
|
|
|
// invoice string must be a single word
|
2021-09-13 22:44:43 +02:00
|
|
|
if !strings.Contains(message, " ") {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IsLnurl(message string) bool {
|
|
|
|
|
message = strings.ToLower(message)
|
2021-12-24 15:34:17 +01:00
|
|
|
if strings.HasPrefix(message, "lnurl") || strings.HasPrefix(message, "lightning:lnurl") {
|
2021-09-13 22:44:43 +02:00
|
|
|
// string must be a single word
|
|
|
|
|
if !strings.Contains(message, " ") {
|
2021-09-10 08:52:44 +02:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IsLightningAddress(address string) bool {
|
|
|
|
|
_, err := mail.ParseAddress(address)
|
|
|
|
|
return err == nil
|
|
|
|
|
}
|