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 ¶
var ( ErrWrongKeyFormat = errors.New("wrong key type") ErrBadSignature = errors.New("bad signature") ErrVerification = errors.New("signature verification failed") ErrFailedSigning = errors.New("failed generating signature") )
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.