serializeSignature
Combines signature components into a hex string
Loading...
Combines signature components into a hex string
Combines signature components (R, S, V, YParity) into a hex formatted signature string.
import "github.com/ChefBingbong/viem-go/utils/signature"import "github.com/ChefBingbong/viem-go/utils/signature"import "math/big"
hexSig, err := signature.SerializeSignature(&signature.Signature{ R: "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf", S: "0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8", YParity: 1,})if err != nil { log.Fatal(err)}fmt.Printf("Signature: %s", hexSig)// Signature: 0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c
// Serialize to bytessigBytes, _ := signature.SerializeSignatureBytes(&signature.Signature{ R: "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf", S: "0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8", YParity: 1,})// []byte{0x6e, 0x10, ...}(string, error) for SerializeSignature, ([]byte, error) for SerializeSignatureBytesThe serialized signature. SerializeSignature returns a hex string with 0x prefix (65 bytes), SerializeSignatureBytes returns raw bytes.
*signature.SignatureThe signature struct containing R, S, V, and YParity components.
sig := &signature.Signature{ R: "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf", S: "0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8", YParity: 1,}
hexSig, _ := signature.SerializeSignature(sig)stringThe R component of the signature (32 bytes as hex string).
sig := &signature.Signature{ R: "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf", // ...}stringThe S component of the signature (32 bytes as hex string).
sig := &signature.Signature{ S: "0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8", // ...}*big.IntThe V value (27 or 28 for legacy signatures). If not provided, YParity is used.
import "math/big"
sig := &signature.Signature{ V: big.NewInt(28), // ...}intThe parity of the y-coordinate (0 or 1). Used for EIP-2930/1559 transactions. If not provided, derived from V.
sig := &signature.Signature{ YParity: 1, // ...}Serializes a signature to a hex string:
hexSig, _ := signature.SerializeSignature(sig)
// "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"
Serializes a signature to bytes:
sigBytes, _ := signature.SerializeSignatureBytes(sig)
// []byte{0x6e, 0x10, ...} (65 bytes)
The serialized signature format is: