Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating animo converters instead of manually creating them #7

Open
2 tasks
stevenkhong opened this issue Nov 19, 2024 · 2 comments
Open
2 tasks
Assignees
Labels
help wanted Extra attention is needed

Comments

@stevenkhong
Copy link
Contributor

stevenkhong commented Nov 19, 2024

Cosmos SDK introduced SIGN_MODE_DIRECT which replaces the original sign mode (now differentiated as SIGN_MODE_LEGACY_AMINO_JSON) cosmos-sdk docs. However, most ledger devices/apps only support the legacy mode, which requires dApps to support both sign modes. In order to support the legacy mode, the dApp will need to provide an Amino converter for each protobuf type, to convert the object instance into an Amino JSON used for the signing.

In the legacy Carbon JS SDK implementation, the Amino converters were manually written for each new type added (example). We would like to explore possibility of generating the type converters instead. The information is already available in the type .proto files, however I am not sure if the generator we're using ts-proto is able to parse it.

An snippet of the source .proto file:

message MsgCreateToken {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "carbon/MsgCreateToken"; // <-- amino type converters need this
  option (gogoproto.goproto_getters) = false;

  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  CreateTokenParams create_token_params = 2 [ (gogoproto.nullable) = false ];
}

message CreateTokenParams {
  option (gogoproto.goproto_getters) = false;

  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  string name = 2;
  string symbol = 3;
  int64 decimals = 4;
  uint64 chain_id = 5;
  uint64 bridge_id = 6;
  string bridge_address = 7;
  string token_address = 8;
}

The Animo types is usually registered when instantiating some version of a signing client.

const aminoTypes = getAminoTypes();
SigningStargateClient.connectWithSigner(rpcUrl, signer, { aminoTypes });

To summarise, there're two main unknowns we need to get past before knowing we can proceed with implementing a generator for animo types.

  • can existing TypeScript generator include animo.name option in the output? otherwise does it make sense to extract if using another tool/script?
  • is it possible to auto map the sdk/Dec, Long, Duration and other common types, such that majority of the amino type converter generations can be automated?
@stevenkhong stevenkhong added the help wanted Extra attention is needed label Nov 19, 2024
@stevenkhong
Copy link
Contributor Author

adding on, identifying the cosmos.msg.v1.signer in the exported types will be helpful with the group proposal support mentioned in #8.

@stevenkhong stevenkhong assigned yan-soon and unassigned randy75828 Nov 21, 2024
@randy75828
Copy link
Contributor

Derived amino and signer mapping from protobuf so that we do not need an Amino Map #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants