mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/data persistence (#1180)
- **feat: add documentation and GitHub Actions workflow for publishing documentation** - **docs(concepts): add documentation for chain modules** - **refactor: Simplify session management with SQLite storage and remove deprecated code** - **refactor: Simplify database initialization and remove DatabaseContext** - **refactor: move connection handling logic to resolver package** - **feat: implement session management with database persistence** - **feat: Ensure config directory exists when creating database path** - **feat: Add SetUserHandle function to set user handle in session** - **feat: Add public methods to set session fields with database save** - **refactor: Remove unused session setter functions** - **feat: Add getter methods for all Session Model properties** - **feat: enhance Session model with user name details** - **feat: add Motr support and update UI elements** - **<no value>** - **feat: Add unique handle constraint and method to check handle existence** - **docs: update site URL to onsonr.dev** - **fix: correct import statement for database package** - **test: updated CI to run tests on pull requests and merge groups** - **docs: remove reference to develop branch in workflow** - **feat: add WebAuthn support for user registration** - **fix: correct smart account attenuation preset name** - **feat: add ComputeIssuerDID and ComputeSonrAddr functions to ucan package** - **test: add unit tests for MPC keyset and keyshare** - **feat: introduce new script to streamline GitHub issue creation**
This commit is contained in:
@@ -16,6 +16,7 @@ type (
|
||||
)
|
||||
|
||||
type Keyset interface {
|
||||
Address() string
|
||||
Val() *ValKeyshare
|
||||
ValJSON() string
|
||||
User() *UserKeyshare
|
||||
@@ -25,6 +26,11 @@ type Keyset interface {
|
||||
type keyset struct {
|
||||
val *ValKeyshare
|
||||
user *UserKeyshare
|
||||
addr string
|
||||
}
|
||||
|
||||
func (k keyset) Address() string {
|
||||
return k.addr
|
||||
}
|
||||
|
||||
func (k keyset) Val() *ValKeyshare {
|
||||
|
||||
+19
-15
@@ -4,23 +4,9 @@ import (
|
||||
"crypto/ecdsa"
|
||||
|
||||
"github.com/onsonr/sonr/crypto/core/protocol"
|
||||
"github.com/onsonr/sonr/crypto/tecdsa/dklsv1/dkg"
|
||||
)
|
||||
|
||||
// Keyshare represents the common interface for both validator and user keyshares
|
||||
type Keyshare interface {
|
||||
GetPayloads() map[string][]byte
|
||||
GetMetadata() map[string]string
|
||||
GetPublicKey() []byte
|
||||
GetProtocol() string
|
||||
GetRole() int32
|
||||
GetVersion() uint32
|
||||
ECDSAPublicKey() (*ecdsa.PublicKey, error)
|
||||
ExtractMessage() *protocol.Message
|
||||
RefreshFunc() (RefreshFunc, error)
|
||||
SignFunc(msg []byte) (SignFunc, error)
|
||||
Marshal() (string, error)
|
||||
}
|
||||
|
||||
// BaseKeyshare contains common fields and methods for both validator and user keyshares
|
||||
type BaseKeyshare struct {
|
||||
Message *protocol.Message `json:"message"`
|
||||
@@ -29,6 +15,24 @@ type BaseKeyshare struct {
|
||||
CompressedPubKey []byte `json:"compressed_public_key"`
|
||||
}
|
||||
|
||||
func initFromAlice(aliceOut *dkg.AliceOutput, originalMsg *protocol.Message) BaseKeyshare {
|
||||
return BaseKeyshare{
|
||||
Message: originalMsg,
|
||||
Role: 1,
|
||||
UncompressedPubKey: aliceOut.PublicKey.ToAffineUncompressed(),
|
||||
CompressedPubKey: aliceOut.PublicKey.ToAffineCompressed(),
|
||||
}
|
||||
}
|
||||
|
||||
func initFromBob(bobOut *dkg.BobOutput, originalMsg *protocol.Message) BaseKeyshare {
|
||||
return BaseKeyshare{
|
||||
Message: originalMsg,
|
||||
Role: 2,
|
||||
UncompressedPubKey: bobOut.PublicKey.ToAffineUncompressed(),
|
||||
CompressedPubKey: bobOut.PublicKey.ToAffineCompressed(),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BaseKeyshare) GetPayloads() map[string][]byte {
|
||||
return b.Message.Payloads
|
||||
}
|
||||
|
||||
+10
-2
@@ -35,7 +35,11 @@ func NewKeyset() (Keyset, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return keyset{val: valShare, user: userShare}, nil
|
||||
addr, err := computeSonrAddr(valShare.CompressedPublicKey())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return keyset{val: valShare, user: userShare, addr: addr}, nil
|
||||
}
|
||||
|
||||
// ExecuteSigning runs the MPC signing protocol
|
||||
@@ -73,7 +77,11 @@ func ExecuteRefresh(refreshFuncVal RefreshFunc, refreshFuncUser RefreshFunc) (Ke
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return keyset{val: valShare, user: userShare}, nil
|
||||
addr, err := computeSonrAddr(valShare.CompressedPublicKey())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return keyset{val: valShare, user: userShare, addr: addr}, nil
|
||||
}
|
||||
|
||||
// SerializeSecp256k1Signature serializes an ECDSA signature into a byte slice
|
||||
|
||||
+23
-22
@@ -3,6 +3,7 @@ package mpc
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/bech32"
|
||||
"github.com/onsonr/sonr/crypto/core/curves"
|
||||
"github.com/onsonr/sonr/crypto/core/protocol"
|
||||
"github.com/onsonr/sonr/crypto/tecdsa/dklsv1"
|
||||
@@ -47,7 +48,16 @@ type ValKeyshare struct {
|
||||
encoded string
|
||||
}
|
||||
|
||||
func computeSonrAddr(pk []byte) (string, error) {
|
||||
sonrAddr, err := bech32.ConvertAndEncode("idx", pk)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return sonrAddr, nil
|
||||
}
|
||||
|
||||
func NewValKeyshare(msg *protocol.Message) (*ValKeyshare, error) {
|
||||
vks := new(ValKeyshare)
|
||||
encoded, err := protocol.EncodeMessage(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -56,15 +66,10 @@ func NewValKeyshare(msg *protocol.Message) (*ValKeyshare, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ValKeyshare{
|
||||
BaseKeyshare: BaseKeyshare{
|
||||
Message: msg,
|
||||
Role: 1,
|
||||
UncompressedPubKey: valShare.PublicKey.ToAffineUncompressed(),
|
||||
CompressedPubKey: valShare.PublicKey.ToAffineCompressed(),
|
||||
},
|
||||
encoded: encoded,
|
||||
}, nil
|
||||
|
||||
vks.BaseKeyshare = initFromAlice(valShare, msg)
|
||||
vks.encoded = encoded
|
||||
return vks, nil
|
||||
}
|
||||
|
||||
func (v *ValKeyshare) RefreshFunc() (RefreshFunc, error) {
|
||||
@@ -83,12 +88,12 @@ func (v *ValKeyshare) String() string {
|
||||
|
||||
// PublicKey returns the uncompressed public key (65 bytes)
|
||||
func (v *ValKeyshare) PublicKey() []byte {
|
||||
return v.BaseKeyshare.UncompressedPubKey
|
||||
return v.UncompressedPubKey
|
||||
}
|
||||
|
||||
// CompressedPublicKey returns the compressed public key (33 bytes)
|
||||
func (v *ValKeyshare) CompressedPublicKey() []byte {
|
||||
return v.BaseKeyshare.CompressedPubKey
|
||||
return v.CompressedPubKey
|
||||
}
|
||||
|
||||
type UserKeyshare struct {
|
||||
@@ -97,6 +102,7 @@ type UserKeyshare struct {
|
||||
}
|
||||
|
||||
func NewUserKeyshare(msg *protocol.Message) (*UserKeyshare, error) {
|
||||
uks := new(UserKeyshare)
|
||||
encoded, err := protocol.EncodeMessage(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -105,15 +111,10 @@ func NewUserKeyshare(msg *protocol.Message) (*UserKeyshare, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &UserKeyshare{
|
||||
BaseKeyshare: BaseKeyshare{
|
||||
Message: msg,
|
||||
Role: 2,
|
||||
UncompressedPubKey: out.PublicKey.ToAffineUncompressed(),
|
||||
CompressedPubKey: out.PublicKey.ToAffineCompressed(),
|
||||
},
|
||||
encoded: encoded,
|
||||
}, nil
|
||||
|
||||
uks.BaseKeyshare = initFromBob(out, msg)
|
||||
uks.encoded = encoded
|
||||
return uks, nil
|
||||
}
|
||||
|
||||
func (u *UserKeyshare) RefreshFunc() (RefreshFunc, error) {
|
||||
@@ -132,12 +133,12 @@ func (u *UserKeyshare) String() string {
|
||||
|
||||
// PublicKey returns the uncompressed public key (65 bytes)
|
||||
func (u *UserKeyshare) PublicKey() []byte {
|
||||
return u.BaseKeyshare.UncompressedPubKey
|
||||
return u.UncompressedPubKey
|
||||
}
|
||||
|
||||
// CompressedPublicKey returns the compressed public key (33 bytes)
|
||||
func (u *UserKeyshare) CompressedPublicKey() []byte {
|
||||
return u.BaseKeyshare.CompressedPubKey
|
||||
return u.CompressedPubKey
|
||||
}
|
||||
|
||||
func encodeMessage(m *protocol.Message) (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user