Skip to content

Commit be4837d

Browse files
authored
chore: pull in snapchain signer protos (#2685)
<!-- start pr-codex --> ## PR-Codex overview This PR primarily focuses on enhancing the protocol buffer definitions and handling for key management messages, including adding support for `KEY_ADD` and `KEY_REMOVE` operations. It also refines the script for generating protocol files. ### Detailed summary - Updated `generate-protos.sh` script to change `PROTO_PATH` and `PROTO_REV`. - Introduced new types: `KeyAddData`, `KeyAddMessage`, `KeyRemoveData`, `KeyRemoveMessage`. - Added type guards for the new message types in `typeguards.ts`. - Enhanced `index.ts` to export new message types and responses. - Created factories for `KeyAddBody`, `KeyRemoveBody`, and their associated messages. - Updated `rpc.ts` and `message.ts` to include new RPC methods and message types for key management. - Added tests for `KeyAdd` and `KeyRemove` functionalities in `typeguards.test.ts`. > The following files were skipped due to too many changes: `packages/core/src/protobufs/generated/message.ts`, `packages/hub-web/src/generated/request_response.ts`, `packages/hub-nodejs/src/generated/request_response.ts`, `packages/core/src/protobufs/generated/request_response.ts`, `yarn.lock` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 373a60f commit be4837d

15 files changed

Lines changed: 4505 additions & 431 deletions

File tree

generate-protos.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
PROTO_REPO=https://github.com/farcasterxyz/snapchain
2-
PROTO_PATH=src/proto
3-
PROTO_REV=e634aa8789fa8196446ce1d68b459864b93a8780 # Update this if you want to generate off updated snapchain protos
2+
PROTO_PATH=proto/definitions
3+
PROTO_REV=e8e89a3e81f2e8da45231ecc5ac44ee85b17bb09 # Update this if you want to generate off updated snapchain protos
44

55
TMPDIR=tmp-protogen
6-
git clone $PROTO_REPO $TMPDIR
7-
cd $TMPDIR
8-
git checkout $PROTO_REV
6+
git clone --no-single-branch $PROTO_REPO $TMPDIR
7+
cd $TMPDIR
8+
git fetch origin "$PROTO_REV" 2>/dev/null || true
9+
git checkout $PROTO_REV || { echo "Failed to checkout $PROTO_REV — aborting"; exit 1; }
910
cd ..
1011

1112

packages/core/src/factories.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,98 @@ const FrameActionMessageFactory = Factory.define<protobufs.FrameActionMessage, {
722722
},
723723
);
724724

725+
const LendStorageBodyFactory = Factory.define<protobufs.LendStorageBody>(() => {
726+
return protobufs.LendStorageBody.create({
727+
toFid: FidFactory.build(),
728+
numUnits: faker.datatype.number({ min: 1, max: 10 }),
729+
unitType: protobufs.StorageUnitType.UNIT_TYPE_2025,
730+
});
731+
});
732+
733+
const LendStorageDataFactory = Factory.define<protobufs.LendStorageData>(() => {
734+
return MessageDataFactory.build({
735+
lendStorageBody: LendStorageBodyFactory.build(),
736+
type: protobufs.MessageType.LEND_STORAGE,
737+
}) as protobufs.LendStorageData;
738+
});
739+
740+
const LendStorageMessageFactory = Factory.define<protobufs.LendStorageMessage, { signer?: Ed25519Signer }>(
741+
({ onCreate, transientParams }) => {
742+
onCreate((message) => {
743+
return MessageFactory.create(message, { transient: transientParams }) as Promise<protobufs.LendStorageMessage>;
744+
});
745+
746+
return MessageFactory.build(
747+
{ data: LendStorageDataFactory.build(), signatureScheme: protobufs.SignatureScheme.ED25519 },
748+
{ transient: transientParams },
749+
) as protobufs.LendStorageMessage;
750+
},
751+
);
752+
753+
const KeyAddBodyFactory = Factory.define<protobufs.KeyAddBody>(() => {
754+
return protobufs.KeyAddBody.create({
755+
key: Ed25519PublicKeyFactory.build(),
756+
keyType: 1,
757+
custodySignature: Eip712SignatureFactory.build(),
758+
deadline: faker.datatype.number({ min: 1, max: 2 ** 31 - 1 }),
759+
nonce: faker.datatype.number({ min: 1, max: 2 ** 31 - 1 }),
760+
metadata: BytesFactory.build({}, { transient: { length: 64 } }),
761+
metadataType: 1,
762+
scopes: [protobufs.MessageType.CAST_ADD as number],
763+
ttl: faker.datatype.number({ min: 1, max: 60 * 60 * 24 * 365 }),
764+
});
765+
});
766+
767+
const KeyAddDataFactory = Factory.define<protobufs.KeyAddData>(() => {
768+
return MessageDataFactory.build({
769+
keyAddBody: KeyAddBodyFactory.build(),
770+
type: protobufs.MessageType.KEY_ADD,
771+
}) as protobufs.KeyAddData;
772+
});
773+
774+
const KeyAddMessageFactory = Factory.define<protobufs.KeyAddMessage, { signer?: Ed25519Signer }>(
775+
({ onCreate, transientParams }) => {
776+
onCreate((message) => {
777+
return MessageFactory.create(message, { transient: transientParams }) as Promise<protobufs.KeyAddMessage>;
778+
});
779+
780+
return MessageFactory.build(
781+
{ data: KeyAddDataFactory.build(), signatureScheme: protobufs.SignatureScheme.ED25519 },
782+
{ transient: transientParams },
783+
) as protobufs.KeyAddMessage;
784+
},
785+
);
786+
787+
const KeyRemoveBodyFactory = Factory.define<protobufs.KeyRemoveBody>(() => {
788+
return protobufs.KeyRemoveBody.create({
789+
key: Ed25519PublicKeyFactory.build(),
790+
signature: Eip712SignatureFactory.build(),
791+
signatureType: 1,
792+
deadline: faker.datatype.number({ min: 1, max: 2 ** 31 - 1 }),
793+
nonce: faker.datatype.number({ min: 1, max: 2 ** 31 - 1 }),
794+
});
795+
});
796+
797+
const KeyRemoveDataFactory = Factory.define<protobufs.KeyRemoveData>(() => {
798+
return MessageDataFactory.build({
799+
keyRemoveBody: KeyRemoveBodyFactory.build(),
800+
type: protobufs.MessageType.KEY_REMOVE,
801+
}) as protobufs.KeyRemoveData;
802+
});
803+
804+
const KeyRemoveMessageFactory = Factory.define<protobufs.KeyRemoveMessage, { signer?: Ed25519Signer }>(
805+
({ onCreate, transientParams }) => {
806+
onCreate((message) => {
807+
return MessageFactory.create(message, { transient: transientParams }) as Promise<protobufs.KeyRemoveMessage>;
808+
});
809+
810+
return MessageFactory.build(
811+
{ data: KeyRemoveDataFactory.build(), signatureScheme: protobufs.SignatureScheme.ED25519 },
812+
{ transient: transientParams },
813+
) as protobufs.KeyRemoveMessage;
814+
},
815+
);
816+
725817
const OnChainEventFactory = Factory.define<protobufs.OnChainEvent>(() => {
726818
return protobufs.OnChainEvent.create({
727819
type: OnChainEventType.EVENT_TYPE_SIGNER,
@@ -853,6 +945,15 @@ export const Factories = {
853945
FrameActionBody: FrameActionBodyFactory,
854946
FrameActionData: FrameActionDataFactory,
855947
FrameActionMessage: FrameActionMessageFactory,
948+
LendStorageBody: LendStorageBodyFactory,
949+
LendStorageData: LendStorageDataFactory,
950+
LendStorageMessage: LendStorageMessageFactory,
951+
KeyAddBody: KeyAddBodyFactory,
952+
KeyAddData: KeyAddDataFactory,
953+
KeyAddMessage: KeyAddMessageFactory,
954+
KeyRemoveBody: KeyRemoveBodyFactory,
955+
KeyRemoveData: KeyRemoveDataFactory,
956+
KeyRemoveMessage: KeyRemoveMessageFactory,
856957
LinkBody: LinkBodyFactory,
857958
LinkAddData: LinkAddDataFactory,
858959
LinkAddMessage: LinkAddMessageFactory,

0 commit comments

Comments
 (0)