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>
74 lines
1.7 KiB
Go
Executable File
74 lines
1.7 KiB
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package bbs
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/onsonr/sonr/crypto/core/curves"
|
|
)
|
|
|
|
// PublicKey is a BBS+ verification key
|
|
type PublicKey struct {
|
|
value curves.PairingPoint
|
|
}
|
|
|
|
func (pk *PublicKey) Init(curve *curves.PairingCurve) *PublicKey {
|
|
pk.value = curve.NewG2IdentityPoint()
|
|
return pk
|
|
}
|
|
|
|
func (pk PublicKey) MarshalBinary() ([]byte, error) {
|
|
return pk.value.ToAffineCompressed(), nil
|
|
}
|
|
|
|
func (pk *PublicKey) UnmarshalBinary(in []byte) error {
|
|
value, err := pk.value.FromAffineCompressed(in)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var ok bool
|
|
pk.value, ok = value.(curves.PairingPoint)
|
|
if !ok {
|
|
return errors.New("incorrect type conversion")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Verify checks a signature where all messages are known to the verifier
|
|
func (pk PublicKey) Verify(signature *Signature, generators *MessageGenerators, msgs []curves.Scalar) error {
|
|
if generators.length < len(msgs) {
|
|
return fmt.Errorf("not enough message generators")
|
|
}
|
|
if len(msgs) < 1 {
|
|
return fmt.Errorf("invalid messages")
|
|
}
|
|
// Identity Point will always return true which is not what we want
|
|
if pk.value.IsIdentity() {
|
|
return fmt.Errorf("invalid public key")
|
|
}
|
|
if signature.a.IsIdentity() {
|
|
return fmt.Errorf("invalid signature")
|
|
}
|
|
a, ok := pk.value.Generator().Mul(signature.e).Add(pk.value).(curves.PairingPoint)
|
|
if !ok {
|
|
return fmt.Errorf("not a valid point")
|
|
}
|
|
b, ok := computeB(signature.s, msgs, generators).Neg().(curves.PairingPoint)
|
|
if !ok {
|
|
return fmt.Errorf("not a valid point")
|
|
}
|
|
|
|
res := a.MultiPairing(signature.a, a, b, pk.value.Generator().(curves.PairingPoint))
|
|
if !res.IsOne() {
|
|
return fmt.Errorf("invalid result")
|
|
}
|
|
|
|
return nil
|
|
}
|