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", },