kms

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package kms provides shared utilities for KMS-based Ethereum signers.

KMS services (GCP, AWS, etc.) return signatures in DER/ASN.1 format, while Ethereum expects a 65-byte R || S || V format. This package handles the conversion between these formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DERToEthereumSignature

func DERToEthereumSignature(hash, derSig []byte, expectedPub *ecdsa.PublicKey) ([]byte, error)

DERToEthereumSignature converts a DER-encoded signature from a KMS service into a 65-byte Ethereum signature (R[32] || S[32] || V[1]).

It parses the DER encoding, normalizes S, recovers V, and adjusts V to 27/28.

func NormalizeS

func NormalizeS(s *big.Int) *big.Int

NormalizeS ensures S is in the lower half of the curve order (canonical form). Ethereum requires S <= N/2 to prevent signature malleability.

func ParseDERSignature

func ParseDERSignature(derSig []byte) (r, s *big.Int, err error)

ParseDERSignature extracts R and S values from a DER-encoded ASN.1 signature.

The expected DER format is:

0x30 <total-len> 0x02 <r-len> <r-bytes> 0x02 <s-len> <s-bytes>

func RecoverV

func RecoverV(hash []byte, r, s *big.Int, expectedPub *ecdsa.PublicKey) (uint8, error)

RecoverV determines the recovery ID (V value) for an Ethereum signature by trying both possible values (0 and 1) and checking which one recovers to the expected public key.

func ValidateSecp256k1PublicKey

func ValidateSecp256k1PublicKey(pub *ecdsa.PublicKey) error

ValidateSecp256k1PublicKey checks that the given public key is on the secp256k1 curve.

Types

This section is empty.

Directories

Path Synopsis
Package gcpkms implements sign.Signer using Google Cloud KMS.
Package gcpkms implements sign.Signer using Google Cloud KMS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL