# Module BSV::WireFormat <a id="module-BSV-WireFormat"></a>

Provides deep camelCase <-> snake_case key conversion for JSON wire
boundaries.

Used wherever the SDK serialises or deserialises JSON payloads that follow the
BRC-100/BRC-103 naming conventions (camelCase on the wire, snake_case in
Ruby).

**@example Convert a hash to wire format**
```ruby
BSV::WireFormat.to_wire({ identity_key: '02abc', protocol_id: [2, 'test'] })
# => { 'identityKey' => '02abc', 'protocolID' => [2, 'test'] }
```

**@example Convert a wire format hash to Ruby**
```ruby
BSV::WireFormat.from_wire({ 'identityKey' => '02abc' })
# => { identity_key: '02abc' }
```

**@example Deep conversion with nested hashes and arrays**
```ruby
BSV::WireFormat.to_wire({ outputs: [{ locking_script: 'abc' }] })
# => { 'outputs' => [{ 'lockingScript' => 'abc' }] }
```

## Constants
### `CAMEL_TO_SNAKE` <a id="constant-CAMEL_TO_SNAKE"></a> <a id="CAMEL_TO_SNAKE-constant"></a>
Inverse lookup table: camelCase -> snake_case.

### `MAX_DEPTH` <a id="constant-MAX_DEPTH"></a> <a id="MAX_DEPTH-constant"></a>
Maximum nesting depth for deep conversions. Prevents stack overflow on
pathologically deep hashes or arrays.

### `SNAKE_TO_CAMEL` <a id="constant-SNAKE_TO_CAMEL"></a> <a id="SNAKE_TO_CAMEL-constant"></a>
Well-known snake_case -> camelCase pairs for BRC-100/BRC-103 protocol keys.

Acronyms like protocolID, keyID are canonical per the TS SDK
(Wallet.interfaces.ts). Generic regex fallback handles all other keys.

## Public Class Methods
### `camel_to_snake(str)` <a id="method-c-camel_to_snake"></a> <a id="camel_to_snake-class_method"></a>
Converts a single camelCase string to snake_case.

Uses the lookup table for known protocol keys. Falls back to generic regex
substitution for unknown keys.
- **@param** `str` [String] a camelCase string
- **@return** [String] the snake_case equivalent

### `from_wire(hash)` <a id="method-c-from_wire"></a> <a id="from_wire-class_method"></a>
Deeply converts all Hash keys from camelCase strings to snake_case symbols.

Recurses into nested Hash values and Array elements. Non-Hash, non-Array
values are passed through unchanged (only keys are converted, not values).
- **@param** `hash` [Hash] the hash to convert
- **@raise** [ArgumentError] if the argument is nil
- **@return** [Hash] a new hash with snake_case symbol keys

### `shallow_from_wire(hash)` <a id="method-c-shallow_from_wire"></a> <a id="shallow_from_wire-class_method"></a>
Converts top-level Hash keys only from camelCase to snake_case symbols.

Unlike {.from_wire}, this does NOT recurse into nested hashes. Use this for
auth handshake messages where nested values may contain user-data keys (e.g.
base64 certificate type identifiers) that must not be mangled.
- **@param** `hash` [Hash] the hash to convert
- **@raise** [ArgumentError]
- **@return** [Hash] a new hash with snake_case symbol keys (values unchanged)

### `shallow_to_wire(hash)` <a id="method-c-shallow_to_wire"></a> <a id="shallow_to_wire-class_method"></a>
Converts top-level Hash keys only from snake_case to camelCase strings.

Unlike {.to_wire}, this does NOT recurse into nested hashes. Use this for auth
handshake messages where nested values may contain user-data keys (e.g. base64
certificate type identifiers) that must not be mangled.
- **@param** `hash` [Hash] the hash to convert
- **@raise** [ArgumentError]
- **@return** [Hash] a new hash with camelCase string keys (values unchanged)

### `snake_to_camel(str)` <a id="method-c-snake_to_camel"></a> <a id="snake_to_camel-class_method"></a>
Converts a single snake_case string to camelCase.

Uses the lookup table for known protocol keys (preserving acronyms like
protocolID). Falls back to generic capitalisation for unknown keys.
- **@param** `str` [String] a snake_case string
- **@return** [String] the camelCase equivalent

### `to_wire(hash)` <a id="method-c-to_wire"></a> <a id="to_wire-class_method"></a>
Deeply converts all Hash keys from snake_case symbols/strings to camelCase
strings.

Recurses into nested Hash values and Array elements. Non-Hash, non-Array
values are passed through unchanged (only keys are converted, not values).
- **@param** `hash` [Hash] the hash to convert
- **@raise** [ArgumentError] if the argument is nil
- **@return** [Hash] a new hash with camelCase string keys
