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>
62 lines
1.4 KiB
Go
Executable File
62 lines
1.4 KiB
Go
Executable File
package bulletproof
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/crypto/sha3"
|
|
|
|
"github.com/onsonr/sonr/crypto/core/curves"
|
|
)
|
|
|
|
func TestGeneratorsHappyPath(t *testing.T) {
|
|
curve := curves.ED25519()
|
|
gs, err := getGeneratorPoints(10, []byte("test"), *curve)
|
|
gsConcatenated := concatIPPGenerators(*gs)
|
|
require.NoError(t, err)
|
|
require.Len(t, gs.G, 10)
|
|
require.Len(t, gs.H, 10)
|
|
require.True(t, noDuplicates(gsConcatenated))
|
|
}
|
|
|
|
func TestGeneratorsUniquePerDomain(t *testing.T) {
|
|
curve := curves.ED25519()
|
|
gs1, err := getGeneratorPoints(10, []byte("test"), *curve)
|
|
gs1Concatenated := concatIPPGenerators(*gs1)
|
|
require.NoError(t, err)
|
|
gs2, err := getGeneratorPoints(10, []byte("test2"), *curve)
|
|
gs2Concatenated := concatIPPGenerators(*gs2)
|
|
require.NoError(t, err)
|
|
require.True(t, areDisjoint(gs1Concatenated, gs2Concatenated))
|
|
}
|
|
|
|
func noDuplicates(gs generators) bool {
|
|
seen := map[[32]byte]bool{}
|
|
for _, G := range gs {
|
|
value := sha3.Sum256(G.ToAffineCompressed())
|
|
if seen[value] {
|
|
return false
|
|
}
|
|
seen[value] = true
|
|
}
|
|
return true
|
|
}
|
|
|
|
func areDisjoint(gs1, gs2 generators) bool {
|
|
for _, g1 := range gs1 {
|
|
for _, g2 := range gs2 {
|
|
if g1.Equal(g2) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func concatIPPGenerators(ippGens ippGenerators) generators {
|
|
var out generators
|
|
out = append(out, ippGens.G...)
|
|
out = append(out, ippGens.H...)
|
|
return out
|
|
}
|