mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/1118 formatter interface creation (#1147)
- **refactor: improve query service code structure** - **chore(deps): update protoc-gen-go-grpc to v1.5.1** - **refactor: replace package with** - **chore(deps): update dependencies** - **fix(deps): update webauthn to v0.11.2** - **refactor: remove onsonr.sonr from package names** - **refactor: improve code readability in vault querier** - **refactor: simplify controller initialization** - **fix: remove unnecessary function for counter data** - **refactor: update button component file paths** - **refactor(authentication): simplify register page** - **fix: update error filenames in marketing section templates**
This commit is contained in:
@@ -6,24 +6,16 @@ import (
|
||||
"github.com/onsonr/sonr/x/did/types"
|
||||
)
|
||||
|
||||
func (k Keeper) NewController(ctx sdk.Context) (uint64, types.ControllerI, error) {
|
||||
func (k Keeper) NewController(ctx sdk.Context) (types.ControllerI, error) {
|
||||
shares, err := mpc.GenerateKeyshares()
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
return nil, err
|
||||
}
|
||||
controller, err := types.NewController(ctx, shares)
|
||||
controller, err := types.NewController(shares)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
return nil, err
|
||||
}
|
||||
entry, err := controller.GetTableEntry()
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
num, err := k.OrmDB.ControllerTable().InsertReturningNumber(ctx, entry)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
return num, controller, nil
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
func (k Keeper) ResolveController(ctx sdk.Context, did string) (types.ControllerI, error) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
|
||||
"github.com/onsonr/crypto/mpc"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -13,53 +11,34 @@ type ControllerI interface {
|
||||
ChainID() string
|
||||
GetPubKey() *didv1.PubKey
|
||||
SonrAddress() string
|
||||
EthAddress() string
|
||||
BtcAddress() string
|
||||
RawPublicKey() []byte
|
||||
// StdPublicKey() cryptotypes.PubKey
|
||||
GetTableEntry() (*didv1.Controller, error)
|
||||
ExportUserKs() (string, error)
|
||||
}
|
||||
|
||||
func NewController(ctx sdk.Context, shares []mpc.Share) (ControllerI, error) {
|
||||
func NewController(shares []mpc.Share) (ControllerI, error) {
|
||||
var (
|
||||
valKs = shares[0]
|
||||
userKs = shares[1]
|
||||
)
|
||||
pbBz := valKs.GetPublicKey()
|
||||
sonrAddr, err := ComputeSonrAddress(pbBz)
|
||||
pb, err := valKs.PublicKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
btcAddr, err := ComputeBitcoinAddress(pbBz)
|
||||
sonrAddr, err := ComputeSonrAddress(pb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ecdsaPub, err := valKs.ECDSAPublicKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ethAddr := ComputeEthAddress(ecdsaPub)
|
||||
|
||||
return &controller{
|
||||
valKs: valKs,
|
||||
userKs: userKs,
|
||||
address: sonrAddr,
|
||||
btcAddr: btcAddr,
|
||||
ethAddr: ethAddr,
|
||||
chainID: ctx.ChainID(),
|
||||
publicKey: pbBz,
|
||||
publicKey: pb,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func LoadControllerFromTableEntry(ctx sdk.Context, entry *didv1.Controller) (ControllerI, error) {
|
||||
return &controller{
|
||||
address: entry.Did,
|
||||
btcAddr: entry.BtcAddress,
|
||||
ethAddr: entry.EthAddress,
|
||||
chainID: ctx.ChainID(),
|
||||
publicKey: entry.PublicKey.RawKey.Key,
|
||||
}, nil
|
||||
@@ -70,28 +49,14 @@ type controller struct {
|
||||
valKs mpc.Share
|
||||
address string
|
||||
chainID string
|
||||
ethAddr string
|
||||
btcAddr string
|
||||
publicKey []byte
|
||||
did string
|
||||
}
|
||||
|
||||
func (c *controller) BtcAddress() string {
|
||||
return c.btcAddr
|
||||
}
|
||||
|
||||
func (c *controller) ChainID() string {
|
||||
return c.chainID
|
||||
}
|
||||
|
||||
func (c *controller) EthAddress() string {
|
||||
return c.ethAddr
|
||||
}
|
||||
|
||||
func (c *controller) ExportUserKs() (string, error) {
|
||||
return c.userKs.Marshal()
|
||||
}
|
||||
|
||||
func (c *controller) GetPubKey() *didv1.PubKey {
|
||||
return &didv1.PubKey{
|
||||
KeyType: "ecdsa",
|
||||
@@ -103,21 +68,6 @@ func (c *controller) GetPubKey() *didv1.PubKey {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *controller) GetTableEntry() (*didv1.Controller, error) {
|
||||
valKs, err := c.valKs.Marshal()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &didv1.Controller{
|
||||
KsVal: valKs,
|
||||
Did: fmt.Sprintf("did:sonr:%s", c.address),
|
||||
SonrAddress: c.address,
|
||||
EthAddress: c.ethAddr,
|
||||
BtcAddress: c.btcAddr,
|
||||
PublicKey: c.GetPubKey(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *controller) RawPublicKey() []byte {
|
||||
return c.publicKey
|
||||
}
|
||||
|
||||
@@ -764,6 +764,7 @@ func _Query_Verify_Handler(srv interface{}, ctx context.Context, dec func(interf
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Query_serviceDesc = _Query_serviceDesc
|
||||
var _Query_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "did.v1.Query",
|
||||
HandlerType: (*QueryServer)(nil),
|
||||
|
||||
@@ -1075,6 +1075,7 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Msg_serviceDesc = _Msg_serviceDesc
|
||||
var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "did.v1.Msg",
|
||||
HandlerType: (*MsgServer)(nil),
|
||||
|
||||
@@ -475,6 +475,7 @@ func _Query_ValidateToken_Handler(srv interface{}, ctx context.Context, dec func
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Query_serviceDesc = _Query_serviceDesc
|
||||
var _Query_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "macaroon.v1.Query",
|
||||
HandlerType: (*QueryServer)(nil),
|
||||
|
||||
@@ -411,6 +411,7 @@ func _Msg_IssueMacaroon_Handler(srv interface{}, ctx context.Context, dec func(i
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Msg_serviceDesc = _Msg_serviceDesc
|
||||
var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "macaroon.v1.Msg",
|
||||
HandlerType: (*MsgServer)(nil),
|
||||
|
||||
@@ -207,6 +207,7 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Query_serviceDesc = _Query_serviceDesc
|
||||
var _Query_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "service.v1.Query",
|
||||
HandlerType: (*QueryServer)(nil),
|
||||
|
||||
@@ -387,6 +387,7 @@ func _Msg_RegisterService_Handler(srv interface{}, ctx context.Context, dec func
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Msg_serviceDesc = _Msg_serviceDesc
|
||||
var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "service.v1.Msg",
|
||||
HandlerType: (*MsgServer)(nil),
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"cosmossdk.io/log"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ipfs/boxo/path"
|
||||
"github.com/ipfs/kubo/client/rpc"
|
||||
|
||||
"github.com/onsonr/sonr/x/vault/types"
|
||||
)
|
||||
@@ -41,14 +40,7 @@ func (k *Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
|
||||
|
||||
// IPFSConnected returns true if the IPFS client is initialized
|
||||
func (c Keeper) IPFSConnected() bool {
|
||||
if c.ipfsClient == nil {
|
||||
ipfsClient, err := rpc.NewLocalApi()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
c.ipfsClient = ipfsClient
|
||||
}
|
||||
return c.ipfsClient != nil
|
||||
return c.hasIpfsConn
|
||||
}
|
||||
|
||||
// HasPathInIPFS checks if a file is in the local IPFS node
|
||||
|
||||
@@ -33,7 +33,8 @@ type Keeper struct {
|
||||
|
||||
authority string
|
||||
|
||||
ipfsClient *rpc.HttpApi
|
||||
ipfsClient *rpc.HttpApi
|
||||
hasIpfsConn bool
|
||||
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
DIDKeeper didkeeper.Keeper
|
||||
@@ -50,6 +51,7 @@ func NewKeeper(
|
||||
didKeeper didkeeper.Keeper,
|
||||
macaroonKeeper macaroonkeeper.Keeper,
|
||||
) Keeper {
|
||||
var hasIpfs bool
|
||||
logger = logger.With(log.ModuleKey, "x/"+types.ModuleName)
|
||||
|
||||
sb := collections.NewSchemaBuilder(storeService)
|
||||
@@ -70,7 +72,11 @@ func NewKeeper(
|
||||
|
||||
ipfsClient, err := rpc.NewLocalApi()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
hasIpfs = false
|
||||
}
|
||||
|
||||
if ipfsClient != nil {
|
||||
hasIpfs = true
|
||||
}
|
||||
|
||||
k := Keeper{
|
||||
@@ -82,8 +88,9 @@ func NewKeeper(
|
||||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
|
||||
OrmDB: store,
|
||||
|
||||
ipfsClient: ipfsClient,
|
||||
authority: authority,
|
||||
ipfsClient: ipfsClient,
|
||||
hasIpfsConn: hasIpfs,
|
||||
authority: authority,
|
||||
}
|
||||
|
||||
schema, err := sb.Build()
|
||||
|
||||
+12
-16
@@ -2,6 +2,7 @@ package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -59,33 +60,28 @@ func (k Querier) Allocate(goCtx context.Context, req *types.QueryAllocateRequest
|
||||
// 1. Get current schema
|
||||
sch, err := k.currentSchema(ctx)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error getting current schema: %s", err.Error()))
|
||||
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||
}
|
||||
shares, err := mpc.GenerateKeyshares()
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
con, err := didtypes.NewController(ctx, shares)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
usrKs, err := con.ExportUserKs()
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error generating keyshares: %s", err.Error()))
|
||||
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||
}
|
||||
v, err := types.NewVault(usrKs, con.SonrAddress(), con.ChainID(), sch)
|
||||
|
||||
con, err := didtypes.NewController(shares)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error creating controller: %s", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
v, err := types.NewVault("", con.SonrAddress(), con.ChainID(), sch)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(fmt.Sprintf("Error creating vault: %s", err.Error()))
|
||||
return nil, types.ErrInvalidSchema.Wrap(err.Error())
|
||||
}
|
||||
cid, err := k.ipfsClient.Unixfs().Add(context.Background(), v.FS)
|
||||
if err != nil {
|
||||
ctx.Logger().Error(err.Error())
|
||||
ctx.Logger().Error(fmt.Sprintf("Error adding to IPFS: %s", err.Error()))
|
||||
return nil, types.ErrVaultAssembly.Wrap(err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@ import (
|
||||
func DefaultParams() Params {
|
||||
// TODO:
|
||||
return Params{
|
||||
IpfsActive: true,
|
||||
Schema: DefaultSchema(),
|
||||
IpfsActive: true,
|
||||
LocalRegistrationEnabled: true,
|
||||
Schema: DefaultSchema(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -652,6 +652,7 @@ func _Query_Sync_Handler(srv interface{}, ctx context.Context, dec func(interfac
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Query_serviceDesc = _Query_serviceDesc
|
||||
var _Query_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "vault.v1.Query",
|
||||
HandlerType: (*QueryServer)(nil),
|
||||
|
||||
@@ -236,6 +236,7 @@ func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(in
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var Msg_serviceDesc = _Msg_serviceDesc
|
||||
var _Msg_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "vault.v1.Msg",
|
||||
HandlerType: (*MsgServer)(nil),
|
||||
|
||||
Reference in New Issue
Block a user