der

package module
v0.0.0-...-107dfd8 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

package der provides DER encoding for Bitcoin signatures as specified in BIP66.

Index

Constants

View Source
const (
	// TypeCompound is the prefix byte for any DER encoded signature.
	TypeCompound byte = 0x30

	// TagInteger is the DER tag byte denoting a large integer which follows.
	TagInteger byte = 2

	// MaxIntegerSize is the maximum size of an integer that BIP66 strict-DER encoding allows.
	MaxIntegerSize = 32

	// MinimumSignatureLength and MaximumSignatureLength describe the min/max lengths possible
	// for DER-encoded signatures allowed by BIP66.
	MinimumSignatureLength = 9
	MaximumSignatureLength = 73
)

Variables

View Source
var (
	// ErrNotEncodable is returned when an encoding function is passed a value
	// which cannot be encoded according to strict-DER as specified in BIP66.
	ErrNotEncodable = errors.New("failed to encode value in strict-DER")

	// ErrInvalidSigHashType is returned when DER-encoding a signature, if the sighash type
	// given is larger than can fit in a byte.
	ErrInvalidSigHashType = errors.New("failed to encode invalid sighash type in strict-DER")
)
View Source
var (
	// ErrInvalidSignatureEncoding is returned when decoding a signature fails
	// due to a BIP66 validation problem.
	ErrInvalidSignatureEncoding = errors.New("failed to decode DER signature")
)

Functions

func CheckEncodableBigInt

func CheckEncodableBigInt(v *big.Int) error

CheckEncodableBigInt validates whether the big.Int v can be encoded in strict-DER as defined by BIP66. Returns ErrNotEncodable if it is not encodable.

func DecodeSignature

func DecodeSignature(derEncoded []byte) (r, s *big.Int, sigHashType uint32, err error)

DecodeSignature decodes the given DER-encoded signature byte slice and returns the signature (r, s), as well as the signature hash type. Validates that the format matches BIP66 strict-DER encoding and returns ErrInvalidSignatureEncoding otherwise.

func EncodeBigInt

func EncodeBigInt(v *big.Int) ([]byte, error)

EncodeBigInt encodes a big.Int as a DER byte slice. Returns ErrNotEncodable if it is not encodable.

func EncodeSignature

func EncodeSignature(r, s *big.Int, sigHashType uint32) ([]byte, error)

EncodeSignature encodes the given signature Returns ErrNotEncodable if the signature is not encodable in strict-DER. Returns ErrInvalidSigHashType if sigHashType cannot encode as a single byte.

Types

This section is empty.

Jump to

Keyboard shortcuts

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