2.8 KiB
2.8 KiB
pub struct Env
Env is the application's configuration, loaded once at startup and cloned into every service that needs it (Api, Query, Command, Billing, Infra, Robot, Stripe). It is the single source of truth for environment-derived settings, and it also owns the robot nostr key used for signing, NIP-44 encryption, and NIP-98 auth.
Members (all populated from environment variables):
server_host: String- fromSERVER_HOST; also used for the NIP-98uhost checkserver_port: u16- fromSERVER_PORTserver_admin_pubkeys: Vec<String>- admin pubkeys fromSERVER_ADMIN_PUBKEYSserver_allow_origins: Vec<String>- CORS origins fromSERVER_ALLOW_ORIGINSdatabase_url: String- fromDATABASE_URLrobot_name: String- fromROBOT_NAMErobot_wallet: String- the system NWC URL fromROBOT_WALLET, used to issue/look up bolt11 invoicesrobot_picture: String- fromROBOT_PICTURErobot_description: String- fromROBOT_DESCRIPTIONrobot_outbox_relays: Vec<String>- fromROBOT_OUTBOX_RELAYSrobot_indexer_relays: Vec<String>- fromROBOT_INDEXER_RELAYSrobot_messaging_relays: Vec<String>- fromROBOT_MESSAGING_RELAYSblossom_s3_region/blossom_s3_bucket/blossom_s3_endpoint/blossom_s3_access_key/blossom_s3_secret_key: String- from the matchingBLOSSOM_S3_*varszooid_api_url: String- fromZOOID_API_URLrelay_domain: String- fromRELAY_DOMAINlivekit_url/livekit_api_key/livekit_api_secret: String- from the matchingLIVEKIT_*varsstripe_secret_key: String- fromSTRIPE_SECRET_KEYstripe_webhook_secret: String- fromSTRIPE_WEBHOOK_SECRETstripe_price_basic: String- Stripe price id for the Basic plan, fromSTRIPE_PRICE_BASICstripe_price_growth: String- Stripe price id for the Growth plan, fromSTRIPE_PRICE_GROWTHkeys: Keys- parsed fromROBOT_SECRET; used for nostr signing, NIP-44 encryption, and NIP-98 auth
pub fn load() -> Self
- Reads every variable above and panics if any is missing or malformed.
- String vars must be present and non-blank (trimmed).
- The port must parse as a
u16. - CSV vars are split on commas, trimmed, and empties dropped; each must contain at least one entry.
keysis parsed fromROBOT_SECRETand panics if it is not a valid nostr secret key.
pub fn encrypt(&self, plaintext: &str) -> Result<String>
- NIP-44 (v2) encrypts
plaintextto the robot's own key. Used to encrypt a tenant'snwc_urlat rest.
pub fn decrypt(&self, ciphertext: &str) -> Result<String>
- NIP-44 decrypts a value previously produced by
encrypt.
pub async fn make_auth(&self, url: &str, method: HttpMethod) -> Result<String>
- Builds a NIP-98
Authorizationheader value for an outgoing request tourlwithmethod, signed withkeys. Used byInfrato authenticate requests to zooid.