dkg

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:  "dkg",
	Long: `Distributed key generation for creating secret shares without any dealer.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		yamlFile, err := os.ReadFile(viper.GetString("config"))
		if err != nil {
			return err
		}

		cfg := DKGConfig{}
		err = yaml.Unmarshal(yamlFile, &cfg)
		if err != nil {
			return err
		}

		rawIdentity, err := base64.StdEncoding.DecodeString(cfg.Identity)
		priv, err := crypto.UnmarshalPrivateKey(rawIdentity)
		if err != nil {
			log.Crit("Failed to unmarshal", "err", err)
		}

		host, err := node.MakeBasicHost(cfg.Port, priv)
		if err != nil {
			log.Crit("Failed to create a basic host", "err", err)
		}

		selfId := host.ID().String()

		log.Debug("my ID", "id", selfId, "addr", host.Addrs())

		pm := node.NewPeerManager(selfId, host, dkgProtocol)

		for _, p := range cfg.Peers {
			pm.AddPeer(p.Id, node.GetPeerAddr(p.Port, p.Id))
		}

		l := node.NewListener()

		dkgCore, err := dkg.NewDKG(utils.GetCurve(), pm, cfg.Threshold, cfg.Rank, l)
		if err != nil {
			log.Warn("Cannot create a new DKG", "config", cfg, "err", err)
			return err
		}

		node := node.New[*dkg.Message, *dkg.Result](dkgCore, l, pm)
		if err != nil {
			log.Crit("Failed to new service", "err", err)
		}

		host.SetStreamHandler(dkgProtocol, func(s network.Stream) {
			node.Handle(s)
		})

		pm.EnsureAllConnected()

		result, err := node.Process()
		if err != nil {
			return err
		}

		dkgResult := &DKGResult{
			Share: result.Share.String(),
			Pubkey: config.Pubkey{
				X: result.PublicKey.GetX().String(),
				Y: result.PublicKey.GetY().String(),
			},
			BKs: make(map[string]config.BK),
		}
		for peerID, bk := range result.Bks {
			dkgResult.BKs[peerID] = config.BK{
				X:    bk.GetX().String(),
				Rank: bk.GetRank(),
			}
		}

		fmt.Println()
		rawResult, _ := yaml.Marshal(dkgResult)
		fmt.Println(string(rawResult))

		return nil
	},
}

Functions

This section is empty.

Types

type DKGConfig

type DKGConfig struct {
	node.PeerConfig `yaml:",omitempty,inline"`

	Rank      uint32 `yaml:"rank"`
	Threshold uint32 `yaml:"threshold"`
}

type DKGResult

type DKGResult struct {
	Share  string               `yaml:"share"`
	Pubkey config.Pubkey        `yaml:"pubkey"`
	BKs    map[string]config.BK `yaml:"bks"`
}

Jump to

Keyboard shortcuts

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