Skip to content

utils

NamespaceDescription
createPieceUrl-
createPieceUrlPDP-
InterfaceDescription
MetadataDataSetInternal-
MetadataPieceInternal-
Type AliasDescription
ClaimTokenResponse-
ClaimTokenResponseError-
ClaimTokensOptions-
FormatUnitsOptions-
MetadataArrayThe metadata array is a tuple of two arrays: the keys and the values. Return type from the getAllDataSetMetadata function.
MetadataEntry-
MetadataObject-
StringErrorTypeFOC contracts errors types
VariableDescription
CDN_FIXED_LOCKUPCDN fixed lockup amounts charged at dataset creation time. These are one-time lockups for CDN egress and cache miss egress rails.
DEFAULT_BUFFER_EPOCHSDefault safety margin in epochs when calculating deposit amounts. Accounts for epoch drift between balance check and on-chain execution.
DEFAULT_RUNWAY_EPOCHSDefault extra runway in epochs beyond the required lockup. 0n means no additional runway beyond the lockup period.
LOCKUP_PERIOD-
METADATA_LIMITS-
PDP_OFFERING_KEYSCapability keys that are decoded into typed PDPOffering fields. (must match ServiceProviderRegistry.sol REQUIRED_PDP_KEYS)
PDP_OFFERING_KEYS_SETSet of PDP offering keys.
PDPOfferingSchemaZod schema for PDP offering
RETRY_CONSTANTS-
SERVICE_PROVIDER_REGISTRYLimits mirrored from ServiceProviderRegistry.sol. Sync with VERSION in that contract (currently 1.1.0) when upgrading.
SIZE_CONSTANTSData size constants
STRING_ERRORSFOC contracts errors strings
TIME_CONSTANTSTime and size constants
USDFC_SYBIL_FEEUSDFC sybil fee charged on new dataset creation. Extracted from client funds into the payments auction pool to prevent state-growth spam. Matches PDPVerifier.USDFC_SYBIL_FEE (immutable, only changes with contract upgrade).
zAddress-
zAddressLoose-
zHex-
zNumberToBigInt-
zPieceCid-
zPieceCidString-
zStringToCid-
FunctionDescription
asReadableStreamConvert AsyncIterable or ReadableStream to ReadableStream
asyncIterableToReadableStreamConvert AsyncIterable to ReadableStream with broad browser compatibility. Provides fallback for environments where ReadableStream.from() is not available.
calculateLastProofDateCalculate when the last proof should have been submitted based on current time
capabilitiesListToObjectConvert capability arrays to object map
claimTokens-
clientFromTransportCreate a Viem public client from a transport configuration
createPieceUrlCreate a piece URL for the CDN or PDP API
createPieceUrlPDPCreate a piece URL for the PDP API
datasetMetadataObjectToEntryConvert a dataset metadata object to an array of metadata entries to be signed.
dateToEpochConvert a JavaScript Date to a Filecoin epoch
decodeAddressCapabilityMatches the behavior of address(uint160(BigEndian.decode(values[i])))
decodePDPCapabilitiesDecode PDP capabilities from keys/values arrays into a PDPOffering object. Based on Curio’s capabilitiesToOffering function.
decodePDPError-
decodePDPOfferingDecode the PDP offering from the provider.
encodePDPCapabilitiesEncode a PDPOffering plus optional user-supplied extras into the (keys[], values[]) tuple consumed by registerProvider / addProduct / updateProduct on ServiceProviderRegistry.
epochsToDaysConvert a number of epochs to whole days (floor division).
epochsToHoursConvert a number of epochs to whole hours (floor division).
epochToDateConvert a Filecoin epoch to a JavaScript Date
fallbackRandIndex-
fallbackRandU256-
formatBalance-
formatFraction-
formatUnits-
isAsyncIterableType guard to check if a value is an AsyncIterable
isProviderExistsRevertCheck whether the given error is a revert emitted by the ServiceProviderRegistry.providerExists modifier (i.e. the provider ID is out of range or maps to an unoccupied storage slot).
isReadableStreamType guard to check if a value is a ReadableStream
isUint8ArrayCheck if value is Uint8Array
isViemErrorCheck if the error is a viem error
metadataArrayToObject-
parseUnitsParse a value to a bigint.
pieceMetadataObjectToEntryConvert a dataset metadata object to an array of metadata entries to be signed.
randIndexProvides a random index into an array of supplied length (0 <= index < length)
randU256-
stringErrorEqualsCheck if the error message equals the expected string
supportsStreamingFetchBodyDetect whether the current environment supports ReadableStream as a fetch request body. Firefox stringifies the stream to “[object ReadableStream]” instead of consuming it, and Safari silently ignores the stream body and the duplex option. This check catches both: a browser that stringifies will set Content-Type to text/plain (string body), and one that ignores duplex will fail the duplexAccessed gate. The try/catch handles any future browser that throws on the Request constructor.
timeUntilEpochCalculate the time until a future epoch
transportFromTransportConfigCreate a Viem public client from a transport configuration
uint8ArrayToAsyncIterableConvert Uint8Array to async iterable with optimal chunk size.