key

package
v0.0.0 Latest Latest
Warning

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

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

Documentation

Overview

A library for dealing with keys, scripts, txIDs and collections thereof

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

View Source
var (
	B58prefixes = map[string]map[string]string{
		"mainnet": {
			"pubkey":  hex.EncodeToString([]byte{byte(83)}),
			"script":  hex.EncodeToString([]byte{byte(9)}),
			"privkey": hex.EncodeToString([]byte{byte(178)}),
		},
		"testnet": {
			"pubkey":  hex.EncodeToString([]byte{byte(18)}),
			"script":  hex.EncodeToString([]byte{byte(188)}),
			"privkey": hex.EncodeToString([]byte{byte(239)}),
		},
		"regtestnet": {
			"pubkey":  hex.EncodeToString([]byte{byte(0)}),
			"script":  hex.EncodeToString([]byte{byte(5)}),
			"privkey": hex.EncodeToString([]byte{byte(128)}),
		},
	}
)

Functions

func Check

func Check(b []byte) bool

func NewCipher

func NewCipher(passphrase []byte) (block cipher.Block, err error)

NewCipher creates a new aes-cbc-256 block cipher

Types

type AffectedKeysVisitor

type AffectedKeysVisitor struct {
	KeyStore *Store
	Keys     []ID
}

AffectedKeysVisitor -

type ID

type ID struct {
	Uint.U160
}

func (*ID) Get

func (i *ID) Get() Uint.U160

Get the value of an ID

func (*ID) Set

func (i *ID) Set(d Uint.U160)

Set the value of an ID

type Map

type Map map[*ID]*Pair

Map of keys

type NoDestination

type NoDestination struct{}

type Pair

type Pair struct {
	Public  *Pub
	Private *Priv
}

type Priv

type Priv struct {
	*Pub
	// contains filtered or unexported fields
}

In memory store for a private key (includes the public key)

func NewPriv

func NewPriv() (p Priv, err error)

Creates a new private key from random bytes

func NewPrivFromBytes

func NewPrivFromBytes(key *memguard.LockedBuffer) (p *Priv)

Creates a new private key from a raw secret in a LockedBuffer

func (*Priv) Bytes

func (p *Priv) Bytes() (B memguard.LockedBuffer)

Returns the full private key as a byte slice

func (*Priv) Clear

func (p *Priv) Clear()

Zeroes out all of the contents of the priv and detaches from the unlock cipher

func (*Priv) GetPub

func (p *Priv) GetPub() (P *Pub)

GetPub returns a copy of the public key

func (*Priv) Invalidate

func (p *Priv) Invalidate()

Marks the invalid flag true and wipes all the data

func (*Priv) IsValid

func (p *Priv) IsValid() bool

Returns true if key is valid

func (*Priv) Recover

func (p *Priv) Recover(hash Uint.U256, S []byte) (key *ec.PublicKey, compressed bool, err error)

Recover public key from a signature, identify if it was compressed

func (*Priv) Set

func (p *Priv) Set(b *memguard.LockedBuffer)

Sets the private key of a Priv from the unencrypted bytes

func (*Priv) Sign

func (p *Priv) Sign(hash Uint.U256) (b []byte, err error)

Sign a 256 bit hash

func (*Priv) SignCompact

func (p *Priv) SignCompact(hash Uint.U256) (sig Uint.U256, err error)

SignCompact makes a compact signature on a 256 bit hash

func (*Priv) Size

func (p *Priv) Size() int

Returns the size of the key

func (*Priv) ToBase58Check

func (p *Priv) ToBase58Check(net string) (b58 string, err error)

ToBase58Check returns a private key encoded in base58check with the network specified prefix

func (*Priv) Verify

func (p *Priv) Verify(hash Uint.U256, S []byte) (key *Pub, err error)

Verify a signature on a hash

type Pub

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

func (*Pub) Compress

func (p *Pub) Compress() bool

Compress doesn't really compress, it just flags that outputs will be compressed if it wasn't before

func (*Pub) Decompress

func (p *Pub) Decompress() bool

Decompress doesn't really decompress, it just flags that outputs will be not compressed if they were before

func (*Pub) GetHash

func (p *Pub) GetHash() (u Uint.U256)

GetHash returns the SHA256 hash of the public key

func (*Pub) GetID

func (p *Pub) GetID() (id *ID)

GetID returns the RIPEMD160 hash of the 256 byte public key

func (*Pub) GetPub

func (p *Pub) GetPub() (P *ec.PublicKey)

GetPub returns the key stored in a Priv

func (*Pub) Invalidate

func (p *Pub) Invalidate()

Invalidate marks the invalid flag true

func (*Pub) IsCompressed

func (p *Pub) IsCompressed() bool

IsCompressed returns whether the serializing commands return compressed format

func (*Pub) IsValid

func (p *Pub) IsValid() bool

IsValid returns whether the key has been invalidated or not

func (*Pub) Key

func (p *Pub) Key() []byte

Key returns the raw bytes according to the compression setting

func (*Pub) SetPub

func (p *Pub) SetPub(P ec.PublicKey)

SetPub sets the public key of a Priv

func (*Pub) Size

func (p *Pub) Size() int

Size returns the size of the key if it were requested as bytes

func (*Pub) ToBase58Check

func (p *Pub) ToBase58Check(net string) string

ToBase58Check returns a private key encoded in base58check with the network specified prefix

type Script

type Script []byte

func (*Script) GetID

func (s *Script) GetID() (sid *ScriptID)

GetID computes the RIPEMD160 hash of the script

type ScriptCompressor

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

ScriptCompressor -

type ScriptID

type ScriptID ID

type ScriptMap

type ScriptMap map[*ScriptID]*Script

ScriptMap stores scripts

type ScriptVisitor

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

ScriptVisitor -

type SigData

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

SigData -

type SignatureCache

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

SignatureCache -

type Store

type Store struct {
	Mutex   sync.Mutex
	Keys    Map
	Scripts ScriptMap
}

func NewStore

func NewStore() *Store

NewStore creates a new basic key.Store

func (*Store) AddKeyPair

func (s *Store) AddKeyPair(priv *Priv, pub *Pub) (err error)

AddKeyPair adds a public key to a key.Store

func (*Store) AddPrivKey

func (s *Store) AddPrivKey(priv *Priv) (err error)

AddPrivKey adds a key

func (*Store) AddScript

func (s *Store) AddScript(script *Script) (err error)

AddScript adds a script to the key.Store

func (*Store) GetPriv

func (s *Store) GetPriv(id *ID) (priv *Priv, err error)

GetPriv gets the key matching an id

func (*Store) GetPrivs

func (s *Store) GetPrivs(ids []*ID) (privs []Priv, err error)

GetPrivs gets a set of keys matching the id's in a request

func (*Store) GetPub

func (s *Store) GetPub(id *ID) (pub *Pub)

GetPub gets only the public key from a key with a specified ID

func (*Store) GetScript

func (s *Store) GetScript(id *ScriptID) (script *Script)

GetScript retrieves a script given an ID

func (*Store) HaveKey

func (s *Store) HaveKey(id *ID) (r bool)

func (*Store) HaveScript

func (s *Store) HaveScript(id *ScriptID) (r bool)

type StoreIsMineVisitor

type StoreIsMineVisitor struct {
	KeyStore *Store
}

StoreIsMineVisitor -

type TxDestination

type TxDestination interface{}

Jump to

Keyboard shortcuts

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