Files
LightningTipBot/internal/telegram/redact.go
T
MichilisandClaude Fable 5.1 3c2ccf8d83 Add the LNURLcash Telegram commands
/note, /notes (list and batch), /redeem and /lnurlmints with confirm
dialogs, group posting with private receipts, claim notifications,
batch export as PDF/JSON/CSV, and LNURLcash notes detected inside the
existing /lnurl, paste and QR-photo flows. Plain withdraw links behave
as before. Two /lnurl log lines no longer print k1.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-13 22:12:27 +00:00

41 lines
1.3 KiB
Go

package telegram
import (
"fmt"
"regexp"
"strings"
"github.com/LightningTipBot/LightningTipBot/pkg/lightning"
)
// cashuTokenPattern matches a Cashu ecash token (a bearer instrument).
var cashuTokenPattern = regexp.MustCompile(`(?i)^cashu[a-z][a-z0-9_-]+$`)
// redactForLog returns text with everything that is money or a credential
// replaced by a placeholder, so the message log never holds bolt11 invoices,
// LNURLs, ecash tokens or node credentials (`/node add lnd <host> <macaroon>`).
func redactForLog(text string) string {
fields := strings.Fields(text)
if len(fields) == 0 {
return text
}
if strings.HasPrefix(strings.ToLower(fields[0]), "/node") {
return fields[0] + " <redacted>"
}
for i, f := range fields {
lower := strings.ToLower(f)
switch {
case lightning.IsInvoice(lower):
fields[i] = fmt.Sprintf("<invoice len=%d>", len(f))
case lightning.IsLnurl(lower) || strings.HasPrefix(lower, "lnurl"):
fields[i] = fmt.Sprintf("<lnurl len=%d>", len(f))
case cashuTokenPattern.MatchString(f):
fields[i] = fmt.Sprintf("<cashu-token len=%d>", len(f))
case strings.Contains(lower, "k1="):
// an LNURLcash note or withdraw link in URL form: the spend is in the query
fields[i] = fmt.Sprintf("<note-url len=%d>", len(f))
}
}
return strings.Join(fields, " ")
}