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

How to obtain OfflineSigner? #17

Closed
ghost opened this issue Oct 27, 2023 · 11 comments · Fixed by #47
Closed

How to obtain OfflineSigner? #17

ghost opened this issue Oct 27, 2023 · 11 comments · Fixed by #47

Comments

@ghost
Copy link

ghost commented Oct 27, 2023

Is there a way to get an OfflineAminoSigner (definition) or OfflineDirectSigner (definition)?

@ghost
Copy link
Author

ghost commented Oct 27, 2023

Also, are there any plans for the ConnectedWallet class to expose methods such as signAmino or signDirect?

@AaronCQL
Copy link
Member

Is there a way to get an OfflineAminoSigner (definition) or OfflineDirectSigner (definition)?

Are you trying to broadcast transactions programmatically? If so, in v0.0.38, we have added the MnemonicWallet class that does this. See the example here: https://github.com/coinhall/cosmes/blob/main/examples/mnemonic-wallet/src/index.ts.

Also, are there any plans for the ConnectedWallet class to expose methods such as signAmino or signDirect?

Yes, but it's rather low priority at the moment since we do not have a use case for them. Do you require signAmino and signDirect across all wallets? Or only for MnemonicWallet?

@ghost
Copy link
Author

ghost commented Oct 30, 2023

Hi @AaronCQL thanks for the response!

I am working in a dApp context, so I do not have access to the wallet mnemonic, therefore I can't use MnemonicWallet.

For my use case, I only need getOfflineSigner method from the connected wallet class. I think a lot of dApps use getOfflineSigner method - we do the same at leapwallet.io.

@AaronCQL
Copy link
Member

@siddharth-leap specifically, you'd like to use the signAmino and signDirect methods correct? Think we can implement these methods directly within the ConnectedWallet class as opposed to having a getOfflineSigner method.

@ghost
Copy link
Author

ghost commented Oct 30, 2023

If you implement signAmino and signDirect, one can derive a getOfflineSigner function out of it, so that should work too.

I want to understand why you are inclined towards implementing signAmino/Direct as opposed to implementing the getOfflineSigner method.

@AaronCQL
Copy link
Member

I want to understand why you are inclined towards implementing signAmino/Direct as opposed to implementing the getOfflineSigner method.

This library is meant to completely replace cosmjs, and is not meant to be compatible with cosmjs. We won't be able to use the same method signatures as cosmjs's OfflineSigner also due to the different protobuf library used

In terms of structuring the API, having the sign methods within the ConnectedWallet class makes more sense than having to instantiate another object just to sign.

What's your exact use case for having getOfflineSigner though? I might be missing something obvious.

@ghost
Copy link
Author

ghost commented Oct 31, 2023

Okay I understand. The getOfflineSigner method is not a hard requirement for my use case. I think the signAmino/Direct methods would do the job as well.

I have seen across various dApps that an OfflineSigner object is used to instantiate a SigningStargateClient or a SigningCosmWasmClient. These are typically used to sign transactions and broadcast them. For example

const offlineSigner = window.leap.getOfflineSigner('osmosis-1');

const client = await SigningStargateClient.connectWithSigner(rpc, offlineSigner, {
  registry: customRegistry,
  broadcastTimeoutMs: 60_000
});

client.simulate()

client.sign()

client.broadcastTx()

@AaronCQL
Copy link
Member

The ConnectedWallet class in cosmes is the equivalent of SigningStargateClient or SigningCosmWasmClient.

A similar flow to your code can be done in cosmes as well:

import { LeapController, WalletType } from "cosmes/wallet";

const WC_PROJECT_ID = "TODO";
const controller = new LeapController(WC_PROJECT_ID);
const wallets = await controller.connect(WalletType.EXTENSION, [
  {
    chainId: "osmosis-1",
    rpc: "https://rpc.osmosis.zone",
    gasPrice: {
      amount: "0.0025",
      denom: "uosmo",
    },
  },
]);
const wallet = wallets.get("osmosis-1");

wallet.estimateFee(...);     // similar to `client.simulate()`
wallet.broadcastTxSync(...); // combines both `client.sign()` and `client.broadcastTx()`

For our dapps' usecases, there is no need to separate the signing from the broadcasting, which is why cosmes combines them both into the same call.

@ghost
Copy link
Author

ghost commented Oct 31, 2023

Thank you for the clarification. I can use these methods for my use case.

I think exposing signAmino and signDirect methods on the ConnectedWallet class will be quite helpful.

Thank you for your time!

@ghost
Copy link
Author

ghost commented Dec 22, 2023

Hi @AaronCQL any updates on this?

AaronCQL added a commit that referenced this issue Mar 21, 2024
This PR changes the behaviour of all wallets such that the
`signAndBroadcastTx` method will always broadcast via the user specified
RPC, rather than broadcasted via the wallet extension.

Unfortunately, Station mobile app does not support signing a tx without
broadcasting it.

Closes #17
@ghost
Copy link
Author

ghost commented Mar 21, 2024

@AaronCQL Thank you for implementing this feature! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant