mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 02:11:40 +00:00
- **refactor: move session-related code to middleware package** - **refactor: update PKL build process and adjust related configurations** - **feat: integrate base.cosmos.v1 Genesis module** - **refactor: pass session context to modal rendering functions** - **refactor: move nebula package to app directory and update templ version** - **refactor: Move home section video view to dedicated directory** - **refactor: remove unused views file** - **refactor: move styles and UI components to global scope** - **refactor: Rename images.go to cdn.go** - **feat: Add Empty State Illustrations** - **refactor: Consolidate Vault Index Logic** - **fix: References to App.wasm and remove Vault Directory embedded CDN files** - **refactor: Move CDN types to Models** - **fix: Correct line numbers in templ error messages for arch_templ.go** - **refactor: use common types for peer roles** - **refactor: move common types and ORM to a shared package** - **fix: Config import dwn** - **refactor: move nebula directory to app** - **feat: Rebuild nebula** - **fix: correct file paths in panels templates** - **feat: Remove duplicate types** - **refactor: Move dwn to pkg/core** - **refactor: Binary Structure** - **feat: Introduce Crypto Pkg** - **fix: Broken Process Start** - **feat: Update pkg/* structure** - **feat: Refactor PKL Structure** - **build: update pkl build process** - **chore: Remove Empty Files** - **refactor: remove unused macaroon package** - **feat: Add WebAwesome Components** - **refactor: consolidate build and generation tasks into a single taskfile, remove redundant makefile targets** - **refactor: refactor server and move components to pkg/core/dwn** - **build: update go modules** - **refactor: move gateway logic into dedicated hway command** - **feat: Add KSS (Krawczyk-Song-Song) MPC cryptography module** - **feat: Implement MPC-based JWT signing and UCAN token generation** - **feat: add support for MPC-based JWT signing** - **feat: Implement MPC-based UCAN capabilities for smart accounts** - **feat: add address field to keyshareSource** - **feat: Add comprehensive MPC test suite for keyshares, UCAN tokens, and token attenuations** - **refactor: improve MPC keyshare management and signing process** - **feat: enhance MPC capability hierarchy documentation** - **refactor: rename GenerateKeyshares function to NewKeyshareSource for clarity** - **refactor: remove unused Ethereum address computation** - **feat: Add HasHandle and IsAuthenticated methods to HTTPContext** - **refactor: Add context.Context support to session HTTPContext** - **refactor: Resolve context interface conflicts in HTTPContext** - **feat: Add session ID context key and helper functions** - **feat: Update WebApp Page Rendering** - **refactor: Simplify context management by using single HTTPContext key** - **refactor: Simplify HTTPContext creation and context management in session middleware** - **refactor: refactor session middleware to use a single data structure** - **refactor: Simplify HTTPContext implementation and session data handling** - **refactor: Improve session context handling and prevent nil pointer errors** - **refactor: Improve session context handling with nil safety and type support** - **refactor: improve session data injection** - **feat: add full-screen modal component and update registration flow** - **chore: add .air.toml to .gitignore** - **feat: add Air to devbox and update dependencies**
126 lines
3.5 KiB
Go
Executable File
126 lines
3.5 KiB
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package ted25519
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/onsonr/sonr/pkg/crypto/core/curves"
|
|
v1 "github.com/onsonr/sonr/pkg/crypto/sharing/v1"
|
|
)
|
|
|
|
func TestGenerateEd25519Key(t *testing.T) {
|
|
config := ShareConfiguration{T: 2, N: 3}
|
|
|
|
// Generate and verify correct number of shares are produced
|
|
pub, shares, _, err := GenerateSharedKey(&config)
|
|
require.NoError(t, err)
|
|
require.Equal(t, config.N, len(shares))
|
|
|
|
// Verify reconstuction works for all permutations of shares
|
|
shareVec := make([]*KeyShare, 2)
|
|
shareVec[0] = shares[0]
|
|
shareVec[1] = shares[1]
|
|
secret1, err := Reconstruct(shareVec, &config)
|
|
require.Nil(t, err)
|
|
shareVec[0] = shares[1]
|
|
shareVec[1] = shares[2]
|
|
secret2, err := Reconstruct(shareVec, &config)
|
|
require.Nil(t, err)
|
|
shareVec[0] = shares[0]
|
|
shareVec[1] = shares[2]
|
|
secret3, err := Reconstruct(shareVec, &config)
|
|
require.Nil(t, err)
|
|
require.Equal(t, secret1, secret2)
|
|
require.Equal(t, secret2, secret3)
|
|
|
|
// Need to reverse secret1
|
|
secret1 = reverseBytes(secret1)
|
|
var secret1Bytes [32]byte
|
|
copy(secret1Bytes[:], secret1)
|
|
scalar1, err := new(curves.ScalarEd25519).SetBytesCanonical(secret1Bytes[:])
|
|
require.NoError(t, err)
|
|
ed25519 := curves.ED25519()
|
|
pubFromSeed := ed25519.Point.Generator().Mul(scalar1)
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, pubFromSeed.ToAffineCompressed(), pub.Bytes())
|
|
}
|
|
|
|
func TestGenerateEd25519KeyInvalidConfig(t *testing.T) {
|
|
invalidConfig := ShareConfiguration{T: 1, N: 1}
|
|
_, _, _, err := GenerateSharedKey(&invalidConfig)
|
|
require.NotNil(t, err)
|
|
require.Error(t, err)
|
|
|
|
invalidConfig = ShareConfiguration{T: 2, N: 1}
|
|
_, _, _, err = GenerateSharedKey(&invalidConfig)
|
|
require.NotNil(t, err)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestVerifyVSSEd25519(t *testing.T) {
|
|
config := ShareConfiguration{T: 2, N: 3}
|
|
pubKey1, shares1, commitments1, err := GenerateSharedKey(&config)
|
|
require.NoError(t, err)
|
|
pubKey2, shares2, commitments2, err := GenerateSharedKey(&config)
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, pubKey1.Bytes(), commitments1[0].ToAffineCompressed())
|
|
require.Equal(t, pubKey2.Bytes(), commitments2[0].ToAffineCompressed())
|
|
|
|
for _, s := range shares1 {
|
|
ok, err := s.VerifyVSS(commitments1, &config)
|
|
require.NoError(t, err)
|
|
require.True(t, ok)
|
|
ok, _ = s.VerifyVSS(commitments2, &config)
|
|
require.True(t, !ok)
|
|
}
|
|
|
|
for _, s := range shares2 {
|
|
ok, err := s.VerifyVSS(commitments2, &config)
|
|
require.NoError(t, err)
|
|
require.True(t, ok)
|
|
ok, _ = s.VerifyVSS(commitments1, &config)
|
|
require.True(t, !ok)
|
|
}
|
|
}
|
|
|
|
func TestCommitmentsFromBytes(t *testing.T) {
|
|
config := ShareConfiguration{T: 2, N: 3}
|
|
_, _, comms, err := GenerateSharedKey(&config)
|
|
require.NoError(t, err)
|
|
|
|
recoveredComms, err := CommitmentsFromBytes(comms.CommitmentsToBytes())
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(comms), len(recoveredComms))
|
|
for i := range comms {
|
|
require.True(t, comms[i].Equal(recoveredComms[i]))
|
|
}
|
|
_, err = CommitmentsFromBytes([][]byte{{0x01}})
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestPublicKeyFromBytes(t *testing.T) {
|
|
_, err := PublicKeyFromBytes([]byte{0x01})
|
|
require.EqualError(t, err, "invalid public key size: 1")
|
|
}
|
|
|
|
func TestKeyShareFromBytes(t *testing.T) {
|
|
field := curves.NewField(curves.Ed25519Order())
|
|
share := &v1.ShamirShare{
|
|
Identifier: 2,
|
|
Value: field.NewElement(big.NewInt(3)),
|
|
}
|
|
shareBytes := share.Bytes()
|
|
recoveredShare := KeyShareFromBytes(shareBytes)
|
|
require.Equal(t, recoveredShare.ShamirShare, share)
|
|
}
|