Infernet
SDK
Reference
EIP712Coordinator

EIP712Coordinator

Git Source (opens in a new tab)

Inherits: EIP712, Coordinator

Coordinator enhanced with ability to created subscriptions via off-chain EIP-712 signature

Allows creating a subscription on behalf of a contract via delegatee EOA signature

Allows nodes to atomically create subscriptions and deliver compute responses

State Variables

EIP712_VERSION

EIP-712 signing domain major version

string public constant EIP712_VERSION = "1";

EIP712_NAME

EIP-712 signing domain name

string public constant EIP712_NAME = "InfernetCoordinator";

EIP712_SUBSCRIPTION_TYPEHASH

EIP-712 struct(Subscription) typeHash

bytes32 private constant EIP712_SUBSCRIPTION_TYPEHASH = keccak256(
    "Subscription(address owner,uint32 activeAt,uint32 period,uint32 frequency,uint16 redundancy,bytes32 containerId,bool lazy,address verifier,uint256 paymentAmount,address paymentToken,address wallet)"
);

EIP712_DELEGATE_SUBSCRIPTION_TYPEHASH

EIP-712 struct(DelegateSubscription) typeHash

struct(DelegateSubscription) == { uint32 nonce, uint32 expiry, Subscription sub }

The nonce represents the nonce of the subscribing contract (sub-owner); prevents signature replay

The expiry is when the delegated subscription signature expires and can no longer be used

bytes32 private constant EIP712_DELEGATE_SUBSCRIPTION_TYPEHASH = keccak256(
    "DelegateSubscription(uint32 nonce,uint32 expiry,Subscription sub)Subscription(address owner,uint32 activeAt,uint32 period,uint32 frequency,uint16 redundancy,bytes32 containerId,bool lazy,address verifier,uint256 paymentAmount,address paymentToken,address wallet)"
);

maxSubscriberNonce

Subscribing contract => maximum seen nonce

The nonce is a uint32 size(4.2B) which would take > 100 years of incrementing nonce per second to overflow

mapping(address => uint32) public maxSubscriberNonce;

delegateCreatedIds

hash(subscribing contract, nonce) => subscriptionId

Allows lookup between a delegated subscription creation (unique(subscriber, nonce)) and subscriptionId

mapping(bytes32 => uint32) public delegateCreatedIds;

Functions

constructor

Initializes new EIP712Coordinator

constructor(Registry registry) Coordinator(registry);

Parameters

NameTypeDescription
registryRegistryregistry contract

_domainNameAndVersion

Overrides Solady.EIP712._domainNameAndVersion to return EIP712-compatible domain name, version

function _domainNameAndVersion() internal pure override returns (string memory, string memory);

_domainNameAndVersionMayChange

Overrides Solady.EIP712._domainNameAndVersionMayChange to always return false since the domain params are not updateable

function _domainNameAndVersionMayChange() internal pure override returns (bool);

createSubscriptionDelegatee

Allows a delegatee to create a subscription on behalf of a subscribing contract (sub.owner)

Unlike Coordinator.createSubscription(), offers maximum flexibility to set subscription parameters

function createSubscriptionDelegatee(
    uint32 nonce,
    uint32 expiry,
    Subscription calldata sub,
    uint8 v,
    bytes32 r,
    bytes32 s
) public returns (uint32);

Parameters

NameTypeDescription
nonceuint32subscribing contract nonce (included in signature)
expiryuint32delegated subscription signature expiry (included in signature)
subSubscriptionsubscription to create
vuint8ECDSA recovery id
rbytes32ECDSA signature output (r)
sbytes32ECDSA signature output (s)

Returns

NameTypeDescription
<none>uint32subscription ID (existing or newly-created)

deliverComputeDelegatee

Allows nodes to (1) atomically create or collect subscription via signed EIP-712 message, (2) deliver container compute responses for created or collected subscription

function deliverComputeDelegatee(
    uint32 nonce,
    uint32 expiry,
    Subscription calldata sub,
    uint8 v,
    bytes32 r,
    bytes32 s,
    uint32 deliveryInterval,
    bytes calldata input,
    bytes calldata output,
    bytes calldata proof,
    address nodeWallet
) external;

Parameters

NameTypeDescription
nonceuint32subscribing contract nonce (included in signature)
expiryuint32delegated subscription signature expiry (included in signature)
subSubscriptionsubscription to create
vuint8ECDSA recovery id
rbytes32ECDSA signature output (r)
sbytes32ECDSA signature output (s)
deliveryIntervaluint32subscription interval
inputbytesoptional off-chain input recorded by Infernet node (empty, hashed input, processed input, or both)
outputbytesoptional off-chain container output (empty, hashed output, processed output, both, or fallback: all encodeable data)
proofbytesoptional container execution proof (or arbitrary metadata)
nodeWalletaddressnode wallet (used to receive payments, and put up escrow/slashing funds); msg.sender must be authorized spender of wallet

Errors

SignerMismatch

Thrown by createSubscriptionDelegatee() if subscription signature does not match contract delegatee

4-byte signature: 0x10c74b03

error SignerMismatch();

SignatureExpired

Thrown by createSubscriptionDelegatee() if signature for delegated subscription has expired

4-byte signature: 0x0819bdcd

error SignatureExpired();