key

package
v0.0.0-...-5a6e01e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package key provides keypairs.

Index

Constants

View Source
const KeyTypeSize = 3
View Source
const MinSeedSize = 36

Variables

View Source
var (
	InvalidKeyError                  = util.NewError("invalid key")
	SignatureVerificationFailedError = util.NewError("signature verification failed")
)
View Source
var (
	BasePrivatekeyType = hint.Type("mpr")
	BasePrivatekeyHint = hint.NewHint(BasePrivatekeyType, "v0.0.1")
	BasePublickeyType  = hint.Type("mpu")
	BasePublickeyHint  = hint.NewHint(BasePublickeyType, "v0.0.1")
)

Functions

This section is empty.

Types

type BasePrivatekey

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

BasePrivatekey is based on BTC Privatekey.

func LoadBasePrivatekey

func LoadBasePrivatekey(s string) (BasePrivatekey, error)

func NewBasePrivatekey

func NewBasePrivatekey() BasePrivatekey

func NewBasePrivatekeyFromSeed

func NewBasePrivatekeyFromSeed(s string) (BasePrivatekey, error)

func ParseBasePrivatekey

func ParseBasePrivatekey(s string) (BasePrivatekey, error)

func (BasePrivatekey) Bytes

func (k BasePrivatekey) Bytes() []byte

func (BasePrivatekey) Equal

func (k BasePrivatekey) Equal(b Key) bool

func (BasePrivatekey) Hint

func (BasePrivatekey) Hint() hint.Hint

func (BasePrivatekey) IsValid

func (k BasePrivatekey) IsValid([]byte) error

func (BasePrivatekey) MarshalBSONValue

func (k BasePrivatekey) MarshalBSONValue() (bsontype.Type, []byte, error)

func (BasePrivatekey) MarshalText

func (k BasePrivatekey) MarshalText() ([]byte, error)

func (BasePrivatekey) Publickey

func (k BasePrivatekey) Publickey() Publickey

func (BasePrivatekey) Sign

func (k BasePrivatekey) Sign(b []byte) (Signature, error)

func (BasePrivatekey) String

func (k BasePrivatekey) String() string

func (*BasePrivatekey) UnmarshalBSONValue

func (k *BasePrivatekey) UnmarshalBSONValue(t bsontype.Type, b []byte) error

func (*BasePrivatekey) UnmarshalText

func (k *BasePrivatekey) UnmarshalText(b []byte) error

func (*BasePrivatekey) UnpackBSON

func (k *BasePrivatekey) UnpackBSON(b []byte, _ *bsonenc.Encoder) error

func (*BasePrivatekey) UnpackJSON

func (k *BasePrivatekey) UnpackJSON(b []byte, _ *jsonenc.Encoder) error

type BasePublickey

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

func LoadBasePublickey

func LoadBasePublickey(s string) (BasePublickey, error)

func NewBasePublickey

func NewBasePublickey(k *btcec.PublicKey) BasePublickey

func ParseBasePublickey

func ParseBasePublickey(s string) (BasePublickey, error)

func (BasePublickey) Bytes

func (k BasePublickey) Bytes() []byte

func (BasePublickey) Equal

func (k BasePublickey) Equal(b Key) bool

func (BasePublickey) Hint

func (BasePublickey) Hint() hint.Hint

func (BasePublickey) IsValid

func (k BasePublickey) IsValid([]byte) error

func (BasePublickey) MarshalBSONValue

func (k BasePublickey) MarshalBSONValue() (bsontype.Type, []byte, error)

func (BasePublickey) MarshalText

func (k BasePublickey) MarshalText() ([]byte, error)

func (BasePublickey) String

func (k BasePublickey) String() string

func (*BasePublickey) UnmarshalBSONValue

func (k *BasePublickey) UnmarshalBSONValue(t bsontype.Type, b []byte) error

func (*BasePublickey) UnmarshalText

func (k *BasePublickey) UnmarshalText(b []byte) error

func (*BasePublickey) UnpackBSON

func (k *BasePublickey) UnpackBSON(b []byte, _ *bsonenc.Encoder) error

func (*BasePublickey) UnpackJSON

func (k *BasePublickey) UnpackJSON(b []byte, _ *jsonenc.Encoder) error

func (BasePublickey) Verify

func (k BasePublickey) Verify(input []byte, sig Signature) error

type Key

type Key interface {
	fmt.Stringer
	hint.Hinter
	util.Byter
	isvalid.IsValider
	Equal(Key) bool
}

func DecodeKeyFromString

func DecodeKeyFromString(s string, enc encoder.Encoder) (Key, error)

DecodeKeyFromString parses and decodes Key from string.

type KeyDecoder

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

KeyDecoder is basic unmarshaler for Keys. It can unmarshal Privatekey and publickey.

func (KeyDecoder) Body

func (kd KeyDecoder) Body() []byte

func (*KeyDecoder) Encode

func (kd *KeyDecoder) Encode(enc encoder.Encoder) (Key, error)

Encode is used with encoder.Encoder.

var de struct {
	Key KeyDecoder
}

err := json.Unmarshal(b, &de)

if err != nil {
	return err
}

enc := jsonenc.NewEncoder() uk, err := de.Key.Encode(enc)

if err != nil {
	return err
}

priv, ok := uk.(Privtekey) pub, ok := uk.(Publickey)

func (KeyDecoder) Type

func (kd KeyDecoder) Type() hint.Type

func (*KeyDecoder) UnmarshalBSON

func (kd *KeyDecoder) UnmarshalBSON(b []byte) error

func (*KeyDecoder) UnmarshalJSON

func (kd *KeyDecoder) UnmarshalJSON(b []byte) error

type Privatekey

type Privatekey interface {
	Key
	Publickey() Publickey
	Sign([]byte) (Signature, error)
}

func DecodePrivatekeyFromString

func DecodePrivatekeyFromString(s string, enc encoder.Encoder) (Privatekey, error)

type PrivatekeyDecoder

type PrivatekeyDecoder struct {
	KeyDecoder
}

PrivatekeyDecoder is basic unmarshaler for Privatekey.

func (*PrivatekeyDecoder) Encode

func (kd *PrivatekeyDecoder) Encode(enc encoder.Encoder) (Privatekey, error)

type Publickey

type Publickey interface {
	Key
	Verify([]byte, Signature) error
}

func DecodePublickeyFromString

func DecodePublickeyFromString(s string, enc encoder.Encoder) (Publickey, error)

type PublickeyDecoder

type PublickeyDecoder struct {
	KeyDecoder
}

PublickeyDecoder is basic unmarshaler for Privatekey.

func (*PublickeyDecoder) Encode

func (kd *PublickeyDecoder) Encode(enc encoder.Encoder) (Publickey, error)

type Signature

type Signature []byte

func NewSignatureFromString

func NewSignatureFromString(s string) Signature

func (Signature) Bytes

func (sg Signature) Bytes() []byte

func (Signature) Equal

func (sg Signature) Equal(ns Signature) bool

func (Signature) IsValid

func (sg Signature) IsValid([]byte) error

func (Signature) MarshalBSONValue

func (sg Signature) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Signature) MarshalJSON

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

func (Signature) String

func (sg Signature) String() string

func (*Signature) UnmarshalBSONValue

func (sg *Signature) UnmarshalBSONValue(_ bsontype.Type, b []byte) error

func (*Signature) UnmarshalJSON

func (sg *Signature) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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