2024-11-18 19:04:10 -05:00
|
|
|
package controller
|
2024-09-25 19:45:28 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/onsonr/crypto/mpc"
|
2024-09-29 14:40:36 -04:00
|
|
|
|
2024-11-18 19:04:10 -05:00
|
|
|
commonv1 "github.com/onsonr/sonr/pkg/common/types"
|
|
|
|
"github.com/onsonr/sonr/x/did/types"
|
2024-09-25 19:45:28 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type ControllerI interface {
|
|
|
|
ChainID() string
|
2024-11-18 19:04:10 -05:00
|
|
|
GetPubKey() *commonv1.PubKey
|
2024-09-25 19:45:28 -04:00
|
|
|
SonrAddress() string
|
2024-10-18 14:09:16 -04:00
|
|
|
RawPublicKey() []byte
|
2024-09-25 19:45:28 -04:00
|
|
|
}
|
|
|
|
|
2024-11-18 19:04:10 -05:00
|
|
|
func New(shares []mpc.Share) (ControllerI, error) {
|
2024-09-25 19:45:28 -04:00
|
|
|
var (
|
|
|
|
valKs = shares[0]
|
|
|
|
userKs = shares[1]
|
|
|
|
)
|
2024-10-21 11:30:52 -04:00
|
|
|
pb, err := valKs.PublicKey()
|
2024-09-25 19:45:28 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-11-18 19:04:10 -05:00
|
|
|
sonrAddr, err := types.ComputeSonrAddr(pb)
|
2024-09-25 19:45:28 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &controller{
|
|
|
|
valKs: valKs,
|
|
|
|
userKs: userKs,
|
|
|
|
address: sonrAddr,
|
2024-10-21 11:30:52 -04:00
|
|
|
publicKey: pb,
|
2024-09-25 19:45:28 -04:00
|
|
|
}, nil
|
|
|
|
}
|
2024-09-25 20:11:30 -04:00
|
|
|
|
|
|
|
type controller struct {
|
|
|
|
userKs mpc.Share
|
|
|
|
valKs mpc.Share
|
|
|
|
address string
|
|
|
|
chainID string
|
|
|
|
publicKey []byte
|
2024-10-15 14:31:19 -04:00
|
|
|
did string
|
2024-09-25 20:11:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *controller) ChainID() string {
|
|
|
|
return c.chainID
|
|
|
|
}
|
|
|
|
|
2024-11-18 19:04:10 -05:00
|
|
|
func (c *controller) GetPubKey() *commonv1.PubKey {
|
|
|
|
return &commonv1.PubKey{
|
2024-09-27 20:58:05 -04:00
|
|
|
KeyType: "ecdsa",
|
2024-11-18 19:04:10 -05:00
|
|
|
RawKey: &commonv1.RawKey{
|
2024-09-27 20:58:05 -04:00
|
|
|
Algorithm: "secp256k1",
|
|
|
|
Key: c.publicKey,
|
|
|
|
},
|
|
|
|
Role: "authentication",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-18 13:45:57 -04:00
|
|
|
func (c *controller) RawPublicKey() []byte {
|
2024-09-25 20:11:30 -04:00
|
|
|
return c.publicKey
|
|
|
|
}
|
|
|
|
|
2024-10-18 13:45:57 -04:00
|
|
|
// func (c *controller) StdPublicKey() cryptotypes.PubKey {
|
|
|
|
// return c.stdPubKey
|
|
|
|
// }
|
|
|
|
|
2024-09-25 20:11:30 -04:00
|
|
|
func (c *controller) SonrAddress() string {
|
|
|
|
return c.address
|
|
|
|
}
|