mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
* 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>
84 lines
2.8 KiB
Go
Executable File
84 lines
2.8 KiB
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
// Package frost is an implementation of t-of-n threshold signature of https://eprint.iacr.org/2020/852.pdf
|
|
package frost
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/onsonr/sonr/crypto/core/curves"
|
|
"github.com/onsonr/sonr/crypto/dkg/frost"
|
|
"github.com/onsonr/sonr/crypto/internal"
|
|
)
|
|
|
|
// Signer is a tSchnorr player performing the signing operation.
|
|
type Signer struct {
|
|
skShare curves.Scalar // secret signing share for this signer
|
|
vkShare curves.Point // store verification key share
|
|
verificationKey curves.Point // verification key
|
|
id uint32 // The ID assigned to this signer's shamir share
|
|
threshold uint32
|
|
curve *curves.Curve
|
|
round uint
|
|
lCoeffs map[uint32]curves.Scalar // lCoeffs are Lagrange coefficients of each cosigner.
|
|
cosigners []uint32
|
|
state *state // Accumulated intermediate values associated with signing
|
|
challengeDeriver ChallengeDerive
|
|
}
|
|
|
|
type state struct {
|
|
// Round 1
|
|
capD, capE curves.Point // capD, capE are commitments this signer generates in signing round 1
|
|
smallD, smallE curves.Scalar // smallD, smallE are scalars this signer generates in signing round 1
|
|
|
|
// Round 2
|
|
commitments map[uint32]*Round1Bcast // Store commitments broadcast after signing round 1
|
|
msg []byte
|
|
c curves.Scalar
|
|
capRs map[uint32]curves.Point
|
|
sumR curves.Point
|
|
}
|
|
|
|
// NewSigner create a signer from a dkg participant
|
|
// Note that we can pre-assign Lagrange coefficients lcoeffs of each cosigner. This optimizes performance.
|
|
// See paragraph 3 of section 3 in the draft - https://tools.ietf.org/pdf/draft-komlo-frost-00.pdf
|
|
func NewSigner(info *frost.DkgParticipant, id, thresh uint32, lcoeffs map[uint32]curves.Scalar, cosigners []uint32, challengeDeriver ChallengeDerive) (*Signer, error) {
|
|
if info == nil || len(cosigners) == 0 || len(lcoeffs) == 0 {
|
|
return nil, internal.ErrNilArguments
|
|
}
|
|
|
|
if thresh > uint32(len(cosigners)) {
|
|
return nil, fmt.Errorf("threshold is higher than number of signers")
|
|
}
|
|
|
|
if len(lcoeffs) != len(cosigners) {
|
|
return nil, fmt.Errorf("expected coefficients to be equal to number of cosigners")
|
|
}
|
|
|
|
// Check if cosigners and lcoeffs contain the same IDs
|
|
for i := 0; i < len(cosigners); i++ {
|
|
id := cosigners[i]
|
|
if _, ok := lcoeffs[id]; !ok {
|
|
return nil, fmt.Errorf("lcoeffs and cosigners have inconsistent ID")
|
|
}
|
|
}
|
|
|
|
return &Signer{
|
|
skShare: info.SkShare,
|
|
vkShare: info.VkShare,
|
|
verificationKey: info.VerificationKey,
|
|
id: id,
|
|
threshold: thresh,
|
|
curve: info.Curve,
|
|
round: 1,
|
|
lCoeffs: lcoeffs,
|
|
cosigners: cosigners,
|
|
state: &state{},
|
|
challengeDeriver: challengeDeriver,
|
|
}, nil
|
|
}
|