mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-06-11 19:29:57 +00:00
* refactor: adopt golang-standards/project-layout Move the legacy kernel wrapper `waku/*` to `pkg/kernel/*` and rename its package `waku` -> `kernel`; nothing outside the package imported it, so this is a mechanical import-path/prefix change. Update the relocated Makefile's relative dep path, the legacy CI workflows (CI/endurance/repeated) build paths, README, and .gitignore accordingly (preserving the libwaku-cache CI from #109). Add scaffolding for the upcoming Messaging API work: `internal/ffi` (cgo bridge), `pkg/messaging` (high-level Node API), and `examples/`. Document `pkg/kernel` as legacy until logos-delivery#3851 consolidates the C libraries. Also stop tracking the accidentally-committed `waku-bindings` build artifact and gitignore the kernel build output. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: cleanup * fix: repair references to removed utils package nwaku_test_utils.go now uses pkg/kernel/utils.GetRSSKB; the memory_record tool is self-contained (local helpers, missing mutex restored). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
879 B
Go
45 lines
879 B
Go
package common
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// MessageHash represents an unique identifier for a message within a pubsub topic
|
|
type MessageHash string
|
|
|
|
func ToMessageHash(val string) (MessageHash, error) {
|
|
if len(val) == 0 {
|
|
return "", errors.New("empty string not allowed")
|
|
}
|
|
|
|
if len(val) < 2 || val[:2] != "0x" {
|
|
return "", errors.New("string must start with 0x")
|
|
}
|
|
|
|
// Remove "0x" prefix for hex decoding
|
|
hexStr := val[2:]
|
|
|
|
// Verify the remaining string is valid hex
|
|
_, err := hex.DecodeString(hexStr)
|
|
if err != nil {
|
|
return "", fmt.Errorf("invalid hex string: %v", err)
|
|
}
|
|
|
|
return MessageHash(val), nil
|
|
}
|
|
|
|
func (h MessageHash) String() string {
|
|
return string(h)
|
|
}
|
|
|
|
func (h MessageHash) Bytes() ([]byte, error) {
|
|
s := string(h)
|
|
// Remove 0x prefix if present
|
|
if len(s) >= 2 && s[:2] == "0x" {
|
|
s = s[2:]
|
|
}
|
|
return hex.DecodeString(s)
|
|
}
|