Prad Nukala 807b2e86ec
feature/1220 origin handle exists method (#1241)
* feat: add docs and CI workflow for publishing to onsonr.dev

* (refactor): Move hway,motr executables to their own repos

* feat: simplify devnet and testnet configurations

* refactor: update import path for didcrypto package

* docs(networks): Add README with project overview, architecture, and community links

* refactor: Move network configurations to deploy directory

* build: update golang version to 1.23

* refactor: move logger interface to appropriate package

* refactor: Move devnet configuration to networks/devnet

* chore: improve release process with date variable

* (chore): Move Crypto Library

* refactor: improve code structure and readability in DID module

* feat: integrate Trunk CI checks

* ci: optimize CI workflow by removing redundant build jobs

---------

Co-authored-by: Darp Alakun <i@prad.nu>
2025-01-06 17:06:10 +00:00

79 lines
1.7 KiB
Go
Executable File

//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package frost
import (
"bytes"
crand "crypto/rand"
"encoding/gob"
"github.com/pkg/errors"
"github.com/onsonr/sonr/crypto/core/curves"
"github.com/onsonr/sonr/crypto/internal"
)
// Round1Bcast contains values to be broadcast to all players after the completion of signing round 1.
type Round1Bcast struct {
Di, Ei curves.Point
}
func (result *Round1Bcast) Encode() ([]byte, error) {
gob.Register(result.Di) // just the point for now
gob.Register(result.Ei)
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)
if err := enc.Encode(result); err != nil {
return nil, errors.Wrap(err, "couldn't encode round 1 broadcast")
}
return buf.Bytes(), nil
}
func (result *Round1Bcast) Decode(input []byte) error {
buf := bytes.NewBuffer(input)
dec := gob.NewDecoder(buf)
if err := dec.Decode(result); err != nil {
return errors.Wrap(err, "couldn't encode round 1 broadcast")
}
return nil
}
func (signer *Signer) SignRound1() (*Round1Bcast, error) {
// Make sure signer is not empty
if signer == nil || signer.curve == nil {
return nil, internal.ErrNilArguments
}
// Make sure round number is correct
if signer.round != 1 {
return nil, internal.ErrInvalidRound
}
// Step 1 - Sample di, ei
di := signer.curve.Scalar.Random(crand.Reader)
ei := signer.curve.Scalar.Random(crand.Reader)
// Step 2 - Compute Di, Ei
Di := signer.curve.ScalarBaseMult(di)
Ei := signer.curve.ScalarBaseMult(ei)
// Update round number
signer.round = 2
// Store di, ei, Di, Ei locally and broadcast Di, Ei
signer.state.capD = Di
signer.state.capE = Ei
signer.state.smallD = di
signer.state.smallE = ei
return &Round1Bcast{
Di,
Ei,
}, nil
}