Verified contractExactMIT
SessionMessageParser
Address0x27dbe57df5dca071aba7e7dddd1a988a8c8cd45f
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.30
- Same code
1 more contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 1 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,388,996
- Creation transaction
- 0x98a195ebfe…c1c8b6761f
127 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/SessionMessageParser.solmain10.99 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/MessageLibBase.sol528 B
- @layerzerolabs/lz-evm-messagelib-v2/contracts/SendLibBase.sol10.51 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/IExecutor.sol1.4 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/IExecutorFeeLib.sol1.66 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/ILayerZeroExecutor.sol1.35 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/ILayerZeroReadExecutor.sol878 B
- @layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/ILayerZeroTreasury.sol442 B
- @layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/IWorker.sol985 B
- @layerzerolabs/lz-evm-messagelib-v2/contracts/libs/ExecutorOptions.sol4.33 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/libs/SafeCall.sol4.64 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/DVNOptions.sol7.32 KB
- @layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/UlnOptions.sol8.48 KB
- @layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol1.53 KB
- @layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppCore.sol3.36 KB
- @layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppReceiver.sol5.41 KB
- @layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppSender.sol5.63 KB
- @layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppCore.sol1.86 KB
- @layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppReceiver.sol1.08 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/EndpointV2ViewUpgradeable.sol3.44 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/MessagingContext.sol1.48 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol2.59 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol519 B
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLib.sol805 B
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLibManager.sol2.76 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingChannel.sol1.54 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingComposer.sol1.03 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessagingContext.sol239 B
- @layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ISendLib.sol923 B
- @layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol1.47 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol1.78 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/libs/Errors.sol1.26 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol460 B
- @layerzerolabs/lz-evm-protocol-v2/contracts/libs/Transfer.sol1.12 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol751 B
- @layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/ExecutorOptions.sol3.56 KB
- @layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/PacketV1Codec.sol3.67 KB
- @layerzerolabs/oapp-evm/contracts/oapp/OAppCore.sol3.36 KB
- @layerzerolabs/oapp-evm/contracts/oapp/OAppReceiver.sol5.41 KB
- @layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol1.86 KB
- @layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppReceiver.sol1.08 KB
- @layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol9.28 KB
- @layerzerolabs/oft-evm/contracts/libs/OFTMsgCodec.sol2.91 KB
- @layerzerolabs/test-devtools-evm-hardhat/contracts/mocks/EndpointV2Mock.sol27.37 KB
- @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol6.64 KB
- @openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol9.38 KB
- @openzeppelin/contracts/access/Ownable.sol2.62 KB
- @openzeppelin/contracts/interfaces/IERC1271.sol666 B
- @openzeppelin/contracts/interfaces/IERC5267.sol738 B
- @openzeppelin/contracts/security/ReentrancyGuard.sol3.13 KB
- @openzeppelin/contracts/token/ERC20/ERC20.sol12.85 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.74 KB
- @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol683 B
- @openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol3.8 KB
- @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol6.94 KB
- @openzeppelin/contracts/token/ERC721/ERC721.sol17.01 KB
- @openzeppelin/contracts/token/ERC721/IERC721.sol4.88 KB
- @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol987 B
- @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol6.81 KB
- @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol1.02 KB
- @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol761 B
- @openzeppelin/contracts/utils/Address.sol9.36 KB
- @openzeppelin/contracts/utils/Base64.sol3.89 KB
- @openzeppelin/contracts/utils/Context.sol962 B
- @openzeppelin/contracts/utils/ShortStrings.sol4.29 KB
- @openzeppelin/contracts/utils/StorageSlot.sol4.11 KB
- @openzeppelin/contracts/utils/Strings.sol2.78 KB
- @openzeppelin/contracts/utils/cryptography/ECDSA.sol9.13 KB
- @openzeppelin/contracts/utils/cryptography/EIP712.sol5.66 KB
- @openzeppelin/contracts/utils/cryptography/MerkleProof.sol9.62 KB
- @openzeppelin/contracts/utils/cryptography/draft-EIP712.sol231 B
- @openzeppelin/contracts/utils/introspection/ERC165.sol987 B
- @openzeppelin/contracts/utils/introspection/IERC165.sol853 B
- @openzeppelin/contracts/utils/math/Math.sol12.79 KB
- @openzeppelin/contracts/utils/math/SafeCast.sol35.08 KB
- @openzeppelin/contracts/utils/math/SignedMath.sol1.26 KB
- @openzeppelin/contracts/utils/structs/EnumerableSet.sol12.96 KB
- contracts/CawActions.sol93.41 KB
- contracts/CawActionsArchive.sol39.68 KB
- contracts/CawActionsERC1271.sol13.13 KB
- contracts/CawBuyAndBurn.sol4.09 KB
- contracts/CawCapOracle.sol23.55 KB
- contracts/CawChallengeRelay.sol11.05 KB
- contracts/CawFontDataA.sol35.4 KB
- contracts/CawFontDataB.sol23.93 KB
- contracts/CawL1PriceReader.sol5.52 KB
- contracts/CawNetworkManager.sol36.56 KB
- contracts/CawProfile.sol59.58 KB
- contracts/CawProfileLedger.sol61.35 KB
- contracts/CawProfileLens.sol5.15 KB
- contracts/CawProfileMarketplace.sol36.94 KB
- contracts/CawProfileMinter.sol46.75 KB
- contracts/CawProfileQuoter.sol18.65 KB
- contracts/CawProfileURI.sol23.24 KB
- contracts/CivicKycVerifier.sol1.01 KB
- contracts/ISwapRouter.sol5.12 KB
- contracts/IZKActionsVerifier.sol565 B
- contracts/MintableCaw.sol951 B
- contracts/MockLayerZeroEndpoint.sol398 B
- contracts/OnlyOnce.sol474 B
- contracts/PathwayExpander.sol16.37 KB
- contracts/SigVerification.sol4.18 KB
- contracts/SmartEOA.sol54.16 KB
- contracts/examples/CawActionVerifier.sol5.98 KB
- contracts/examples/CawMultisigProfile.sol6.22 KB
- contracts/examples/CawTipResponder.sol6.45 KB
- contracts/interfaces/ICawActions.sol2.08 KB
- contracts/interfaces/ICawCapOracle.sol1.06 KB
- contracts/interfaces/IMint.sol2.31 KB
- contracts/interfaces/ISmartEOA.sol1.78 KB
- contracts/interfaces/ISpend.sol578 B
- contracts/interfaces/IUniswapV2Pair.sol599 B
- contracts/mocks/FeeRecipientMock.sol497 B
- contracts/mocks/LzReceiveHelper.sol1.16 KB
- contracts/mocks/MockContractOwner.sol1.87 KB
- contracts/mocks/MockLzEndpointSimple.sol881 B
- contracts/mocks/MockOAppOwnable.sol576 B
- contracts/mocks/MockSwapRouter.sol1.32 KB
- contracts/sp1-vendor/Groth16Verifier.sol26.77 KB
- contracts/sp1-vendor/ISP1Verifier.sol955 B
- contracts/sp1-vendor/SP1VerifierGroth16.sol3.24 KB
- contracts/test-helpers/CawActionsDigestExposer.sol3.04 KB
- contracts/test-helpers/MockCawActionsCapTarget.sol941 B
- contracts/test-helpers/MockSP1Verifier.sol1.5 KB
- contracts/test/GasMeter.sol1.49 KB
- contracts/test/RevertingBidder.sol728 B
- solidity-bytes-utils/contracts/BytesLib.sol19.44 KB
contracts/SessionMessageParser.sol
// contracts/SessionMessageParser.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title SessionMessageParser
/// @notice External library for parsing the human-readable personal_sign session
/// message used by `registerSessionPersonal` in CawProfileLedger.
/// Extracted to keep CawProfileLedger under the EIP-170 24,576-byte
/// deployed-bytecode limit. `parseSessionMessage` and `uint2str` are
/// `external` so they live in the library's own deployed bytecode —
/// the consuming contract only carries a small delegatecall stub
/// (~50 bytes per linked function).
///
/// Message format (13 newline-separated lines):
/// Enable Quick Sign
/// ------------------
/// Spend limit:
/// 5M CAW
/// (blank)
/// Tip per action:
/// 1000 CAW
/// (blank)
/// Expires:
/// 25 April 2026 00:00:00 UTC
/// (blank)
/// CAW Key:
/// 0x742d...3e
library SessionMessageParser {
error BadParse();
error BadDate();
/// @notice Parse the multi-line session message.
/// @return spendLimit Parsed CAW spend limit (whole tokens with M/K/B suffix).
/// @return perActionTipRate Parsed tip-rate in whole CAW tokens.
/// @return expiry Unix timestamp parsed from the human-readable date line.
/// @return sessionKey Session key address parsed from the hex line.
function parseSessionMessage(bytes memory msg_)
external pure returns (uint256 spendLimit, uint64 perActionTipRate, uint64 expiry, address sessionKey)
{
bytes[] memory lines = _splitLines(msg_);
if (lines.length != 13) revert BadParse();
// Line 0: "Enable Quick Sign"
if (keccak256(lines[0]) != keccak256("Enable Quick Sign")) revert BadParse();
// Line 1: "------------------" (decorative, skip)
// Line 2: "Spend limit:" (label, skip)
// Line 3: "5M CAW"
spendLimit = _parseSpendLimitValue(lines[3]);
// Line 4: "" (blank, skip)
// Line 5: "Tip per action:" (label, skip)
// Line 6: "1000 CAW"
perActionTipRate = _parseTipRateValue(lines[6]);
// Line 7: "" (blank, skip)
// Line 8: "Expires:" (label, skip)
// Line 9: "25 April 2026 00:00:00 UTC"
expiry = _parseExpiryValue(lines[9]);
// Line 10: "" (blank, skip)
// Line 11: "CAW Key:" (label, skip)
// Line 12: "0x..."
sessionKey = _parseAddressLine(lines[12]);
}
/// @notice Convert a uint256 to its decimal ASCII bytes representation.
/// Used by `registerSessionPersonal` to build the EIP-191 prefix.
function uint2str(uint256 value) external pure returns (bytes memory) {
if (value == 0) return "0";
uint256 temp = value;
uint256 digits;
while (temp != 0) { digits++; temp /= 10; }
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits--;
buffer[digits] = bytes1(uint8(48 + value % 10));
value /= 10;
}
return buffer;
}
// -------------------------------------------------------------------------
// Internal helpers (only called within parseSessionMessage chain)
// -------------------------------------------------------------------------
/// @dev Parse a tip-rate line like "1000 CAW", "1M CAW", "0 CAW", or with a
/// trailing human-readable note "1M CAW (~$0.0010)" → uint64 whole tokens.
/// Accepts the same M/K/B magnitude suffix as the spend-limit line so the
/// message can stay short, and IGNORES an optional " (...)" note after
/// "CAW" (the FE shows a USD estimate there; it does not affect the value).
/// Grammar: <digits>[M|K|B]<space>CAW[<space>(...)] . 0 (opt-out) allowed.
function _parseTipRateValue(bytes memory line) internal pure returns (uint64) {
if (line.length < 5) revert BadParse();
uint256 number = 0;
uint256 i = 0;
while (i < line.length && line[i] >= 0x30 && line[i] <= 0x39) {
number = number * 10 + (uint8(line[i]) - 0x30);
i++;
}
// Optional magnitude suffix (M/K/B), mirroring _parseSpendLimitValue. A 0
// value never carries a suffix ("0 CAW"), so this only fires for number > 0.
if (i < line.length && (line[i] == 'M' || line[i] == 'K' || line[i] == 'B')) {
if (line[i] == 'M') number = number * 1_000_000;
else if (line[i] == 'K') number = number * 1_000;
else number = number * 1_000_000_000;
i++;
}
if (number > type(uint64).max) revert BadParse();
// Require "<space>CAW" at position i.
if (!(i + 3 < line.length && line[i] == 0x20 &&
line[i+1] == 'C' && line[i+2] == 'A' && line[i+3] == 'W')) revert BadParse();
uint256 end = i + 4; // first index after "CAW"
// Accept either end-of-line, or a trailing note " (...)" with '(' right after
// the space and ')' as the final byte. The note is decorative and ignored.
if (end != line.length) {
if (!(
end + 2 < line.length &&
line[end] == 0x20 && line[end+1] == '(' &&
line[line.length - 1] == ')'
)) revert BadParse();
}
return uint64(number);
}
function _splitLines(bytes memory data) internal pure returns (bytes[] memory) {
// Count newlines
uint256 count = 1;
for (uint256 i = 0; i < data.length; i++) {
if (data[i] == 0x0A) count++;
}
bytes[] memory lines = new bytes[](count);
uint256 lineIdx = 0;
uint256 start = 0;
for (uint256 i = 0; i < data.length; i++) {
if (data[i] == 0x0A) {
lines[lineIdx] = _slice(data, start, i);
lineIdx++;
start = i + 1;
}
}
lines[lineIdx] = _slice(data, start, data.length);
return lines;
}
function _slice(bytes memory data, uint256 from, uint256 to) internal pure returns (bytes memory) {
bytes memory result = new bytes(to - from);
for (uint256 i = from; i < to; i++) result[i - from] = data[i];
return result;
}
/// @dev Parse "5M CAW" → 5000000
function _parseSpendLimitValue(bytes memory line) internal pure returns (uint256) {
if (line.length < 5) revert BadParse();
uint256 number = 0;
uint256 i = 0;
while (i < line.length && line[i] >= 0x30 && line[i] <= 0x39) {
number = number * 10 + (uint8(line[i]) - 0x30);
i++;
}
if (number == 0) revert BadParse();
if (i >= line.length) revert BadParse();
if (line[i] == 'M') return number * 1_000_000;
if (line[i] == 'K') return number * 1_000;
if (line[i] == 'B') return number * 1_000_000_000;
revert BadParse();
}
/// @dev Parse "25 April 2026 00:00:00 UTC" → unix timestamp
function _parseExpiryValue(bytes memory line) internal pure returns (uint64) {
if (line.length <= 20) revert BadDate();
uint256 i = 0;
// Day (1-2 digits)
uint256 day = 0;
while (i < line.length && line[i] >= 0x30 && line[i] <= 0x39) {
day = day * 10 + (uint8(line[i]) - 0x30);
i++;
}
if (day < 1 || day > 31) revert BadDate();
i++; // skip space
// Month name
uint256 monthStart = i;
while (i < line.length && line[i] != 0x20) i++;
uint256 month = _parseMonth(_slice(line, monthStart, i));
i++; // skip space
// Year (4 digits)
uint256 year = 0;
for (uint256 j = 0; j < 4; j++) {
year = year * 10 + (uint8(line[i + j]) - 0x30);
}
i += 4;
i++; // skip space
// HH:MM:SS
uint256 hour = (uint8(line[i]) - 0x30) * 10 + (uint8(line[i+1]) - 0x30);
uint256 minute = (uint8(line[i+3]) - 0x30) * 10 + (uint8(line[i+4]) - 0x30);
uint256 second = (uint8(line[i+6]) - 0x30) * 10 + (uint8(line[i+7]) - 0x30);
// Validate ranges so silent rollover can't extend the user's intended
// expiry. Without these: "Feb 31" parses fine and rolls into March, or
// "30:99:99" parses and rolls into the next day + extra hours/minutes.
// Audit fix: L2 M-4 (range validation).
if (hour >= 24) revert BadDate();
if (minute >= 60) revert BadDate();
if (second >= 60) revert BadDate();
// Month-aware day bound. 28-day Feb default; +1 for leap years.
uint8[12] memory daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
if (_isLeapYear(year)) daysInMonth[1] = 29;
if (day > uint256(daysInMonth[month - 1])) revert BadDate();
// Sanity cap on year so the for-loop in _toUnixTimestamp can't be
// weaponized into a 30M-gas DoS (~10K iterations max from 1970).
if (year > 2200) revert BadDate();
return uint64(_toUnixTimestamp(year, month, day, hour, minute, second));
}
function _parseMonth(bytes memory m) internal pure returns (uint256) {
bytes32 h = keccak256(m);
if (h == keccak256("January")) return 1;
if (h == keccak256("February")) return 2;
if (h == keccak256("March")) return 3;
if (h == keccak256("April")) return 4;
if (h == keccak256("May")) return 5;
if (h == keccak256("June")) return 6;
if (h == keccak256("July")) return 7;
if (h == keccak256("August")) return 8;
if (h == keccak256("September")) return 9;
if (h == keccak256("October")) return 10;
if (h == keccak256("November")) return 11;
if (h == keccak256("December")) return 12;
revert BadParse();
}
/// @dev Convert date components to unix timestamp (UTC). Only valid for years >= 1970.
function _toUnixTimestamp(uint256 year, uint256 month, uint256 day, uint256 hour, uint256 minute, uint256 second) internal pure returns (uint256) {
if (year < 1970) revert BadDate();
uint256 timestamp = 0;
// Years
for (uint256 y = 1970; y < year; y++) {
timestamp += _isLeapYear(y) ? 366 days : 365 days;
}
// Months
uint8[12] memory daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
if (_isLeapYear(year)) daysInMonth[1] = 29;
for (uint256 m = 1; m < month; m++) {
timestamp += uint256(daysInMonth[m - 1]) * 1 days;
}
// Days, hours, minutes, seconds
timestamp += (day - 1) * 1 days + hour * 1 hours + minute * 1 minutes + second;
return timestamp;
}
function _isLeapYear(uint256 year) internal pure returns (bool) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
/// @dev Parse "0x742d...3e" → address
function _parseAddressLine(bytes memory line) internal pure returns (address) {
// "0x" + 40 hex chars = 42 bytes
if (line.length != 42) revert BadDate();
bytes memory hexStr = _slice(line, 2, 42);
return address(uint160(_hexToUint(hexStr)));
}
function _hexToUint(bytes memory hexStr) internal pure returns (uint256 result) {
for (uint256 i = 0; i < hexStr.length; i++) {
uint8 c = uint8(hexStr[i]);
uint8 val;
if (c >= 0x30 && c <= 0x39) val = c - 0x30;
else if (c >= 0x61 && c <= 0x66) val = c - 0x61 + 10;
else if (c >= 0x41 && c <= 0x46) val = c - 0x41 + 10;
else revert BadParse();
result = result * 16 + val;
}
}
}
Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 1,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.