diff --git a/Makefile b/Makefile index 0625ecb80c..97420a3eed 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ build: cd node && make build cd retriever && make build cd tools/traffic && make build + cd tools/kzgpad && make build dataapi-build: cd disperser && go build -o ./bin/dataapi ./cmd/dataapi diff --git a/tools/kzgpad/Makefile b/tools/kzgpad/Makefile new file mode 100644 index 0000000000..58fd90e94f --- /dev/null +++ b/tools/kzgpad/Makefile @@ -0,0 +1,6 @@ +clean: + rm -rf ./bin + +build: clean + go mod tidy + go build -o ./bin/kzgpad ./cmd \ No newline at end of file diff --git a/tools/kzgpad/cmd/main.go b/tools/kzgpad/cmd/main.go new file mode 100644 index 0000000000..e8754dda4b --- /dev/null +++ b/tools/kzgpad/cmd/main.go @@ -0,0 +1,55 @@ +package main + +import ( + "bufio" + "encoding/base64" + "fmt" + "os" + + "github.com/Layr-Labs/eigenda/encoding/utils/codec" +) + +func main() { + if len(os.Args) < 3 { + fmt.Fprintln(os.Stderr, "Usage: go run main.go [-e|-d] [input]") + os.Exit(1) + } + + mode := os.Args[1] + input := os.Args[2] + + if input == "-" { + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + processInput(mode, scanner.Text()) + } + if err := scanner.Err(); err != nil { + fmt.Fprintln(os.Stderr, "Error reading stdin:", err) + os.Exit(1) + } + } else { + processInput(mode, input) + } +} + +func processInput(mode, text string) { + switch mode { + case "-e": + // Encode the input to base64 + bz := []byte(text) + padded := codec.ConvertByPaddingEmptyByte(bz) + encoded := base64.StdEncoding.EncodeToString(padded) + fmt.Println(encoded) + case "-d": + // Decode the base64 input + decoded, err := base64.StdEncoding.DecodeString(text) + if err != nil { + fmt.Fprintln(os.Stderr, "Error decoding base64:", err) + return + } + unpadded := codec.RemoveEmptyByteFromPaddedBytes(decoded) + fmt.Println(string(unpadded)) + default: + fmt.Fprintln(os.Stderr, "Invalid mode. Use -e for encoding or -d for decoding.") + } +}