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

1661 en 2 #1747

Merged
merged 14 commits into from
Jan 28, 2025
Merged

1661 en 2 #1747

merged 14 commits into from
Jan 28, 2025

Conversation

lucanicoladebiasi
Copy link
Collaborator

@lucanicoladebiasi lucanicoladebiasi commented Jan 26, 2025

Description

en_2 recommendation implemented.

The Address at packages/core/src/vcdm/Address.ts removes the useless isCompressed parameter in the ofPrivateKey method.

Fixes # EN_2

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • yarn test:solo
  • yarn test:unit
  • yarn test:examples

Test Configuration:

  • Node.js Version: v23.1.0
  • Yarn Version: 1.22.22

Summary by CodeRabbit

Summary by CodeRabbit

  • Documentation

    • Updated documentation for KECCAK 256 hash operation, removing SHA-3 references.
    • Clarified method and class documentation for Address and Keccak256 classes.
    • Modified examples and documentation to reflect synchronous private key generation.
  • Refactor

    • Simplified ofPrivateKey method in Address class.
    • Streamlined error handling in unit tests.
    • Removed unnecessary parameter and error checks.
    • Updated generatePrivateKey method to be synchronous in Secp256k1 class.
  • Tests

    • Improved test case organization and readability.
    • Updated error handling in Address and keystore unit tests.
    • Adjusted tests to reflect changes in private key generation method.

@lucanicoladebiasi lucanicoladebiasi self-assigned this Jan 26, 2025
@lucanicoladebiasi lucanicoladebiasi requested a review from a team as a code owner January 26, 2025 12:14
@lucanicoladebiasi lucanicoladebiasi linked an issue Jan 26, 2025 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Jan 26, 2025

Walkthrough

This pull request introduces modifications to several files in the VeChain SDK core package, focusing on documentation updates, error handling, and method signature refinements. The changes primarily affect the Address.ts, Keccak256.ts, and corresponding unit test files. The modifications include removing SHA-3 references, simplifying method signatures, updating error handling, and improving test case clarity and organization.

Changes

File Change Summary
packages/core/src/vcdm/Address.ts - Removed isCompressed parameter from ofPrivateKey method
- Updated method documentation
- Simplified error handling
packages/core/src/vcdm/hash/Keccak256.ts - Removed SHA-3 references in class and method documentation
- Kept KECCAK 256 URL consistent
packages/core/tests/keystore/keystore.unit.test.ts - Added InvalidDataType error import
- Conditional error handling based on experimentalCryptography flag
packages/core/tests/vcdm/Address.unit.test.ts - Removed InvalidSecp256k1PrivateKey import
- Simplified test cases
- Streamlined error handling
packages/core/src/secp256k1/Secp256k1.ts - Changed generatePrivateKey from async to sync
- Updated documentation for randomBytes method
docs/*.md - Updated private key generation from async to sync across multiple documentation files

Possibly related PRs

Suggested labels

Type: Documentation, Priority: Low

Suggested reviewers

  • claytonneal

Poem

🐰 A rabbit's tale of code so bright,
Refactoring errors with pure delight.
SHA-3 fades, KECCAK takes the stage,
Simplifying methods on every page.
Clean and crisp, the changes gleam,
A developer's most elegant dream! 🔧

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@lucanicoladebiasi lucanicoladebiasi added this to the 1.0.0 milestone Jan 26, 2025
Copy link

github-actions bot commented Jan 26, 2025

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
98.98% (4376/4421) 97.01% (1398/1441) 98.9% (906/916)
Title Tests Skipped Failures Errors Time
core 838 0 💤 0 ❌ 0 🔥 2m 29s ⏱️
network 731 0 💤 0 ❌ 0 🔥 5m 14s ⏱️
errors 40 0 💤 0 ❌ 0 🔥 17.364s ⏱️
logging 3 0 💤 0 ❌ 0 🔥 18.617s ⏱️
hardhat-plugin 19 0 💤 0 ❌ 0 🔥 1m 5s ⏱️
aws-kms-adapter 23 0 💤 0 ❌ 0 🔥 1m 38s ⏱️
ethers-adapter 5 0 💤 0 ❌ 0 🔥 1m 20s ⏱️
rpc-proxy 37 0 💤 0 ❌ 0 🔥 1m 8s ⏱️

Copy link
Contributor

@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

🧹 Nitpick comments (3)
docs/examples/accounts/keystore.ts (1)

8-8: Consider adding async/sync documentation note.

While the private key generation is now synchronous, it might be helpful to add a comment clarifying that subsequent keystore operations (encrypt/decrypt) remain asynchronous. This helps developers understand the mixed sync/async nature of the operations.

 const privateKey = Secp256k1.generatePrivateKey();
+// Note: While key generation is synchronous, keystore operations below are asynchronous
docs/examples/transactions/blockref-expiration.ts (1)

40-40: LGTM! Consider grouping related operations.

The synchronous key generation is correctly implemented. For better readability, consider grouping the key generation with the signing operation since they're closely related.

-// 3 - Create private key
-
-const privateKey = Secp256k1.generatePrivateKey();
-
-// 4 - Sign transaction
+// 3 - Sign transaction with a new private key
+const privateKey = Secp256k1.generatePrivateKey();
const signedTransaction = Transaction.of(body).sign(privateKey);
packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts (1)

172-173: Consider using a more descriptive variable name.

The variable name delegatorPrivateKey could be more descriptive to indicate its test purpose, such as testDelegatorPrivateKey or mockDelegatorPrivateKey.

-                    delegatorPrivateKey: Hex.of(Secp256k1.generatePrivateKey())
+                    delegatorPrivateKey: Hex.of(Secp256k1.generatePrivateKey()) // Mock private key for testing
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66dbfd7 and 6af3507.

📒 Files selected for processing (17)
  • apps/sdk-vite-integration/package.json (1 hunks)
  • docs/accounts.md (1 hunks)
  • docs/certificates.md (1 hunks)
  • docs/cryptography.md (1 hunks)
  • docs/examples/accounts/keystore.ts (1 hunks)
  • docs/examples/certificates/sign_verify.ts (1 hunks)
  • docs/examples/cryptography/secp256k1.ts (1 hunks)
  • docs/examples/transactions/blockref-expiration.ts (1 hunks)
  • docs/examples/transactions/multiple-clauses.ts (1 hunks)
  • docs/examples/transactions/sign-decode.ts (1 hunks)
  • docs/examples/transactions/tx-dependency.ts (1 hunks)
  • docs/transactions.md (4 hunks)
  • packages/core/src/secp256k1/Secp256k1.ts (2 hunks)
  • packages/core/tests/keystore/keystore.unit.test.ts (6 hunks)
  • packages/core/tests/secp256k1/Secp256k1.unit.test.ts (1 hunks)
  • packages/core/tests/secp256k1/fixture.ts (0 hunks)
  • packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/tests/secp256k1/fixture.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/sdk-vite-integration/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/tests/keystore/keystore.unit.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit-integration-test / Build & Lint (latest)
  • GitHub Check: unit-integration-test / Build & Lint (lts/*)
  • GitHub Check: unit-integration-test / Build & Lint (18)
  • GitHub Check: unit-integration-test-browser / Build & Lint (18)
🔇 Additional comments (13)
docs/examples/certificates/sign_verify.ts (1)

7-7: LGTM! Clean update to synchronous private key generation.

The change aligns with the broader refactoring of Secp256k1.generatePrivateKey() to be synchronous, while maintaining the correct flow of the certificate signing example.

docs/examples/transactions/sign-decode.ts (1)

43-43: LGTM! Consistent with transaction flow.

The synchronous private key generation aligns well with the transaction signing and encoding flow, which are also synchronous operations.

docs/examples/transactions/multiple-clauses.ts (1)

49-49: LGTM! Correctly updated to use synchronous private key generation.

The change aligns with the updated Secp256k1.generatePrivateKey() API.

docs/examples/cryptography/secp256k1.ts (1)

8-8: LGTM! Example updated to reflect the new synchronous API.

The example correctly demonstrates the usage of Secp256k1.generatePrivateKey() in its synchronous form.

docs/examples/transactions/tx-dependency.ts (1)

60-60: LGTM! Correctly updated transaction dependency example.

The example has been properly updated to use the synchronous generatePrivateKey() method while maintaining the correct transaction dependency logic.

packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts (1)

172-173: LGTM! Test updated to use synchronous private key generation.

The test has been properly updated to use the synchronous generatePrivateKey() method.

packages/core/src/secp256k1/Secp256k1.ts (2)

97-115: LGTM! Clean implementation of synchronous private key generation.

The changes correctly simplify the method by making it synchronous while maintaining proper error handling and clear error messages.


180-191: LGTM! Good improvement to the API.

Adding a default value of 32 for bytesLength is a sensible choice as it matches the common use case for generating private keys while maintaining flexibility for other use cases.

docs/certificates.md (1)

50-50: LGTM! Documentation correctly updated.

The example code has been properly updated to reflect the synchronous nature of generatePrivateKey.

docs/cryptography.md (1)

54-54: LGTM! Documentation correctly updated.

The example code has been properly updated to reflect the synchronous nature of generatePrivateKey.

packages/core/tests/secp256k1/Secp256k1.unit.test.ts (2)

10-38: LGTM! Well-organized test constants.

The reorganization of test constants into HASHES, KEYS, and SIGNATURES improves code readability and maintainability.


79-101: LGTM! Comprehensive test coverage for private key generation.

The tests properly verify both successful generation and error handling cases, including mocking hardware crypto support failure.

docs/transactions.md (1)

50-50: LGTM! Method signatures updated consistently across examples.

All instances of Secp256k1.generatePrivateKey() have been correctly updated from async to sync calls across the transaction examples.

Let's verify that all examples in the transactions documentation have been updated:

Also applies to: 102-102, 217-217, 280-280

✅ Verification successful

Verified: Documentation examples consistently use sync generatePrivateKey()

All instances in the transactions documentation and related example files have been correctly updated to use the synchronous version of Secp256k1.generatePrivateKey(). While there is one async usage in the Cloudflare integration SDK, it's outside the scope of these documentation changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining async calls to generatePrivateKey in transaction examples
rg -l "await.*Secp256k1\.generatePrivateKey\(\)" "docs/examples/transactions/"

Length of output: 78


Script:

#!/bin/bash
# First, find all transaction-related markdown and code files
echo "=== Transaction-related files ==="
fd -e md -e js -e ts "transaction" 

echo -e "\n=== Checking for remaining async calls ==="
rg "await.*Secp256k1\.generatePrivateKey\(\)"

echo -e "\n=== Checking sync usage pattern ==="
rg "Secp256k1\.generatePrivateKey\(\)" -A 1

Length of output: 9774

@@ -130,7 +130,7 @@ Through the use of mnemonics and keystore, VeChainSDK ensures secure and user-fr
```typescript { name=keystore, category=example }
// 1 - Create private key using Secp256k1

const privateKey = await Secp256k1.generatePrivateKey();
const privateKey = Secp256k1.generatePrivateKey();
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Architecture diagram needs updating to reflect sync signature

All code examples correctly use the synchronous generatePrivateKey(), but the architecture diagram in docs/diagrams/architecture/secp256k1.md still shows it as async. Specific location:

  • docs/diagrams/architecture/secp256k1.md: Update Promise~Uint8Array~ async generatePrivateKey() to reflect the new sync signature
🔗 Analysis chain

LGTM! Method signature updated correctly.

The change from async to sync call for Secp256k1.generatePrivateKey() is consistent with the method signature refinement.

Let's verify the consistency of this change across all examples:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining async calls to generatePrivateKey
rg -l "await.*Secp256k1\.generatePrivateKey\(\)" docs/

Length of output: 56


Script:

#!/bin/bash
# Search for any mention of generatePrivateKey with context
rg -C 2 "generatePrivateKey" docs/

Length of output: 4785

@victhorbi victhorbi removed this from the 1.0.0 milestone Jan 28, 2025
@lucanicoladebiasi lucanicoladebiasi merged commit 5bcbf8a into main Jan 28, 2025
17 checks passed
@lucanicoladebiasi lucanicoladebiasi deleted the 1661-en_2 branch January 28, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EN_2
4 participants