fix: correct CHANMODES ISUPPORT classification and deduplicate MintChannelHashcash
Some checks failed
check / check (push) Failing after 1m51s

- 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
This commit is contained in:
clawbot
2026-03-17 02:49:59 -07:00
parent 3d285f1b66
commit 80f17dc335
2 changed files with 8 additions and 18 deletions

View File

@@ -7,6 +7,8 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"time" "time"
"git.eeqj.de/sneak/neoirc/internal/hashcash"
) )
const ( const (
@@ -41,29 +43,17 @@ func MintHashcash(bits int, resource string) string {
// a specific channel and message body. The stamp format // a specific channel and message body. The stamp format
// is 1:bits:YYMMDD:channel:bodyhash:counter where // is 1:bits:YYMMDD:channel:bodyhash:counter where
// bodyhash is the hex-encoded SHA-256 of the message // bodyhash is the hex-encoded SHA-256 of the message
// body bytes. // body bytes. Delegates to the internal/hashcash package.
func MintChannelHashcash( func MintChannelHashcash(
bits int, bits int,
channel string, channel string,
body []byte, body []byte,
) string { ) string {
bodyHash := sha256.Sum256(body) bodyHash := hashcash.BodyHash(body)
bodyHashHex := hex.EncodeToString(bodyHash[:])
date := time.Now().UTC().Format("060102") return hashcash.MintChannelStamp(
prefix := fmt.Sprintf( bits, channel, bodyHash,
"1:%d:%s:%s:%s:",
bits, date, channel, bodyHashHex,
) )
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 // hasLeadingZeroBits checks if hash has at least numBits

View File

@@ -300,7 +300,7 @@ func (hdlr *Handlers) deliverWelcome(
[]string{ []string{
"CHANTYPES=#", "CHANTYPES=#",
"NICKLEN=32", "NICKLEN=32",
"CHANMODES=,H,," + "imnst", "CHANMODES=,,H," + "imnst",
"NETWORK=neoirc", "NETWORK=neoirc",
"CASEMAPPING=ascii", "CASEMAPPING=ascii",
}, },