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

feat: supporting WELLDONE Wallet in wallet-ts #193

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

Yoon-Suji
Copy link

@Yoon-Suji Yoon-Suji commented May 17, 2023

Description

Hello, We are WELLDONE Studio team from DSRV. We want to add supporting WELLDONE Wallet in wallet-ts.
WELLDONE extension wallet is multi-chain wallet that support Injective protocol. You can find more information about WELLDONE Wallet here.

Summary by CodeRabbit

  • New Features
    • Introduced support for the Welldone wallet, enabling users to interact with Cosmos-based chains directly from the app.
    • Added new functionalities for the Welldone wallet, including transaction signing, address retrieval, and wallet enabling.

@Yoon-Suji
Copy link
Author

Hi, @bangjelkoski
Thank you for comment and sorry for the code format issue. I fixed it. Would you check that again?

return {
signed: signDoc,
signature: {
pub_key: encodeSecp256k1Pubkey(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this on Injective tho? Because we are using another pubkey encoding/signing scheme and I think this will not work for us.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bangjelkoski
When I tested it with simple counter example it worked well. But I agree that it's wrong. I'll fix it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, thanks, ping me when its done!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const getPublicKey = ({
chainId,
key,
}: {
chainId: string
key: string | GoogleProtobufAny.Any
}) => {
if (typeof key !== 'string') {
return key
}
let proto
let path
let baseProto
if (chainId.startsWith('injective')) {
proto = CosmosCryptoSecp256k1Keys.PubKey.create()
baseProto = CosmosCryptoSecp256k1Keys.PubKey
path = '/injective.crypto.v1beta1.ethsecp256k1.PubKey'
} else if (chainId.startsWith('evmos')) {
proto = CosmosCryptoSecp256k1Keys.PubKey.create()
baseProto = CosmosCryptoSecp256k1Keys.PubKey
path = '/ethermint.crypto.v1.ethsecp256k1.PubKey'
} else {
proto = CosmosCryptoSecp256k1Keys.PubKey.create()
baseProto = CosmosCryptoSecp256k1Keys.PubKey
path = '/cosmos.crypto.secp256k1.PubKey'
}
proto.key = Buffer.from(key, 'base64')
return createAny(baseProto.encode(proto).finish(), path)
}
you can use this function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bangjelkoski Thank you! I modified the code using getPublicKey function. Please check it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check it. @bangjelkoski

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did but there are some pending changes requested below that are still open and not implemented

@bangjelkoski
Copy link
Collaborator

@daoauth @Yoon-Suji can we update the PR so we can finally finish it?

@Yoon-Suji
Copy link
Author

@bangjelkoski Yes, I already updated my code so we can finish :)


authInfo.signerInfos.forEach((signerInfo) => {
if (signerInfo.publicKey) {
signerInfo.publicKey.typeUrl = '/cosmos.crypto.secp256k1.PubKey'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be related to the chainId, not hardcoded for Cosmos

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bangjelkoski
WELLDONE Wallet use ‘secp245k1’ instead of ‘ethsecp256k1’ for unity with other cosmos chains. Therefore the injective account provided in the wallet is also made of ‘secp255k1’.

However, in the case of using MsgBroadCaster, the method createSignerinfo() is used in the process of making txRaw, and inside that method, it uses getPublicKey() that put publicKey’s type to '/injective.crypto.v1beta1.ethsecp256k1.PubKey' when the chainId starts with injective.
https://github.com/InjectiveLabs/injective-ts/blob/master/packages/sdk-ts/src/core/modules/tx/utils/tx.ts#L14

Therefore, in order to prepare for these exceptions, we added a part that changes the pubkey of authinfo to ‘secp256k1’ if you want to sign using WELLDONE Wallet. This is because we can use ‘stargate’ with the same environment as other cosmos chains.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now change to '/injective.crypto.v1beta1.ethsecp256k1.PubKey'

method: 'dapp:signTransaction',
params: [`0x${Buffer.from(signBytes).toString('hex')}`],
})
const pubKey = getPublicKey({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank space above

return {
signed: signDoc,
signature: {
pub_key: pubKey as any,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you cast it as any here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because getPublicKey() return type is Any. So it throws an error that "Property 'type' is missing in type 'Any' but required in type 'Pubkey'."

return {
signed: signDoc,
signature: {
pub_key: encodeSecp256k1Pubkey(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did but there are some pending changes requested below that are still open and not implemented

@bangjelkoski
Copy link
Collaborator

@bangjelkoski Yes, I already updated my code so we can finish :)

How about these changes: #193 (comment)

@daoauth
Copy link

daoauth commented Jan 9, 2024

@bangjelkoski Yes, I already updated my code so we can finish :)

How about these changes: #193 (comment)

i change to /injective.crypto.v1beta1.ethsecp256k1.PubKey
thanks

Copy link

coderabbitai bot commented Mar 7, 2024

Walkthrough

The recent update introduces the Welldone wallet strategy for Cosmos-based chains, expanding the wallet's capabilities within the project. It includes a new wallet strategy class, updates to enums and utility functions, and the introduction of a WelldoneWallet class for detailed interactions with the Welldone wallet. This enhancement broadens support for Cosmos transactions and wallet management, ensuring better integration and functionality for users of the Welldone wallet.

Changes

File Path Change Summary
.../strategies/wallet-strategy/strategies/Welldone.ts Introduced Welldone wallet strategy class with various wallet interaction methods.
.../types/enums.ts Added Welldone enum value.
.../utils/wallets/cosmos/utils.ts Updated to support Welldone wallet checks.
.../utils/wallets/index.ts Added export for welldone module.
.../utils/wallets/welldone/WelldoneWallet.ts
.../utils/wallets/welldone/index.ts
.../utils/wallets/welldone/welldone.d.ts
Added WelldoneWallet class and related exports and interfaces for interacting with the Welldone wallet.

🐰✨
In the realm of code, where wallets intertwine,
A new strategy emerges, Welldone, so fine.
With Cosmos in heart, it strides with grace,
Across the blockchain, it finds its place.
So here's to the builders, with vision so bright,
May your wallets connect, in the soft moonlight.
🌕💼✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c7c6d91 and 0cd7408.
Files selected for processing (9)
  • packages/wallet-ts/src/strategies/cosmos-wallet-strategy/strategies/Welldone.ts (1 hunks)
  • packages/wallet-ts/src/strategies/wallet-strategy/WalletStrategy.ts (2 hunks)
  • packages/wallet-ts/src/strategies/wallet-strategy/strategies/Welldone.ts (1 hunks)
  • packages/wallet-ts/src/types/enums.ts (1 hunks)
  • packages/wallet-ts/src/utils/wallets/cosmos/utils.ts (4 hunks)
  • packages/wallet-ts/src/utils/wallets/index.ts (1 hunks)
  • packages/wallet-ts/src/utils/wallets/welldone/WelldoneWallet.ts (1 hunks)
  • packages/wallet-ts/src/utils/wallets/welldone/index.ts (1 hunks)
  • packages/wallet-ts/src/utils/wallets/welldone/welldone.d.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/wallet-ts/src/utils/wallets/welldone/index.ts
Additional comments: 11
packages/wallet-ts/src/utils/wallets/index.ts (1)
  • 6-6: The addition of the welldone module export is correctly implemented and aligns with the PR's objective to support the WELLDONE Wallet.
packages/wallet-ts/src/utils/wallets/welldone/welldone.d.ts (1)
  • 1-17: The interface definitions for RequestParams and WalletProvider, along with the extension of the global Window interface, are correctly implemented and align with the PR's objectives for integrating WELLDONE Wallet support.
packages/wallet-ts/src/types/enums.ts (1)
  • 19-19: The addition of the Welldone value to the Wallet enum is correctly implemented and necessary for the library to recognize and interact with the WELLDONE Wallet.
packages/wallet-ts/src/utils/wallets/cosmos/utils.ts (3)
  • 5-5: Importing WalletProvider from ../welldone/welldone is necessary for the changes related to the WELLDONE Wallet support.
  • 30-30: Expanding the isCosmosBrowserWallet function to include Wallet.Welldone is correctly implemented and aligns with the PR's objectives.
  • 52-59: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [43-56]

Updating the isCosmosWalletInstalled function to check for the presence of dapp in the wallet provider object for Wallet.Welldone is correctly implemented and necessary for the integration.

packages/wallet-ts/src/strategies/cosmos-wallet-strategy/strategies/Welldone.ts (1)
  • 1-133: The Welldone class implementing ConcreteCosmosWalletStrategy is correctly implemented, including methods for wallet interaction that align with the PR's objectives. The explicit handling of unsupported operations and consistent error handling are notable.
packages/wallet-ts/src/utils/wallets/welldone/WelldoneWallet.ts (1)
  • 1-209: The WelldoneWallet class is correctly implemented, including methods for wallet interaction that align with the PR's objectives. The explicit handling of unsupported operations, consistent error handling, and the method to check for supported networks are notable.
packages/wallet-ts/src/strategies/wallet-strategy/strategies/Welldone.ts (1)
  • 1-209: The Welldone class implementing ConcreteWalletStrategy is correctly implemented, including methods for wallet interaction that align with the PR's objectives. The explicit handling of unsupported operations and consistent error handling are notable.
packages/wallet-ts/src/strategies/wallet-strategy/WalletStrategy.ts (2)
  • 25-25: The import statement for the Welldone strategy is correctly placed and follows the existing pattern of importing wallet strategies. This ensures that the Welldone class is available for use within the WalletStrategy class.
  • 106-107: The integration of the Welldone strategy within the createStrategy function is correctly implemented. It follows the established pattern for integrating new wallet strategies, ensuring consistency and maintainability. The use of the spread operator to pass arguments is appropriate and aligns with the implementation of other strategies.

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 this pull request may close these issues.

None yet

3 participants