sonr/crypto/signatures/bbs/blind_signature.go
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

80 lines
1.9 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"
"github.com/onsonr/sonr/crypto/signatures/common"
)
// BlindSignature is a BBS+ blind signature
// structurally identical to `Signature` but
// is used to help avoid misuse and confusion.
//
// 1 or more message have been hidden by the
// potential signature holder so the signer
// only knows a subset of the messages to be signed
type BlindSignature struct {
a curves.PairingPoint
e, s curves.Scalar
}
// Init creates an empty signature to a specific curve
// which should be followed by UnmarshalBinary
func (sig *BlindSignature) Init(curve *curves.PairingCurve) *BlindSignature {
sig.a = curve.NewG1IdentityPoint()
sig.e = curve.NewScalar()
sig.s = curve.NewScalar()
return sig
}
func (sig BlindSignature) MarshalBinary() ([]byte, error) {
out := append(sig.a.ToAffineCompressed(), sig.e.Bytes()...)
out = append(out, sig.s.Bytes()...)
return out, nil
}
func (sig *BlindSignature) UnmarshalBinary(data []byte) error {
pointLength := len(sig.a.ToAffineCompressed())
scalarLength := len(sig.s.Bytes())
expectedLength := pointLength + scalarLength*2
if len(data) != expectedLength {
return fmt.Errorf("invalid byte sequence")
}
a, err := sig.a.FromAffineCompressed(data[:pointLength])
if err != nil {
return err
}
e, err := sig.e.SetBytes(data[pointLength:(pointLength + scalarLength)])
if err != nil {
return err
}
s, err := sig.s.SetBytes(data[(pointLength + scalarLength):])
if err != nil {
return err
}
var ok bool
sig.a, ok = a.(curves.PairingPoint)
if !ok {
return errors.New("incorrect type conversion")
}
sig.e = e
sig.s = s
return nil
}
func (sig BlindSignature) ToUnblinded(blinder common.SignatureBlinding) *Signature {
return &Signature{
a: sig.a,
e: sig.e,
s: sig.s.Add(blinder),
}
}