ecc

package
v1.12.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 16 Imported by: 26

Documentation

Index

Constants

View Source
const (
	CurveK1 = CurveID(iota)
	CurveR1
	CurveWA
	CurveGM
)
View Source
const PrivKeyBytesLen = 32
View Source
const PrivateKeyPrefix = "PVT_"
View Source
const SignatureGMPrefix = "SIG_GM_"
View Source
const SignatureK1Prefix = "SIG_K1_"
View Source
const SignatureR1Prefix = "SIG_R1_"
View Source
const SignatureWAPrefix = "SIG_WA_"

Variables

View Source
var B3 = big.NewInt(3)

We use 3 a couple of times in the decompress algorithm below

View Source
var ErrChecksumMismatch = errors.New("checksum mismatch")

ErrChecksumMismatch describes an error where decoding failed due to a bad checksum.

View Source
var ErrMalformedPrivateKey = errors.New("malformed private key")

ErrMalformedPrivateKey describes an error where a WIF-encoded private key cannot be decoded due to being improperly formatted. This may occur if the byte length is incorrect or an unexpected magic number was encountered.

View Source
var PublicKeyGMPrefix = "PUB_GM_"
View Source
var PublicKeyK1Prefix = "PUB_K1_"
View Source
var PublicKeyPrefix = "PUB_"
View Source
var PublicKeyPrefixCompat = "EOS"
View Source
var PublicKeyR1Prefix = "PUB_R1_"
View Source
var PublicKeyWAPrefix = "PUB_WA_"

Functions

func CompressReal added in v1.9.0

func CompressReal(a *sm2.PublicKey) []byte

func DecodeWIFBytes added in v1.8.0

func DecodeWIFBytes(wif string, suffix string) ([]byte, error)

func DoubleHashWIF added in v1.8.0

func DoubleHashWIF(b []byte) []byte

DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.

func DoubleHashWIFSuffix added in v1.9.0

func DoubleHashWIFSuffix(b []byte, suffix string) []byte

func EncodeWifSM2PrivateKey added in v1.8.0

func EncodeWifSM2PrivateKey(netID byte, wifBytes []byte, compressed bool) string

func ReadSM2PrivateKeyFromBytes added in v1.8.0

func ReadSM2PrivateKeyFromBytes(d []byte) (*sm2.PrivateKey, error)

func Ripe160SuffixStringChecksum added in v1.9.0

func Ripe160SuffixStringChecksum(b []byte, suffix string) []byte

Types

type CurveID

type CurveID uint8

func (CurveID) String

func (c CurveID) String() string

func (CurveID) StringPrefix

func (c CurveID) StringPrefix() string

type DecodedWIF added in v1.8.0

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

type PrivateKey

type PrivateKey struct {
	Curve CurveID
	// contains filtered or unexported fields
}

func NewDeterministicPrivateKey

func NewDeterministicPrivateKey(randSource io.Reader) (*PrivateKey, error)

func NewPrivateKey

func NewPrivateKey(wif string) (*PrivateKey, error)

func NewPrivateKeyFromSeed

func NewPrivateKeyFromSeed(seed string) (*PrivateKey, error)

func NewRandomPrivateKey

func NewRandomPrivateKey() (*PrivateKey, error)

func (*PrivateKey) MarshalJSON

func (p *PrivateKey) MarshalJSON() ([]byte, error)

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey() PublicKey

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(hash []byte) (out Signature, err error)

Sign signs a 32 bytes SHA256 hash..

func (*PrivateKey) String

func (p *PrivateKey) String() string

func (*PrivateKey) UnmarshalJSON

func (p *PrivateKey) UnmarshalJSON(v []byte) (err error)

type PublicKey

type PublicKey struct {
	Curve   CurveID
	Content []byte
	// contains filtered or unexported fields
}

func MustNewPublicKey

func MustNewPublicKey(pubKey string) PublicKey

func MustNewPublicKeyFromData

func MustNewPublicKeyFromData(data []byte) PublicKey

func NewPublicKey

func NewPublicKey(pubKey string) (out PublicKey, err error)

func NewPublicKeyFromData

func NewPublicKeyFromData(data []byte) (out PublicKey, err error)

func (PublicKey) IsEmpty

func (p PublicKey) IsEmpty() bool

func (PublicKey) Key

func (p PublicKey) Key() (*btcec.PublicKey, error)

func (PublicKey) KeyMaterialSize

func (p PublicKey) KeyMaterialSize() int

func (PublicKey) MarshalJSON

func (p PublicKey) MarshalJSON() ([]byte, error)

func (PublicKey) String

func (p PublicKey) String() string

func (*PublicKey) UnmarshalJSON

func (p *PublicKey) UnmarshalJSON(data []byte) error

func (PublicKey) Validate

func (p PublicKey) Validate() error

type Signature

type Signature struct {
	Curve   CurveID
	Content []byte // the Compact signature as bytes
	// contains filtered or unexported fields
}

Signature represents a signature for some hash

func MustNewSignature

func MustNewSignature(fromText string) Signature

func MustNewSignatureFromData

func MustNewSignatureFromData(data []byte) Signature

func NewSignature

func NewSignature(signature string) (out Signature, err error)

func NewSignatureFromData

func NewSignatureFromData(data []byte) (Signature, error)

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

func (Signature) PublicKey

func (s Signature) PublicKey(hash []byte) (out PublicKey, err error)

func (Signature) String

func (s Signature) String() string

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(data []byte) (err error)

func (Signature) Validate

func (s Signature) Validate() error

func (Signature) Verify

func (s Signature) Verify(hash []byte, pubKey PublicKey) bool

Jump to

Keyboard shortcuts

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