auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package auth is a generated protocol buffer package.

It is generated from these files:
	x/auth/codec.proto

It has these top-level messages:
	UserData
	StdSignature

Package auth provides basic authentication middleware to verify the signatures on the transaction, and maintain nonces for replay protection.

Index

Constants

View Source
const (
	CodeInvalidSequence uint32 = 20
)

ABCI Response Codes x/auth reserves 20 ~ 29.

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)
View Source
var IsInvalidSignatureErr = errors.IsInvalidSignatureErr

Functions

func BuildSignBytes

func BuildSignBytes(signBytes []byte, chainID string, seq int64) ([]byte, error)

BuildSignBytes combines all info on the actual tx before signing

func BuildSignBytesTx

func BuildSignBytesTx(tx SignedTx, chainID string, seq int64) ([]byte, error)

BuildSignBytesTx calculates the sign bytes given a tx

func ErrInvalidSequence

func ErrInvalidSequence(why string, args ...interface{}) error

func ErrMissingPubKey

func ErrMissingPubKey() error

func ErrPubKeyAddressMismatch

func ErrPubKeyAddressMismatch() error

func GetSigners

func GetSigners(ctx weave.Context) []weave.Address

GetSigners returns who signed the current Context. May be empty

func IsInvalidSequenceErr

func IsInvalidSequenceErr(err error) bool

func VerifySignature

func VerifySignature(store weave.KVStore, sig *StdSignature,
	signBytes []byte, chainID string) (weave.Address, error)

VerifySignature checks one signature against signbytes, check chain and updates state in the store

func VerifyTxSignatures

func VerifyTxSignatures(store weave.KVStore, tx SignedTx,
	chainID string) ([]weave.Address, error)

VerifyTxSignatures checks all the signatures on the tx, which must have at least one.

returns list of signer addresses (possibly empty), or error if any signature is invalid

Types

type Decorator

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

Decorator verifies the signatures and adds them to the context

func NewDecorator

func NewDecorator() Decorator

NewDecorator returns a default authentication decorator, which appends the chainID before checking the signature, and requires at least one signature to be present

func (Decorator) AllowMissingSigs

func (d Decorator) AllowMissingSigs() Decorator

AllowMissingSigs allows us to pass along items with no signatures

func (Decorator) Check

func (d Decorator) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Checker) (weave.CheckResult, error)

Check verifies signatures before calling down the stack

func (Decorator) Deliver

func (d Decorator) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Deliverer) (weave.DeliverResult, error)

Deliver verifies signatures before calling down the stack

type Key

type Key []byte

Key is the primary key we use to distinguish users This should be []byte, in order to index with our KVStore. Any structure to these bytes should be defined by the constructor.

Question: allow objects with a Marshal method???

func NewKey

func NewKey(addr weave.Address) Key

NewKey constructs the user key from a key hash, by appending a prefix.

type SignedTx

type SignedTx interface {
	// GetSignBytes returns the canonical byte representation of the Msg.
	// Equivalent to weave.MustMarshal(tx.GetMsg()) if Msg has a deterministic
	// serialization.
	//
	// Helpful to store original, unparsed bytes here, just in case.
	GetSignBytes() ([]byte, error)

	// Signatures returns the signature of signers who signed the Msg.
	GetSignatures() []*StdSignature
}

SignedTx represents a transaction that contains signatures, which can be verified by the auth.Decorator

type StdSignature

type StdSignature struct {
	Sequence int64 `protobuf:"varint,1,opt,name=Sequence,proto3" json:"Sequence,omitempty"`
	// PubKey required if Sequence == 0
	PubKey *crypto.PublicKey `protobuf:"bytes,2,opt,name=PubKey" json:"PubKey,omitempty"`
	// Address required if PubKey is not present
	Address   []byte            `protobuf:"bytes,3,opt,name=Address,proto3" json:"Address,omitempty"`
	Signature *crypto.Signature `protobuf:"bytes,4,opt,name=Signature" json:"Signature,omitempty"`
}

StdSignature represents the signature, the identity of the signer (either the PubKey or the Address), and a sequence number to prevent replay attacks.

A given signer must submit transactions with the sequence number increasing by 1 each time (starting at 0)

func SignTx

func SignTx(signer crypto.Signer, tx SignedTx, chainID string,
	seq int64) (*StdSignature, error)

SignTx creates a signature for the given tx

func (*StdSignature) Descriptor

func (*StdSignature) Descriptor() ([]byte, []int)

func (*StdSignature) GetAddress

func (m *StdSignature) GetAddress() []byte

func (*StdSignature) GetPubKey

func (m *StdSignature) GetPubKey() *crypto.PublicKey

func (*StdSignature) GetSequence

func (m *StdSignature) GetSequence() int64

func (*StdSignature) GetSignature

func (m *StdSignature) GetSignature() *crypto.Signature

func (*StdSignature) Marshal

func (m *StdSignature) Marshal() (dAtA []byte, err error)

func (*StdSignature) MarshalTo

func (m *StdSignature) MarshalTo(dAtA []byte) (int, error)

func (*StdSignature) ProtoMessage

func (*StdSignature) ProtoMessage()

func (*StdSignature) Reset

func (m *StdSignature) Reset()

func (*StdSignature) Size

func (m *StdSignature) Size() (n int)

func (*StdSignature) String

func (m *StdSignature) String() string

func (*StdSignature) Unmarshal

func (m *StdSignature) Unmarshal(dAtA []byte) error

func (*StdSignature) Validate

func (s *StdSignature) Validate() error

Validate ensures the StdSignature meets basic standards

type User

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

User is the actual object that we want to pass around in our code. It handles loading and saving the data to/from the persistent store. It also adds helpers to manipulate state.

It may allow full access to manipulate all variables on the data, or limit it. It maintains a reference to the store it was loaded from, to know how to save itself.

func GetOrCreateUser

func GetOrCreateUser(store weave.KVStore, key Key) *User

GetOrCreateUser loads this user if present, or initializes a new user with this key if not present.

func GetUser

func GetUser(store weave.KVStore, key Key) *User

GetUser loads this user if present, or returns nil if missing

func (*User) CheckAndIncrementSequence

func (u *User) CheckAndIncrementSequence(check int64) error

CheckAndIncrementSequence checks if the current Sequence matches the expected value. If so, it will increase the sequence by one and return nil If not, it will not change the sequence, but return an error

func (User) HasPubKey

func (u User) HasPubKey() bool

HasPubKey returns true iff the pubkey has been set

func (User) PubKey

func (u User) PubKey() *crypto.PublicKey

PubKey checks the current pubkey for this account

func (*User) Save

func (u *User) Save()

Save writes the current user state to the backing store panics if invalid state

func (User) Sequence

func (u User) Sequence() int64

Sequence checks the current sequence for this account

func (*User) SetPubKey

func (u *User) SetPubKey(pubKey *crypto.PublicKey)

SetPubKey will try to set the PubKey or panic on an illegal operation. It is illegal to reset an already set key Otherwise, we don't control (although we could verify the hash, we leave that to the controller)

type UserData

type UserData struct {
	PubKey   *crypto.PublicKey `protobuf:"bytes,1,opt,name=pub_key,json=pubKey" json:"pub_key,omitempty"`
	Sequence int64             `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"`
}

UserData just stores the data and is used for serialization.

Note: This should not be created from outside the module, User is the entry point you want

func (*UserData) Descriptor

func (*UserData) Descriptor() ([]byte, []int)

func (*UserData) GetPubKey

func (m *UserData) GetPubKey() *crypto.PublicKey

func (*UserData) GetSequence

func (m *UserData) GetSequence() int64

func (*UserData) Marshal

func (m *UserData) Marshal() (dAtA []byte, err error)

func (*UserData) MarshalTo

func (m *UserData) MarshalTo(dAtA []byte) (int, error)

func (*UserData) ProtoMessage

func (*UserData) ProtoMessage()

func (*UserData) Reset

func (m *UserData) Reset()

func (*UserData) Size

func (m *UserData) Size() (n int)

func (*UserData) String

func (m *UserData) String() string

func (*UserData) Unmarshal

func (m *UserData) Unmarshal(dAtA []byte) error

func (UserData) Validate

func (u UserData) Validate() error

Validate must determine if this is a legal state (eg. all required fields set, sequence non-negative, etc.)

Returns an explanation if the data is invalid

Jump to

Keyboard shortcuts

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