SparseCalldataSegmentLib
Title: SparseCalldataSegmentLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ERC-6900 reference implementation (https://github.com/erc6900/reference-implementation)
Reads an ERC-6900 sparse-segment signature/authorization blob: a sequence of
[uint8 index][uint32 length][length bytes body] per-hook segments, in strictly increasing index
order (a hook with no data is OMITTED, never zero-length), terminated by a final
[0xFF][raw bytes …] segment (no length prefix) carrying the validation function's own signature.
Pure calldata reader, re-implemented FRESH from the ERC-6900 reference semantics
distribute per-hook signature data.
Functions
getIndex
The leading index byte of source (which hook/segment it belongs to, or 0xFF for the final).
function getIndex(bytes calldata source) internal pure returns (uint8);Parameters
| Name | Type | Description |
|---|---|---|
| source | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint8 |
getNextSegment
Splits off the leading length-prefixed segment body, returning it and the remaining blob.
function getNextSegment(bytes calldata source)
internal
pure
returns (bytes calldata body, bytes calldata remainder);Parameters
| Name | Type | Description |
|---|---|---|
| source | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| body | bytes | |
| remainder | bytes |
advanceSegmentIfAtIndex
If the leading segment's index equals index, returns its body + the remaining blob (advancing the
cursor); if it is greater, returns an empty body and the unchanged blob (this index has no data);
if it is smaller, reverts SegmentOutOfOrder.
function advanceSegmentIfAtIndex(bytes calldata source, uint8 index)
internal
pure
returns (bytes calldata body, bytes calldata remainder);Parameters
| Name | Type | Description |
|---|---|---|
| source | bytes | |
| index | uint8 |
Returns
| Name | Type | Description |
|---|---|---|
| body | bytes | |
| remainder | bytes |
getFinalSegment
The final validation-function segment: requires the reserved 0xFF index marker, returns the rest.
function getFinalSegment(bytes calldata source) internal pure returns (bytes calldata);Parameters
| Name | Type | Description |
|---|---|---|
| source | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes |