Skip to content

Commit

Permalink
feat(vault): introduce assembly of the initial vault
Browse files Browse the repository at this point in the history
  • Loading branch information
prnk28 committed Oct 7, 2024
1 parent e424faa commit ab47671
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ sh-testnet: mod-tidy

hway:
@echo "(motr) Building Highway gateway"
templ generate
go build -o ./build/hway ./cmd/hway

motr:
Expand All @@ -313,6 +312,7 @@ templ:
nebula:
@echo "(nebula) Building nebula"
cd pkg/nebula && bun run build
templ generate

pkl:
@echo "(pkl) Building PKL"
Expand Down
55 changes: 55 additions & 0 deletions x/vault/keeper/assembly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package keeper

import (
"context"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/onsonr/sonr/pkg/dwn"
"github.com/onsonr/sonr/x/vault/types"
)

// assembleVault assembles the initial vault
func (k Keeper) AssembleVault(ctx sdk.Context) (string, int64, error) {
_, con, err := k.DIDKeeper.NewController(ctx)
if err != nil {
return "", 0, err
}
usrKs, err := con.ExportUserKs()
if err != nil {
return "", 0, err
}
sch, err := k.CurrentSchema(ctx)
if err != nil {
return "", 0, err
}
v, err := types.NewVault(usrKs, con.SonrAddress(), con.ChainID(), sch)
if err != nil {
return "", 0, err
}
cid, err := k.ipfsClient.Unixfs().Add(context.Background(), v.FS)
if err != nil {
return "", 0, err
}
return cid.String(), k.CalculateExpiration(ctx, time.Second*15), nil
}

// currentSchema returns the current schema
func (k Keeper) CurrentSchema(ctx sdk.Context) (*dwn.Schema, error) {
p, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
schema := p.Schema
return &dwn.Schema{
Version: int(schema.Version),
Account: schema.Account,
Asset: schema.Asset,
Chain: schema.Chain,
Credential: schema.Credential,
Jwk: schema.Jwk,
Grant: schema.Grant,
Keyshare: schema.Keyshare,
Profile: schema.Profile,
}, nil
}
50 changes: 0 additions & 50 deletions x/vault/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package keeper

import (
"context"
"time"

"cosmossdk.io/collections"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/orm/model/ormdb"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/ipfs/kubo/client/rpc"

apiv1 "github.com/onsonr/sonr/api/vault/v1"
"github.com/onsonr/sonr/pkg/dwn"
didkeeper "github.com/onsonr/sonr/x/did/keeper"
"github.com/onsonr/sonr/x/vault/types"
)
Expand Down Expand Up @@ -88,48 +83,3 @@ func NewKeeper(

return k
}

// currentSchema returns the current schema
func (k Keeper) CurrentSchema(ctx sdk.Context) (*dwn.Schema, error) {
p, err := k.Params.Get(ctx)
if err != nil {
return nil, err
}
schema := p.Schema
return &dwn.Schema{
Version: int(schema.Version),
Account: schema.Account,
Asset: schema.Asset,
Chain: schema.Chain,
Credential: schema.Credential,
Jwk: schema.Jwk,
Grant: schema.Grant,
Keyshare: schema.Keyshare,
Profile: schema.Profile,
}, nil
}

// assembleVault assembles the initial vault
func (k Keeper) AssembleVault(ctx sdk.Context) (string, int64, error) {
_, con, err := k.DIDKeeper.NewController(ctx)
if err != nil {
return "", 0, err
}
usrKs, err := con.ExportUserKs()
if err != nil {
return "", 0, err
}
sch, err := k.CurrentSchema(ctx)
if err != nil {
return "", 0, err
}
v, err := types.NewVault(usrKs, con.SonrAddress(), con.ChainID(), sch)
if err != nil {
return "", 0, err
}
cid, err := k.ipfsClient.Unixfs().Add(context.Background(), v.FS)
if err != nil {
return "", 0, err
}
return cid.String(), k.CalculateExpiration(ctx, time.Second*15), nil
}

0 comments on commit ab47671

Please sign in to comment.