injective-ts icon indicating copy to clipboard operation
injective-ts copied to clipboard

feat: turnkey wallet

Open billyjacoby opened this issue 9 months ago β€’ 4 comments

First cut at adding Turnkey support to our SDK. One big gotcha to know here is that you need to provide endpoints for purpose built API to communicate with the Turnkey API server side. I'll include what this looks like and a minimal example before merging.

There's a lot going on here and could certainly use some cleaning up, but I've successfully tested and used this in our MsgBroadcaster to broadcast an transaction.

I'll post some more concrete general docs for how to properly use this in the near future.

Summary by CodeRabbit

  • New Features

    • Introduced Turnkey wallet support with OTP (email-based) and OAuth (Google/Apple) authentication strategies.
    • Added Turnkey OTP and OAuth as new wallet types selectable in the wallet system.
    • Enhanced wallet metadata to include Turnkey-specific configuration, session, and status management.
    • Added new error codes and modules for detailed error reporting in Turnkey authentication flows.
    • Added Turnkey wallet strategy classes handling session, account management, and Cosmos transaction support.
  • Documentation

    • Added comprehensive README for the Turnkey wallet package with installation and usage guidance.
  • Bug Fixes

    • Improved error handling and validation for wallet authentication and session lifecycle.
  • Refactor

    • Updated wallet strategy interfaces to replace options with metadata for consistency.
    • Refactored HTTP client utilities for improved data extraction and error handling.
    • Modified wallet strategies to lazily initialize resources and unify metadata handling.
  • Chores

    • Added configuration, build scripts, and package metadata for the Turnkey wallet package.
    • Updated dependencies to include the new Turnkey wallet integration.

billyjacoby avatar Mar 29 '25 01:03 billyjacoby

[!CAUTION]

Review failed

The pull request is closed.

Walkthrough

This update introduces a new Turnkey wallet strategy package, supporting both OTP and OAuth authentication for Injective Protocol. It adds new wallet types, refactors wallet metadata handling, and implements strategy and utility classes for Turnkey integration. Documentation, configuration, and error handling are expanded, and several existing wallet strategies are updated for compatibility with the new metadata structure.

Changes

File(s) / Group Change Summary
packages/wallets/wallet-base/src/types/enums.ts Added TurnkeyOtp and TurnkeyOauth to the Wallet enum.
packages/wallets/wallet-base/src/utils/wallet.ts Updated isEvmWallet and isEvmBrowserWallet to include new Turnkey wallet types; adjusted order of Trezor entries.
packages/wallets/wallet-base/src/types/strategy.ts Refactored wallet metadata types, replaced options with metadata, introduced Turnkey-specific types and enums, and updated interfaces accordingly.
packages/wallets/wallet-base/src/base.ts
packages/wallets/wallet-core/src/strategy/BaseWalletStrategy.ts
Added metadata property and updated constructor to use metadata. Replaced setOptions with setMetadata.
packages/wallets/wallet-strategy/src/strategy/index.ts Updated strategy creation logic for new Turnkey types and metadata structure; refactored setOptions to setMetadata.
packages/wallets/wallet-magic/src/strategy/strategy.ts
packages/wallets/wallet-wallet-connect/src/strategy/strategy.ts
packages/wallets/wallet-private-key/src/strategy/strategy.ts
Refactored to remove direct constructor-based options/metadata, now use deferred/lazy initialization from metadata.
packages/wallets/wallet-cosmos/src/strategy/strategy.ts
packages/wallets/wallet-cosmostation/src/strategy/strategy.ts
Updated constructors to cast arguments for type safety; reformatted error handling for readability.
packages/wallets/wallet-turnkey/README.md
packages/wallets/wallet-turnkey/package.json
Added new package documentation and configuration for Turnkey wallet strategy.
packages/wallets/wallet-turnkey/tsconfig.build.json
packages/wallets/wallet-turnkey/tsconfig.build.esm.json
packages/wallets/wallet-turnkey/tsconfig.json
Added TypeScript build and project configuration for the new package.
packages/wallets/wallet-turnkey/src/index.ts Added entry point exporting Turnkey wallet strategies and related modules.
packages/wallets/wallet-turnkey/src/strategy/consts.ts
packages/wallets/wallet-turnkey/src/strategy/types.ts
Added constants and types for Turnkey wallet API endpoints and authentication flows.
packages/wallets/wallet-turnkey/src/strategy/strategy/base.ts Implemented BaseTurnkeyWalletStrategy class for Turnkey wallet session, authentication, and transaction management.
packages/wallets/wallet-turnkey/src/strategy/strategy/oauth.ts
packages/wallets/wallet-turnkey/src/strategy/strategy/otp.ts
Added specialized Turnkey wallet strategy classes for OAuth and OTP providers.
packages/wallets/wallet-turnkey/src/strategy/turnkey/turnkey.ts Implemented TurnkeyWallet class for session, account, and iframe management.
packages/wallets/wallet-turnkey/src/strategy/turnkey/oauth.ts Implemented TurnkeyOauthWallet class for OAuth nonce generation and login.
packages/wallets/wallet-turnkey/src/strategy/turnkey/otp.ts Implemented TurnkeyOtpWallet class for OTP initialization and confirmation.
packages/wallets/wallet-turnkey/src/utils.ts Added utility function to generate Google OAuth URLs.
packages/sdk-ts/src/utils/address.spec.ts Added test for Ethereum checksum address utility.
packages/exceptions/src/exceptions/types/codes.ts Extended ErrorContextCode type to allow any number.
packages/utils/src/classes/HttpRestClient.ts Enhanced error message extraction logic to include statusMessage.
package.json Added a local resolution for the next package.
packages/networks/src/constants.ts Updated CW20_ADAPTER_CONTRACT_BY_NETWORK addresses for multiple devnet and local networks.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant WalletStrategy
    participant TurnkeyOtpWalletStrategy
    participant TurnkeyOauthWalletStrategy
    participant BaseTurnkeyWalletStrategy
    participant TurnkeyWallet
    participant TurnkeyIframeClient
    participant HttpRestClient

    App->>WalletStrategy: createStrategy({ wallet, metadata })
    WalletStrategy->>TurnkeyOtpWalletStrategy: new (args)
    WalletStrategy->>TurnkeyOauthWalletStrategy: new (args)
    Note over TurnkeyOtpWalletStrategy,TurnkeyOauthWalletStrategy: Both extend BaseTurnkeyWalletStrategy

    App->>TurnkeyOtpWalletStrategy: enable()
    TurnkeyOtpWalletStrategy->>BaseTurnkeyWalletStrategy: enable()
    BaseTurnkeyWalletStrategy->>TurnkeyWallet: getSessionOrConfirm()
    TurnkeyWallet->>TurnkeyIframeClient: getSession()
    TurnkeyWallet->>HttpRestClient: API call (OTP/OAuth login)
    HttpRestClient-->>TurnkeyWallet: credentialBundle/session
    TurnkeyWallet-->>BaseTurnkeyWalletStrategy: session info

    App->>TurnkeyOtpWalletStrategy: getAddresses()
    TurnkeyOtpWalletStrategy->>BaseTurnkeyWalletStrategy: getAddresses()
    BaseTurnkeyWalletStrategy->>TurnkeyWallet: getAccounts()
    TurnkeyWallet->>TurnkeyIframeClient: fetch accounts
    TurnkeyIframeClient-->>TurnkeyWallet: accounts
    TurnkeyWallet-->>BaseTurnkeyWalletStrategy: addresses

    App->>TurnkeyOtpWalletStrategy: sendTransaction()
    TurnkeyOtpWalletStrategy->>BaseTurnkeyWalletStrategy: sendTransaction()
    BaseTurnkeyWalletStrategy->>TurnkeyWallet: sign/broadcast transaction
    TurnkeyWallet->>HttpRestClient: broadcast transaction
    HttpRestClient-->>TurnkeyWallet: tx result
    TurnkeyWallet-->>BaseTurnkeyWalletStrategy: tx result

Poem

πŸ‡
A new Turnkey door swings open wide,
With OTP and OAuth by my side.
Metadata flows in a structured stream,
Strategies now work as a seamless team.
From browser to blockchain, the journey is brightβ€”
Rabbits leap forward, with wallets done right!
🌱✨

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

πŸ”§ ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/networks/src/constants.ts

Oops! Something went wrong! :(

ESLint: 7.32.0

Error: Error while loading rule 'jest/unbound-method': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Occurred while linting /packages/networks/src/constants.ts at throwError (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:39:11) at getParserServices (/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:31:9) at create (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:116:55) at Object.create (/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20) at create (/node_modules/eslint-plugin-jest/lib/rules/unbound-method.js:47:88) at Object.create (/node_modules/eslint-plugin-jest/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:41:20) at createRuleListeners (/node_modules/eslint/lib/linter/linter.js:765:21) at /node_modules/eslint/lib/linter/linter.js:937:31 at Array.forEach () at runRules (/node_modules/eslint/lib/linter/linter.js:882:34)

[!NOTE]

⚑️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Learn more here.


[!NOTE]

⚑️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings. Enjoy the performance boostβ€”your workflow just got faster.


πŸ“œ Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro (Legacy) Cache: Disabled due to data retention organization setting Knowledge Base: Disabled due to data retention organization setting

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 62911cb06bc7af56179d0882a38d5093daaf646e and 3d70b208ce1e662c8aec1452e452befbecb00abe.

πŸ“’ Files selected for processing (1)
  • packages/networks/src/constants.ts (1 hunks)

πŸͺ§ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 29 '25 01:03 coderabbitai[bot]

Hmm for some reason this doesn't work when I branch off dev, but it does off master. This branch works for me after building

billyjacoby avatar Mar 29 '25 01:03 billyjacoby

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

socket-security[bot] avatar Apr 28 '25 10:04 socket-security[bot]

Flow diagram found here:

https://www.tldraw.com/f/FSN_z4lqYjQoHsBm35kF1?d=v-1589.-1724.5917.5246.page

billyjacoby avatar May 12 '25 14:05 billyjacoby