Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

LibAddress

Git Source

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

NameTypeDescription
addraddressThe address to convert

Returns

NameTypeDescription
identifierbytes32The 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

NameTypeDescription
identifierbytes32The bytes32 identifier to convert

Returns

NameTypeDescription
addraddressThe 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

NameTypeDescription
identifieruint256The uint256 identifier to convert

Returns

NameTypeDescription
addraddressThe 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

NameTypeDescription
identifieruint256The uint256 identifier to check and convert

Returns

NameTypeDescription
addraddressValidates and casted Ethereum address.

Errors

InvalidAddress

The input isn’t safely coerced to an address

error InvalidAddress();