key

package
v0.0.0-...-c9cba37 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: Unlicense Imports: 10 Imported by: 0

Documentation

Overview

Package key is a library of functions for handling Bitcoin-style secp256k1 elliptic curve signatures, and a simple in-memory keychain, with support for encryption of non-active private key data.

Index

Constants

View Source
const (
	// SigHashAll is
	SigHashAll = 1
	// SigHashNone is
	SigHashNone = 2
	// SigHashSingle is
	SigHashSingle = 3
	// SigHashAnyoneCanPay is
	SigHashAnyoneCanPay = 0x80
	// VerifyNone is
	VerifyNone = 0
	// VerifyP2SH is
	VerifyP2SH = 1
	// VerifyStrictEnc is
	VerifyStrictEnc = 1 << 1
	// VerifyNocache is
	VerifyNocache = 1 << 2
	// TxNonstandard is a nonstandard transaction (eg just writing bytes)
	TxNonstandard = iota
	// TxPubKey is is a public key
	TxPubKey
	// TxPubKeyHash is the hash of a public key
	TxPubKeyHash
	// TxScriptHash is the hash of a script
	TxScriptHash
	// TxMultisig is a multisignature transaction
	TxMultisig
)

Various script flags

Variables

This section is empty.

Functions

func NewID

func NewID(bytes *[]byte) (out core.Address)

NewID creates an ID out of the bytes of an object, used for address (public key ID) and script ID

Types

type AffectedKeysVisitor

type AffectedKeysVisitor struct {
	KeyStore *Store
	Keys     []core.Address
}

AffectedKeysVisitor -

type Priv

type Priv struct {
	crypt.Crypt

	core.State
	// contains filtered or unexported fields
}

Priv is a private key, stored in a Crypt

func NewPriv

func NewPriv() (priv *Priv)

NewPriv creates a new Priv

func (*Priv) AsEC

func (r *Priv) AsEC() (ecpriv *ecdsa.PrivateKey)

AsEC returns the key in ecdsa.PrivateKey format

func (*Priv) Bytes

func (r *Priv) Bytes() (out *[]byte)

Bytes returns the buffer via the Get function of the Crypt

func (*Priv) Copy

func (r *Priv) Copy(in *[]byte) core.Buffer

Copy stores the input buffer using the Put function of the Crypt

func (*Priv) Free

func (r *Priv) Free() core.Buffer

Free frees the crypt inside the Priv and marks it invalid

func (*Priv) GetID

func (r *Priv) GetID() core.Address

GetID returns the hash160 ID of the public key

func (*Priv) Hex

func (r *Priv) Hex() (out string)

Hex returns the hex representation of the contennt of the crypt via the get function

func (*Priv) Invalidate

func (r *Priv) Invalidate() *Priv

Invalidate zeroes the key and marks it invalid

func (*Priv) IsValid

func (r *Priv) IsValid() bool

IsValid returns true if the Priv is currently valid

func (*Priv) Make

func (r *Priv) Make() *Priv

Make generates a new private key from random bytes. By default it uses compressed format for the public key, to get another format append a further decompression or hybrid method invocation.

func (*Priv) NewIf

func (r *Priv) NewIf() *Priv

NewIf creates a new Pub if the receiver is nil

func (*Priv) PubKey

func (r *Priv) PubKey() core.Buffer

PubKey returns a copy of the public key

func (*Priv) SetKey

func (r *Priv) SetKey(priv *[]byte, pub *[]byte) (out *Priv)

SetKey loads a private key from raw bytes, and zeroes the input bytes of the private key

func (*Priv) Sign

func (r *Priv) Sign(h *[]byte) (out *Sig)

Sign the hash of a message

func (*Priv) SignCompact

func (r *Priv) SignCompact(h *[]byte) (out *Sig)

SignCompact produces a compact signature for BTC type systems

func (*Priv) WithBC

func (r *Priv) WithBC(bc *bc.BlockCrypt) *Priv

WithBC copies in the reference to a BlockCrypt to enable encryption

func (*Priv) Zero

func (r *Priv) Zero() core.Buffer

Zero zeroes the key and marks it invalid

type Pub

type Pub struct {
	buf.Byte
}

Pub is a secp256k1 EC public key which can be represented as a compressed, uncompressed or hybrid for wire and storage

func NewPub

func NewPub() *Pub

NewPub creates a new public key

func (*Pub) AsCompressed

func (r *Pub) AsCompressed() (out *buf.Byte)

AsCompressed returns the compressed serialised form (33 bytes, prefix 2 or 3 depending on whether y is odd or even)

func (*Pub) AsEC

func (r *Pub) AsEC() (out *ecdsa.PublicKey)

AsEC returns the EC public key

func (*Pub) AsHybrid

func (r *Pub) AsHybrid() (out *buf.Byte)

AsHybrid returns the uncompressed serialised form with the first byte taken from the first bit of the y coordinate, either 0 or 1, with both x and y coordinates (this is not really used)

func (*Pub) AsUncompressed

func (r *Pub) AsUncompressed() (out *buf.Byte)

AsUncompressed returns the uncompressed serialised form (65 bytes with x and y with the prefix 4)

func (*Pub) Bytes

func (r *Pub) Bytes() (out *[]byte)

Bytes returns the private key

func (*Pub) Compress

func (r *Pub) Compress() *Pub

Compress converts the key to compressed format if it is in another format

func (*Pub) Copy

func (r *Pub) Copy(in *[]byte) core.Buffer

Copy loads the public key

func (*Pub) Decompress

func (r *Pub) Decompress() *Pub

Decompress converts the key to compressed format if it is in anothter format

func (*Pub) Free

func (r *Pub) Free() core.Buffer

Free deallocates the buffer of the key

func (*Pub) GetID

func (r *Pub) GetID() core.Address

GetID returns the hash160 ID of the public key

func (*Pub) IsCompressed

func (r *Pub) IsCompressed() bool

IsCompressed returns true if the key is compressed

func (*Pub) NewIf

func (r *Pub) NewIf() *Pub

NewIf creates a new Pub if the receiver is nil

func (*Pub) Zero

func (r *Pub) Zero() core.Buffer

Zero wipes the key

type ScriptVisitor

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

ScriptVisitor -

type Sig

type Sig struct {
	buf.Byte
	// contains filtered or unexported fields
}

Sig is a bitcoin EC signature

func NewSig

func NewSig() (out *Sig)

NewSig creates a new signature

func (*Sig) AsEC

func (r *Sig) AsEC() (out *btcec.Signature)

AsEC returns the signature in ecdsa format

func (*Sig) Recover

func (r *Sig) Recover(h *[]byte, addr *[]byte) (out *Pub)

Recover returns a public key with a buffer containing the public key if found and a status indicating if it was successful

type SigData

type SigData struct {
	Hash   core.Hash
	Sig    []byte
	Pubkey Pub
}

SigData -

type SignatureCache

type SignatureCache struct {
	ValidSet []bool
	Mutex    sync.RWMutex
}

SignatureCache -

type Store

type Store struct {
	BC *bc.BlockCrypt

	core.State
	// contains filtered or unexported fields
}

Store is a keychain for public and private keys

func NewStore

func NewStore() *Store

NewStore creates a new Store

func (*Store) AddPriv

func (r *Store) AddPriv(priv *Priv) *Store

AddPriv adds a new private key to the store

func (*Store) AddPub

func (r *Store) AddPub(pub *Pub) *Store

AddPub adds a new public key to the store

func (*Store) Decrypt

func (r *Store) Decrypt() *Store

Decrypt sets the store to not encrypt private keys

func (*Store) Encrypt

func (r *Store) Encrypt(blockCrypt *bc.BlockCrypt) *Store

Encrypt sets the store to encrypt private keys

func (*Store) Find

func (r *Store) Find(id core.Address) (out *Priv)

Find returns the key with matching ID as requested. The return type is Priv but if there is no private key the field is empty

func (*Store) OK

func (r *Store) OK() bool

OK returns true if there is no error

func (*Store) Remove

func (r *Store) Remove(id core.Address) *Store

Remove a key from the store by ID (address)

func (*Store) SetStatus

func (r *Store) SetStatus(s string) core.Status

SetStatus is a

func (*Store) SetStatusIf

func (r *Store) SetStatusIf(err error) core.Status

SetStatusIf is a

func (*Store) UnsetStatus

func (r *Store) UnsetStatus() core.Status

UnsetStatus is a

type StoreIsMineVisitor

type StoreIsMineVisitor struct {
	KeyStore *Store
}

StoreIsMineVisitor -

Jump to

Keyboard shortcuts

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