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 Config
- type LoginRequest
- type LoginResponse
- type NonceResponse
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 Config ¶ added in v0.9.0
type Config struct {
// PrivateKey is the RSA signing key as a base64-encoded PEM (PKCS#1 or PKCS#8).
// Supply it via env substitution — private_key: "${JWT_PRIVATE_KEY}" — where the
// env holds `base64 < key.pem`. It is base64-encoded so the (multi-line) PEM
// survives being expanded into a single YAML scalar.
PrivateKey string `yaml:"private_key" validate:"required"`
// KeyID is the JWKS "kid" advertised for the signing key.
KeyID string `yaml:"kid" validate:"required" default:"default"`
// Issuer is the JWT "iss" claim (and the value validators check).
Issuer string `yaml:"issuer" validate:"required" default:"canton-middleware"`
// Audience is the JWT "aud" claim.
Audience string `yaml:"audience" validate:"required" default:"canton-middleware-api"`
// TokenTTL is how long an issued JWT stays valid.
TokenTTL time.Duration `yaml:"token_ttl" validate:"required,gt=0" default:"30m"`
// NonceTTL is how long a login nonce stays valid before it must be re-fetched.
NonceTTL time.Duration `yaml:"nonce_ttl" validate:"required,gt=0" default:"5m"`
// Domain is the EIP-4361 domain the SIWE message must bind to (e.g. "app.example.com").
Domain string `yaml:"domain" validate:"required"`
// URI is the EIP-4361 uri the SIWE message must bind to (e.g. "https://app.example.com").
URI string `yaml:"uri" validate:"required"`
// ChainID is the EIP-155 chain id the SIWE message must declare.
ChainID int `yaml:"chain_id" validate:"required,gt=0"`
}
Config configures Sign-In with Ethereum (EIP-4361) login and the JWTs it issues for read endpoints. It is always required; read endpoints are gated by a bearer token. The matching public key is published at /.well-known/jwks.json so other services (e.g. the indexer) can validate tokens without a shared secret.
type LoginRequest ¶ added in v0.9.0
type LoginResponse ¶ added in v0.9.0
type NonceResponse ¶ added in v0.9.0
type NonceResponse struct {
Nonce string `json:"nonce"`
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package service implements the Sign-In with Ethereum (EIP-4361) login flow: it issues single-use nonces, verifies signed SIWE messages, and mints the JWTs that authenticate read endpoints.
|
Package service implements the Sign-In with Ethereum (EIP-4361) login flow: it issues single-use nonces, verifies signed SIWE messages, and mints the JWTs that authenticate read endpoints. |
|
nonce_provider
Package nonceprovider contains implementations of the login nonce store.
|
Package nonceprovider contains implementations of the login nonce store. |