// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; interface IIdentityRegistry { function register(string memory agentURI) external returns (uint256 agentId); function transferFrom(address from, address to, uint256 tokenId) external; } /// Registers an ERC-8004 agent for someone else, so the agent's owner needs no gas. The registry mints a new id to /// whoever calls it, so this contract takes the id and passes it on to `owner` in the same transaction. /// /// Only Fiber's relayer may call it. The first version let anyone call, and within two minutes of its first use some /// 200 wallets had each replayed that call, minting copies of the same agent. A copy sent by anyone else now reverts. /// It keeps nothing between calls and has no owner; a new relayer means a new desk. contract FiberDesk { IIdentityRegistry public immutable registry; address public immutable relayer; event RegisteredFor(address indexed owner, uint256 indexed agentId, string agentURI); error NotRelayer(); error NotAMint(); constructor(IIdentityRegistry registry_, address relayer_) { registry = registry_; relayer = relayer_; } function registerFor(address owner, string calldata agentURI) external returns (uint256 agentId) { if (msg.sender != relayer) revert NotRelayer(); agentId = registry.register(agentURI); // The transfer clears the id's `agentWallet` (the registry set it to this contract at the mint), so the new // owner starts with none and sets their own. registry.transferFrom(address(this), owner, agentId); emit RegisteredFor(owner, agentId, agentURI); } /// Accepts only the registry's own mint to this contract, made by this contract. Nothing else can be sent here. function onERC721Received(address operator, address from, uint256, bytes calldata) external view returns (bytes4) { if (msg.sender != address(registry) || operator != address(this) || from != address(0)) revert NotAMint(); return this.onERC721Received.selector; } }