Files
sonr/x/did/context/client.go
T
Prad NukalaandGitHub bbfe2a2329 feature/refactor did state (#10)
* 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
2024-09-11 15:10:54 -04:00

56 lines
1.2 KiB
Go

package context
import (
"context"
"fmt"
"net"
"strings"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
)
type ClientInfo struct {
Authority string
ContentType string
UserAgent string
Hostname string
IPAddress string
}
func ExtractClientInfo(ctx context.Context) (*ClientInfo, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, fmt.Errorf("failed to get metadata from context")
}
info := &ClientInfo{}
// Extract authority, content-type, and user-agent
if authority := md.Get("authority"); len(authority) > 0 {
info.Authority = authority[0]
}
if contentType := md.Get("content-type"); len(contentType) > 0 {
info.ContentType = contentType[0]
}
if userAgent := md.Get("user-agent"); len(userAgent) > 0 {
info.UserAgent = userAgent[0]
}
// Extract hostname and IP address
p, ok := peer.FromContext(ctx)
if ok {
if tcpAddr, ok := p.Addr.(*net.TCPAddr); ok {
info.IPAddress = tcpAddr.IP.String()
// Try to get hostname
names, err := net.LookupAddr(info.IPAddress)
if err == nil && len(names) > 0 {
info.Hostname = strings.TrimSuffix(names[0], ".")
}
}
}
return info, nil
}