Skip to content

Commit

Permalink
Fname register signature fix (#2384)
Browse files Browse the repository at this point in the history
## Why is this change needed?

There was a bug due to which fname registration was failing on example
package `hello-world`. The PR fixes this.


<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces a new function for creating user name proof claims
and updates the way user name proof signatures are generated and
processed in the `registerFname` function. It also adds a utility
function for converting bytes to hex.

### Detailed summary
- Added `makeUserNameProofClaim` function import.
- Introduced `bytesToHex` function import.
- Updated `registerFname` to use `await signer.signUserNameProofClaim`
with `makeUserNameProofClaim`.
- Changed signature processing to use `bytesToHex` for
`userNameProofSignature.value`.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
prtk418 authored Nov 7, 2024
1 parent 3ae52bc commit 2cc08d9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/hub-nodejs/examples/hello-world/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
idRegistryABI,
ViemLocalEip712Signer,
makeCastRemove,
makeUserNameProofClaim,
} from "@farcaster/hub-nodejs";
import { mnemonicToAccount, toAccount } from "viem/accounts";
import {
Expand All @@ -29,6 +30,7 @@ import {
publicActions,
toHex,
zeroAddress,
bytesToHex,
} from "viem";
import { optimism } from "viem/chains";
import { ed25519 } from "@noble/curves/ed25519";
Expand Down Expand Up @@ -182,11 +184,13 @@ const registerFname = async (fid: number) => {
const timestamp = Math.floor(Date.now() / 1000);
const localAccount = toAccount(account);
const signer = new ViemLocalEip712Signer(localAccount as LocalAccount<string>);
const userNameProofSignature = signer.signUserNameProofClaim({
name: fname,
timestamp: BigInt(timestamp),
owner: account.address,
});
const userNameProofSignature = await signer.signUserNameProofClaim(
makeUserNameProofClaim({
name: fname,
timestamp: timestamp,
owner: account.address,
})
);

console.log(`Registering fname: ${fname} to fid: ${fid}`);
try {
Expand All @@ -197,7 +201,7 @@ const registerFname = async (fid: number) => {
fid: fid, // Fid making the request (must match from or to)
owner: account.address, // Custody address of fid making the request
timestamp: timestamp, // Current timestamp in seconds
signature: userNameProofSignature, // EIP-712 signature signed by the current custody address of the fid
signature: bytesToHex(userNameProofSignature.value), // EIP-712 signature signed by the current custody address of the fid
});
return fname;
} catch (e) {
Expand Down

0 comments on commit 2cc08d9

Please sign in to comment.