security

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SEd25519 = 1
	Secdsa   = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyState

type KeyState struct {
	SigGroups map[string]SigGroup
}

KeyState Required to provide the signatures for managing chains within an ADI A KeyState always has at

type MultiSig

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

MultiSig A slice of Sig structs where each Sig signs a message. It gives the m signatures of a possible n specified by the MultiSigSpec

func (*MultiSig) AddSig

func (s *MultiSig) AddSig(msgHash [32]byte, sig Sig)

AddSig Add a Sig to a MultiSig. panics if the signature doesn't match the message Hash

func (*MultiSig) Check

func (s *MultiSig) Check()

Check Throws a panic if anything is wrong about the MultiSig. Mostly that the signatures given have no duplicates.

func (*MultiSig) Marshal

func (s *MultiSig) Marshal() (data []byte)

Marshal Marshals the MultiSig into a byte slice

func (*MultiSig) Unmarshal

func (s *MultiSig) Unmarshal(data []byte) []byte

Unmarshal Get the values from a data slice to set up a MultiSig Note anything off, this function panics

func (*MultiSig) Verify

func (s *MultiSig) Verify(message [32]byte) bool

Verify Check that the signatures of the MultiSig all validly sign a given message.

type Sig

type Sig interface {
	Type() int                                           // Returns the type implementing the interface
	Signature() []byte                                   // Returns the signature
	Marshal() []byte                                     // Marshals the object implementing Sig into a slice
	PublicKey() []byte                                   // Returns the public key
	Unmarshal(data []byte) []byte                        // Sets object implementing Sig to state defined by byte slice
	Verify(ms *MultiSig, idx int, msgHash [32]byte) bool // Validates message. True if message is validated by signature
	Equal(sig Sig) bool                                  // Returns true if two signatures are equal
}

func Unmarshal

func Unmarshal(data []byte) (sig Sig, newData []byte)

Unmarshal detects the type of sig in the data stream, then allocates a sig and Unmarshal() its state into the new sig. Returns the sig and the updated data slice

type SigEd25519

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

func (*SigEd25519) Equal

func (s *SigEd25519) Equal(sig Sig) bool

Equal compare two Sig instances and return true if they are the same

func (*SigEd25519) Marshal

func (s *SigEd25519) Marshal() (data []byte)

Marshal Marshals the Signature

func (*SigEd25519) PublicKey

func (s *SigEd25519) PublicKey() []byte

PublicKey Returns public key for the signature. We can in many cases eliminate the public key from the signature, but for now we will include it.

func (*SigEd25519) Sign

func (s *SigEd25519) Sign(msg []byte)

Sign Signs the given message, and populates the signature in the Sig

func (*SigEd25519) Signature

func (s *SigEd25519) Signature() []byte

Signature Returns the bytes holding the signature

func (*SigEd25519) Type

func (s *SigEd25519) Type() int

Type Returns the type for an Ed25519 signature

func (*SigEd25519) Unmarshal

func (s *SigEd25519) Unmarshal(data []byte) []byte

Unmarshal UnMarshals the data stream into a SigEd25519 Note that the type byte is assumed to be present, and a panic is thrown if the the byte isn't present, or the data stream is not sufficent to hold the Ed25519 signature

func (*SigEd25519) Verify

func (s *SigEd25519) Verify(_ *MultiSig, _ int, msgHash [32]byte) bool

Verify Verify that the signature is valid for the given message

type SigGroup

type SigGroup struct {
	SigSpecs []SigSpec // The SigSpec of a hash if not a MAST SigSpec
}

SigGroup Defines a set of SigSpecs. The priorities of the SigSpecs is indicated by their position in the SigSpecs slice, where a lower index indicates a higher priority.

SigGroups are persisted as a slice of hashes. On load, the SigSpecs are loaded for not MAST SigSpecs. For MAST SigSpecs, transactions must provide a SigSpec that validates against the hash in the SigGroup

func (*SigGroup) AddSigSpec

func (s *SigGroup) AddSigSpec(auth, dest int, sigSpec SigSpec) error

AddSigSpec Adds or replaces a SigSpec authorized by the SigSpec at index auth, and placed at the index dest. Note that the destination cannot leave a nil entry in the SigSpecs slice.

func (*SigGroup) DeleteSigSpec

func (s *SigGroup) DeleteSigSpec(auth, dest int, sigSpec SigSpec) error

DeleteSigSpec Removes a SigSpec from the the SigSpec Slice

type SigSpec

type SigSpec struct {
	PublicKeys [][32]byte // Candidate Signatures.  Must be exactly equal to n
	// contains filtered or unexported fields
}

SigSpec Defines the public keys that can be used in a multiSignature

func (*SigSpec) AddSig

func (s *SigSpec) AddSig(publicKey [32]byte)

AddSig Add a Sig to a SigSpec

func (*SigSpec) Check

func (s *SigSpec) Check()

Check Panics if m of n and list of public keys are not consistent. As a side effect, Check sorts the Public Keys

func (*SigSpec) Marshal

func (s *SigSpec) Marshal() (data []byte)

Marshal Marshals the SigSpec into a byte slice

func (*SigSpec) Unmarshal

func (s *SigSpec) Unmarshal(data []byte) []byte

Unmarshal Get the values from a data slice to set up a SigSpec Note anything off, this function panics

func (*SigSpec) Verify

func (s *SigSpec) Verify(mSig *MultiSig) (r bool)

Verify SigSpec verifies a MultiSig instance meets the SigSpec. Note that the sigs in a MultiSig likely come from different parties, so we can tolerate some not matching, or more matching than we need.

type Signature

type Signature interface {
	Validate(sigSpec SigSpec, trans []byte) // Validates a given transaction.  Note that the sigSpec may be required

}

Jump to

Keyboard shortcuts

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