Skip to content

Instantly share code, notes, and snippets.

@vrypan
Created February 8, 2025 11:56
Show Gist options
  • Save vrypan/14665de71d93003a77f59e0ec3ab3590 to your computer and use it in GitHub Desktop.
Save vrypan/14665de71d93003a77f59e0ec3ab3590 to your computer and use it in GitHub Desktop.
Decode SignedKeyRequest payload (Farcaster protocol)
package fctools
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/mitchellh/mapstructure"
)
type SignedKeyRequestMetadata struct {
RequestFid *big.Int
RequestSigner common.Address
Signature []byte
Deadline *big.Int
}
func (skr *SignedKeyRequestMetadata) FromPayload(data []byte) error {
arguments, _ := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
{
Name: "requestFid",
Type: "uint256",
},
{
Name: "requestSigner",
Type: "address",
},
{
Name: "signature",
Type: "bytes",
},
{
Name: "deadline",
Type: "uint256",
},
})
argumentsTuple := abi.Arguments{
{
Type: arguments,
},
}
decoded, err := argumentsTuple.Unpack(data)
if err != nil {
return fmt.Errorf("Error unpacking data: %w", err)
}
if err := mapstructure.Decode(decoded[0], skr); err != nil {
return fmt.Errorf("Error converting decode[0] to SignedKeyRequestMetadata. %w\n", err)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment