Skip to content

Commit

Permalink
remove solana related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazzymandias committed Jan 31, 2024
1 parent 1afc542 commit 9add14d
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 175 deletions.
7 changes: 0 additions & 7 deletions apps/replicator/src/processors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
isUserDataAddMessage,
isUsernameProofMessage,
isVerificationAddAddressMessage,
isVerificationAddSolAddressMessage,
isVerificationRemoveMessage,
} from "@farcaster/hub-nodejs";
import { Redis } from "ioredis";
Expand Down Expand Up @@ -180,12 +179,6 @@ export async function processMessage(
break;
case MessageType.FRAME_ACTION:
throw new AssertionError("Unexpected FRAME_ACTION message type");
case MessageType.VERIFICATION_ADD_SOL_ADDRESS:
if (!isVerificationAddSolAddressMessage(message))
throw new AssertionError(`Invalid VerificationAddSolAddressMessage: ${message}`);
log.debug(`Processing VerificationAddSolAddressMessage ${hash} (fid ${fid})`, { fid, hash });
// await processVerificationAddSolAddress(message, operation, trx);
break;
case MessageType.NONE:
throw new AssertionError("Message contained no type");
default:
Expand Down
11 changes: 0 additions & 11 deletions apps/replicator/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,6 @@ export function convertProtobufMessageBodyToJson(message: Message): MessageBodyJ
blockHash: bytesToHex(blockHash),
} satisfies VerificationAddEthAddressBodyJson;
}
case MessageType.VERIFICATION_ADD_SOL_ADDRESS: {
if (!message.data.verificationAddAddressBody) {
throw new Error("Missing verificationAddSolAddressBody");
}
const { address, protocolSignature, blockHash } = message.data.verificationAddAddressBody;
return {
address: bytesToHex(address),
protocolSignature: bytesToHex(protocolSignature),
blockHash: bytesToHex(blockHash),
} satisfies VerificationAddSolAddressBodyJson;
}
case MessageType.VERIFICATION_REMOVE: {
if (!message.data.verificationRemoveBody) throw new Error("Missing verificationRemoveBody");
const { address, protocol } = message.data.verificationRemoveBody;
Expand Down
14 changes: 0 additions & 14 deletions packages/core/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,6 @@ export const makeVerificationAddEthAddressData = (
);
};

// TODO: Add Solana public clients
export const makeVerificationAddSolAddressData = (
body: protobufs.VerificationAddAddressBody,
dataOptions: MessageDataOptions,
publicClients: PublicClients = defaultPublicClients,
): HubAsyncResult<protobufs.VerificationAddSolAddressData> => {
return makeMessageData(
{ verificationAddAddressBody: body },
protobufs.MessageType.VERIFICATION_ADD_SOL_ADDRESS,
dataOptions,
publicClients,
);
};

export const makeVerificationRemoveData = (
body: protobufs.VerificationRemoveBody,
dataOptions: MessageDataOptions,
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/protobufs/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export enum MessageType {
USERNAME_PROOF = 12,
/** FRAME_ACTION - A Farcaster Frame action */
FRAME_ACTION = 13,
/** VERIFICATION_ADD_SOL_ADDRESS - Add a Verification of a Solana Address */
VERIFICATION_ADD_SOL_ADDRESS = 14,
}

export function messageTypeFromJSON(object: any): MessageType {
Expand Down Expand Up @@ -143,9 +141,6 @@ export function messageTypeFromJSON(object: any): MessageType {
case 13:
case "MESSAGE_TYPE_FRAME_ACTION":
return MessageType.FRAME_ACTION;
case 14:
case "MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS":
return MessageType.VERIFICATION_ADD_SOL_ADDRESS;
default:
throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum MessageType");
}
Expand Down Expand Up @@ -177,8 +172,6 @@ export function messageTypeToJSON(object: MessageType): string {
return "MESSAGE_TYPE_USERNAME_PROOF";
case MessageType.FRAME_ACTION:
return "MESSAGE_TYPE_FRAME_ACTION";
case MessageType.VERIFICATION_ADD_SOL_ADDRESS:
return "MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS";
default:
throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum MessageType");
}
Expand Down
19 changes: 0 additions & 19 deletions packages/core/src/protobufs/typeguards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,6 @@ export const isVerificationAddAddressMessage = (
isVerificationAddEthAddressData(message.data)
);
};
export const isVerificationAddSolAddressData = (
data: protobufs.MessageData,
): data is types.VerificationAddSolAddressData => {
return (
data.type === protobufs.MessageType.VERIFICATION_ADD_SOL_ADDRESS &&
typeof data.verificationAddAddressBody !== "undefined"
);
};

export const isVerificationAddSolAddressMessage = (
message: protobufs.Message,
): message is types.VerificationAddSolAddressMessage => {
return (
message.signatureScheme === protobufs.SignatureScheme.ED25519 &&
typeof message.data !== "undefined" &&
isVerificationAddSolAddressData(message.data)
);
};

export const isVerificationRemoveData = (data: protobufs.MessageData): data is types.VerificationRemoveData => {
return data.type === protobufs.MessageType.VERIFICATION_REMOVE && typeof data.verificationRemoveBody !== "undefined";
};
Expand Down
10 changes: 0 additions & 10 deletions packages/core/src/protobufs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ export type VerificationAddAddressMessage = protobufs.Message & {
signatureScheme: protobufs.SignatureScheme.ED25519;
};

export type VerificationAddSolAddressData = protobufs.MessageData & {
type: protobufs.MessageType.VERIFICATION_ADD_SOL_ADDRESS;
verificationAddSolAddressBody: protobufs.VerificationAddAddressBody;
};

export type VerificationAddSolAddressMessage = protobufs.Message & {
data: VerificationAddSolAddressData;
signatureScheme: protobufs.SignatureScheme.ED25519;
};

export type VerificationRemoveData = protobufs.MessageData & {
type: protobufs.MessageType.VERIFICATION_REMOVE;
verificationRemoveBody: protobufs.VerificationRemoveBody;
Expand Down
44 changes: 1 addition & 43 deletions packages/core/src/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { bytesCompare, bytesToUtf8String, utf8StringToBytes } from "./bytes";
import { ed25519, eip712 } from "./crypto";
import { HubAsyncResult, HubError, HubResult } from "./errors";
import { getFarcasterTime, toFarcasterTime } from "./time";
import { makeVerificationEthAddressClaim, makeVerificationSolAddressClaim } from "./verifications";
import { makeVerificationEthAddressClaim } from "./verifications";
import { UserNameType } from "./protobufs";
import { normalize } from "viem/ens";
import { defaultPublicClients, PublicClients } from "./eth/clients";
Expand Down Expand Up @@ -384,24 +384,6 @@ export const validateVerificationAddEthAddressSignature = async (
return ok(body.protocolSignature);
};

export const validateVerificationAddSolAddressSignature = async (
body: protobufs.VerificationAddAddressBody,
fid: number,
network: protobufs.FarcasterNetwork,
publicClients: PublicClients = defaultPublicClients,
): HubAsyncResult<Uint8Array> => {
if (body.protocolSignature.length > 256) {
return err(new HubError("bad_request.validation_failure", "protocolSignature > 256 bytes"));
}

const reconstructedClaim = makeVerificationSolAddressClaim(fid, body.address, network, body.blockHash);
if (reconstructedClaim.isErr()) {
return err(reconstructedClaim.error);
}

return ok(body.protocolSignature);
};

export const validateUrl = (url: string): HubResult<string> => {
if (typeof url !== "string") {
return err(new HubError("bad_request.validation_failure", "url must be a string"));
Expand Down Expand Up @@ -663,30 +645,6 @@ export const validateVerificationAddEthAddressBody = async (
return ok(body);
};

export const validateVerificationAddSolAddressBody = async (
body: protobufs.VerificationAddAddressBody,
fid: number,
network: protobufs.FarcasterNetwork,
publicClients: PublicClients,
): HubAsyncResult<protobufs.VerificationAddAddressBody> => {
const validAddress = validateSolAddress(body.address);
if (validAddress.isErr()) {
return err(validAddress.error);
}

// Solana block hash uses SHA-256 algorithm
const validBlockHash = validateSolBlockHash(body.blockHash);
if (validBlockHash.isErr()) {
return err(validBlockHash.error);
}

const validSignature = await validateVerificationAddSolAddressSignature(body, fid, network, publicClients);

// TODO: add validation to reconstruct user claim and validate signature against claim using input FID

return ok(body);
};

export const validateVerificationRemoveBody = (
body: protobufs.VerificationRemoveBody,
): HubResult<protobufs.VerificationRemoveBody> => {
Expand Down
13 changes: 1 addition & 12 deletions packages/core/src/verifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factories } from "./factories";
import { makeVerificationEthAddressClaim, makeVerificationSolAddressClaim } from "./verifications";
import { makeVerificationEthAddressClaim } from "./verifications";

describe("makeVerificationEthAddressClaim", () => {
test("succeeds", () => {
Expand All @@ -11,14 +11,3 @@ describe("makeVerificationEthAddressClaim", () => {
expect(claim.isOk()).toBeTruthy();
});
});

describe("makeVerificationSolAddressClaim", () => {
test("succeeds", () => {
const fid = Factories.Fid.build();
const solAddress = Factories.EthAddress.build();
const network = Factories.FarcasterNetwork.build();
const blockHash = Factories.BlockHash.build();
const claim = makeVerificationSolAddressClaim(fid, solAddress, network, blockHash);
expect(claim.isOk()).toBeTruthy();
});
});
37 changes: 0 additions & 37 deletions packages/core/src/verifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ export type VerificationEthAddressClaim = {
blockHash: `0x${string}`;
};

export type VerificationSolAddressClaim = {
fid: bigint;
// Solana addresses use base58 encoding and do not have a 0x prefix
address: string;
network: FarcasterNetwork;
// Solana block hash is base58 encoded and does not have a 0x prefix
blockHash: string;
};

export const makeVerificationEthAddressClaim = (
fid: number,
ethAddress: Uint8Array,
Expand Down Expand Up @@ -47,31 +38,3 @@ export const makeVerificationEthAddressClaim = (
blockHash: blockHashHex.value,
});
};

export const makeVerificationSolAddressClaim = (
fid: number,
solAddress: Uint8Array,
network: FarcasterNetwork,
blockHash: Uint8Array,
): HubResult<VerificationEthAddressClaim> => {
const solAddressHex = validateEthAddress(solAddress).andThen((validatedEthAddress) =>
bytesToHexString(validatedEthAddress),
);
if (solAddressHex.isErr()) {
return err(solAddressHex.error);
}

const blockHashHex = validateEthBlockHash(blockHash).andThen((validatedBlockHash) =>
bytesToHexString(validatedBlockHash),
);
if (blockHashHex.isErr()) {
return err(blockHashHex.error);
}

return ok({
fid: BigInt(fid),
address: solAddressHex.value,
network: network,
blockHash: blockHashHex.value,
});
};
7 changes: 0 additions & 7 deletions packages/hub-nodejs/src/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export enum MessageType {
USERNAME_PROOF = 12,
/** FRAME_ACTION - A Farcaster Frame action */
FRAME_ACTION = 13,
/** VERIFICATION_ADD_SOL_ADDRESS - Add a Verification of a Solana Address */
VERIFICATION_ADD_SOL_ADDRESS = 14,
}

export function messageTypeFromJSON(object: any): MessageType {
Expand Down Expand Up @@ -143,9 +141,6 @@ export function messageTypeFromJSON(object: any): MessageType {
case 13:
case "MESSAGE_TYPE_FRAME_ACTION":
return MessageType.FRAME_ACTION;
case 14:
case "MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS":
return MessageType.VERIFICATION_ADD_SOL_ADDRESS;
default:
throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum MessageType");
}
Expand Down Expand Up @@ -177,8 +172,6 @@ export function messageTypeToJSON(object: MessageType): string {
return "MESSAGE_TYPE_USERNAME_PROOF";
case MessageType.FRAME_ACTION:
return "MESSAGE_TYPE_FRAME_ACTION";
case MessageType.VERIFICATION_ADD_SOL_ADDRESS:
return "MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS";
default:
throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum MessageType");
}
Expand Down
7 changes: 0 additions & 7 deletions packages/hub-web/src/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export enum MessageType {
USERNAME_PROOF = 12,
/** FRAME_ACTION - A Farcaster Frame action */
FRAME_ACTION = 13,
/** VERIFICATION_ADD_SOL_ADDRESS - Add a Verification of a Solana Address */
VERIFICATION_ADD_SOL_ADDRESS = 14,
}

export function messageTypeFromJSON(object: any): MessageType {
Expand Down Expand Up @@ -143,9 +141,6 @@ export function messageTypeFromJSON(object: any): MessageType {
case 13:
case "MESSAGE_TYPE_FRAME_ACTION":
return MessageType.FRAME_ACTION;
case 14:
case "MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS":
return MessageType.VERIFICATION_ADD_SOL_ADDRESS;
default:
throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum MessageType");
}
Expand Down Expand Up @@ -177,8 +172,6 @@ export function messageTypeToJSON(object: MessageType): string {
return "MESSAGE_TYPE_USERNAME_PROOF";
case MessageType.FRAME_ACTION:
return "MESSAGE_TYPE_FRAME_ACTION";
case MessageType.VERIFICATION_ADD_SOL_ADDRESS:
return "MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS";
default:
throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum MessageType");
}
Expand Down
1 change: 0 additions & 1 deletion protobufs/schemas/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ enum MessageType {
MESSAGE_TYPE_USER_DATA_ADD = 11; // Add metadata about a user
MESSAGE_TYPE_USERNAME_PROOF = 12; // Add or replace a username proof
MESSAGE_TYPE_FRAME_ACTION = 13; // A Farcaster Frame action
MESSAGE_TYPE_VERIFICATION_ADD_SOL_ADDRESS = 14; // Add a Verification of a Solana Address
}

/** Farcaster network the message is intended for */
Expand Down

0 comments on commit 9add14d

Please sign in to comment.