farcasterxyz / fname-registry

27 stars 19 forks source link

Missing username on warpcast after successful registration #130

Closed pedropregueiro closed 11 months ago

pedropregueiro commented 11 months ago

I see a few users who registered new usernames via farcord, but they never show up on Warpcast. Instead, the fid is shown.

Screenshot 2023-10-19 at 19 11 23

However the registration went through successfully, their username comes up in Neynar apis, and even warpcast redirects username links correctly (e.g. https://warpcast.com/prego)

Here are 2 examples:

And some sample code using wagmi/viem for wallet account:

const EIP_712_USERNAME_DOMAIN = {
  name: "Farcaster name verification",
  version: "1",
  chainId: 1,
  verifyingContract: "0xe3be01d99baa8db9905b33a3ca391238234b79d1",
};

export const EIP_712_USERNAME_PROOF = [
  { name: "name", type: "string" },
  { name: "timestamp", type: "uint256" },
  { name: "owner", type: "address" },
];

const proofTimestamp = Math.floor(Date.now() / 1000);
const usernameProofClaim = {
  owner: address,  // connected wallet (via wagmi)
  name: usernameUpdateValue,  // new username
  timestamp: BigInt(proofTimestamp),
};

const signature = await signTypedData({
  domain: EIP_712_USERNAME_DOMAIN,
  types: { UserNameProof: EIP_712_USERNAME_PROOF },
  primaryType: "UserNameProof",
  message: usernameProofClaim,
});

const response = await fetch(
 "https://fnames.farcaster.xyz/transfers",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: usernameUpdateValue,
      from: 0,
      to: Number(fid),
      fid: Number(fid),
      owner: accountAddress,
      timestamp: proofTimestamp,
      signature: signature,
    }),
  }
);

const data = await response.json();

Am I missing any steps here?

I also noticed that the hub's GetUserDataByFid response is not sending back the event with type 6 with username, which makes me think either the registry is not sending the events to the hub OR I need to send them myself 🤷

sanjayprabhu commented 11 months ago

The registry does not send these events by itself, they have to come from the user. I checked the hubs, and they've correctly picked up the proofs for both these users: e.g.

hub> res = await rpcClient.getUserNameProofsByFid({fid: 189922})
Ok { value: { proofs: [ [Object] ] } }
34.125.44.148:2283 hub> res.value.proofs[0].name.toString()
'flotski'

See example here:

https://github.com/farcasterxyz/hub-monorepo/blob/main/packages/hub-nodejs/examples/write-data/index.ts#L302-L312

pedropregueiro commented 11 months ago

Oh, there was no mention of this in the docs: https://docs.farcaster.xyz/protocol/fnames.html. Could be good to add something there for clients handling fresh registrations.

Curious, what will happen if a user tries to set the username via hub and there are no proofs there yet?

Also, I transferred one of the accounts with error to a different wallet this am, before submitting the user data change to the hub, so now I have a username proof for 189276 but from the wrong wallet. Any way to sort this one out without moving the fid back to that wallet or waiting ~28 days?

sanjayprabhu commented 11 months ago

Good point. I'll update the docs.

Curious, what will happen if a user tries to set the username via hub and there are no proofs there yet?

The hub will not accept the message. Validation fails.

Also, I transferred one of the accounts with error to a different wallet this am, before submitting the user data change to the hub, so now I have a username proof for 189276 but from the wrong wallet. Any way to sort this one out without moving the fid back to that wallet or waiting ~28 days?

Sorry what do you mean? Did you transfer the fid to a different wallet? Or the name to a different fid?

Transferring fids to other wallets does not impact existing fname proofs (until new owner submits a more recent proof). Transferring name to a different fid would mean that you either have to set the username on the hub using the new fid, or register a new name to the old fid.

sanjayprabhu commented 11 months ago

Oh, there was no mention of this in the docs: https://docs.farcaster.xyz/protocol/fnames.html. Could be good to add something there for clients handling fresh registrations.

Updated fname docs https://github.com/farcasterxyz/www/pull/71

pedropregueiro commented 11 months ago

Sorry what do you mean? Did you transfer the fid to a different wallet? Or the name to a different fid?

I first had that fid on wallet A and used the fname registry to create proof and register a new username X. However, I didn't submit the new username to the hub at the time. In the meantime, I transferred that same fid to wallet B.

Now, if I query the fname registry, the username X is still attached to wallet A, and the proof submitted was also created from wallet A. I'd assume I wouldn't be able to set the username in the hub from wallet B.

Fwiw I tested this now and was able to submit a set username message to the hub signed by wallet B's signer. Not sure if expected behaviour. If so, then ignore me.