mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
feature/implement wss routes (#1196)
* feat(database): create schema for hway and motr * fix(gateway): correct naming inconsistencies in handlers * build: update schema file to be compatible with postgresql syntax * fix: update schema to be compatible with PostgreSQL syntax * chore: update query_hway.sql to follow sqlc syntax * ```text refactor: update query_hway.sql for PostgreSQL and sqlc ``` * feat: add vaults table to store encrypted data * refactor: Update vaults table schema for sqlc compatibility * chore(deps): Upgrade dependencies and add pgx/v5 * refactor(Makefile): move sqlc generate to internal/models * docs(foundations): remove outdated pages * chore(build): add Taskfile for build tasks * refactor(embed): move embed files to internal package * docs: add documentation for Cosmos SDK ORM
This commit is contained in:
+39
-12
@@ -32,35 +32,62 @@ func (gs GenesisState) Validate() error {
|
||||
return gs.Params.Validate()
|
||||
}
|
||||
|
||||
func (s *Schema) Equal(that *Schema) bool {
|
||||
// Equal checks if two Attenuation are equal
|
||||
func (a *Attenuation) Equal(that *Attenuation) bool {
|
||||
if that == nil {
|
||||
return false
|
||||
}
|
||||
if s.Version != that.Version {
|
||||
if a.Resource != nil {
|
||||
if that.Resource == nil {
|
||||
return false
|
||||
}
|
||||
if !a.Resource.Equal(that.Resource) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if len(a.Capabilities) != len(that.Capabilities) {
|
||||
return false
|
||||
}
|
||||
if s.Account != that.Account {
|
||||
for i := range a.Capabilities {
|
||||
if !a.Capabilities[i].Equal(that.Capabilities[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal checks if two Capability are equal
|
||||
func (c *Capability) Equal(that *Capability) bool {
|
||||
if that == nil {
|
||||
return false
|
||||
}
|
||||
if s.Asset != that.Asset {
|
||||
if c.Name != that.Name {
|
||||
return false
|
||||
}
|
||||
if s.Chain != that.Chain {
|
||||
if c.Parent != that.Parent {
|
||||
return false
|
||||
}
|
||||
if s.Credential != that.Credential {
|
||||
// TODO: check description
|
||||
if len(c.Resources) != len(that.Resources) {
|
||||
return false
|
||||
}
|
||||
if s.Jwk != that.Jwk {
|
||||
for i := range c.Resources {
|
||||
if c.Resources[i] != that.Resources[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equal checks if two Resource are equal
|
||||
func (r *Resource) Equal(that *Resource) bool {
|
||||
if that == nil {
|
||||
return false
|
||||
}
|
||||
if s.Grant != that.Grant {
|
||||
if r.Kind != that.Kind {
|
||||
return false
|
||||
}
|
||||
if s.Keyshare != that.Keyshare {
|
||||
return false
|
||||
}
|
||||
if s.Profile != that.Profile {
|
||||
if r.Template != that.Template {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
+292
-1301
File diff suppressed because it is too large
Load Diff
@@ -2,20 +2,11 @@ package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/onsonr/sonr/internal/models"
|
||||
"github.com/onsonr/sonr/internal/models/keyalgorithm"
|
||||
"github.com/onsonr/sonr/internal/models/keycurve"
|
||||
"github.com/onsonr/sonr/internal/models/keyencoding"
|
||||
"github.com/onsonr/sonr/internal/models/keyrole"
|
||||
)
|
||||
|
||||
// DefaultParams returns default module parameters.
|
||||
func DefaultParams() Params {
|
||||
return Params{
|
||||
ConveyancePreference: "direct",
|
||||
AttestationFormats: []string{"packed", "android-key", "fido-u2f", "apple"},
|
||||
Schema: DefaultSchema(),
|
||||
AllowedOperators: []string{ // TODO:
|
||||
"localhost",
|
||||
"didao.xyz",
|
||||
@@ -39,87 +30,3 @@ func (p Params) Validate() error {
|
||||
// TODO:
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultSchema returns the default schema
|
||||
func DefaultSchema() *Schema {
|
||||
return &Schema{
|
||||
Version: SchemaVersion,
|
||||
Account: GetSchema(&models.Account{}),
|
||||
Asset: GetSchema(&models.Asset{}),
|
||||
Chain: GetSchema(&models.Chain{}),
|
||||
Credential: GetSchema(&models.Credential{}),
|
||||
Grant: GetSchema(&models.Grant{}),
|
||||
Keyshare: GetSchema(&models.Keyshare{}),
|
||||
Profile: GetSchema(&models.Profile{}),
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultKeyInfos() map[string]*KeyInfo {
|
||||
return map[string]*KeyInfo{
|
||||
// Identity Key Info
|
||||
// Sonr Controller Key Info - From MPC
|
||||
"auth.dwn": {
|
||||
Role: keyrole.Invocation.String(),
|
||||
Curve: keycurve.P256.String(),
|
||||
Algorithm: keyalgorithm.Ecdsa.String(),
|
||||
Encoding: keyencoding.Hex.String(),
|
||||
},
|
||||
|
||||
// Sonr Vault Shared Key Info - From Registration
|
||||
"auth.zk": {
|
||||
Role: keyrole.Assertion.String(),
|
||||
Curve: keycurve.Bls12381.String(),
|
||||
Algorithm: keyalgorithm.Es256k.String(),
|
||||
Encoding: keyencoding.Multibase.String(),
|
||||
},
|
||||
|
||||
// Blockchain Key Info
|
||||
// Ethereum Key Info
|
||||
"auth.ethereum": {
|
||||
Role: keyrole.Delegation.String(),
|
||||
Curve: keycurve.Keccak256.String(),
|
||||
Algorithm: keyalgorithm.Ecdsa.String(),
|
||||
Encoding: keyencoding.Hex.String(),
|
||||
},
|
||||
// Bitcoin/IBC Key Info
|
||||
"auth.bitcoin": {
|
||||
Role: keyrole.Delegation.String(),
|
||||
Curve: keycurve.Secp256k1.String(),
|
||||
Algorithm: keyalgorithm.Ecdsa.String(),
|
||||
Encoding: keyencoding.Hex.String(),
|
||||
},
|
||||
|
||||
// Authentication Key Info
|
||||
// Browser based WebAuthn
|
||||
"webauthn.browser": {
|
||||
Role: keyrole.Authentication.String(),
|
||||
Curve: keycurve.P256.String(),
|
||||
Algorithm: keyalgorithm.Es256.String(),
|
||||
Encoding: keyencoding.Raw.String(),
|
||||
},
|
||||
// FIDO U2F
|
||||
"webauthn.fido": {
|
||||
Role: keyrole.Authentication.String(),
|
||||
Curve: keycurve.P256.String(),
|
||||
Algorithm: keyalgorithm.Es256.String(),
|
||||
Encoding: keyencoding.Raw.String(),
|
||||
},
|
||||
// Cross-Platform Passkeys
|
||||
"webauthn.passkey": {
|
||||
Role: keyrole.Authentication.String(),
|
||||
Curve: keycurve.Ed25519.String(),
|
||||
Algorithm: keyalgorithm.Eddsa.String(),
|
||||
Encoding: keyencoding.Raw.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// # Genesis Structures
|
||||
//
|
||||
// Equal returns true if two key infos are equal
|
||||
func (k *KeyInfo) Equal(b *KeyInfo) bool {
|
||||
if k == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
+28
-914
File diff suppressed because it is too large
Load Diff
@@ -51,24 +51,6 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal
|
||||
|
||||
}
|
||||
|
||||
func request_Query_Schema_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QuerySchemaRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.Schema(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Schema_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QuerySchemaRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.Schema(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_Allocate_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryAllocateRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
@@ -87,42 +69,6 @@ func local_request_Query_Allocate_0(ctx context.Context, marshaler runtime.Marsh
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_Query_Sync_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_Query_Sync_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QuerySyncRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Sync_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.Sync(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_Sync_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QuerySyncRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Sync_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.Sync(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
|
||||
// UnaryRPC :call QueryServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
@@ -152,29 +98,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Schema_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Schema_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Schema_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Allocate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
@@ -198,29 +121,6 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Sync_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Query_Sync_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Sync_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -282,26 +182,6 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Schema_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Schema_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Schema_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Allocate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
@@ -322,45 +202,17 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_Sync_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Query_Sync_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Query_Sync_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"vault", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Schema_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"vault", "v1", "schema"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Allocate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"vault", "v1", "allocate"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_Sync_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"vault", "v1", "sync"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Query_Params_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Schema_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Allocate_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_Sync_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const SchemaVersion = 1
|
||||
|
||||
func toCamelCase(s string) string {
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
if len(s) == 1 {
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
return strings.ToLower(s[:1]) + s[1:]
|
||||
}
|
||||
|
||||
func GetSchema(structType interface{}) string {
|
||||
t := reflect.TypeOf(structType)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
if t.Kind() != reflect.Struct {
|
||||
return ""
|
||||
}
|
||||
|
||||
var fields []string
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
fieldName := toCamelCase(field.Name)
|
||||
fields = append(fields, fieldName)
|
||||
}
|
||||
|
||||
// Add "++" at the beginning, separated by a comma
|
||||
return "++, " + strings.Join(fields, ", ")
|
||||
}
|
||||
Reference in New Issue
Block a user