Amarula.Protocol.Auth.QRCodeGenerator (amarula v0.1.0)

View Source

QR Code Generator for WhatsApp authentication.

This module provides utilities for generating QR codes from authentication data and handling QR code formatting and validation.

Summary

Functions

Extracts the advertisement secret key from a QR code string.

Extracts the identity key from a QR code string.

Extracts the noise key from a QR code string.

Extracts the reference from a QR code string.

Formats a QR code for display (e.g., in terminal or UI).

Convenience function that generates a QR string and renders it as terminal output.

Generates a QR code string from authentication components.

Generates a QR code reference string.

Generates multiple QR code references.

Parses a QR code string into its components.

Checks if a QR code has expired based on its generation time.

Renders a QR string as ASCII art using the qr_code library.

Renders a QR string with pretty terminal formatting including borders and branding.

Validates a QR code string format.

Functions

extract_adv_secret_key(qr_string)

@spec extract_adv_secret_key(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Extracts the advertisement secret key from a QR code string.

extract_identity_key(qr_string)

@spec extract_identity_key(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Extracts the identity key from a QR code string.

extract_noise_key(qr_string)

@spec extract_noise_key(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Extracts the noise key from a QR code string.

extract_ref(qr_string)

@spec extract_ref(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Extracts the reference from a QR code string.

format_qr_for_display(qr_string)

@spec format_qr_for_display(String.t()) :: String.t()

Formats a QR code for display (e.g., in terminal or UI).

generate_and_render(ref, noise_key_b64, identity_key_b64, adv_b64)

@spec generate_and_render(String.t(), String.t(), String.t(), String.t()) ::
  {:ok, String.t()} | {:error, String.t()}

Convenience function that generates a QR string and renders it as terminal output.

Takes authentication components and returns a formatted ASCII QR code.

generate_qr_string(ref, noise_key_b64, identity_key_b64, adv_secret_key_b64)

@spec generate_qr_string(String.t(), String.t(), String.t(), String.t()) :: String.t()

Generates a QR code string from authentication components.

The QR code format is: "ref,noiseKeyB64,identityKeyB64,advSecretKeyB64"

generate_ref()

@spec generate_ref() :: String.t()

Generates a QR code reference string.

This creates a unique reference string for QR code generation.

generate_refs(count)

@spec generate_refs(integer()) :: [String.t()]

Generates multiple QR code references.

parse_qr_string(qr_string)

@spec parse_qr_string(String.t()) ::
  {:ok, {String.t(), String.t(), String.t(), String.t()}} | {:error, String.t()}

Parses a QR code string into its components.

Returns {:ok, {ref, noise_key_b64, identity_key_b64, adv_secret_key_b64}} on success, or {:error, reason} on failure.

qr_expired?(generation_time, timeout_ms)

@spec qr_expired?(integer(), integer()) :: boolean()

Checks if a QR code has expired based on its generation time.

render_ascii(qr_string)

@spec render_ascii(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Renders a QR string as ASCII art using the qr_code library.

Takes a QR string and returns an ASCII representation of the QR code matrix. Uses half-height blocks to correct for terminal character aspect ratio.

render_terminal(qr_string)

@spec render_terminal(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Renders a QR string with pretty terminal formatting including borders and branding.

Takes a QR string and returns a formatted ASCII QR code suitable for terminal display.

validate_qr_string(qr_string)

@spec validate_qr_string(String.t()) :: :ok | {:error, String.t()}

Validates a QR code string format.