-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
WalkthroughThe pull request includes updates to the Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files
|
There was a problem hiding this 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 parameterThe 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 supportThe 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 theeth
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
⛔ 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary by CodeRabbit
New Features
MnemonicKey
andRawKey
classes.Bug Fixes
package.json
to reflect the latest release.