mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
- **refactor: remove unused auth components** - **refactor: improve devbox configuration and deployment process** - **refactor: improve devnet and testnet setup** - **fix: update templ version to v0.2.778** - **refactor: rename pkl/net.matrix to pkl/matrix.net** - **refactor: migrate webapp components to nebula** - **refactor: protobuf types** - **chore: update dependencies for improved security and stability** - **feat: implement landing page and vault gateway servers** - **refactor: Migrate data models to new module structure and update related files** - **feature/1121-implement-ucan-validation** - **refactor: Replace hardcoded constants with model types in attns.go** - **feature/1121-implement-ucan-validation** - **chore: add origin Host struct and update main function to handle multiple hosts** - **build: remove unused static files from dwn module** - **build: remove unused static files from dwn module** - **refactor: Move DWN models to common package** - **refactor: move models to pkg/common** - **refactor: move vault web app assets to embed module** - **refactor: update session middleware import path** - **chore: configure port labels and auto-forwarding behavior** - **feat: enhance devcontainer configuration** - **feat: Add UCAN middleware for Echo with flexible token validation** - **feat: add JWT middleware for UCAN authentication** - **refactor: update package URI and versioning in PklProject files** - **fix: correct sonr.pkl import path** - **refactor: move JWT related code to auth package** - **feat: introduce vault configuration retrieval and management** - **refactor: Move vault components to gateway module and update file paths** - **refactor: remove Dexie and SQLite database implementations** - **feat: enhance frontend with PWA features and WASM integration** - **feat: add Devbox features and streamline Dockerfile** - **chore: update dependencies to include TigerBeetle** - **chore(deps): update go version to 1.23** - **feat: enhance devnet setup with PATH environment variable and updated PWA manifest** - **fix: upgrade tigerbeetle-go dependency and remove indirect dependency** - **feat: add PostgreSQL support to devnet and testnet deployments** - **refactor: rename keyshare cookie to token cookie** - **feat: upgrade Go version to 1.23.3 and update dependencies** - **refactor: update devnet and testnet configurations** - **feat: add IPFS configuration for devnet** - **I'll help you update the ipfs.config.pkl to include all the peers from the shell script. Here's the updated configuration:** - **refactor: move mpc package to crypto directory** - **feat: add BIP32 support for various cryptocurrencies** - **feat: enhance ATN.pkl with additional capabilities** - **refactor: simplify smart account and vault attenuation creation** - **feat: add new capabilities to the Attenuation type** - **refactor: Rename MPC files for clarity and consistency** - **feat: add DIDKey support for cryptographic operations** - **feat: add devnet and testnet deployment configurations** - **fix: correct key derivation in bip32 package** - **refactor: rename crypto/bip32 package to crypto/accaddr** - **fix: remove duplicate indirect dependency** - **refactor: move vault package to root directory** - **refactor: update routes for gateway and vault** - **refactor: remove obsolete web configuration file** - **refactor: remove unused TigerBeetle imports and update host configuration** - **refactor: adjust styles directory path** - **feat: add broadcastTx and simulateTx functions to gateway** - **feat: add PinVault handler**
139 lines
4.0 KiB
Go
Executable File
139 lines
4.0 KiB
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package curves
|
|
|
|
import (
|
|
crand "crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/onsonr/sonr/crypto/core/curves/native/pasta/fp"
|
|
"github.com/onsonr/sonr/crypto/core/curves/native/pasta/fq"
|
|
)
|
|
|
|
func TestPointPallasAddDoubleMul(t *testing.T) {
|
|
g := new(Ep).Generator()
|
|
id := new(Ep).Identity()
|
|
require.Equal(t, g.Add(g, id), g)
|
|
|
|
g2 := new(Ep).Add(g, g)
|
|
require.True(t, new(Ep).Double(g).Equal(g2))
|
|
require.Equal(t, new(Ep).Double(g), new(Ep).Add(g, g))
|
|
g3 := new(Ep).Add(g, g2)
|
|
require.True(t, g3.Equal(new(Ep).Mul(g, new(fq.Fq).SetUint64(3))))
|
|
|
|
g4 := new(Ep).Add(g3, g)
|
|
require.True(t, g4.Equal(new(Ep).Double(g2)))
|
|
require.True(t, g4.Equal(new(Ep).Mul(g, new(fq.Fq).SetUint64(4))))
|
|
}
|
|
|
|
func TestPointPallasHash(t *testing.T) {
|
|
h0 := new(Ep).Hash(nil)
|
|
require.True(t, h0.IsOnCurve())
|
|
h1 := new(Ep).Hash([]byte{})
|
|
require.True(t, h1.IsOnCurve())
|
|
require.True(t, h0.Equal(h1))
|
|
h2 := new(Ep).Hash([]byte{1})
|
|
require.True(t, h2.IsOnCurve())
|
|
}
|
|
|
|
func TestPointPallasNeg(t *testing.T) {
|
|
g := new(Ep).Generator()
|
|
g.Neg(g)
|
|
require.True(t, g.Neg(g).Equal(new(Ep).Generator()))
|
|
id := new(Ep).Identity()
|
|
require.True(t, new(Ep).Neg(id).Equal(id))
|
|
}
|
|
|
|
func TestPointPallasRandom(t *testing.T) {
|
|
a := new(Ep).Random(testRng())
|
|
require.NotNil(t, a.x)
|
|
require.NotNil(t, a.y)
|
|
require.NotNil(t, a.z)
|
|
require.True(t, a.IsOnCurve())
|
|
e := &Ep{
|
|
x: &fp.Fp{
|
|
0x7263083d01d4859c,
|
|
0x65a03323b5a3d204,
|
|
0xe71d73222b136668,
|
|
0x1d1b1bcf1256b539,
|
|
},
|
|
y: &fp.Fp{
|
|
0x8cc2516ffe23e1bb,
|
|
0x5418f941eeaca812,
|
|
0x16c9af658a846f29,
|
|
0x11c572091c418668,
|
|
},
|
|
z: &fp.Fp{
|
|
0xa879589adb77a88e,
|
|
0x5444a531a19f2406,
|
|
0x637ff77c51dda524,
|
|
0x0369e90d219ce821,
|
|
},
|
|
}
|
|
require.True(t, a.Equal(e))
|
|
}
|
|
|
|
func TestPointPallasSerialize(t *testing.T) {
|
|
ss := new(ScalarPallas).Random(testRng()).(*ScalarPallas)
|
|
g := new(Ep).Generator()
|
|
|
|
ppt := new(Ep).Mul(g, ss.value)
|
|
require.Equal(t, ppt.ToAffineCompressed(), []byte{0x1c, 0x6d, 0x47, 0x1f, 0x4a, 0x81, 0xcd, 0x8, 0x4e, 0xb3, 0x17, 0x9a, 0xcd, 0x17, 0xe2, 0x9a, 0x24, 0x69, 0xb, 0x4e, 0x69, 0x5f, 0x35, 0x1a, 0x92, 0x12, 0x95, 0xc9, 0xe6, 0xd3, 0x7a, 0x0})
|
|
require.Equal(t, ppt.ToAffineUncompressed(), []byte{0x1c, 0x6d, 0x47, 0x1f, 0x4a, 0x81, 0xcd, 0x8, 0x4e, 0xb3, 0x17, 0x9a, 0xcd, 0x17, 0xe2, 0x9a, 0x24, 0x69, 0xb, 0x4e, 0x69, 0x5f, 0x35, 0x1a, 0x92, 0x12, 0x95, 0xc9, 0xe6, 0xd3, 0x7a, 0x0, 0x80, 0x5c, 0xa1, 0x56, 0x6d, 0x1b, 0x87, 0x5f, 0xb0, 0x2e, 0xae, 0x85, 0x4e, 0x86, 0xa9, 0xcd, 0xde, 0x37, 0x6a, 0xc8, 0x4a, 0x80, 0xf6, 0x43, 0xaa, 0xe6, 0x2c, 0x2d, 0x15, 0xdb, 0xda, 0x29})
|
|
retP, err := new(Ep).FromAffineCompressed(ppt.ToAffineCompressed())
|
|
require.NoError(t, err)
|
|
require.True(t, ppt.Equal(retP))
|
|
retP, err = new(Ep).FromAffineUncompressed(ppt.ToAffineUncompressed())
|
|
require.NoError(t, err)
|
|
require.True(t, ppt.Equal(retP))
|
|
|
|
// smoke test
|
|
for i := 0; i < 25; i++ {
|
|
s := new(ScalarPallas).Random(crand.Reader).(*ScalarPallas)
|
|
pt := new(Ep).Mul(g, s.value)
|
|
cmprs := pt.ToAffineCompressed()
|
|
require.Equal(t, len(cmprs), 32)
|
|
retC, err := new(Ep).FromAffineCompressed(cmprs)
|
|
require.NoError(t, err)
|
|
require.True(t, pt.Equal(retC))
|
|
|
|
un := pt.ToAffineUncompressed()
|
|
require.Equal(t, len(un), 64)
|
|
retU, err := new(Ep).FromAffineUncompressed(un)
|
|
require.NoError(t, err)
|
|
require.True(t, pt.Equal(retU))
|
|
}
|
|
}
|
|
|
|
func TestPointPallasCMove(t *testing.T) {
|
|
a := new(Ep).Random(crand.Reader)
|
|
b := new(Ep).Random(crand.Reader)
|
|
require.True(t, new(Ep).CMove(a, b, 1).Equal(b))
|
|
require.True(t, new(Ep).CMove(a, b, 0).Equal(a))
|
|
}
|
|
|
|
func TestPointPallasSumOfProducts(t *testing.T) {
|
|
lhs := new(Ep).Generator()
|
|
lhs.Mul(lhs, new(fq.Fq).SetUint64(50))
|
|
points := make([]*Ep, 5)
|
|
for i := range points {
|
|
points[i] = new(Ep).Generator()
|
|
}
|
|
scalars := []Scalar{
|
|
new(ScalarPallas).New(8),
|
|
new(ScalarPallas).New(9),
|
|
new(ScalarPallas).New(10),
|
|
new(ScalarPallas).New(11),
|
|
new(ScalarPallas).New(12),
|
|
}
|
|
rhs := lhs.SumOfProducts(points, scalars)
|
|
require.NotNil(t, rhs)
|
|
require.True(t, lhs.Equal(rhs))
|
|
}
|