flatcosi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package flatcosi is a flat implementation of a collective signing so that the orchestrator will contact all the participants to require their signatures and then aggregate them to the final one.

Documentation Last Review: 05.10.2020

Example
package main

import (
	"context"
	"errors"
	"fmt"
	"time"

	"go.dedis.ch/dela/crypto"
	"go.dedis.ch/dela/crypto/bls"
	"go.dedis.ch/dela/mino"
	"go.dedis.ch/dela/mino/minoch"
	"go.dedis.ch/dela/serde"
	"go.dedis.ch/dela/testing/fake"
)

func main() {
	// Create the network overlay instances. It uses channels to communicate.
	manager := minoch.NewManager()

	mA := minoch.MustCreate(manager, "A")
	mB := minoch.MustCreate(manager, "B")

	// The list of participants to the signature.
	roster := fake.NewAuthorityFromMino(bls.Generate, mA, mB)

	// Create the collective signing endpoints for both A and B.
	cosiA := NewFlat(mA, roster.GetSigner(0).(crypto.AggregateSigner))

	actor, err := cosiA.Listen(exampleReactor{})
	if err != nil {
		panic(fmt.Sprintf("failed to listen on root: %+v", err))
	}

	cosiB := NewFlat(mB, roster.GetSigner(1).(crypto.AggregateSigner))
	_, err = cosiB.Listen(exampleReactor{})
	if err != nil {
		panic(fmt.Sprintf("failed to listen on child: %+v", err))
	}

	// Context to timeout after 30 seconds if no signature is received.
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	msg := exampleMessage{Value: "42"}

	signature, err := actor.Sign(ctx, msg, roster)
	if err != nil {
		panic(fmt.Sprintf("failed to sign: %+v", err))
	}

	// We need a verifier implementation to support collective signatures.
	verifier, err := cosiA.GetVerifierFactory().FromAuthority(roster)
	if err != nil {
		panic(fmt.Sprintf("verifier failed: %+v", err))
	}

	err = verifier.Verify([]byte(msg.Value), signature)
	if err != nil {
		panic(fmt.Sprintf("signature is invalid: %+v", err))
	}

	fmt.Println("Success", err == nil)

}

type exampleMessage struct {
	Value string
}

func (msg exampleMessage) Serialize(ctx serde.Context) ([]byte, error) {
	return ctx.Marshal(msg)
}

type exampleReactor struct{}

func (exampleReactor) Invoke(from mino.Address, msg serde.Message) ([]byte, error) {
	example, ok := msg.(exampleMessage)
	if !ok {
		return nil, errors.New("unsupported message")
	}

	fmt.Println("Signing value", example.Value)

	return []byte(example.Value), nil
}

func (exampleReactor) Deserialize(ctx serde.Context, data []byte) (serde.Message, error) {
	var msg exampleMessage
	err := ctx.Unmarshal(data, &msg)

	return msg, err
}
Output:

Signing value 42
Signing value 42
Signing value 42
Success true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flat

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

Flat is an implementation of the collective signing interface by using BLS signatures. It ignores the threshold and always requests a signature from every participant.

- implements cosi.CollectiveSigning

func NewFlat

func NewFlat(o mino.Mino, signer crypto.AggregateSigner) *Flat

NewFlat returns a new collective signing instance.

func (*Flat) GetPublicKeyFactory

func (flat *Flat) GetPublicKeyFactory() crypto.PublicKeyFactory

GetPublicKeyFactory implements cosi.CollectiveSigning. It returns the public key factory.

func (*Flat) GetSignatureFactory

func (flat *Flat) GetSignatureFactory() crypto.SignatureFactory

GetSignatureFactory implements cosi.CollectiveSigning. It returns the signature factory.

func (*Flat) GetSigner

func (flat *Flat) GetSigner() crypto.Signer

GetSigner implements cosi.CollectiveSigning. It returns the signer of the instance.

func (*Flat) GetVerifierFactory

func (flat *Flat) GetVerifierFactory() crypto.VerifierFactory

GetVerifierFactory implements cosi.CollectiveSigning. It returns the verifier factory.

func (*Flat) Listen

func (flat *Flat) Listen(r cosi.Reactor) (cosi.Actor, error)

Listen implements cosi.CollectiveSigning. It creates an actor that starts an RPC called cosi and respond to signing requests. The actor can also be used to sign a message.

func (*Flat) SetThreshold

func (flat *Flat) SetThreshold(fn cosi.Threshold)

SetThreshold implements cosi.CollectiveSigning. It ignores the new threshold as this implementation only accepts full participation.

Jump to

Keyboard shortcuts

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