mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
* feat(did): remove account types * feat: Refactor Property to Proof in zkprop.go * feat: add ZKP proof mechanism for verifications * fix: return bool and error from pinInitialVault * feat: implement KeyshareSet for managing user and validator keyshares * feat: Update Credential type in protobuf * feat: update credential schema with sign count * feat: migrate and modules to middleware * refactor: rename vault module to ORM * chore(dwn): add service worker registration to index template * feat: integrate service worker for offline functionality * refactor(did): use DIDNamespace enum for verification method in proto reflection * refactor: update protobuf definitions to support Keyshare * feat: expose did keeper in app keepers * Add Motr Web App * refactor: rename motr/handlers/discovery.go to motr/handlers/openid.go * refactor: move session related code to middleware * feat: add database operations for managing assets, chains, and credentials * feat: add htmx support for UI updates * refactor: extract common helper scripts * chore: remove unused storage GUI components * refactor: Move frontend rendering to dedicated handlers * refactor: rename to * refactor: move alert implementation to templ * feat: add alert component with icon, title, and message * feat: add new RequestHeaders struct to store request headers * Feature/create home view (#9) * refactor: move view logic to new htmx handler * refactor: remove unnecessary dependencies * refactor: remove unused dependencies * feat(devbox): integrate air for local development * feat: implement openid connect discovery document * refactor: rename to * refactor(did): update service handling to support DNS discovery * feat: add support for user and validator keyshares * refactor: move keyshare signing logic to signer
107 lines
2.5 KiB
Go
107 lines
2.5 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/ipfs/boxo/files"
|
|
"github.com/ipfs/boxo/path"
|
|
"github.com/ipfs/kubo/client/rpc"
|
|
"github.com/ipfs/kubo/core/coreiface/options"
|
|
"github.com/onsonr/sonr/internal/vfs"
|
|
)
|
|
|
|
// assembleInitialVault assembles the initial vault
|
|
func (k Keeper) assembleInitialVault(ctx sdk.Context) (string, int64, error) {
|
|
cid, err := k.ipfsClient.Unixfs().Add(context.Background(), vfs.AssembleDirectory())
|
|
if err != nil {
|
|
return "", 0, err
|
|
}
|
|
return cid.String(), k.GetExpirationBlockHeight(ctx, time.Second*15), nil
|
|
}
|
|
|
|
// pinInitialVault pins the initial vault to the local IPFS node
|
|
func (k Keeper) pinInitialVault(_ sdk.Context, cid string, address string) (bool, error) {
|
|
// Resolve the path
|
|
path, err := path.NewPath(cid)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
// 1. Initialize vault.db sqlite database in local IPFS with Mount
|
|
|
|
// 2. Insert the InitialWalletAccounts
|
|
|
|
// 3. Publish the path to the IPNS
|
|
_, err = k.ipfsClient.Name().Publish(context.Background(), path, options.Name.Key(address))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
// 4. Insert the accounts into x/auth
|
|
|
|
// 5. Insert the controller into state
|
|
return true, nil
|
|
}
|
|
|
|
// GetFromIPFS gets a file from the local IPFS node
|
|
func (k Keeper) GetFromIPFS(ctx sdk.Context, cid string) (files.Directory, error) {
|
|
path, err := path.NewPath(cid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
node, err := k.ipfsClient.Unixfs().Get(ctx, path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
dir, ok := node.(files.Directory)
|
|
if !ok {
|
|
return nil, fmt.Errorf("retrieved node is not a directory")
|
|
}
|
|
return dir, nil
|
|
}
|
|
|
|
// HasIPFSConnection returns true if the IPFS client is initialized
|
|
func (k *Keeper) HasIPFSConnection() bool {
|
|
if k.ipfsClient == nil {
|
|
ipfsClient, err := rpc.NewLocalApi()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
k.ipfsClient = ipfsClient
|
|
}
|
|
return k.ipfsClient != nil
|
|
}
|
|
|
|
// HasPathInIPFS checks if a file is in the local IPFS node
|
|
func (k Keeper) HasPathInIPFS(ctx sdk.Context, cid string) (bool, error) {
|
|
path, err := path.NewPath(cid)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
v, err := k.ipfsClient.Unixfs().Get(ctx, path)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if v == nil {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
// PinToIPFS pins a file to the local IPFS node
|
|
func (k Keeper) PinToIPFS(ctx sdk.Context, cid string, name string) error {
|
|
path, err := path.NewPath(cid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = k.ipfsClient.Pin().Add(ctx, path, options.Pin.Name(name))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|