Skip to content

Commit

Permalink
refactor: rename verification message (#1637)
Browse files Browse the repository at this point in the history
* feat: rename verification message to support additional protocols in the future

* chore: add changeset

* refactor: change signature for verification message
  • Loading branch information
Wazzymandias authored Jan 31, 2024
1 parent 80c8f7d commit fd9f9ff
Show file tree
Hide file tree
Showing 44 changed files with 622 additions and 389 deletions.
9 changes: 9 additions & 0 deletions .changeset/old-dolphins-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@farcaster/hub-nodejs": minor
"@farcaster/hub-web": minor
"@farcaster/replicator": minor
"@farcaster/core": minor
"@farcaster/hubble": minor
---

Rename verification message
2 changes: 2 additions & 0 deletions apps/hubble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"abitype": "^0.8.3",
"async-lock": "^1.4.0",
"axios": "^1.6.0",
"bs58": "^5.0.0",
"cli-progress": "^3.12.0",
"commander": "~10.0.0",
"fastify": "^4.22.0",
Expand All @@ -97,6 +98,7 @@
"semver": "^7.5.4",
"tar": "^6.1.15",
"tiny-typed-emitter": "~2.1.0",
"tweetnacl": "^1.0.3",
"viem": "^1.12.2"
}
}
2 changes: 1 addition & 1 deletion apps/hubble/src/console/warpcastTestCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class WarpcastTestCommand implements ConsoleCommandInterface {
data: {
fid,
network,
verificationRemoveBody: { address: verificationAdd.data.verificationAddEthAddressBody.address },
verificationRemoveBody: { address: verificationAdd.data.verificationAddAddressBody.address },
},
},
{ transient: { signer } },
Expand Down
8 changes: 4 additions & 4 deletions apps/hubble/src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
TrieNodeMetadataResponse,
TrieNodeSnapshotResponse,
UserDataAddMessage,
VerificationAddEthAddressMessage,
VerificationAddAddressMessage,
VerificationRemoveMessage,
ValidationResponse,
UserNameProof,
Expand Down Expand Up @@ -816,7 +816,7 @@ export default class Server {

const verificationResult = await this.engine?.getVerification(request.fid, request.address);
verificationResult?.match(
(verification: VerificationAddEthAddressMessage) => {
(verification: VerificationAddAddressMessage) => {
callback(null, verification);
},
(err: HubError) => {
Expand All @@ -836,7 +836,7 @@ export default class Server {
reverse,
});
verificationsResult?.match(
(page: MessagesPage<VerificationAddEthAddressMessage>) => {
(page: MessagesPage<VerificationAddAddressMessage>) => {
callback(null, messagesPageToResponse(page));
},
(err: HubError) => {
Expand Down Expand Up @@ -1056,7 +1056,7 @@ export default class Server {
reverse,
});
result?.match(
(page: MessagesPage<VerificationAddEthAddressMessage | VerificationRemoveMessage>) => {
(page: MessagesPage<VerificationAddAddressMessage | VerificationRemoveMessage>) => {
callback(null, messagesPageToResponse(page));
},
(err: HubError) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/hubble/src/rpc/test/bulkService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ReactionRemoveMessage,
UserDataAddMessage,
UserDataType,
VerificationAddEthAddressMessage,
VerificationAddAddressMessage,
VerificationRemoveMessage,
} from "@farcaster/hub-nodejs";
import SyncEngine from "../../network/sync/syncEngine.js";
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("getAllReactionMessagesByFid", () => {
});

describe("getAllVerificationMessagesByFid", () => {
let verificationAdd: VerificationAddEthAddressMessage;
let verificationAdd: VerificationAddAddressMessage;
let verificationRemove: VerificationRemoveMessage;

beforeAll(async () => {
Expand Down
14 changes: 6 additions & 8 deletions apps/hubble/src/rpc/test/httpServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
UserNameType,
utf8StringToBytes,
ValidationResponse,
VerificationAddEthAddressMessage,
VerificationAddAddressMessage,
} from "@farcaster/hub-nodejs";
import Engine from "../../storage/engine/index.js";
import { MockHub } from "../../test/mocks.js";
Expand Down Expand Up @@ -664,7 +664,7 @@ describe("httpServer", () => {
});

describe("verification APIs", () => {
let verificationAdd: VerificationAddEthAddressMessage;
let verificationAdd: VerificationAddAddressMessage;

beforeAll(async () => {
verificationAdd = await Factories.VerificationAddEthAddressMessage.create(
Expand All @@ -676,17 +676,15 @@ describe("httpServer", () => {
test("getVerification", async () => {
expect((await engine.mergeMessage(verificationAdd)).isOk()).toBeTruthy();

const address = verificationAdd.data.verificationAddEthAddressBody.address;
const address = verificationAdd.data.verificationAddAddressBody.address;
const url = getFullUrl(`/v1/verificationsByFid?fid=${fid}&address=${bytesToHexString(address)._unsafeUnwrap()}`);
const response = await axiosGet(url);

expect(response.status).toBe(200);
expect(response.data).toEqual(protoToJSON(verificationAdd, Message));
expect(response.data.data.verificationAddEthAddressBody.address).toEqual(
bytesToHexString(address)._unsafeUnwrap(),
);
expect(response.data.data.verificationAddEthAddressBody.blockHash).toEqual(
bytesToHexString(verificationAdd.data.verificationAddEthAddressBody.blockHash)._unsafeUnwrap(),
expect(response.data.data.verificationAddAddressBody.address).toEqual(bytesToHexString(address)._unsafeUnwrap());
expect(response.data.data.verificationAddAddressBody.blockHash).toEqual(
bytesToHexString(verificationAdd.data.verificationAddAddressBody.blockHash)._unsafeUnwrap(),
);

// Get via fid
Expand Down
14 changes: 8 additions & 6 deletions apps/hubble/src/rpc/test/verificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
HubRpcClient,
Message,
FarcasterNetwork,
VerificationAddEthAddressMessage,
VerificationAddAddressMessage,
VerificationRequest,
FidRequest,
OnChainEvent,
Expand Down Expand Up @@ -47,7 +47,7 @@ let custodyEvent: OnChainEvent;
let signerEvent: OnChainEvent;
let storageEvent: OnChainEvent;

let verificationAdd: VerificationAddEthAddressMessage;
let verificationAdd: VerificationAddAddressMessage;

beforeAll(async () => {
const signerKey = (await signer.getSignerKey())._unsafeUnwrap();
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("getVerification", () => {
const result = await client.getVerification(
VerificationRequest.create({
fid,
address: verificationAdd.data.verificationAddEthAddressBody.address ?? new Uint8Array(),
address: verificationAdd.data.verificationAddAddressBody.address ?? new Uint8Array(),
}),
);
expect(Message.toJSON(result._unsafeUnwrap())).toEqual(Message.toJSON(verificationAdd));
Expand All @@ -86,7 +86,7 @@ describe("getVerification", () => {
const result = await client.getVerification(
VerificationRequest.create({
fid,
address: verificationAdd.data.verificationAddEthAddressBody.address ?? new Uint8Array(),
address: verificationAdd.data.verificationAddAddressBody.address ?? new Uint8Array(),
}),
);
expect(result._unsafeUnwrapErr().errCode).toEqual("not_found");
Expand All @@ -99,13 +99,15 @@ describe("getVerification", () => {
address: new Uint8Array(),
}),
);
expect(result._unsafeUnwrapErr()).toEqual(new HubError("bad_request.validation_failure", "address is missing"));
expect(result._unsafeUnwrapErr()).toEqual(
new HubError("bad_request.validation_failure", "Ethereum address is missing"),
);
});

test("fails without fid", async () => {
const result = await client.getVerification(
VerificationRequest.create({
address: verificationAdd.data.verificationAddEthAddressBody.address ?? new Uint8Array(),
address: verificationAdd.data.verificationAddAddressBody.address ?? new Uint8Array(),
}),
);
expect(result._unsafeUnwrapErr()).toEqual(new HubError("bad_request.validation_failure", "fid is missing"));
Expand Down
Binary file modified apps/hubble/src/rustfunctions.test.ts
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/hubble/src/storage/db/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const typeToSetPostfix = (type: MessageType): UserMessagePostfix => {
return UserPostfix.ReactionMessage;
}

if (type === MessageType.VERIFICATION_ADD_ETH_ADDRESS || type === MessageType.VERIFICATION_REMOVE) {
if (type === MessageType.VERIFICATION_ADD_ADDRESS || type === MessageType.VERIFICATION_REMOVE) {
return UserPostfix.VerificationMessage;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { performDbMigrations } from "./migrations.js";
import { Factories, isVerificationAddEthAddressMessage } from "@farcaster/hub-nodejs";
import { Factories, isVerificationAddAddressMessage } from "@farcaster/hub-nodejs";
import { jestRocksDB } from "../jestUtils.js";
import StoreEventHandler from "../../stores/storeEventHandler.js";
import VerificationStore, {
makeVerificationAddsKey,
makeVerificationRemovesKey,
} from "../../stores/verificationStore.js";
import { VerificationAddEthAddressMessage, VerificationRemoveMessage } from "@farcaster/core";
import { VerificationAddAddressMessage, VerificationRemoveMessage } from "@farcaster/core";
import RocksDB from "../rocksdb.js";
import { makeTsHash, putMessageTransaction } from "../message.js";
import OnChainEventStore from "../../stores/onChainEventStore.js";
Expand All @@ -16,13 +16,13 @@ const db = jestRocksDB("uniqueverifications.migration.test");
describe("uniqueVerifications migration", () => {
const putVerificationMessage = async (
db: RocksDB,
message: VerificationAddEthAddressMessage | VerificationRemoveMessage,
message: VerificationAddAddressMessage | VerificationRemoveMessage,
) => {
const txn = db.transaction();
const tsHash = makeTsHash(message.data?.timestamp, message.hash)._unsafeUnwrap();
putMessageTransaction(txn, message);
if (isVerificationAddEthAddressMessage(message)) {
const addKey = makeVerificationAddsKey(message.data.fid, message.data.verificationAddEthAddressBody.address);
if (isVerificationAddAddressMessage(message)) {
const addKey = makeVerificationAddsKey(message.data.fid, message.data.verificationAddAddressBody.address);
txn.put(addKey, Buffer.from(tsHash));
} else {
const removeKey = makeVerificationRemovesKey(message.data.fid, message.data.verificationRemoveBody.address);
Expand All @@ -37,7 +37,7 @@ describe("uniqueVerifications migration", () => {
const ethSignerKey = (await ethSigner.getSignerKey())._unsafeUnwrap();
const verificationAdd1 = await Factories.VerificationAddEthAddressMessage.create(
{
data: { fid, verificationAddEthAddressBody: { address: ethSignerKey } },
data: { fid, verificationAddAddressBody: { address: ethSignerKey } },
},
{ transient: { ethSigner } },
);
Expand Down
28 changes: 16 additions & 12 deletions apps/hubble/src/storage/engine/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import {
UserNameProof,
UserNameType,
utf8StringToBytes,
VerificationAddEthAddressMessage,
VerificationAddAddressMessage,
} from "@farcaster/hub-nodejs";
import { err, Ok, ok } from "neverthrow";
import { jestRocksDB } from "../db/jestUtils.js";
import Engine from "../engine/index.js";
import { sleep } from "../../utils/crypto.js";
import { getMessage, makeTsHash, typeToSetPostfix } from "../db/message.js";
import { StoreEvents } from "../stores/storeEventHandler.js";
import { IdRegisterOnChainEvent, makeVerificationEthAddressClaim } from "@farcaster/core";
import { IdRegisterOnChainEvent, makeVerificationAddressClaim } from "@farcaster/core";
import { setReferenceDateForTest } from "../../utils/versions.js";
import { getUserNameProof } from "../db/nameRegistryEvent.js";
import { publicClient } from "../../test/utils.js";
Expand All @@ -60,7 +60,7 @@ let signerRemoveEvent: OnChainEvent;
let castAdd: CastAddMessage;
let reactionAdd: ReactionAddMessage;
let linkAdd: LinkAddMessage;
let verificationAdd: VerificationAddEthAddressMessage;
let verificationAdd: VerificationAddAddressMessage;
let userDataAdd: UserDataAddMessage;

beforeAll(async () => {
Expand Down Expand Up @@ -177,15 +177,15 @@ describe("mergeMessage", () => {
test("succeeds", async () => {
await expect(engine.mergeMessage(verificationAdd)).resolves.toBeInstanceOf(Ok);
await expect(
engine.getVerification(fid, verificationAdd.data.verificationAddEthAddressBody.address),
engine.getVerification(fid, verificationAdd.data.verificationAddAddressBody.address),
).resolves.toEqual(ok(verificationAdd));
expect(mergedMessages).toEqual([verificationAdd]);
});

test("fails when network does not match claim network", async () => {
const address = custodySignerKey;
const blockHash = Factories.BlockHash.build();
const mainnetClaim = await makeVerificationEthAddressClaim(
const mainnetClaim = await makeVerificationAddressClaim(
fid,
address,
FarcasterNetwork.MAINNET,
Expand All @@ -197,19 +197,23 @@ describe("mergeMessage", () => {
data: {
fid,
network: FarcasterNetwork.TESTNET,
verificationAddEthAddressBody: { address: address, blockHash: blockHash, ethSignature: claimSignature },
verificationAddAddressBody: {
address: address,
blockHash: blockHash,
protocolSignature: claimSignature,
},
},
},
{ transient: { signer: signer, ethSigner: custodySigner } },
);
const result = await engine.mergeMessage(testnetVerificationAdd);
// Signature will not match because we're attempting to recover the address based on the wrong network
expect(result).toEqual(err(new HubError("bad_request.validation_failure", "invalid ethSignature")));
expect(result).toEqual(err(new HubError("bad_request.validation_failure", "invalid protocolSignature")));
});

describe("validateOrRevokeMessage", () => {
let mergedMessage: Message;
let verifications: VerificationAddEthAddressMessage[] = [];
let verifications: VerificationAddAddressMessage[] = [];

const getVerifications = async () => {
const verificationsResult = await engine.getVerificationsByFid(fid);
Expand All @@ -223,7 +227,7 @@ describe("mergeMessage", () => {
{
data: {
fid,
verificationAddEthAddressBody: Factories.VerificationAddEthAddressBody.build({
verificationAddAddressBody: Factories.VerificationAddEthAddressBody.build({
chainId: 1,
verificationType: 1,
}),
Expand Down Expand Up @@ -631,7 +635,7 @@ describe("mergeMessage", () => {
test("succeeds for valid proof for verified eth address", async () => {
await engine.mergeMessage(verificationAdd);
const verificationAddress = bytesToHexString(
verificationAdd.data.verificationAddEthAddressBody.address,
verificationAdd.data.verificationAddAddressBody.address,
)._unsafeUnwrap();
jest.spyOn(publicClient, "getEnsAddress").mockImplementation(() => {
return Promise.resolve(verificationAddress);
Expand Down Expand Up @@ -675,7 +679,7 @@ describe("mergeMessage", () => {
beforeEach(async () => {
const custodyAddress = bytesToHexString(custodyEvent.idRegisterEventBody.to)._unsafeUnwrap();
const verificationAddress = bytesToHexString(
verificationAdd.data.verificationAddEthAddressBody.address,
verificationAdd.data.verificationAddAddressBody.address,
)._unsafeUnwrap();

jest.spyOn(publicClient, "getEnsAddress").mockImplementation((opts) => {
Expand Down Expand Up @@ -746,7 +750,7 @@ describe("mergeMessage", () => {
data: {
fid,
timestamp: verificationAdd.data.timestamp + 2,
verificationRemoveBody: { address: verificationAdd.data.verificationAddEthAddressBody.address },
verificationRemoveBody: { address: verificationAdd.data.verificationAddAddressBody.address },
},
},
{ transient: { signer } },
Expand Down
8 changes: 4 additions & 4 deletions apps/hubble/src/storage/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
UserNameType,
utf8StringToBytes,
validations,
VerificationAddEthAddressMessage,
VerificationAddAddressMessage,
VerificationRemoveMessage,
} from "@farcaster/hub-nodejs";
import { err, ok, ResultAsync } from "neverthrow";
Expand Down Expand Up @@ -585,7 +585,7 @@ class Engine extends TypedEmitter<EngineEvents> {
/* Verification Store Methods */
/* -------------------------------------------------------------------------- */

async getVerification(fid: number, address: Uint8Array): HubAsyncResult<VerificationAddEthAddressMessage> {
async getVerification(fid: number, address: Uint8Array): HubAsyncResult<VerificationAddAddressMessage> {
const validatedFid = validations.validateFid(fid);
if (validatedFid.isErr()) {
return err(validatedFid.error);
Expand All @@ -602,7 +602,7 @@ class Engine extends TypedEmitter<EngineEvents> {
async getVerificationsByFid(
fid: number,
pageOptions: PageOptions = {},
): HubAsyncResult<MessagesPage<VerificationAddEthAddressMessage>> {
): HubAsyncResult<MessagesPage<VerificationAddAddressMessage>> {
const validatedFid = validations.validateFid(fid);
if (validatedFid.isErr()) {
return err(validatedFid.error);
Expand All @@ -617,7 +617,7 @@ class Engine extends TypedEmitter<EngineEvents> {
async getAllVerificationMessagesByFid(
fid: number,
pageOptions: PageOptions = {},
): HubAsyncResult<MessagesPage<VerificationAddEthAddressMessage | VerificationRemoveMessage>> {
): HubAsyncResult<MessagesPage<VerificationAddAddressMessage | VerificationRemoveMessage>> {
const validatedFid = validations.validateFid(fid);
if (validatedFid.isErr()) {
return err(validatedFid.error);
Expand Down
2 changes: 1 addition & 1 deletion apps/hubble/src/storage/jobs/pruneMessagesJob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe("doJobs", () => {
}

expect(prunedMessages.length).toEqual(2); // 1 verification for each of the 2 fids
expect(prunedMessages.filter((m) => m.data?.type !== MessageType.VERIFICATION_ADD_ETH_ADDRESS)).toEqual([]);
expect(prunedMessages.filter((m) => m.data?.type !== MessageType.VERIFICATION_ADD_ADDRESS)).toEqual([]);
},
15 * 1000,
);
Expand Down
Loading

0 comments on commit fd9f9ff

Please sign in to comment.