mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 18:31:41 +00:00
feature/did accounts (#23)
* feat: add support for DID number as primary key for Controllers * refactor: rename pkg/proxy to app/proxy * feat: add vault module keeper tests * feat(vault): add DID keeper to vault module * refactor: move vault client code to its own package * refactor(vault): extract schema definition * refactor: use vaulttypes for MsgAllocateVault * refactor: update vault assembly logic to use new methods * feat: add dwn-proxy command * refactor: remove unused context.go file * refactor: remove unused web-related code * feat: add DWN proxy server * feat: add BuildTx RPC to vault module * fix: Implement BuildTx endpoint * feat: add devbox integration to project
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/onsonr/sonr/config/dwn"
|
||||
vault "github.com/onsonr/sonr/x/vault/internal"
|
||||
"github.com/onsonr/sonr/x/vault/types"
|
||||
)
|
||||
|
||||
// AssembleVault assembles the initial vault
|
||||
func (k Keeper) AssembleVault(ctx sdk.Context, subject string, origin string) (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
|
||||
}
|
||||
cnfg := vault.NewConfig(usrKs, con.SonrAddress(), con.ChainID(), sch)
|
||||
|
||||
v, err := types.NewVault(cnfg, "sonr-testnet")
|
||||
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,
|
||||
PublicKey: schema.PublicKey,
|
||||
Profile: schema.Profile,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user