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>
51 lines
2.2 KiB
Go
Executable File
51 lines
2.2 KiB
Go
Executable File
// Package ottest contains some utilities to test ot functions. The main goal is to reduce the code duplication in
|
|
// various other packages that need to run an OT in their test setup stage.
|
|
package ottest
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/onsonr/sonr/crypto/core/curves"
|
|
"github.com/onsonr/sonr/crypto/ot/base/simplest"
|
|
)
|
|
|
|
// RunSimplestOT is a utility function used _only_ during various tests.
|
|
// essentially, it encapsulates the entire process of running a base OT, so that other tests can use it / bootstrap themselves.
|
|
// it handles the creation of the base OT sender and receiver, as well as orchestrates the rounds on them;
|
|
// it returns their outsputs, so that others can use them.
|
|
func RunSimplestOT(curve *curves.Curve, batchSize int, uniqueSessionId [simplest.DigestSize]byte) (*simplest.SenderOutput, *simplest.ReceiverOutput, error) {
|
|
receiver, err := simplest.NewReceiver(curve, batchSize, uniqueSessionId)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "constructing OT receiver in run simplest OT")
|
|
}
|
|
sender, err := simplest.NewSender(curve, batchSize, uniqueSessionId)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "constructing OT sender in run simplest OT")
|
|
}
|
|
proof, err := sender.Round1ComputeAndZkpToPublicKey()
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "sender round 1 in run simplest OT")
|
|
}
|
|
receiversMaskedChoice, err := receiver.Round2VerifySchnorrAndPadTransfer(proof)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "receiver round 2 in run simplest OT")
|
|
}
|
|
challenge, err := sender.Round3PadTransfer(receiversMaskedChoice)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "sender round 3 in run simplest OT")
|
|
}
|
|
challengeResponse, err := receiver.Round4RespondToChallenge(challenge)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "receiver round 4 in run simplest OT")
|
|
}
|
|
challengeOpenings, err := sender.Round5Verify(challengeResponse)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "sender round 5 in run simplest OT")
|
|
}
|
|
err = receiver.Round6Verify(challengeOpenings)
|
|
if err != nil {
|
|
return nil, nil, errors.Wrap(err, "receiver round 6 in run simplest OT")
|
|
}
|
|
return sender.Output, receiver.Output, nil
|
|
}
|