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

Add eth option for mnemonic and raw key #90

Merged
merged 2 commits into from
Oct 31, 2024
Merged

Add eth option for mnemonic and raw key #90

merged 2 commits into from
Oct 31, 2024

Conversation

joon9823
Copy link
Collaborator

@joon9823 joon9823 commented Oct 31, 2024

Summary by CodeRabbit

  • New Features

    • Added support for Ethereum public keys in the MnemonicKey and RawKey classes.
    • Users can now specify whether to use an Ethereum public key through a new optional parameter.
  • Bug Fixes

    • Updated version number in package.json to reflect the latest release.

@joon9823 joon9823 requested a review from ALPAC-4 October 31, 2024 04:25
Copy link

coderabbitai bot commented Oct 31, 2024

Walkthrough

The pull request includes updates to the package.json file to increment the version number from "0.2.19" to "0.2.20". Additionally, modifications were made to the MnemonicKey and RawKey classes. The MnemonicKey class now supports an optional eth property in its options, which is passed to the superclass constructor. The RawKey class constructor has been updated to accept an eth parameter, determining the type of public key to create. These changes enhance the functionality related to Ethereum public keys.

Changes

File Change Summary
package.json Version updated: "version": "0.2.19""version": "0.2.20"
src/key/MnemonicKey.ts - Added optional property eth?: boolean to MnemonicKeyOptions interface.
- Updated DEFAULT_OPTIONS to include eth: false.
- Modified constructor to include eth in destructured options and pass it to superclass.
src/key/RawKey.ts - Updated constructor to accept an additional boolean parameter eth.
- Added import statement for EthPublicKey.

Possibly related PRs

  • Feat/eth-pubkey #85: The changes in this PR also involve an update to the package.json file for a version bump, similar to the main PR's version update from "0.2.19" to "0.2.20".

Suggested reviewers

  • Vritra4

Poem

In the code where rabbits hop,
A version change, we won't stop!
With keys for Ethereum's might,
Our features now shine bright.
Hopping forward, one step more,
New options added, let’s explore! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc1c973 and daaad17.

📒 Files selected for processing (1)
  • src/key/RawKey.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/key/RawKey.ts

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>, please review it.
    • Generate unit testing code 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 testing code 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 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 generate unit testing code.
    • @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.

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 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.

Copy link

github-actions bot commented Oct 31, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails
npm/tslib 2.7.0 🟢 5.5
Details
CheckScoreReason
Maintained⚠️ 00 commit(s) out of 30 and 1 issue activity out of 30 found in the last 90 days -- score normalized to 0
Code-Review🟢 7GitHub code reviews found for 23 commits out of the last 30 -- score normalized to 7
CII-Best-Practices⚠️ 0no badge detected
Vulnerabilities🟢 10no vulnerabilities detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Packaging⚠️ -1no published package detected
Token-Permissions⚠️ 0non read-only tokens detected in GitHub workflows
License🟢 10license file detected
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies🟢 9dependency not pinned by hash detected -- score normalized to 9
Signed-Releases⚠️ -1no releases found
Security-Policy🟢 10security policy file detected
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ -1internal error: internal error: Client.Search.Code: Search.Code: GET https://api.github.com/search/code?q=github.com+microsoft+tslib+repo%3Agoogle%2Foss-fuzz+in%3Afile+filename%3Aproject.yaml: 400 []

Scanned Files

  • package-lock.json

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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
src/key/RawKey.ts (2)

Line range hint 32-36: Update fromHex factory method to support eth parameter

The fromHex factory method needs to be updated to support the new eth parameter to maintain consistency with the constructor.

Suggested fix:

- public static fromHex(key: string): RawKey {
+ public static fromHex(key: string, eth = false): RawKey {
    const hex = key.startsWith('0x') ? key.slice(2) : key
    if (hex.length !== 64) throw new Error('Invalid private key length')
-   return new RawKey(Buffer.from(hex, 'hex'))
+   return new RawKey(Buffer.from(hex, 'hex'), eth)
  }

Line range hint 8-11: Update class documentation to reflect Ethereum support

The class documentation should be updated to mention the new Ethereum public key support.

Suggested update:

 /**
  * An implementation of the Key interfaces that uses a raw private key.
+ * Supports both standard and Ethereum public key formats.
  */
src/key/MnemonicKey.ts (3)

28-31: Enhance the JSDoc comment for the eth property.

The current comment could be more descriptive about the purpose and implications of using an Ethereum public key.

Consider updating the comment to:

  /**
-  * Whether to use eth pubkey
+  * Whether to use Ethereum public key format instead of the default format.
+  * When true, the key will be compatible with Ethereum-based operations.
   */

75-78: Consider adding parameter validation.

The eth parameter is passed directly to the superclass without any type checking or validation.

Consider adding explicit validation:

   const { account, index, coinType, eth } = {
     ...DEFAULT_OPTIONS,
     ...options,
   }
+  if (eth !== undefined && typeof eth !== 'boolean') {
+    throw new TypeError('eth option must be a boolean')
+  }

Line range hint 44-73: Update constructor documentation with eth option examples.

The JSDoc comment for the constructor should be updated to include examples of using the new eth option.

Consider adding an example:

   * ### Generating a random mnemonic
   *
   * ```ts
   * const mk2 = new MnemonicKey();
   * console.log(mk2.mnemonic);
   * ```
   *
+  * ### Using Ethereum public key format
+  *
+  * ```ts
+  * const mk3 = new MnemonicKey({ eth: true });
+  * // The key will use Ethereum public key format
+  * ```
   *
   * @param options
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e7c724e and fc1c973.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/key/MnemonicKey.ts (3 hunks)
  • src/key/RawKey.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (4)
src/key/RawKey.ts (2)

4-4: LGTM: Clean import organization

The import statement is well-organized, grouping related public key types together.


16-16: LGTM: Backward-compatible parameter addition

The optional eth parameter with default false maintains backward compatibility.

src/key/MnemonicKey.ts (2)

38-38: LGTM!

The default value of false maintains backward compatibility with existing implementations.


93-93: Verify the impact of eth parameter in RawKey.

The eth parameter is passed to the RawKey constructor, which according to the AI summary determines the type of public key created.

Let's verify the RawKey implementation:

✅ Verification successful

Based on the shell script results, I can now generate the final response:

The eth parameter in RawKey is correctly implemented and impacts the public key type

The verification confirms that the eth parameter in RawKey's constructor determines whether an EthPublicKey or SimplePublicKey is created. When eth is true, it initializes with EthPublicKey, which:

  • Uses a different type identifier ('initia/PubKeyEthSecp256k1')
  • Has specific serialization/deserialization logic for Ethereum-compatible keys
  • Implements custom address derivation for Ethereum compatibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the RawKey implementation and its handling of the eth parameter

# Check RawKey constructor implementation
ast-grep --pattern 'class RawKey {
  constructor($_) {
    $$$
  }
}'

# Check for EthPublicKey usage
rg "EthPublicKey" -A 5

Length of output: 5500

src/key/RawKey.ts Show resolved Hide resolved
Copy link
Contributor

@ALPAC-4 ALPAC-4 left a comment

Choose a reason for hiding this comment

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

LGTM

@joon9823 joon9823 merged commit 0c83620 into main Oct 31, 2024
4 checks passed
@joon9823 joon9823 deleted the feat/ethsecp256k1 branch October 31, 2024 05:02
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
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.

2 participants