What is a Signed Key Request? - When a user adds a key to their account (the primary fid), it must include a signature from the person that requested it (the request fid). This enables anyone to identify who requested a specific key. Typically, the primary fid is the end user and the requesting fid is an app the user wishes to connect to.
Read
encodeMetadata
Convert aSignedKeyRequestMetadata struct into bytes to pass into contract functions like add, register.
SignedKeyRequestMetadata struct
TheSignedKeyRequestMetadata struct contains data to validate authenticity of a Signed Key Request: requesting fid, the requesting fid owner, and an EIP-712 SignedKeyRequest signature.
See below for code examples that demonstrate two methods of generating encoded
SignedKeyRequestMetadata — using the @farcaster/hub-web library to sign and encode in a single step, or using Viem to sign and encode separately.
[@farcaster/hub-web]
[Viem]
[signature.ts]
[helpers.ts]
[signer.ts]
validate
Validate an encodedSignedKeyRequestMetadata. The KeyRegistry calls this function internally when a user adds a key to validate the Signed Key Request. If you are creating keys on behalf of users, you can call this function yourself to validate the Signed Key Request created by your app.
SignedKeyRequest signature
TheSignedKeyRequest message is an EIP-712 typed signature signed by the requesting fid owner in the following format:
SignedKeyRequest(uint256 requestFid,bytes key,uint256 deadline)
Why sign metadata? - The
SignedKeyRequest signature proves that the requesting fid asked the primary fid to authorize a key pair. For example, when an app asks a user to add a new key, the app creates a Signed Key Request proving that it made the request and the KeyRegistry emits it in an onchain event. This allows anyone to attribute a signer to the specific person who requested it, which is useful for a wide range of things from knowing which apps are being used to filtering content based on the applications that generated them.[@farcaster/hub-web]
[Viem]
[helpers.ts]
[signer.ts]
Source
SignedKeyRequestValidator.sol