Signing Cosmos Transactions with Lit PKPs

Learn how to use Lit Programmable Key Pairs (PKPs) to sign and send transactions on the Cosmos Hub.

Signing Cosmos Transactions with Lit PKPs
image generated using dall-e.

Intro

Lit Protocol is a distributed key management network that powers condition-based encryption and access control, compute, and programmable signing. Lit can be harnessed by application developers building products that leverage public key infrastructure (PKI) at their core, that don’t want to rely on a centralized key custodian.

We are excited to announce that Lit can now be used to send and sign testnet transactions on Cosmos (see the State of the Network). With the new upgrade, Programmable Key Pairs (PKPs) can be used as a valid Cosmos signer on all Cosmos SDK based chains, starting with the Cosmos Hub. In this article, we will explore potential use cases for this new feature and how devs building in the Cosmos ecosystem can get started with these new tools!

Overview of Programmable Key Pairs (PKPs) and Lit Actions

A PKP is an ECDSA key-pair (wallet) that is generated and stored as shares across the Lit network. Each PKP can be programmed to automatically sign based on predefined rules and application logic, specified in a JavaScript program called a Lit Action. All Lit Actions are immutable, blockchain agnostic, and can make arbitrary HTTP requests. This means that they can utilize both on and off-chain data in their computation natively, without requiring any third-party oracle.

Together, these two features create a powerful primitive (a “programmable key”) that can be used to facilitate complex DeFi automations, cross-chain swaps, event-based transaction execution, and more.

PKPs on Cosmos

With the recent upgrade to the Lit SDK, PKPs can now be used as a valid signer on chains within the Cosmos ecosystem. This opens up a range of new possibilities and potential use cases, as well as helping bring us closer to our goal of enabling seamless interoperability between all web3 apps, regardless of origin. To explore how this new feature works, check out this demo video that shows how a PKP can be used to sign a transaction on the Cosmos Hub: https://youtu.be/zJEVPH1UUxM

If you are a developer and want to play around with the code yourself or integrate this functionality into your own app, take a look at the PKP Client package which is a part of the Lit SDK. This package provides a PKPClient class that can be used to manage multiple wallets for different blockchain networks (e.g. Ethereum and Cosmos) and offers a convenient way to create and interact with these wallets.

To see the PKP Client in action, you can play around with the example app that is highlighted in the demo video above.

Use Cases

Okay, awesome, PKPs on Cosmos. But what does this mean for me as a developer? What are some examples of apps that can be built with this functionality? Let’s explore some potential use cases below:

On-chain limit orders

PKPs and Lit Actions can be used to facilitate condition-based orders for a variety of different DeFi applications. These may take the form of simple limit orders, enabling the automation of buys and sells based on customizable price parameters (i.e. “sell my ATOM when the price hits $10 USD”), or even more complex orders that utilize off-chain data (such as pulling in an off-chain price feed or making a call to any other external API). To read more about ways Lit can be used to power DeFi automation use cases, check out this article exploring the use of the Lit event listener for conditional portfolio rebalancing.

Automated compounding of staking rewards

When it comes to staking your tokens — whether depositing into a DeFi protocol, locking up as a security deposit, or delegating to another Validator — there exists no easy way to automatically claim or redistribute rewards to other sources. For example, automatically compounding or redistributing a percentage of your rewards every month, re-delegating them to another validator, or even sending them across chain to an external account for use in another blockchain ecosystem.

Using Lit Actions and PKPs in conjunction with the Cosmos authz module, we can start to program this functionality around staked assets. The authz module allows a user to delegate permission(s) to other accounts to execute actions or transaction logic on their behalf. In this example, the module could be used to allow a user to grant arbitrary permissions to a PKP to spend / transact their staked assets on their behalf.

Recurring payments

One of the biggest hassles in using blockchains and dApps is the requirement on the user to sign every time. Whether its making a simple swap on a DEX, sending a buddy some crypto, or staking some tokens, a user is always required to be “online”. This requirement of always having a human-in-the-loop creates an unnecessary burden and poor UX, especially as it relates to recurring payments (such as a subscription or payment to an employee).

This is another strong use case for PKPs and Lit Actions. A potential example would be dollar-cost averaging, where a user could define conditions for making recurring investments based on certain time scales or price movements.

Using PKPs with Authz

The Cosmos authz module allows you to delegate permission(s) to other accounts to execute actions on your behalf. The basic authorization type is a "generic" authorization, which is one that takes a message type as a parameter and allows the grantee unlimited authorization to execute that message on behalf of the granter. Other authorization types include "send", "delegate", "unbond", and "redelegate" in which case a limit on the number of tokens can be set by the granter. If no limit is set, the grantee can vote as many times as they want until the granter revokes the authorization.

We can use the authz module to facilitate interactions between Cosmos accounts and Lit PKPs, whereby a user can delegate certain permissions to a PKP to spend assets on their behalf. A possible user flow looks like:

  1. A user starts by sending an authz message, granting arbitrary privileges from their account (the granter) to a PKP (the grantee).
  2. The grant object encapsulates an Authorization type and an expiration timestamp, outlining the actions that a grantee has permission to make on behalf of the granter.
  3. After specific permissions have been granted (such as "grantee can only spend < 50% of portfolio"), the PKP will be able to execute arbitrary transaction logic on behalf of users, using Lit Actions to define certain condition-based automations (for example, the logic for the limit orders discussed above).

If you have worked with the Cosmos authz module in the past and you are interested in helping develop any of the use cases mentioned above, please reach out to us on Discord! We are eager to work with experienced builders in the Cosmos ecosystem to bring these examples to life.

Conclusion

We are thrilled to make this announcement expanding Lit’s programmable signing functionality into the Cosmos, and can’t wait to see the types of projects that are developed using this new feature! If you are building within the wider Cosmos ecosystem and are interested in exploring any of the use cases mentioned above, please get in touch.

If you’d like to contribute to the Lit community at large, check out our Request for Ecosystem Proposals and Grants program. We are always looking to fund the development of open source infrastructure that expands the capabilities of Lit and web3 as a whole.

For developer support (or if you just want to say hey!) don’t forget join the community on Discord.

Resources

📄 Developer Documentation: https://developer.litprotocol.com/

👾 Discord: https://litgateway.com/discord

🧑‍💻 GitHub: https://github.com/LIT-Protocol

🕊 Twitter: https://twitter.com/LitProtocol

🖥 Website: https://litprotocol.com/