secp256k1

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 6 Imported by: 0

README

jwt-go-secp256k1

Build Status codecov GoDoc

An implementation of a secp256k1 SignatureMethod for github.com/dgrijalva/jwt-go.

Implements two different algorithms:

  • ES256K
  • ES256K-R

The latter allows for public key recovery.

Documentation

Overview

Package secp256k1 implements a jwt.SigningMethod for secp256k1 signatures.

Two different algorithms are implemented: ES256K and ES256K-R. The former produces and verifies using signatures in the R || S format, and the latter in R || S || V. V is the recovery byte, making it possible to recover public keys from signatures.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongKeyFormat  = errors.New("wrong key type")
	ErrBadSignature    = errors.New("bad signature")
	ErrVerification    = errors.New("signature verification failed")
	ErrFailedSigning   = errors.New("failed generating signature")
	ErrHashUnavailable = errors.New("hasher unavailable")
)

Errors returned on different problems.

Functions

This section is empty.

Types

type SigningMethodSecp256k1

type SigningMethodSecp256k1 struct {
	// contains filtered or unexported fields
}

SigningMethodSecp256k1 is the implementation of jwt.SigningMethod.

var (
	// SigningMethodES256K produces and accepts 256-bit signatures using the
	// secp256k1 curve.
	// The signature is in R || S format.
	SigningMethodES256K *SigningMethodSecp256k1
	// SigningMethodES256KR produces and accepts 264-bit signatures using the
	// secp256k1 curve.
	// The signature is in R || S || V format, with V being the recovery byte.
	SigningMethodES256KR *SigningMethodSecp256k1
)

ES256K and ES256K-R algorithms. uPort uses SigningMethodES256KR.

func (*SigningMethodSecp256k1) Alg

func (sm *SigningMethodSecp256k1) Alg() string

Alg returns the algorithm name.

func (*SigningMethodSecp256k1) Sign

func (sm *SigningMethodSecp256k1) Sign(signingString string, key interface{}) ([]byte, error)

Sign produces a secp256k1 signature for a JWT. The type of key has to be *PrivateKey.

func (*SigningMethodSecp256k1) Verify

func (sm *SigningMethodSecp256k1) Verify(signingString string, sig []byte, key interface{}) error

Verify verifies a secp256k1 signature in a JWT. The type of key has to be *ecdsa.PublicKey.

Verify it is a secp256k1 key before passing, otherwise it will validate with that type of key instead. This can be done using ethereum's crypto package.

Jump to

Keyboard shortcuts

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