LibAddress
Title: LibAddress
Library for address-related utility functions
Provides functions for converting addresses to cross-chain identifiers
Functions
toIdentifier
Converts an Ethereum address to a bytes32 identifier that can be used across chains.
Uses the address’s numeric value as a bytes32 identifier by casting type in-place.
function toIdentifier(address addr) internal pure returns (bytes32 identifier);
Parameters
| Name | Type | Description |
|---|---|---|
addr | address | The address to convert |
Returns
| Name | Type | Description |
|---|---|---|
identifier | bytes32 | The bytes32 identifier representation of the address |
fromIdentifier
Converts a bytes32 identifier back to an Ethereum address.
Reverses the toIdentifier operation by cleaning the top 96 bits and then returning the address remaining from the last 160 bits.
function fromIdentifier(bytes32 identifier) internal pure returns (address addr);
Parameters
| Name | Type | Description |
|---|---|---|
identifier | bytes32 | The bytes32 identifier to convert |
Returns
| Name | Type | Description |
|---|---|---|
addr | address | The address representation of the identifier |
fromIdentifier
Converts a uint256 identifier back to an Ethereum address.
Reverses the toIdentifier operation by cleaning the top 96 bits and then returning the address remaining from the last 160 bits.
function fromIdentifier(uint256 identifier) internal pure returns (address addr);
Parameters
| Name | Type | Description |
|---|---|---|
identifier | uint256 | The uint256 identifier to convert |
Returns
| Name | Type | Description |
|---|---|---|
addr | address | The address representation of the identifier |
safeFromIdentifier
Converts a uint256 identifier to an Ethereum address while requiring that the leftmost 12 bytes are empty.
Reverts if any bit is set in the leftmost 12 bytes. Then typecasts transparently.
function safeFromIdentifier(uint256 identifier) internal pure returns (address addr);
Parameters
| Name | Type | Description |
|---|---|---|
identifier | uint256 | The uint256 identifier to check and convert |
Returns
| Name | Type | Description |
|---|---|---|
addr | address | Validates and casted Ethereum address. |
Errors
InvalidAddress
The input isn’t safely coerced to an address
error InvalidAddress();