mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +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>
58 lines
1.8 KiB
Go
Executable File
58 lines
1.8 KiB
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package bulletproof
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"golang.org/x/crypto/sha3"
|
|
|
|
"github.com/onsonr/sonr/crypto/core/curves"
|
|
)
|
|
|
|
// generators contains a list of points to be used as generators for bulletproofs.
|
|
type generators []curves.Point
|
|
|
|
// ippGenerators holds generators necessary for an Inner Product Proof
|
|
// It includes a single u generator, and a list of generators divided in half to G and H
|
|
// See lines 10 on pg 16 of https://eprint.iacr.org/2017/1066.pdf
|
|
type ippGenerators struct {
|
|
G generators
|
|
H generators
|
|
}
|
|
|
|
// getGeneratorPoints generates generators using HashToCurve with Shake256(domain) as input
|
|
// lenVector is the length of the scalars used for the Inner Product Proof
|
|
// getGeneratorPoints will return 2*lenVector + 1 total points, split between a single u generator
|
|
// and G and H lists of vectors per the IPP specification
|
|
// See lines 10 on pg 16 of https://eprint.iacr.org/2017/1066.pdf
|
|
func getGeneratorPoints(lenVector int, domain []byte, curve curves.Curve) (*ippGenerators, error) {
|
|
shake := sha3.NewShake256()
|
|
_, err := shake.Write(domain)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "getGeneratorPoints shake.Write")
|
|
}
|
|
numPoints := lenVector * 2
|
|
points := make([]curves.Point, numPoints)
|
|
for i := 0; i < numPoints; i++ {
|
|
bytes := [64]byte{}
|
|
_, err := shake.Read(bytes[:])
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "getGeneratorPoints shake.Read")
|
|
}
|
|
nextPoint := curve.Point.Hash(bytes[:])
|
|
points[i] = nextPoint
|
|
}
|
|
// Get G and H by splitting points in half
|
|
G, H, err := splitPointVector(points)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "getGeneratorPoints splitPointVector")
|
|
}
|
|
out := ippGenerators{G: G, H: H}
|
|
|
|
return &out, nil
|
|
}
|