Skip to content

Identity & Security

The identity module manages caller authentication, cryptographic verification, consumer rate limits, and secure upstream credential injection. It verifies inbound API keys with constant-time comparison, validates HMAC signatures on inbound webhooks, and injects upstream authorization tokens without exposing secrets to client callers. It forms the security gatekeeper for sensitive upstream endpoints.

SymbolKindSignaturePurpose
crc32functionfunction crc32(input: string): numberFunction export for crc32.
checksum4functionfunction checksum4(input: string): stringFunction export for checksum4.
API_KEY_FORMATconstconst API_KEY_FORMAT = /^tsgk_[a-z0-9-]{1,16}_[A-Za-z0-9]{32}_[0-9a-f]{4}$/Const export for API_KEY_FORMAT.
BUCKET_FORMATconstconst BUCKET_FORMAT = /^[a-z0-9-]{1,16}$/Const export for BUCKET_FORMAT.
generateApiKeyfunctionfunction generateApiKey(bucket: string): stringFunction export for generateApiKey.
validateFormatfunctionfunction validateFormat(key: string): booleanFunction export for validateFormat.
parseApiKeyfunctionfunction parseApiKey(key: string): { bucket: string; random32: string; checksum: string } Function export for parseApiKey.
verifyChecksumfunctionfunction verifyChecksum(key: string): booleanFunction export for verifyChecksum.
hashKeyfunctionfunction hashKey(key: string): stringFunction export for hashKey.
ApiKeyPolicyConfiginterfaceinterface ApiKeyPolicyConfigInterface export for ApiKeyPolicyConfig.
ApiKeyPolicyclassclass ApiKeyPolicy implements GatewayPolicyClass export for ApiKeyPolicy.
ConsumerRateLimitPolicyConfiginterfaceinterface ConsumerRateLimitPolicyConfigInterface export for ConsumerRateLimitPolicyConfig.
ConsumerRateLimitPolicyclassclass ConsumerRateLimitPolicy implements GatewayPolicyClass export for ConsumerRateLimitPolicy.
ConsumerRecordinterfaceinterface ConsumerRecordInterface export for ConsumerRecord.
ApiKeyRecordinterfaceinterface ApiKeyRecordInterface export for ApiKeyRecord.
ConsumerStoreclassclass ConsumerStoreClass export for ConsumerStore.
HmacSignPolicyConfiginterfaceinterface HmacSignPolicyConfigInterface export for HmacSignPolicyConfig.
verifyHmacSignaturefunctionfunction verifyHmacSignature(Function export for verifyHmacSignature.
HmacSignPolicyclassclass HmacSignPolicy implements GatewayPolicyClass export for HmacSignPolicy.
SetUpstreamHeaderPolicyConfiginterfaceinterface SetUpstreamHeaderPolicyConfigInterface export for SetUpstreamHeaderPolicyConfig.
SetUpStreamHeaderPolicyclassclass SetUpStreamHeaderPolicy implements GatewayPolicyClass export for SetUpStreamHeaderPolicy.
UpstreamCredentialinterfaceinterface UpstreamCredentialInterface export for UpstreamCredential.
UpstreamCredentialStoreclassclass UpstreamCredentialStoreClass export for UpstreamCredentialStore.
VerifyInboundHmacConfiginterfaceinterface VerifyInboundHmacConfigInterface export for VerifyInboundHmacConfig.
VerifyInboundHmacPolicyclassclass VerifyInboundHmacPolicy implements GatewayPolicyClass export for VerifyInboundHmacPolicy.

Performs timing-attack safe comparisons of hashed consumer keys.

Tracks authenticated consumer identities, associated plan tiers, and daily quota ceilings.

Computes SHA-256 HMAC signatures over payload bodies to verify webhook integrity.

  • src/identity/api-key-crypto.ts
  • src/identity/api-key-policy.ts
  • src/identity/consumer-rate-limit-policy.ts
  • src/identity/consumer-store.ts
  • src/identity/hmac-sign-policy.ts
  • src/identity/set-upstream-header-policy.ts
  • src/identity/upstream-credential-store.ts
  • src/identity/verify-inbound-hmac-policy.ts