From 80f17dc335876b8c9a232c6cfb2e82c60c3614d2 Mon Sep 17 00:00:00 2001 From: clawbot Date: Tue, 17 Mar 2026 02:49:59 -0700 Subject: [PATCH] fix: correct CHANMODES ISUPPORT classification and deduplicate MintChannelHashcash - Move H from Type B to Type C in CHANMODES ISUPPORT string (H takes a parameter only when set, not when unset) - Refactor MintChannelHashcash to delegate to hashcash.BodyHash() and hashcash.MintChannelStamp() instead of reimplementing them --- internal/cli/api/hashcash.go | 24 +++++++----------------- internal/handlers/api.go | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/internal/cli/api/hashcash.go b/internal/cli/api/hashcash.go index 0eac84c..d83cebd 100644 --- a/internal/cli/api/hashcash.go +++ b/internal/cli/api/hashcash.go @@ -7,6 +7,8 @@ import ( "fmt" "math/big" "time" + + "git.eeqj.de/sneak/neoirc/internal/hashcash" ) const ( @@ -41,29 +43,17 @@ func MintHashcash(bits int, resource string) string { // a specific channel and message body. The stamp format // is 1:bits:YYMMDD:channel:bodyhash:counter where // bodyhash is the hex-encoded SHA-256 of the message -// body bytes. +// body bytes. Delegates to the internal/hashcash package. func MintChannelHashcash( bits int, channel string, body []byte, ) string { - bodyHash := sha256.Sum256(body) - bodyHashHex := hex.EncodeToString(bodyHash[:]) - date := time.Now().UTC().Format("060102") - prefix := fmt.Sprintf( - "1:%d:%s:%s:%s:", - bits, date, channel, bodyHashHex, + bodyHash := hashcash.BodyHash(body) + + return hashcash.MintChannelStamp( + bits, channel, bodyHash, ) - - for { - counter := randomCounter() - stamp := prefix + counter - hash := sha256.Sum256([]byte(stamp)) - - if hasLeadingZeroBits(hash[:], bits) { - return stamp - } - } } // hasLeadingZeroBits checks if hash has at least numBits diff --git a/internal/handlers/api.go b/internal/handlers/api.go index 19723ee..eeadd51 100644 --- a/internal/handlers/api.go +++ b/internal/handlers/api.go @@ -300,7 +300,7 @@ func (hdlr *Handlers) deliverWelcome( []string{ "CHANTYPES=#", "NICKLEN=32", - "CHANMODES=,H,," + "imnst", + "CHANMODES=,,H," + "imnst", "NETWORK=neoirc", "CASEMAPPING=ascii", },