merklesignature

package
v0.0.0-...-15eb78e Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MerkleSignatureSchemeHashFunction = crypto.Sumhash
	MerkleSignatureSchemeRootSize     = crypto.SumhashDigestSize
)

HashType/ hashSize relate to the type of hash this package uses.

Variables

View Source
var (
	ErrStartBiggerThanEndRound           = errors.New("cannot create Merkle Signature Scheme because end round is smaller then start round")
	ErrDivisorIsZero                     = errors.New("received zero Interval")
	ErrNoStateProofKeyForRound           = errors.New("no stateproof key exists for this round")
	ErrSignatureSchemeVerificationFailed = errors.New("merkle signature verification failed")
)

Errors for the merkle signature scheme

View Source
var CryptoPrimitivesID = uint16(0)

CryptoPrimitivesID is an identification that the Merkle Signature Scheme uses a subset sum hash function and a falcon signature scheme.

View Source
var ErrIndexOutOfBound = errors.New("index is out of bound")

ErrIndexOutOfBound returned when an index is out of the array's bound

Functions

func InstallStateProofTable

func InstallStateProofTable(tx *sql.Tx) error

InstallStateProofTable creates (or migrates if exists already) the StateProofKeys database table

func KeysBuilder

func KeysBuilder(numberOfKeys uint64) ([]crypto.FalconSigner, error)

KeysBuilder Responsible for generate slice of falcon keys

Types

type CommittablePublicKey

type CommittablePublicKey struct {
	VerifyingKey crypto.FalconVerifier
	Round        uint64
}

CommittablePublicKey is used to create a binary representation of public keys in the merkle signature scheme.

func (*CommittablePublicKey) ToBeHashed

func (e *CommittablePublicKey) ToBeHashed() (protocol.HashID, []byte)

ToBeHashed returns the sequence of bytes that would be used as an input for the hash function when creating a merkle tree. In order to create a more SNARK-friendly commitment we must avoid using the msgpack infrastructure. msgpack creates a compressed representation of the struct which might be varied in length, this will be bad for creating SNARK

type KeyRoundPair

type KeyRoundPair struct {
	Round uint64               `codec:"rnd"`
	Key   *crypto.FalconSigner `codec:"key"`
	// contains filtered or unexported fields
}

KeyRoundPair represents an ephemeral signing key with it's corresponding round

func (*KeyRoundPair) CanMarshalMsg

func (_ *KeyRoundPair) CanMarshalMsg(z interface{}) bool

func (*KeyRoundPair) CanUnmarshalMsg

func (_ *KeyRoundPair) CanUnmarshalMsg(z interface{}) bool

func (*KeyRoundPair) MarshalMsg

func (z *KeyRoundPair) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*KeyRoundPair) MsgIsZero

func (z *KeyRoundPair) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*KeyRoundPair) Msgsize

func (z *KeyRoundPair) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*KeyRoundPair) UnmarshalMsg

func (z *KeyRoundPair) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Secrets

type Secrets struct {
	SignerContext
	// contains filtered or unexported fields
}

Secrets contains the private data needed by the merkle signature scheme.

func New

func New(firstValid, lastValid, interval uint64) (*Secrets, error)

New creates secrets needed for the merkle signature scheme. This function generates one key for each round within the participation period [firstValid, lastValid] (inclusive bounds) which holds round % interval == 0. In case firstValid equals zero then signer will generate all keys from (0,Z], i.e will not generate key for round zero.

func (*Secrets) CanMarshalMsg

func (_ *Secrets) CanMarshalMsg(z interface{}) bool

func (*Secrets) CanUnmarshalMsg

func (_ *Secrets) CanUnmarshalMsg(z interface{}) bool

func (*Secrets) GetAllKeys

func (s *Secrets) GetAllKeys() []KeyRoundPair

GetAllKeys returns all stateproof secrets. An empty array will be return if no stateproof secrets are found

func (*Secrets) GetKey

func (s *Secrets) GetKey(round uint64) *crypto.FalconSigner

GetKey retrieves key from memory the function return nil if the key does not exists

func (*Secrets) GetSigner

func (s *Secrets) GetSigner(round uint64) *Signer

GetSigner returns the secret keys required for the specified round as well as the rest of the required state proof immutable data

func (*Secrets) GetVerifier

func (s *Secrets) GetVerifier() *Verifier

GetVerifier can be used to store the commitment and verifier for this signer.

func (*Secrets) MarshalMsg

func (z *Secrets) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*Secrets) MsgIsZero

func (z *Secrets) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Secrets) Msgsize

func (z *Secrets) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Secrets) Persist

func (s *Secrets) Persist(store db.Accessor) error

Persist dumps the keys into the database and deletes the reference to them in Secrets

func (*Secrets) RestoreAllSecrets

func (s *Secrets) RestoreAllSecrets(store db.Accessor) error

RestoreAllSecrets fetch all stateproof secrets from a persisted storage into memory

func (*Secrets) UnmarshalMsg

func (z *Secrets) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Signature

type Signature struct {
	Signature        crypto.FalconSignature      `codec:"sig"`
	MerkleArrayIndex uint64                      `codec:"idx"`
	Proof            merklearray.SingleLeafProof `codec:"prf"`
	VerifyingKey     crypto.FalconVerifier       `codec:"vkey"`
	// contains filtered or unexported fields
}

Signature represents a signature in the merkle signature scheme using falcon signatures as an underlying crypto scheme. It consists of an ephemeral public key, a signature, a merkle verification path and an index. The merkle signature considered valid only if the Signature is verified under the ephemeral public key and the Merkle verification path verifies that the ephemeral public key is located at the given index of the tree (for the root given in the long-term public key). More details can be found on Algorand's spec

서명은 기본 암호 체계로 FalconSignature을 사용하는 머클 서명 체계의 서명을 나타냅니다.
임시 공개 키, 서명, 머클 검증 경로 및 인덱스로 구성됩니다.
머클 서명은 서명이 임시 공개 키에서 확인되고 머클 검증 경로가 임시 공개 키가
트리의 주어진 인덱스(장기 공개 키에 주어진 루트에 대해)에 있는지 확인하는 경우에만 유효한 것으로 간주됩니다.

func (*Signature) CanMarshalMsg

func (_ *Signature) CanMarshalMsg(z interface{}) bool

func (*Signature) CanUnmarshalMsg

func (_ *Signature) CanUnmarshalMsg(z interface{}) bool

func (*Signature) GetFixedLengthHashableRepresentation

func (s *Signature) GetFixedLengthHashableRepresentation() ([]byte, error)

GetFixedLengthHashableRepresentation returns the signature as a hashable byte sequence. the format details can be found in the Algorand's spec.

func (*Signature) MarshalMsg

func (z *Signature) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*Signature) MsgIsZero

func (z *Signature) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Signature) Msgsize

func (z *Signature) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Signature) UnmarshalMsg

func (z *Signature) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Signer

type Signer struct {
	SigningKey *crypto.FalconSigner

	// The round for which this SigningKey is related to
	Round uint64

	SignerContext
}

Signer represents the StateProof signer for a specified round.

서명자는 지정된 라운드에 대한 StateProof 서명자를 나타냅니다.

func (*Signer) Sign

func (s *Signer) Sign(hashable crypto.Hashable) (Signature, error)

Sign signs a hash of a given message. The signature is valid on a specific round

type SignerContext

type SignerContext struct {
	FirstValid uint64           `codec:"fv"`
	Interval   uint64           `codec:"iv"`
	Tree       merklearray.Tree `codec:"tree"`
	// contains filtered or unexported fields
}

SignerContext contains all the immutable data and metadata related to merklesignature.Secrets (without the secret keys)

func (*SignerContext) CanMarshalMsg

func (_ *SignerContext) CanMarshalMsg(z interface{}) bool

func (*SignerContext) CanUnmarshalMsg

func (_ *SignerContext) CanUnmarshalMsg(z interface{}) bool

func (*SignerContext) GetVerifier

func (s *SignerContext) GetVerifier() *Verifier

GetVerifier can be used to store the commitment and verifier for this signer.

func (*SignerContext) MarshalMsg

func (z *SignerContext) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*SignerContext) MsgIsZero

func (z *SignerContext) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*SignerContext) Msgsize

func (z *SignerContext) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*SignerContext) UnmarshalMsg

func (z *SignerContext) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Verifier

Verifier is used to verify a merklesignature.Signature produced by merklesignature.Secrets.

func (*Verifier) CanMarshalMsg

func (_ *Verifier) CanMarshalMsg(z interface{}) bool

func (*Verifier) CanUnmarshalMsg

func (_ *Verifier) CanUnmarshalMsg(z interface{}) bool

func (*Verifier) IsEmpty

func (v *Verifier) IsEmpty() bool

IsEmpty returns true if the verifier contains an empty key

func (*Verifier) MarshalMsg

func (z *Verifier) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*Verifier) MsgIsZero

func (z *Verifier) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Verifier) Msgsize

func (z *Verifier) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Verifier) UnmarshalMsg

func (z *Verifier) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Verifier) Verify

func (v *Verifier) Verify(round uint64, msg crypto.Hashable, sig Signature) error

Verify verifies that a merklesignature sig is valid, on a specific round, under a given public key

Jump to

Keyboard shortcuts

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