-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kzgpad util for using grpcurl to test eigenda
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule eigenlayer-middleware
updated
15 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
clean: | ||
rm -rf ./bin | ||
|
||
build: clean | ||
go mod tidy | ||
go build -o ./bin/kzgpad ./cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
} | ||
} |