mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
feat(vault): introduce assembly of the initial vault
This commit is contained in:
parent
e424faaba2
commit
ab476712af
2
Makefile
2
Makefile
@ -299,7 +299,6 @@ sh-testnet: mod-tidy
|
|||||||
|
|
||||||
hway:
|
hway:
|
||||||
@echo "(motr) Building Highway gateway"
|
@echo "(motr) Building Highway gateway"
|
||||||
templ generate
|
|
||||||
go build -o ./build/hway ./cmd/hway
|
go build -o ./build/hway ./cmd/hway
|
||||||
|
|
||||||
motr:
|
motr:
|
||||||
@ -313,6 +312,7 @@ templ:
|
|||||||
nebula:
|
nebula:
|
||||||
@echo "(nebula) Building nebula"
|
@echo "(nebula) Building nebula"
|
||||||
cd pkg/nebula && bun run build
|
cd pkg/nebula && bun run build
|
||||||
|
templ generate
|
||||||
|
|
||||||
pkl:
|
pkl:
|
||||||
@echo "(pkl) Building PKL"
|
@echo "(pkl) Building PKL"
|
||||||
|
55
x/vault/keeper/assembly.go
Normal file
55
x/vault/keeper/assembly.go
Normal file
@ -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
|
||||||
|
}
|
@ -1,22 +1,17 @@
|
|||||||
package keeper
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"cosmossdk.io/collections"
|
"cosmossdk.io/collections"
|
||||||
storetypes "cosmossdk.io/core/store"
|
storetypes "cosmossdk.io/core/store"
|
||||||
"cosmossdk.io/log"
|
"cosmossdk.io/log"
|
||||||
"cosmossdk.io/orm/model/ormdb"
|
"cosmossdk.io/orm/model/ormdb"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
"github.com/ipfs/kubo/client/rpc"
|
"github.com/ipfs/kubo/client/rpc"
|
||||||
|
|
||||||
apiv1 "github.com/onsonr/sonr/api/vault/v1"
|
apiv1 "github.com/onsonr/sonr/api/vault/v1"
|
||||||
"github.com/onsonr/sonr/pkg/dwn"
|
|
||||||
didkeeper "github.com/onsonr/sonr/x/did/keeper"
|
didkeeper "github.com/onsonr/sonr/x/did/keeper"
|
||||||
"github.com/onsonr/sonr/x/vault/types"
|
"github.com/onsonr/sonr/x/vault/types"
|
||||||
)
|
)
|
||||||
@ -88,48 +83,3 @@ func NewKeeper(
|
|||||||
|
|
||||||
return k
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user