SiweParser

Git Source

Call parseSiweMsg() and provide the EIP-4361 SIWE message. The parser will generate the ParsedSiweMessage struct which you can then use to extract the authentication information in your on-chain contract.

Functions

_hexStringToAddress

Convert string containing hex address without 0x prefix to solidity address object.

function _hexStringToAddress(bytes memory s) internal pure returns (address);

_fromHexChar

function _fromHexChar(uint8 c) internal pure returns (uint8);

_substr

Substring.

function _substr(bytes memory str, uint256 startIndex, uint256 endIndex) internal pure returns (bytes memory);

_parseUint

String to Uint using decimal format. No error handling.

function _parseUint(bytes memory b) internal pure returns (uint256);

_parseField

Parse "NAME: VALUE" in str starting at index i and ending at \n or end of bytes.

function _parseField(bytes calldata str, string memory name, uint256 i) internal pure returns (bytes memory, uint256);

Returns

NameTypeDescription
<none>bytesVALUE and new i, if NAME matched; otherwise empty value and old i.
<none>uint256

_parseArray

Parse bullets, one per line in str starting at i.

function _parseArray(bytes calldata str, uint256 i) internal pure returns (bytes[] memory, uint256);

Returns

NameTypeDescription
<none>bytes[]Array of parsed values and a new i.
<none>uint256

parseSiweMsg

Parse SIWE message.

function parseSiweMsg(bytes calldata siweMsg) internal pure returns (ParsedSiweMessage memory);

Returns

NameTypeDescription
<none>ParsedSiweMessageParsedSiweMessage struct with populated fields from the message.

timestampFromIso

Parse RFC 3339 (ISO 8601) string to timestamp.

function timestampFromIso(bytes memory str) internal pure returns (uint256);

Errors

InvalidAddressLength

Invalid length of the hex-encoded address

error InvalidAddressLength();

InvalidNonce

Invalid length of the nonce

error InvalidNonce();