Documentation
¶
Index ¶
- Constants
- func CantonPartyFromContext(ctx context.Context) (string, bool)
- func ComputeFingerprint(evmAddress string) string
- func ComputeFingerprintFromPublicKey(publicKey []byte) string
- func EVMAddressFromContext(ctx context.Context) (string, bool)
- func ExtractFingerprintFromPartyID(partyID string) (string, error)
- func ExtractHintFromPartyID(partyID string) (string, error)
- func FingerprintFromContext(ctx context.Context) (string, bool)
- func IsCantonPartyID(s string) bool
- func NormalizeAddress(address string) string
- func UserIDFromContext(ctx context.Context) (int64, bool)
- func ValidateCantonPartyID(partyID string) error
- func ValidateEVMAddress(address string) bool
- func ValidateTimedMessage(msg string, maxAge time.Duration) error
- func VerifyCantonSignature(partyID, message, signature string) (bool, error)
- func VerifyEIP191Signature(message, signature string) (common.Address, error)
- func WithAuthInfo(ctx context.Context, info *AuthInfo) context.Context
- func WithCantonParty(ctx context.Context, party string) context.Context
- func WithEVMAddress(ctx context.Context, address string) context.Context
- func WithFingerprint(ctx context.Context, fingerprint string) context.Context
- func WithUserID(ctx context.Context, userID int64) context.Context
- type AuthInfo
- type JWK
- type JWKS
- type JWTValidator
Constants ¶
const ( // ContextKeyEVMAddress is the context key for the authenticated EVM address ContextKeyEVMAddress contextKey = "evm_address" // ContextKeyCantonParty is the context key for the user's Canton party ContextKeyCantonParty contextKey = "canton_party" // ContextKeyFingerprint is the context key for the user's fingerprint ContextKeyFingerprint contextKey = "fingerprint" // ContextKeyUserID is the context key for the user's database ID ContextKeyUserID contextKey = "user_id" )
Variables ¶
This section is empty.
Functions ¶
func CantonPartyFromContext ¶
CantonPartyFromContext retrieves the Canton party from the context
func ComputeFingerprint ¶
ComputeFingerprint computes the fingerprint from an EVM address The fingerprint is used to link Canton parties to EVM addresses
func ComputeFingerprintFromPublicKey ¶
ComputeFingerprintFromPublicKey computes a Canton-style fingerprint from a compressed public key.
func EVMAddressFromContext ¶
EVMAddressFromContext retrieves the EVM address from the context
func ExtractFingerprintFromPartyID ¶
ExtractFingerprintFromPartyID extracts the fingerprint from a Canton party ID. Party ID format: "hint::fingerprint" where fingerprint is hex-encoded. The fingerprint may have a "1220" prefix (multihash prefix for SHA-256).
func ExtractHintFromPartyID ¶
ExtractHintFromPartyID extracts the hint portion from a Canton party ID. Party ID format: "hint::fingerprint"
func FingerprintFromContext ¶
FingerprintFromContext retrieves the fingerprint from the context
func IsCantonPartyID ¶
IsCantonPartyID checks if a string looks like a Canton party ID. Returns true if it contains "::" separator.
func NormalizeAddress ¶
NormalizeAddress returns a checksummed EVM address
func UserIDFromContext ¶
UserIDFromContext retrieves the user ID from the context
func ValidateCantonPartyID ¶
ValidateCantonPartyID validates that a string is a properly formatted Canton party ID.
func ValidateEVMAddress ¶
ValidateEVMAddress checks if a string is a valid EVM address
func ValidateTimedMessage ¶
ValidateTimedMessage checks that a message contains a Unix timestamp suffix (format: "{prefix}:{unix_seconds}") and that it is within maxAge of now. This provides replay protection: captured signatures expire after maxAge.
func VerifyCantonSignature ¶
VerifyCantonSignature verifies a Canton signature from Loop wallet's signMessage. Canton uses secp256k1 (same curve as Ethereum). The partyID format is "hint::fingerprint" where fingerprint is a hex-encoded hash. Returns true if the signature is valid for the given party.
func VerifyEIP191Signature ¶
VerifyEIP191Signature verifies an EIP-191 personal_sign signature Returns the recovered Ethereum address if valid
func WithAuthInfo ¶
WithAuthInfo adds all authentication info to the context
func WithCantonParty ¶
WithCantonParty adds the Canton party to the context
func WithEVMAddress ¶
WithEVMAddress adds the EVM address to the context
func WithFingerprint ¶
WithFingerprint adds the fingerprint to the context
Types ¶
type AuthInfo ¶
AuthInfo contains all authentication information for a request
func AuthInfoFromContext ¶
AuthInfoFromContext retrieves all authentication info from the context
type JWK ¶
type JWK struct {
Kid string `json:"kid"`
Kty string `json:"kty"`
Alg string `json:"alg"`
Use string `json:"use"`
N string `json:"n"`
E string `json:"e"`
}
JWK represents a JSON Web Key
type JWTValidator ¶
type JWTValidator struct {
// contains filtered or unexported fields
}
JWTValidator validates JWT tokens using JWKS
func NewJWTValidator ¶
func NewJWTValidator(jwksURL, issuer string) *JWTValidator
NewJWTValidator creates a new JWT validator
func (*JWTValidator) IsConfigured ¶
func (v *JWTValidator) IsConfigured() bool
IsConfigured returns true if JWKS validation is configured
func (*JWTValidator) ValidateToken ¶
func (v *JWTValidator) ValidateToken(tokenString string) (jwt.MapClaims, error)
ValidateToken validates a JWT token and returns the claims