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

Polyfill #84

Closed
wants to merge 11 commits into from
Closed

Polyfill #84

wants to merge 11 commits into from

Conversation

joon9823
Copy link
Collaborator

@joon9823 joon9823 commented Oct 8, 2024

  • replace Buffer with Uint8Array

Summary by CodeRabbit

  • New Features

    • Updated dependencies to enhance performance and maintainability.
  • Bug Fixes

    • Improved code examples and formatting in the README file for better readability.
  • Documentation

    • Enhanced clarity in documentation comments throughout the codebase.
  • Refactor

    • Removed deprecated Ledger-related classes and methods to streamline the codebase.
  • Chores

    • Updated package version and cleaned up unused dependencies.

@joon9823 joon9823 requested a review from Vritra4 October 8, 2024 07:41
Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The pull request includes multiple changes across various files, primarily focusing on code formatting, dependency management, and the removal of certain functionalities. Key modifications involve the removal of semicolons from TypeScript import statements and function calls for consistency, updates to the package.json file to reflect version changes and the removal of specific dependencies, as well as the deletion of several files related to Ledger hardware wallet functionality.

Changes

File Path Change Summary
README.md Reformatted TypeScript import statements and function calls by removing semicolons.
package.json Updated version to 0.2.17 and removed several devDependencies including crypto-browserify, webpack, and Ledger-related packages.
src/client/WebSocketClient.ts Updated import path for hashToHex and removed semicolons in example code.
src/key/index.ts Removed export for ./ledger module; other exports remain unchanged.
src/key/ledger/LedgerKey.ts Deleted file containing the LedgerKey class and its associated methods.
src/key/ledger/app.ts Deleted file containing the InitiaApp class and its methods for interacting with Ledger devices.
src/key/ledger/constants.ts Deleted file containing constants and enumerations for Ledger operations.
src/key/ledger/device.ts Deleted file containing functions for communication with Ledger devices.
src/key/ledger/index.ts Deleted file that served as an entry point for the ledger module, re-exporting various components.
src/key/ledger/types.ts Deleted file containing TypeScript interface definitions for ledger responses.
vite.config.ts Removed external dependency @ledgerhq/hw-transport from the build configuration.

Possibly related PRs

  • cleanse deps #73: This PR modifies the package.json file, which is also updated in the main PR. Both PRs involve changes to dependencies, specifically the removal of certain packages and updates to others, indicating a related focus on dependency management.
  • Apply updates from core #81: This PR also updates the package.json file, including a version increment that aligns with the version change in the main PR. The changes in both PRs reflect updates to dependencies and overall project structure.

Suggested reviewers

  • Vritra4: Suggested for review due to familiarity with the codebase and recent changes.

🐰 In the land of code, where rabbits play,
Formatting changes brighten the day.
Semicolons gone, imports refined,
With Ledger's departure, new paths aligned.
Dependencies trimmed, our project takes flight,
Hopping towards clarity, everything feels right! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4733e0a and f593173.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • package.json (1 hunks)
  • src/client/WebSocketClient.ts (4 hunks)
  • src/key/index.ts (0 hunks)
  • src/key/ledger/LedgerKey.ts (0 hunks)
  • src/key/ledger/app.ts (0 hunks)
  • src/key/ledger/constants.ts (0 hunks)
  • src/key/ledger/device.ts (0 hunks)
  • src/key/ledger/index.ts (0 hunks)
  • src/key/ledger/types.ts (0 hunks)
  • vite.config.ts (0 hunks)
💤 Files with no reviewable changes (8)
  • src/key/index.ts
  • src/key/ledger/LedgerKey.ts
  • src/key/ledger/app.ts
  • src/key/ledger/constants.ts
  • src/key/ledger/device.ts
  • src/key/ledger/index.ts
  • src/key/ledger/types.ts
  • vite.config.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/client/WebSocketClient.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 8, 2024

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ✅ 0 package(s) with unknown licenses.
  • ⚠️ 1 packages with OpenSSF Scorecard issues.
See the Details below.

OpenSSF Scorecard

PackageVersionScoreDetails
npm/elliptic 6.5.7 ⚠️ 2.1
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/29 approved changesets -- score normalized to 2
Maintained🟢 44 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Signed-Releases⚠️ -1no releases found
Token-Permissions⚠️ -1No tokens found
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow⚠️ -1no workflows found
Packaging⚠️ -1packaging workflow not detected
License⚠️ 0license file not detected
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Pinned-Dependencies⚠️ -1no dependencies found
Security-Policy⚠️ 0security policy file not detected
Fuzzing⚠️ 0project is not fuzzed
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
Vulnerabilities⚠️ 041 existing vulnerabilities detected
npm/eventemitter3 ^5.0.1 🟢 4
Details
CheckScoreReason
Code-Review⚠️ 1GitHub code reviews found for 3 commits out of the last 30 -- score normalized to 1
Maintained⚠️ 23 commit(s) out of 30 and 0 issue activity out of 30 found in the last 90 days -- score normalized to 2
CII-Best-Practices⚠️ 0no badge detected
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Token-Permissions⚠️ 0non read-only tokens detected in GitHub workflows
Packaging⚠️ -1no published package detected
License🟢 10license file detected
Pinned-Dependencies🟢 7dependency not pinned by hash detected -- score normalized to 7
Vulnerabilities🟢 10no vulnerabilities detected
Dependency-Update-Tool⚠️ 0no update tool detected
Signed-Releases⚠️ -1no releases found
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Fuzzing⚠️ 0project is not fuzzed
Security-Policy⚠️ 0security policy file not detected

Scanned Manifest Files

package-lock.json
package.json
  • eventemitter3@^5.0.1
  • @ledgerhq/hw-transport@^6.27.12
  • @ledgerhq/hw-transport-webhid@^6.27.12
  • @ledgerhq/hw-transport-webusb@^6.27.12
  • crypto-browserify@^3.12.0
  • process@^0.11.10
  • stream-browserify@^3.0.0
  • ts-loader@^9.4.1
  • tsconfig-paths-webpack-plugin@^4.0.0
  • webpack@^5.94.0
  • webpack-bundle-analyzer@^4.6.1
  • webpack-cli@^4.10.0

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: 15

🧹 Outside diff range and nitpick comments (43)
src/client/lcd/api/ForwardingAPI.ts (1)

42-43: LGTM! Minor improvement in parseInt usage.

The change from parseInt to Number.parseInt is a slight improvement in code clarity. Both functions behave identically in modern JavaScript/TypeScript environments, but Number.parseInt is more explicit about being a method of the Number object. This change maintains the existing functionality while potentially improving code readability.

Consider adding a radix parameter (e.g., Number.parseInt(d.num_of_accounts, 10)) to explicitly specify base 10, which is a good practice to ensure consistent behavior across all environments.

src/core/celestia/BlobTx.ts (1)

45-47: LGTM! Consider updating the constructor parameter name for consistency.

The changes in the fromProto method look good and align with the PR objectives:

  1. Using Tx.fromBytes(data.tx) instead of Tx.fromBuffer(Buffer.from(data.tx)) is consistent with the goal of replacing Buffer with Uint8Array.
  2. The change from type_id to typeId in the parameter reference improves naming consistency.

For complete consistency, consider updating the constructor parameter name from type_id to typeId. This would align with the naming convention used in the fromProto method. Here's the suggested change:

  constructor(
    public tx: Tx,
    public blobs: Blob[],
-   public type_id: string
+   public typeId: string
  ) {
    super()
  }

Don't forget to update any references to this.type_id in other methods of the class if you make this change.

src/client/lcd/api/TendermintAPI.spec.ts (1)

15-15: LGTM: Replaced Buffer.from with bytesFromBase64

The bytesFromBase64 function is correctly used to decode the transaction bytes, replacing the previous Buffer.from method. This change aligns with the PR objective of replacing Buffer with Uint8Array for better compatibility.

Consider adding a comment explaining the purpose of this decoding step for improved readability:

// Decode base64-encoded transaction bytes to Uint8Array
const txProto = Tx_pb.decode(bytesFromBase64(txBytes))
src/client/lcd/api/OpchildAPI.ts (1)

Update Remaining parseInt Instances to Number.parseInt

While many instances have been updated to use Number.parseInt, there are still some occurrences of the global parseInt function, such as in src/util/polyfill.ts. For consistency and to avoid potential scope issues, please update all remaining instances to Number.parseInt.

  • src/util/polyfill.ts: (hex.match(/.{1,2}/g) ?? []).map((byte) => parseInt(byte, 16))
🔗 Analysis chain

Line range hint 1-74: Consider updating all instances of parseInt in the codebase

The changes made to use Number.parseInt instead of parseInt in this file are good improvements. For consistency, it might be beneficial to update all instances of parseInt across the entire codebase to use Number.parseInt.

To identify other instances of parseInt usage in the codebase, you can run the following command:

This will help ensure consistent usage of Number.parseInt throughout the project.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for remaining instances of parseInt in TypeScript files
rg 'parseInt\(' --type ts

Length of output: 19835

src/core/ibc/core/client/Height.ts (1)

36-37: Approve the change to Number.parseInt with a minor suggestion.

The switch from parseInt to Number.parseInt is a good change. It makes the code more explicit and less prone to confusion with the global parseInt function.

For consistency, consider applying this change throughout the codebase, including in the fromData method of this class.

Here's a suggestion for the fromData method:

  public static fromData(data: Height.Data): Height {
    const { revision_number, revision_height } = data
    return new Height(
-     parseInt(revision_number),
-     parseInt(revision_height)
+     Number.parseInt(revision_number),
+     Number.parseInt(revision_height)
    )
  }
src/core/ophost/msgs/MsgRecordBatch.ts (2)

72-72: Approved: Effective use of polyfill function

The replacement of Buffer.from(data.batchBytes).toString('base64') with base64FromBytes(data.batchBytes) is an excellent change. It aligns with the PR objective and simplifies the code.

Consider adding a null check for data.batchBytes to handle potential undefined values gracefully:

base64FromBytes(data.batchBytes ?? new Uint8Array())

This ensures that the function always receives a valid input, even if data.batchBytes is undefined.


81-81: Approved: Consistent use of polyfill function with null check

The replacement of Buffer.from(batch_bytes, 'base64') with bytesFromBase64(batch_bytes) is excellent. The null check is a good practice to handle potential undefined values.

For consistency with the fromProto method, consider using a default empty Uint8Array:

batchBytes: bytesFromBase64(batch_bytes ?? ''),

This approach ensures that batchBytes is always a Uint8Array, maintaining consistency with the fromProto method and potentially simplifying type handling in the proto message.

src/core/tx/SignDoc.ts (2)

67-68: LGTM: Successful replacement of Buffer with base64FromBytes

The changes in the toData method successfully replace the Node.js-specific Buffer usage with the more compatible base64FromBytes function. This modification aligns well with the PR's objective and improves cross-platform compatibility.

For consistency, consider using template literals for the entire return object:

return {
  body_bytes: base64FromBytes(tx_body.toBytes()),
  auth_info_bytes: base64FromBytes(auth_info.toBytes()),
  account_number: `${account_number}`,
  chain_id,
};

This change would make the account_number conversion consistent with the new base64 conversions, using template literals instead of the toFixed() method.


Buffer usage detected in multiple TypeScript files

The verification identified remaining instances of Buffer usage in the following files:

  • src/util/polyfill.ts
  • src/key/ledger/app.ts
  • src/key/ledger/device.ts
  • src/key/ledger/LedgerKey.ts

Please review these instances to ensure they align with the PR's objective of removing Node.js-specific dependencies and enhancing cross-platform compatibility.

🔗 Analysis chain

Line range hint 1-124: Overall assessment: Changes successfully implement PR objectives

The modifications in this file successfully replace the Node.js-specific Buffer usage with the more compatible base64FromBytes function. These changes align well with the PR's objective of enhancing compatibility and maintain the existing functionality of the SignDoc class. The implementation is clean and consistent with the rest of the codebase.

To ensure that all Buffer usages have been replaced in the codebase, run the following verification script:

This script will help identify any remaining Buffer usages that may need to be addressed in other parts of the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Buffer usages in the codebase

# Test: Search for Buffer usages. Expect: No results or only in comments/strings
rg --type typescript 'Buffer\.' -C 3

Length of output: 73


Script:

#!/bin/bash
# Description: Check for any remaining Buffer usages in TypeScript files

# Test: Search for Buffer usages in .ts files. Expect: No results or only in comments/strings
rg 'Buffer\.' -g '*.ts' -C 3

Length of output: 7931

src/core/wasm/msgs/MsgExecuteContract.ts (2)

71-71: LGTM: Appropriate use of polyfill function

The replacement of Buffer.from(data.msg).toString('base64') with base64FromBytes(data.msg) is a good change. It aligns with the PR objective and should improve cross-platform compatibility.

Consider adding error handling to account for potential invalid input:

base64FromBytes(data.msg ?? new Uint8Array())

This ensures that even if data.msg is undefined or null, the function won't throw an error.


81-81: LGTM: Appropriate use of polyfill function

The replacement of Buffer.from(msg, 'base64') with bytesFromBase64(msg) is a good change. It aligns with the PR objective and should improve cross-platform compatibility.

Consider adding error handling to account for potential invalid input:

bytesFromBase64(msg || '')

This ensures that even if msg is undefined or null, the function won't throw an error.

src/core/ibc/core/channel/msgs/MsgChannelOpenConfirm.ts (1)

Incomplete Buffer Replacement Detected

The verification process identified multiple instances of Buffer usage that were not addressed in the recent changes. To maintain consistency and achieve the PR's objectives, please ensure that all Buffer usages are replaced accordingly.

Affected Files:

  • src/util/polyfill.ts
  • src/key/ledger/app.ts
  • src/key/ledger/device.ts
  • Numerous files within src/core/ and its subdirectories.
🔗 Analysis chain

Line range hint 1-114: Summary: Successful implementation of Buffer replacement

The changes in this file consistently replace Buffer usage with new utility functions for base64 encoding and decoding. This aligns well with the PR objective of enhancing compatibility and performance. The existing interface and functionality are maintained while improving the internal handling of base64 data.

To ensure consistency across the project, it would be beneficial to verify similar changes in other files. You can use the following script to check for any remaining Buffer usages:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining Buffer usages in TypeScript files

# Search for Buffer usages in TypeScript files
echo "Searching for remaining Buffer usages:"
rg --type typescript 'Buffer\.' -g '!node_modules'

# Search for files that might need similar changes
echo "Files that might need similar changes:"
rg --type typescript -l 'base64' -g '!node_modules'

Length of output: 348


Script:

#!/bin/bash
# Description: Check for remaining Buffer usages in TypeScript files

# Search for Buffer usages in .ts files
echo "Searching for remaining Buffer usages:"
rg 'Buffer\.' -g '*.ts' --ignore-dir node_modules

# Search for files that might need similar changes by looking for 'base64'
echo "Files that might need similar changes:"
rg 'base64' -g '*.ts' --ignore-dir node_modules

Length of output: 1159


Script:

#!/bin/bash
# Description: Check for remaining Buffer usages in TypeScript files

# Search for Buffer usages in .ts files, excluding node_modules
echo "Searching for remaining Buffer usages:"
rg 'Buffer\.' -g '*.ts' -g '!node_modules/**'

# Search for files that might need similar changes by looking for 'base64', excluding node_modules
echo "Files that might need similar changes:"
rg 'base64' -g '*.ts' -g '!node_modules/**'

Length of output: 18555

src/core/wasm/msgs/MsgMigrateContract.ts (2)

80-80: LGTM: Successful replacement of Buffer with base64FromBytes.

The change effectively replaces the Buffer usage with the new base64FromBytes utility function, aligning with the PR objectives. This should improve cross-platform compatibility.

For improved clarity, consider adding a comment explaining the purpose of this conversion:

// Convert binary message data to base64 string
base64FromBytes(data.msg)

90-90: LGTM: Successful replacement of Buffer with bytesFromBase64.

The change effectively replaces the Buffer usage with the new bytesFromBase64 utility function, aligning with the PR objectives. This should improve cross-platform compatibility.

For improved clarity, consider adding a comment explaining the purpose of this conversion:

// Convert base64 string message to binary data
msg: bytesFromBase64(msg),
src/core/ibc/core/channel/msgs/MsgRecvAcknowledgement.ts (1)

79-80: LGTM: Replaced Buffer usage with bytesFromBase64 utility

The changes in the toProto method effectively replace the use of Buffer with the bytesFromBase64 utility function. This modification aligns with the PR objective and enhances cross-platform compatibility while maintaining the method's functionality.

Consider updating the property name proof_acked to proofAcked for consistency with the proto object property name. This would improve code readability and maintain a consistent naming convention throughout the class.

src/core/bech32.spec.ts (1)

25-25: LGTM: Replaced Buffer with bytesFromUtf8.

The change from Buffer.from('foobar', 'utf8') to bytesFromUtf8('foobar') is correct and aligns with the PR objective. This modification enhances cross-platform compatibility.

Consider extracting the string 'foobar' into a constant at the top of the file, as it's used multiple times in the tests. This would improve maintainability:

const TEST_STRING = 'foobar';
// Then use it like this:
const words = bech32.toWords(bytesFromUtf8(TEST_STRING));
src/core/ibc/core/client/msgs/tendermint/crypto.ts (2)

14-21: LGTM: Consistent naming convention applied.

The renaming of leafHash to leaf_hash improves consistency with snake_case naming conventions often used in protobuf definitions. This change is correctly reflected in both the constructor parameter and the public property declaration.

Consider updating the JSDoc comment to reflect the new parameter name:

 /**
  * @param total
  * @param index
- * @param leaf_hash
+ * @param leaf_hash
  * @param aunts
  */

130-131: LGTM: Consistent use of new utility functions for base64 conversions.

The changes in the PublicKey class methods (fromProto and toProto) are consistent with the modifications made in the Proof class. The use of base64FromBytes and bytesFromBase64 for converting ed25519 and secp256k1 aligns with the PR objective of replacing Buffer with Uint8Array.

For consistency with the Proof class implementation, consider using the nullish coalescing operator (??) instead of the ternary operator:

- ed25519: ed25519 ? bytesFromBase64(ed25519) : undefined,
- secp256k1: secp256k1 ? bytesFromBase64(secp256k1) : undefined,
+ ed25519: bytesFromBase64(ed25519 ?? ''),
+ secp256k1: bytesFromBase64(secp256k1 ?? ''),

This change would make the code more concise and consistent with the Proof class implementation.

Also applies to: 138-139

src/util/polyfill.spec.ts (2)

43-81: LGTM: Hex tests are well-structured and comprehensive.

The hex tests cover essential scenarios:

  1. Converting hex string to Uint8Array
  2. Handling empty hex strings
  3. Converting Uint8Array to hex string
  4. Handling empty Uint8Array

The test data and expected results are correct, ensuring robust coverage of the hex utility functions.

Consider updating the comment on line 65 to remove the reference to Buffer:

- // Converts a hex string to a Uint8Array using Buffer when available
+ // Converts a Uint8Array to a hex string

83-121: LGTM: UTF-8 tests are well-structured and comprehensive.

The UTF-8 tests cover essential scenarios:

  1. Converting UTF-8 string to Uint8Array
  2. Handling empty UTF-8 strings
  3. Converting Uint8Array to UTF-8 string
  4. Handling empty Uint8Array

The test data and expected results are correct, ensuring robust coverage of the UTF-8 utility functions.

Consider updating the comment on line 105 to remove the reference to Buffer:

- // Converts a utf8 string to a Uint8Array using Buffer when available
+ // Converts a Uint8Array to a UTF-8 string
src/core/ibc/core/channel/msgs/MsgChannelOpenAck.ts (1)

Line range hint 1-150: Overall assessment: Changes look good and align with PR objectives.

The modifications in this file consistently replace Buffer usage with the new utility functions base64FromBytes and bytesFromBase64. These changes should improve compatibility across different JavaScript environments and potentially enhance performance, as intended by the PR objectives.

To ensure full compatibility, consider adding unit tests that cover these changes, especially focusing on edge cases for base64 encoding and decoding.

Would you like assistance in generating unit tests for the updated MsgChannelOpenAck class?

src/core/ophost/msgs/MsgProposeOutput.ts (1)

95-95: LGTM with a minor suggestion: Use of base64FromBytes in fromProto method

The replacement of Buffer.from(data.outputRoot).toString('base64') with base64FromBytes(data.outputRoot) is consistent with the PR objective and improves cross-environment compatibility.

Consider handling the case where data.outputRoot might be undefined:

base64FromBytes(data.outputRoot ?? new Uint8Array())

This ensures that the function always receives a valid input, even if data.outputRoot is undefined.

src/core/ibc/core/channel/msgs/MsgChannelOpenTry.ts (3)

95-95: LGTM: Replaced Buffer usage with polyfill utility.

The change from Buffer.from(proto.proofInit).toString('base64') to base64FromBytes(proto.proofInit) successfully replaces the Buffer usage with the new polyfill utility function. This aligns with the PR objective and maintains the same functionality.

Consider adding a comment explaining the purpose of this conversion for better code readability:

// Convert proof_init from Uint8Array to base64 string
base64FromBytes(proto.proofInit),

116-116: LGTM: Replaced Buffer usage with polyfill utility.

The change from Buffer.from(proof_init, 'base64') to bytesFromBase64(proof_init) successfully replaces the Buffer usage with the new polyfill utility function. This aligns with the PR objective and maintains the same functionality.

Consider adding a comment explaining the purpose of this conversion for better code readability:

// Convert proof_init from base64 string to Uint8Array
proofInit: bytesFromBase64(proof_init),

Line range hint 1-164: Overall implementation looks good.

The changes in this file consistently replace Buffer usage with polyfill utilities, aligning well with the PR objectives. The modifications improve compatibility and potentially enhance performance without altering the core functionality. The implementation is correct and consistent throughout the file.

Consider adding a brief comment at the top of the file explaining the transition from Buffer to Uint8Array and the use of polyfill utilities. This would provide context for future developers working on this code.

src/core/move/msgs/MsgExecute.ts (2)

87-87: Approved: Consistent use of polyfill function

The change from Buffer.from(arg).toString('base64') to base64FromBytes is consistent with the PR objective and the new import. This modification enhances compatibility by removing the dependency on Node.js Buffer.

For improved clarity, consider adding a comment explaining the purpose of this transformation:

data.args.map(base64FromBytes) // Convert byte arrays to base64 strings

106-106: Approved: Consistent use of polyfill function

The change from args.map((arg) => Buffer.from(arg, 'base64')) to args.map(bytesFromBase64) is consistent with the PR objective and the new import. This modification enhances compatibility by removing the dependency on Node.js Buffer.

For improved clarity, consider adding a comment explaining the purpose of this transformation:

args: args.map(bytesFromBase64), // Convert base64 strings to byte arrays
src/core/wasm/msgs/MsgInstantiateContract.ts (1)

114-114: LGTM: Improved base64 encoding in toProto method

The use of bytesFromBase64(msg) simplifies the encoding process and aligns with the PR objective of replacing Buffer operations. This change enhances code consistency with the fromProto method.

For consistency with the class property name, consider renaming the destructured variable:

-const { sender, admin, code_id, label, msg, funds } = this
+const { sender, admin, code_id, label, msg: msgBase64, funds } = this

Then use msgBase64 in the bytesFromBase64 call:

-msg: bytesFromBase64(msg),
+msg: bytesFromBase64(msgBase64),

This change would make it clearer that we're working with a base64-encoded string.

src/core/wasm/msgs/MsgStoreAndMigrateContract.ts (2)

2-2: LGTM! Consider grouping related imports.

The addition of base64FromBytes and bytesFromBase64 imports aligns with the PR objective of replacing Buffer with Uint8Array for improved compatibility and performance.

Consider grouping related imports together. You could move this import statement next to other utility imports for better organization.


Line range hint 1-164: Overall assessment: Changes align with PR objectives, but clarification needed.

The modifications in this file successfully replace Buffer usage with new utility functions for base64 encoding/decoding, aligning with the PR's goal of enhancing compatibility and potentially improving performance. The changes are applied consistently throughout the file.

However, there's a discrepancy between the AI-generated summary and the visible changes regarding method signature updates for fromProto and toProto. This inconsistency needs to be addressed to ensure accuracy in the PR description and to verify if any additional changes are required.

Please review the comments above, address the suggestions, and clarify the status of the method signature changes mentioned in the AI summary.

src/core/wasm/msgs/MsgInstantiateContractV2.ts (2)

114-116: LGTM: Successful replacement of Buffer with base64FromBytes

The changes in the fromProto method successfully replace the Buffer usage with the new base64FromBytes function, aligning with the PR objective. This maintains the same functionality while improving compatibility.

Consider adding a comment explaining the base64 conversion for future maintainers:

// Convert binary data to base64 string
base64FromBytes(data.msg),
// ...
base64FromBytes(data.salt),

128-130: LGTM: Successful replacement of Buffer with bytesFromBase64

The changes in the toProto method successfully replace the Buffer usage with the new bytesFromBase64 function, aligning with the PR objective. This maintains the same functionality while improving compatibility.

Consider adding a comment explaining the base64 conversion for future maintainers:

// Convert base64 string to binary data
msg: bytesFromBase64(msg),
// ...
salt: bytesFromBase64(salt),
src/client/lcd/api/OphostAPI.ts (1)

167-167: LGTM: Improved parsing method, consider specifying radix.

The change from parseInt(d.next_l1_sequence) to Number.parseInt(d.next_l1_sequence) is a good improvement. It uses the more explicit Number.parseInt() method, which is the preferred approach in modern JavaScript.

For even better clarity and to prevent potential issues with different string formats, consider specifying the radix:

Number.parseInt(d.next_l1_sequence, 10)

This ensures the string is always parsed as a base-10 number.

src/core/ophost/BridgeConfig.ts (3)

142-142: LGTM: Replaced Buffer with polyfill function.

The change from Buffer.from(data.metadata).toString('base64') to base64FromBytes(data.metadata) successfully replaces the Buffer usage with the new polyfill function, aligning with the PR objective.

For improved clarity, consider adding a comment explaining the purpose of this conversion:

metadata: base64FromBytes(data.metadata) // Convert metadata from Uint8Array to base64 string

166-166: LGTM: Replaced Buffer with polyfill function.

The change from Buffer.from(metadata, 'base64') to bytesFromBase64(metadata) successfully replaces the Buffer usage with the new polyfill function, aligning with the PR objective. The null-check logic is correctly maintained.

For consistency with the fromProto method, consider adding a comment explaining the purpose of this conversion:

metadata: metadata ? bytesFromBase64(metadata) : undefined, // Convert metadata from base64 string to Uint8Array if it exists

Line range hint 1-201: Summary: Successfully replaced Buffer with polyfill functions.

The changes in this file consistently replace Buffer usage with polyfill functions (base64FromBytes and bytesFromBase64). This aligns well with the PR objective of replacing Buffer with Uint8Array, improving compatibility across different JavaScript environments.

The implementation is correct and consistent throughout the file, maintaining the existing logic while enhancing cross-platform compatibility. These changes should improve the portability of the code without introducing any functional changes.

Consider adding unit tests to verify that the serialization and deserialization processes using these new polyfill functions produce the same results as the previous Buffer-based implementation. This will ensure that the changes haven't introduced any subtle differences in behavior.

src/core/PublicKey.ts (2)

1-21: LGTM! Consider grouping related imports.

The changes to import statements and constant definitions align well with the PR objective of replacing Buffer with Uint8Array. The use of bytesFromHex for constant definitions is consistent with this approach.

Consider grouping related imports together for better readability. For example:

import { bech32 } from 'bech32'
import { sha256, ripemd160 } from '../util/hash'
import { JSONSerializable } from '../util/json'
import {
  bytesFromBase64,
  bytesFromHex,
  base64FromBytes,
  concatBytes,
} from '../util/polyfill'

import { LegacyAminoPubKey as LegacyAminoPubKey_pb } from '@initia/initia.proto/cosmos/crypto/multisig/keys'
import { PubKey as PubKey_pb } from '@initia/initia.proto/cosmos/crypto/secp256k1/keys'
import { PubKey as ValConsPubKey_pb } from '@initia/initia.proto/cosmos/crypto/ed25519/keys'
import { Any } from '@initia/initia.proto/google/protobuf/any'

Line range hint 1-377: Overall assessment: Excellent refactoring to replace Buffer with Uint8Array

The changes in this file consistently replace Buffer with Uint8Array-based utilities, aligning perfectly with the PR objective. Key improvements include:

  1. Consistent use of bytesFromBase64, base64FromBytes, and concatBytes utilities.
  2. Updated method signatures with return types, enhancing type safety.
  3. Maintained functionality while modernizing the codebase.

These changes should improve compatibility and potentially performance, as stated in the PR objectives. The code is now more consistent and easier to maintain.

Consider adding unit tests to verify that the behavior of these methods remains unchanged after the refactoring, especially for edge cases involving different types of input data.

src/core/ibc/core/client/msgs/tendermint/types.ts (2)

2-5: Approve import changes and note potential impact.

The addition of base64FromBytes and bytesFromBase64 imports aligns with the PR objective of replacing Buffer with Uint8Array. This change may have a widespread impact on the codebase, potentially improving cross-platform compatibility.

Consider reviewing other parts of the codebase that may still be using Buffer for similar operations to ensure consistency across the project.


Line range hint 1-739: Summary of changes and their impact.

This PR introduces two main changes to the types.ts file:

  1. Consistent renaming of properties from camelCase to snake_case across all classes.
  2. Replacement of Buffer with new utility functions (base64FromBytes and bytesFromBase64) for base64 encoding/decoding.

These changes align with the PR objective of replacing Buffer with Uint8Array and improve consistency in the codebase. The new naming convention may enhance readability for developers familiar with Python-style naming.

Key points to consider:

  • The changes may impact other parts of the codebase that rely on these types.
  • Performance implications of the new base64 handling should be verified.
  • Thorough testing is crucial to ensure no functionality has been broken.

Consider updating the project's coding guidelines to reflect the new naming convention and base64 handling approach. This will ensure future contributions maintain consistency with these changes.

src/util/polyfill.ts (2)

1-1: Consider minimizing the use of ESLint disable directives

Using extensive eslint-disable directives reduces the effectiveness of linting. Instead of disabling multiple rules for the entire file, consider addressing the underlying issues or disabling rules for specific lines where necessary to maintain code quality.


28-107: Add unit tests for the newly introduced utility functions

Comprehensive unit tests will ensure that the utility functions behave as expected across different environments and edge cases. This is especially important given the environment-specific code paths.

Would you like assistance in creating the unit tests for these functions?

src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts (1)

2-2: Replace Node.js 'Buffer' with utility functions for broader compatibility

Importing base64FromBytes and bytesFromBase64 from ../../../util/polyfill replaces the use of Node.js Buffer, enhancing compatibility with environments where Buffer is unavailable, such as browsers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f90dad3 and 4733e0a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (82)
  • README.md (8 hunks)
  • package.json (1 hunks)
  • src/client/WebSocketClient.ts (4 hunks)
  • src/client/lcd/LCDClient.ts (1 hunks)
  • src/client/lcd/api/FeeGrantAPI.spec.ts (1 hunks)
  • src/client/lcd/api/ForwardingAPI.ts (1 hunks)
  • src/client/lcd/api/GovAPI.spec.ts (1 hunks)
  • src/client/lcd/api/IbcAPI.spec.ts (2 hunks)
  • src/client/lcd/api/IbcTransferAPI.spec.ts (1 hunks)
  • src/client/lcd/api/OpchildAPI.ts (1 hunks)
  • src/client/lcd/api/OphostAPI.ts (3 hunks)
  • src/client/lcd/api/TendermintAPI.spec.ts (2 hunks)
  • src/client/lcd/api/TxAPI.ts (2 hunks)
  • src/core/PublicKey.ts (5 hunks)
  • src/core/auction/AuctionParams.ts (3 hunks)
  • src/core/auction/msgs/MsgAuctionBid.ts (3 hunks)
  • src/core/bank/msgs/MsgMultiSend.ts (3 hunks)
  • src/core/bech32.spec.ts (5 hunks)
  • src/core/bech32.ts (3 hunks)
  • src/core/celestia/Blob.ts (3 hunks)
  • src/core/celestia/BlobTx.ts (1 hunks)
  • src/core/celestia/msgs/MsgPayForBlobs.ts (3 hunks)
  • src/core/ibc/core/channel/Packet.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgChannelCloseConfirm.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgChannelOpenAck.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgChannelOpenConfirm.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgChannelOpenTry.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgRecvAcknowledgement.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgRecvPacket.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgTimeout.ts (3 hunks)
  • src/core/ibc/core/channel/msgs/MsgTimeoutClose.ts (3 hunks)
  • src/core/ibc/core/client/Height.ts (1 hunks)
  • src/core/ibc/core/client/msgs/MsgUpgradeClient.ts (3 hunks)
  • src/core/ibc/core/client/msgs/tendermint/crypto.ts (5 hunks)
  • src/core/ibc/core/client/msgs/tendermint/types.ts (19 hunks)
  • src/core/ibc/core/commitment/MerklePrefix.ts (2 hunks)
  • src/core/ibc/core/commitment/MerkleRoot.ts (2 hunks)
  • src/core/ibc/core/connection/msgs/MsgConnectionOpenAck.ts (3 hunks)
  • src/core/ibc/core/connection/msgs/MsgConnectionOpenConfirm.ts (3 hunks)
  • src/core/ibc/core/connection/msgs/MsgConnectionOpenTry.ts (4 hunks)
  • src/core/move/msgs/MsgExecute.ts (3 hunks)
  • src/core/move/msgs/MsgGovExecute.ts (3 hunks)
  • src/core/move/msgs/MsgGovPublish.ts (3 hunks)
  • src/core/move/msgs/MsgGovScript.ts (3 hunks)
  • src/core/move/msgs/MsgGovScriptJSON.ts (3 hunks)
  • src/core/move/msgs/MsgPublish.ts (3 hunks)
  • src/core/move/msgs/MsgScript.ts (2 hunks)
  • src/core/move/msgs/MsgScriptJSON.ts (3 hunks)
  • src/core/opchild/msgs/MsgFinalizeTokenDeposit.ts (3 hunks)
  • src/core/opchild/msgs/MsgUpdateOracle.ts (3 hunks)
  • src/core/ophost/BridgeConfig.ts (3 hunks)
  • src/core/ophost/Output.ts (3 hunks)
  • src/core/ophost/msgs/MsgFinalizeTokenWithdrawal.ts (3 hunks)
  • src/core/ophost/msgs/MsgInitiateTokenDeposit.ts (3 hunks)
  • src/core/ophost/msgs/MsgProposeOutput.ts (3 hunks)
  • src/core/ophost/msgs/MsgRecordBatch.ts (3 hunks)
  • src/core/ophost/msgs/MsgUpdateMetadata.ts (3 hunks)
  • src/core/params/proposals/ParameterChangeProposal.ts (1 hunks)
  • src/core/slashing/SlashingParams.ts (3 hunks)
  • src/core/tx/CompactBitArray.ts (4 hunks)
  • src/core/tx/SignDoc.ts (2 hunks)
  • src/core/tx/SignatureV2.ts (2 hunks)
  • src/core/tx/Tx.ts (3 hunks)
  • src/core/wasm/authorizations/AcceptedMessagesFilter.ts (2 hunks)
  • src/core/wasm/authorizations/CodeGrant.ts (3 hunks)
  • src/core/wasm/msgs/MsgExecuteContract.ts (3 hunks)
  • src/core/wasm/msgs/MsgInstantiateContract.ts (3 hunks)
  • src/core/wasm/msgs/MsgInstantiateContractV2.ts (3 hunks)
  • src/core/wasm/msgs/MsgMigrateContract.ts (3 hunks)
  • src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts (3 hunks)
  • src/core/wasm/msgs/MsgStoreAndMigrateContract.ts (3 hunks)
  • src/core/wasm/msgs/MsgStoreCode.ts (3 hunks)
  • src/core/wasm/msgs/MsgSudoContract.ts (3 hunks)
  • src/key/Key.ts (6 hunks)
  • src/key/MnemonicKey.ts (3 hunks)
  • src/key/RawKey.ts (2 hunks)
  • src/key/ledger/app.ts (1 hunks)
  • src/util/bcs.ts (2 hunks)
  • src/util/hash.ts (0 hunks)
  • src/util/index.ts (1 hunks)
  • src/util/polyfill.spec.ts (1 hunks)
  • src/util/polyfill.ts (1 hunks)
⛔ Files not processed due to max files limit (1)
  • webpack.config.js
💤 Files with no reviewable changes (1)
  • src/util/hash.ts
✅ Files skipped from review due to trivial changes (9)
  • src/client/WebSocketClient.ts
  • src/client/lcd/LCDClient.ts
  • src/client/lcd/api/FeeGrantAPI.spec.ts
  • src/client/lcd/api/GovAPI.spec.ts
  • src/client/lcd/api/IbcAPI.spec.ts
  • src/client/lcd/api/IbcTransferAPI.spec.ts
  • src/core/bank/msgs/MsgMultiSend.ts
  • src/core/params/proposals/ParameterChangeProposal.ts
  • src/key/ledger/app.ts
🧰 Additional context used
🪛 Markdownlint
README.md

106-106: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


120-120: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)


134-134: Expected: dash; Actual: asterisk
Unordered list style

(MD004, ul-style)

🔇 Additional comments (235)
src/util/index.ts (1)

4-4: LGTM! The new export enhances utility accessibility.

The addition of export * from './polyfill' is consistent with the existing export pattern and aligns with the PR objective of replacing the Buffer class with Uint8Array. This change makes the polyfill utilities accessible to other parts of the codebase that import from this index file.

To ensure the change doesn't introduce any unintended side effects, please verify that all imports referencing this utility index are still valid. You can run the following script to check for any potential issues:

This script will help identify any potential conflicts or redundancies in imports across the codebase.

✅ Verification successful

Verification Successful: No Issues Detected

The shell scripts confirmed that all imports from the util module and util/polyfill are intact and not broken by the new export. No unintended side effects were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for imports of the util module and verify they're not broken by the new export

# Search for imports from the util module
rg --type typescript --type javascript "from ['\"].*?/util['\"]" -g '!**/node_modules/**'

# Check for any direct imports of polyfill that might now be redundant
rg --type typescript --type javascript "from ['\"].*?/util/polyfill['\"]" -g '!**/node_modules/**'

Length of output: 270


Script:

#!/bin/bash
# Description: Check for imports of the util module and verify they're not broken by the new export

# Search for imports from the util module
rg --type ts --type js "from ['\"].*?/util['\"]" -g '!**/node_modules/**'

# Check for any direct imports of polyfill that might now be redundant
rg --type ts --type js "from ['\"].*?/util/polyfill['\"]" -g '!**/node_modules/**'

Length of output: 6989

src/client/lcd/api/ForwardingAPI.ts (1)

Line range hint 1-45: Overall, the changes and file structure look good.

The modifications to use Number.parseInt are a minor improvement in code clarity. The file is well-structured, uses TypeScript features effectively, and maintains clear separation of concerns. The suggestions for adding error handling and specifying the radix parameter should further enhance the code's robustness and reliability.

src/core/ibc/core/commitment/MerkleRoot.ts (4)

3-3: LGTM: New utility functions imported for base64 operations.

The addition of base64FromBytes and bytesFromBase64 from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances cross-platform compatibility.


40-40: LGTM: Improved base64 encoding in fromProto method.

The use of base64FromBytes instead of Buffer.from(...).toString('base64') enhances cross-platform compatibility and aligns with the PR objective. The functionality remains unchanged while simplifying the code.


45-45: LGTM: Improved base64 decoding in toProto method.

The use of bytesFromBase64 instead of Buffer.from(..., 'base64') enhances cross-platform compatibility and aligns with the PR objective. The functionality remains unchanged while simplifying the code.


Line range hint 1-58: Verify the impact of changes across the codebase.

While the public interface of the MerkleRoot class remains unchanged, the internal implementation of fromProto and toProto methods has been modified. To ensure the changes don't introduce any unintended side effects:

  1. Verify that the new utility functions (base64FromBytes and bytesFromBase64) provide identical results to the previous Buffer-based implementation.
  2. Update any tests that were expecting Buffer objects to work with the new Uint8Array-based implementation.
  3. Check for any code that might be directly accessing the hash property and ensure it's compatible with the base64 string format.

To help with verification, you can run the following script:

src/key/RawKey.ts (7)

5-5: LGTM: Import statement updated correctly.

The new import for base64FromBytes and bytesFromHex from '../util' is consistent with the changes in the class implementation, replacing Buffer operations with these utility functions.


15-15: LGTM: Property type updated to Uint8Array.

The change from Buffer to Uint8Array for the privateKey property is consistent with the PR objective and aligns with modern JavaScript practices. This update improves cross-platform compatibility.


17-21: LGTM: Constructor updated to use Uint8Array.

The constructor has been correctly updated to accept a Uint8Array instead of a Buffer. The publicKey creation and super call remain unchanged, maintaining the existing functionality. The privateKey assignment is now direct, eliminating the need for type conversion.


26-26: LGTM: fromHex method updated to use bytesFromHex.

The fromHex method has been correctly updated to use bytesFromHex instead of Buffer.from. This change is consistent with the transition from Buffer to Uint8Array and maintains the existing hex string validation.


30-33: LGTM: sign method updated to use Uint8Array.

The sign method has been correctly updated to accept and return Uint8Array instead of Buffer. The hash creation now uses bytesFromHex, which is consistent with the move away from Buffer. The signature is returned directly as a Uint8Array, eliminating unnecessary type conversion.


37-43: LGTM: signWithKeccak256 method updated to use Uint8Array.

The signWithKeccak256 method has been correctly updated to accept and return Uint8Array instead of Buffer. The keccak256 hash is now used directly without conversion to Buffer, and the signature is returned as a Uint8Array, eliminating unnecessary type conversions.


Line range hint 1-45: Summary: Successful transition from Buffer to Uint8Array

The changes in this file successfully replace all instances of Buffer with Uint8Array, achieving the PR objective. This transition improves cross-platform compatibility and aligns the code with modern JavaScript practices. The modifications are consistent across the entire class, including property types, method signatures, and internal implementations. No issues or potential bugs were identified during the review.

Key improvements:

  1. Enhanced compatibility by using Uint8Array instead of Node.js-specific Buffer.
  2. Consistent use of utility functions (bytesFromHex, base64FromBytes) for type conversions.
  3. Simplified code by removing unnecessary type conversions.

These changes contribute to a more robust and portable implementation of the RawKey class.

src/core/ibc/core/commitment/MerklePrefix.ts (4)

3-3: LGTM: New import statement for polyfill functions.

The addition of this import statement aligns with the PR objective of replacing Buffer operations with polyfill functions for base64 encoding and decoding.


49-49: LGTM: Replaced Buffer with polyfill function in fromProto method.

The change successfully replaces the Buffer operation with the base64FromBytes polyfill function, maintaining the same functionality of converting keyPrefix from bytes to a base64 string.


55-55: LGTM: Replaced Buffer with polyfill function in toProto method.

The change successfully replaces the Buffer operation with the bytesFromBase64 polyfill function, maintaining the same functionality of converting key_prefix from a base64 string to bytes.


Line range hint 1-70: Overall: Excellent implementation of Buffer replacement.

The changes in this file consistently replace Buffer operations with polyfill functions for base64 encoding and decoding. This aligns perfectly with the PR objective of replacing Buffer with Uint8Array for improved compatibility and performance. The functionality of the MerklePrefix class remains unchanged, and the implementation is consistent throughout the file.

src/client/lcd/api/TendermintAPI.spec.ts (2)

4-4: LGTM: New import statement for bytesFromBase64

The import statement for bytesFromBase64 from the polyfill utility is correctly added. This aligns with the PR objective of replacing Buffer with Uint8Array for better compatibility.


Line range hint 11-19: Verify test results after Buffer replacement

The changes to replace Buffer.from with bytesFromBase64 are minimal and focused, which is good. However, it's crucial to ensure that this modification doesn't alter the behavior of the "load block and decode txs" test case.

Please run the test suite and confirm that all tests, especially this modified one, still pass successfully. You can use the following command to run the tests:

If any issues are found, please investigate and address them before merging this PR.

src/core/celestia/Blob.ts (4)

2-2: LGTM: New utility functions imported for base64 operations.

The addition of base64FromBytes and bytesFromBase64 from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances cross-platform compatibility.


51-52: LGTM: Buffer replaced with base64FromBytes in fromProto method.

The use of base64FromBytes instead of Buffer operations improves cross-platform compatibility and aligns with the PR objectives. The functionality remains the same, but the code is now more consistent with the polyfill approach.


61-62: LGTM: Buffer replaced with bytesFromBase64 in toProto method.

The use of bytesFromBase64 instead of Buffer operations improves cross-platform compatibility and aligns with the PR objectives. This change maintains symmetry with the fromProto method, ensuring consistent encoding and decoding operations throughout the class.


Line range hint 1-85: Overall assessment: Excellent refactoring to improve compatibility.

The changes in this file successfully replace Buffer operations with polyfill utility functions (base64FromBytes and bytesFromBase64). This refactoring enhances cross-platform compatibility without altering the Blob class's functionality. The code remains clear and maintainable, with consistent use of the new utility functions in both fromProto and toProto methods.

These modifications align perfectly with the PR objective of replacing the Buffer class with Uint8Array-based operations. Great job on improving the codebase's portability!

src/key/MnemonicKey.ts (3)

53-56: LGTM: Improved code example consistency

The removal of semicolons from the code example improves consistency with the rest of the codebase and enhances readability.


62-63: LGTM: Consistent code example formatting

The removal of semicolons in this code example maintains the consistency established in the previous example.


77-77: Approve Uint8Array usage, but clarify sync method choice

The change to wrap privateKey in Uint8Array.from() is a good improvement. It ensures type consistency and aligns with the PR objective of replacing Buffer with Uint8Array.

However, I noticed that bip39.mnemonicToSeedSync is now used instead of an async version. While this makes the constructor synchronous and potentially improves performance, it could block the main thread for large mnemonics.

Could you please clarify the rationale behind switching to the sync version? Are there any performance benchmarks or specific use cases that prompted this change?

To verify the impact of this change, we can run the following script to check for any async usage of MnemonicKey in the codebase:

This will help us understand if the switch to a synchronous constructor might cause issues in existing async contexts.

Also applies to: 86-86

src/client/lcd/api/OpchildAPI.ts (2)

46-46: Approve the use of Number.parseInt

The change from parseInt to Number.parseInt is a good improvement. It makes the code more explicit and robust, especially in environments where the global parseInt function might have been modified. This change maintains the same functionality while slightly enhancing code quality.


54-54: Approve consistent use of Number.parseInt

This change mirrors the improvement made in the nextL1Sequence method. Using Number.parseInt here maintains consistency throughout the class and brings the same benefits of explicitness and robustness.

src/core/wasm/authorizations/AcceptedMessagesFilter.ts (2)

2-2: LGTM: New import for base64 utility functions.

The addition of base64FromBytes and bytesFromBytes imports from the polyfill utility aligns with the PR objective of replacing Buffer usage. This change promotes better compatibility and consistency across different environments.


44-44: LGTM: Replaced Buffer usage with base64FromBytes utility.

The change effectively replaces the Buffer-based base64 decoding with the new base64FromBytes utility function. This modification aligns with the PR objective of removing Buffer dependencies, potentially improving cross-platform compatibility and performance.

src/core/wasm/authorizations/CodeGrant.ts (4)

2-2: LGTM: Import statement for polyfill functions.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill module aligns with the PR objective of replacing Buffer with Uint8Array. This change supports the modifications in the fromProto and toProto methods.


56-56: LGTM: Replaced Buffer usage with polyfill function in fromProto.

The change from Buffer.from(data.codeHash).toString('base64') to base64FromBytes(data.codeHash) successfully replaces the Buffer usage with the imported polyfill function. This modification maintains the same functionality while aligning with the PR objective.


66-66: LGTM: Replaced Buffer usage with polyfill function in toProto.

The change from Buffer.from(code_hash, 'base64') to bytesFromBase64(code_hash) successfully replaces the Buffer usage with the imported polyfill function. This modification maintains the same functionality while aligning with the PR objective.


2-2: Summary: Successful replacement of Buffer with polyfill functions.

The changes in this file consistently replace Buffer usage with the newly imported polyfill functions base64FromBytes and bytesFromBase64. These modifications:

  1. Align with the PR objective of replacing Buffer with Uint8Array.
  2. Maintain the original functionality of base64 encoding and decoding.
  3. Improve cross-platform compatibility by using polyfills instead of Node.js-specific Buffer class.

The implementation is consistent throughout the file and achieves the intended goal without introducing any apparent issues.

Also applies to: 56-56, 66-66

package.json (4)

Line range hint 3-3: Version update looks good.

The package version has been updated to "0.2.17". This change follows semantic versioning principles, which is a good practice for managing package releases.


59-59: Repositioning of vite-plugin-dts is fine.

The vite-plugin-dts dependency has been moved to the end of the devDependencies list. This change doesn't affect the functionality and is likely due to automatic sorting or a preference for organizing dependencies.


Line range hint 1-91: Summary of package.json changes

The changes to package.json align with the PR objectives and seem to modernize the build process:

  1. The package version has been updated to "0.2.17".
  2. Several webpack-related devDependencies have been removed, suggesting a shift towards using Vite for building.
  3. The vite-plugin-dts dependency has been repositioned within the devDependencies list.

These changes appear to be part of a larger effort to update the project's build process and potentially improve performance. The removal of the Buffer-related dependencies aligns with the stated goal of replacing Buffer with Uint8Array.

To ensure a smooth transition:

  1. Verify that the build process works correctly with the new configuration.
  2. Update any development workflows or CI/CD pipelines that might have depended on the removed webpack-related tools.
  3. Test the package thoroughly to ensure that the removal of these dependencies hasn't introduced any unexpected issues.

59-59: Verify build process after removing webpack-related dependencies.

The removal of webpack-related dependencies (ts-loader, tsconfig-paths-webpack-plugin, webpack, webpack-bundle-analyzer, and webpack-cli) suggests a shift in the build process, possibly towards using Vite. This aligns with the PR objective of replacing Buffer with Uint8Array and modernizing the codebase.

Please ensure that:

  1. The build process still works as expected without these dependencies.
  2. All necessary build steps are now handled by Vite or other remaining tools.
  3. The development workflow and any CI/CD pipelines are updated to reflect these changes.

To verify the build process, you can run:

src/core/wasm/msgs/MsgSudoContract.ts (3)

2-2: LGTM: New import for base64 utility functions.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility module is consistent with the PR objective of replacing Buffer with Uint8Array. This change promotes better cross-platform compatibility.


63-63: LGTM: Replaced Buffer usage with polyfill function.

The change from Buffer.from(data.msg).toString('base64') to base64FromBytes(data.msg) successfully eliminates the use of the Node.js-specific Buffer class. This modification enhances cross-platform compatibility while maintaining the same functionality of converting the message data to a base64 string.


72-72: LGTM: Replaced Buffer usage with polyfill function.

The change from Buffer.from(msg, 'base64') to bytesFromBase64(msg) successfully eliminates the use of the Node.js-specific Buffer class. This modification enhances cross-platform compatibility while maintaining the same functionality of converting the base64 string back to bytes.

src/core/opchild/msgs/MsgUpdateOracle.ts (4)

2-2: LGTM: New import aligns with PR objectives

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility module aligns well with the PR objective of replacing Buffer with Uint8Array. This change supports the goal of enhancing compatibility and performance within the codebase.


68-68: LGTM: Simplified base64 encoding

The use of base64FromBytes(data.data) simplifies the code by directly converting the input to base64 without explicitly using Buffer. This change enhances readability and aligns with the PR's goal of replacing Buffer usage.


77-77: LGTM: Simplified base64 decoding

The use of bytesFromBase64(data) simplifies the code by directly converting the base64 input to bytes without explicitly using Buffer. This change improves code clarity and aligns with the PR's objective of replacing Buffer usage.


Line range hint 1-114: Overall: Successful replacement of Buffer with polyfill utilities

The changes in this file successfully replace Buffer usage with the new polyfill utility functions for base64 encoding and decoding. This aligns perfectly with the PR objectives of enhancing compatibility and potentially improving performance. The modifications maintain the overall structure and functionality of the MsgUpdateOracle class while simplifying the code.

To fully validate the impact of these changes:

  1. Ensure that the new polyfill functions (base64FromBytes and bytesFromBase64) are thoroughly tested for correctness and edge cases.
  2. Consider running performance benchmarks to verify any potential performance improvements, especially for large data sets.

To verify the implementation of the polyfill functions, you can run the following script:

src/core/ibc/core/channel/msgs/MsgRecvPacket.ts (4)

2-2: LGTM: Import polyfill functions for base64 encoding/decoding

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change provides the necessary functionality for base64 encoding and decoding without relying on the Node.js Buffer class.


64-64: LGTM: Update base64 encoding in fromProto method

The change from Buffer to base64FromBytes for encoding proofCommitment is correct and consistent with the PR objective. This modification maintains the method's functionality while removing the dependency on the Node.js Buffer class.


74-74: LGTM: Update base64 decoding in toProto method

The change from Buffer to bytesFromBase64 for decoding proof_commitment is correct and consistent with the PR objective. This modification maintains the method's functionality while removing the dependency on the Node.js Buffer class.


Line range hint 1-105: Overall assessment: Changes successfully implement Buffer replacement

The modifications in this file successfully replace the usage of the Node.js Buffer class with Uint8Array-based polyfill functions for base64 encoding and decoding. The changes are consistent throughout the file and maintain the functionality and backwards compatibility of the MsgRecvPacket class. These updates align well with the PR objective of enhancing compatibility and performance.

src/core/ophost/msgs/MsgRecordBatch.ts (2)

2-2: Excellent addition of polyfill utilities

The import of base64FromBytes and bytesFromBase64 from the polyfill utility module aligns well with the PR objective of replacing the Buffer class. This change promotes better code organization and enhances compatibility across different environments.


Line range hint 1-114: Overall approval: Successful implementation of Buffer replacement

The changes in this file successfully replace the usage of the Buffer class with polyfill functions, aligning perfectly with the PR objective. Key points:

  1. Consistent use of base64FromBytes and bytesFromBase64 functions.
  2. Localized changes to fromProto and toProto methods, minimizing potential side effects.
  3. Improved cross-platform compatibility by reducing dependency on Node.js-specific APIs.
  4. Maintained functionality while simplifying the code.

These modifications contribute to a more portable and maintainable codebase. Great job on implementing these changes consistently and effectively!

src/core/auction/msgs/MsgAuctionBid.ts (4)

2-2: LGTM: Import of polyfill functions for base64 operations

This import aligns with the PR objective of replacing Buffer with Uint8Array. The base64FromBytes and bytesFromBase64 functions are likely polyfills that provide consistent base64 encoding and decoding operations across different environments.


64-64: LGTM: Simplified base64 encoding in fromProto method

This change replaces the previous Buffer-based implementation with the new base64FromBytes function. It simplifies the code and makes it more consistent with the PR objective of replacing Buffer usage. The use of map ensures that all transactions are properly encoded.


73-73: LGTM: Simplified base64 decoding in toProto method

This change replaces the previous Buffer-based implementation with the new bytesFromBase64 function. It simplifies the code and aligns with the PR objective of replacing Buffer usage. The use of map ensures that all transactions are properly decoded when converting to the Proto format.


Line range hint 1-114: Summary: Successful replacement of Buffer with polyfill functions

The changes in this file successfully replace the use of Buffer with new polyfill functions for base64 encoding and decoding. These modifications:

  1. Introduce new imports for base64FromBytes and bytesFromBase64.
  2. Update the fromProto and toProto methods to use these new functions.

These changes align well with the PR objective of replacing the Buffer class with Uint8Array, enhancing compatibility and potentially improving performance. The implementation is consistent throughout the file and maintains the existing functionality while simplifying the code.

src/core/ophost/msgs/MsgUpdateMetadata.ts (4)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility module aligns with the PR objective of replacing Buffer with Uint8Array. These functions will provide the necessary base64 encoding and decoding operations without relying on the Node.js Buffer class, enhancing cross-platform compatibility.


73-73: LGTM: Replaced Buffer usage with new utility function

The change from Buffer.from(data.metadata).toString('base64') to base64FromBytes(data.metadata) successfully eliminates the use of the Buffer class, aligning with the PR objective. This modification enhances cross-platform compatibility and maintains the same functionality using the new utility function. The clear function name also improves code readability.


82-82: LGTM: Consistent replacement of Buffer usage

The change from Buffer.from(metadata, 'base64') to bytesFromBase64(metadata) is consistent with the previous modification in the fromProto method. It successfully removes the Buffer usage, replacing it with the newly imported utility function. This change maintains the desired functionality while improving cross-platform compatibility and code consistency throughout the class.


Line range hint 1-124: Summary: Successful replacement of Buffer with cross-platform utility functions

The changes in this file consistently replace the usage of the Node.js Buffer class with newly imported utility functions (base64FromBytes and bytesFromBase64). These modifications align perfectly with the PR objective of replacing Buffer with Uint8Array-based solutions. The implementation:

  1. Improves cross-platform compatibility
  2. Maintains the same functionality for base64 encoding and decoding
  3. Enhances code readability with clear function names

Overall, these changes contribute positively to the codebase by removing platform-specific dependencies and promoting a more universal approach to handling base64 operations.

src/core/ophost/Output.ts (4)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


72-72: LGTM: Replaced Buffer with base64FromBytes utility

The change from Buffer-based conversion to base64FromBytes(data.outputRoot) aligns with the PR objective of replacing Buffer usage. This modification maintains the same functionality while potentially improving performance and compatibility.


83-83: LGTM: Replaced Buffer with bytesFromBase64 utility

The change from Buffer-based conversion to bytesFromBase64(output_root) is in line with the PR objective of replacing Buffer usage. This modification maintains the same functionality of converting the base64 string back to bytes while potentially improving performance and compatibility.


Line range hint 1-108: Summary: Successfully replaced Buffer with polyfill utilities

The changes in this file consistently replace Buffer usage with the newly imported base64FromBytes and bytesFromBase64 utility functions. These modifications:

  1. Align with the PR objective of replacing the Buffer class with Uint8Array.
  2. Maintain the existing functionality for base64 encoding and decoding.
  3. Potentially improve performance and compatibility.

The implementation is consistent and well-executed across the file.

src/core/move/msgs/MsgPublish.ts (4)

2-2: LGTM: Import statement for polyfill functions added.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer usage. This change enhances compatibility across different JavaScript environments.


55-55: LGTM: Replaced Buffer usage with polyfill function in fromProto.

The modification to use base64FromBytes instead of Buffer.from(code).toString('base64') simplifies the code and removes the dependency on the Node.js-specific Buffer class. This change improves cross-platform compatibility while maintaining the same functionality of converting byte arrays to base64 strings.


64-64: LGTM: Replaced Buffer usage with polyfill function in toProto.

The modification to use bytesFromBase64 instead of Buffer.from(code, 'base64') simplifies the code and removes the dependency on the Node.js-specific Buffer class. This change improves cross-platform compatibility while maintaining the same functionality of converting base64 strings to byte arrays.


2-2: Summary: Successful replacement of Buffer with polyfill functions.

The changes in this file consistently replace Buffer usage with polyfill functions (base64FromBytes and bytesFromBase64). These modifications achieve the following:

  1. Improve cross-platform compatibility by removing Node.js-specific Buffer dependencies.
  2. Maintain the same functionality for base64 encoding and decoding.
  3. Simplify the code by using direct polyfill function calls.

These changes align well with the PR objectives and contribute to making the codebase more portable across different JavaScript environments.

Also applies to: 55-55, 64-64

src/core/move/msgs/MsgScript.ts (4)

2-2: LGTM: New import statement for base64 utility functions.

The import statement for base64FromBytes and bytesFromBase64 from the polyfill utility is correctly added. This import supports the replacement of Buffer usage with these utility functions throughout the file.


56-58: LGTM: Replaced Buffer usage with base64FromBytes utility function.

The changes in the fromProto method successfully replace Buffer usage with the base64FromBytes utility function. This modification aligns with the PR objective of replacing Buffer with Uint8Array and makes the code more concise while maintaining the same functionality.


66-68: LGTM: Replaced Buffer usage with bytesFromBase64 utility function.

The changes in the toProto method successfully replace Buffer usage with the bytesFromBase64 utility function. This modification aligns with the PR objective of replacing Buffer with Uint8Array and makes the code more concise while maintaining the same functionality.


Line range hint 1-134: Summary: Successfully replaced Buffer usage with base64 utility functions.

The changes in this file consistently replace Buffer usage with the new utility functions base64FromBytes and bytesFromBase64. These modifications align with the PR objective of replacing Buffer with Uint8Array and improve code consistency. The changes maintain the existing functionality while making the code more concise and potentially more performant.

Key improvements:

  1. Added import for new utility functions.
  2. Updated fromProto method to use base64FromBytes.
  3. Updated toProto method to use bytesFromBase64.

These changes contribute to better compatibility and performance within the codebase.

src/core/move/msgs/MsgScriptJSON.ts (4)

2-2: LGTM: Import statement for base64 utility functions.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer usage. This change enhances compatibility and maintains consistent coding style.


72-72: LGTM: Improved base64 encoding in fromProto method.

The replacement of Buffer.from(data.codeBytes).toString('base64') with base64FromBytes(data.codeBytes) successfully eliminates the Buffer usage, aligning with the PR objective. This change simplifies the code and potentially improves performance while maintaining the same functionality.


82-82: LGTM: Improved base64 decoding in toProto method.

The replacement of Buffer.from(code_bytes, 'base64') with bytesFromBase64(code_bytes) successfully eliminates the Buffer usage, aligning with the PR objective. This change simplifies the code and potentially improves performance while maintaining the same functionality.


Line range hint 1-124: Overall assessment: Changes successfully implement Buffer replacement.

The modifications in this file consistently replace Buffer usage with polyfill functions for base64 encoding and decoding. These changes align perfectly with the PR objective of enhancing compatibility and performance by replacing the Buffer class with Uint8Array. The existing functionality is maintained, and the code becomes more concise. No further changes are necessary for this file within the current scope of the PR.

src/core/tx/SignDoc.ts (1)

2-2: LGTM: New import aligns with PR objectives

The addition of the base64FromBytes import from the polyfill utility is consistent with the PR's goal of replacing Buffer with Uint8Array. This change supports the transition to a more compatible implementation.

src/core/wasm/msgs/MsgExecuteContract.ts (2)

2-2: LGTM: Appropriate utility functions imported

The addition of base64FromBytes and bytesFromBase64 from the polyfill utility aligns well with the PR objective of replacing the Buffer class. This change should improve cross-platform compatibility and consistency in base64 encoding/decoding operations.


Line range hint 1-118: Overall: Good implementation of Buffer replacement

The changes in this file successfully replace Buffer usage with polyfill utility functions, improving cross-platform compatibility without altering the class's behavior. This aligns well with the PR objective.

To ensure the changes haven't introduced any regressions, please update the relevant unit tests to cover these modifications. Run the following command to check for existing tests:

If tests exist, update them to explicitly check the encoding/decoding with the new polyfill functions. If no tests are found, consider adding new ones to cover this functionality.

src/core/ibc/core/channel/msgs/MsgChannelOpenConfirm.ts (3)

2-2: LGTM: Import of base64 utility functions

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


73-73: LGTM: Updated base64 encoding in fromProto method

The replacement of Buffer usage with base64FromBytes(proto.proofAck) is correct and aligns with the PR objective. This change maintains the existing functionality while improving compatibility and potentially enhancing performance.


84-84: LGTM: Updated base64 decoding in toProto method

The replacement of Buffer usage with bytesFromBase64(proof_ack) is correct and aligns with the PR objective. This change maintains the existing functionality while improving compatibility and potentially enhancing performance.

src/core/ibc/core/connection/msgs/MsgConnectionOpenConfirm.ts (4)

2-2: LGTM: Import of polyfill utilities

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns well with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


69-69: LGTM: Replacement of Buffer with polyfill utility in fromProto

The change from Buffer.from(proto.proofAck).toString('base64') to base64FromBytes(proto.proofAck) successfully replaces the Buffer usage with the new polyfill utility. This modification maintains the same functionality while aligning with the PR's objective.


79-79: LGTM: Replacement of Buffer with polyfill utility in toProto

The change from Buffer.from(proof_ack, 'base64') to bytesFromBase64(proof_ack) successfully replaces the Buffer usage with the new polyfill utility. This modification maintains the same functionality while aligning with the PR's objective.


Line range hint 1-108: Summary: Successful replacement of Buffer with polyfill utilities

The changes in this file consistently replace Buffer usage with new polyfill utilities (base64FromBytes and bytesFromBase64). These modifications:

  1. Align with the PR objective of replacing Buffer with Uint8Array.
  2. Maintain the original functionality of base64 encoding and decoding.
  3. Potentially enhance compatibility and performance.

The changes are well-implemented and consistent throughout the file. No issues or potential improvements were identified.

src/core/wasm/msgs/MsgMigrateContract.ts (2)

2-2: LGTM: Import of base64 utility functions aligns with PR objectives.

The addition of base64FromBytes and bytesFromBase64 from the polyfill utility is consistent with the PR's goal of replacing the Buffer class. This change should enhance compatibility and potentially improve performance.


Line range hint 1-124: Consider updating related tests and documentation.

The changes to fromProto and toProto methods are well-implemented and consistent with the PR objectives. To ensure completeness:

  1. Update any unit tests related to these methods to reflect the new implementation.
  2. Review and update any documentation that might reference the old Buffer-based implementation.

This will help maintain the overall quality and consistency of the codebase.

To assist in identifying related tests and documentation, you can run the following script:

src/core/ibc/core/channel/msgs/MsgChannelCloseConfirm.ts (4)

2-2: LGTM: Import of base64 utility functions

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances cross-platform compatibility.


73-73: LGTM: Updated base64 encoding in fromProto

The replacement of Buffer.from(proto.proofInit).toString('base64') with base64FromBytes(proto.proofInit) is consistent with the PR objective. This change maintains the same functionality while improving cross-platform compatibility.


84-84: LGTM: Updated base64 decoding in toProto

The replacement of Buffer.from(proof_init, 'base64') with bytesFromBase64(proof_init) is consistent with the PR objective. This change maintains the same functionality while improving cross-platform compatibility.


Line range hint 1-114: Summary: Successful replacement of Buffer with cross-platform base64 utilities

The changes in this file consistently replace Buffer usage with new utility functions (base64FromBytes and bytesFromBase64) for base64 encoding and decoding. These modifications align perfectly with the PR objective of enhancing cross-platform compatibility.

Key points:

  1. Import statements have been updated to include the new utility functions.
  2. The fromProto and toProto methods now use these new functions instead of Buffer.
  3. The core functionality of the MsgChannelCloseConfirm class remains unchanged.

These changes should improve the codebase's compatibility across different JavaScript environments while maintaining the existing behavior.

src/core/ibc/core/channel/msgs/MsgRecvAcknowledgement.ts (3)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances cross-platform compatibility and performance.


68-69: LGTM: Replaced Buffer usage with base64FromBytes utility

The changes in the fromProto method effectively replace the use of Buffer with the base64FromBytes utility function. This modification aligns with the PR objective and enhances cross-platform compatibility while maintaining the method's functionality.


Line range hint 1-114: Summary: Successful implementation of Buffer replacement with Uint8Array

The changes in this file successfully replace the use of Buffer with Uint8Array-based utility functions for base64 encoding and decoding operations. This modification enhances cross-platform compatibility and aligns with the PR objectives. The implementation maintains the existing functionality while improving the code's portability.

Key improvements:

  1. Added imports for base64FromBytes and bytesFromBase64 utility functions.
  2. Updated fromProto and toProto methods to use these new utility functions.

These changes contribute to a more consistent and platform-independent codebase.

src/core/ibc/core/channel/msgs/MsgTimeout.ts (4)

2-2: LGTM: Import of polyfill utilities

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change sets the foundation for the subsequent modifications in the file.


81-81: LGTM: Utilization of base64FromBytes in fromProto

The replacement of direct assignment with base64FromBytes(proto.proofUnreceived) effectively implements the PR's objective. This change ensures that the proof_unreceived is properly converted from bytes to a base64 string, maintaining the method's functionality while moving away from Buffer operations.


98-98: LGTM: Utilization of bytesFromBase64 in toProto

The replacement of Buffer.from(proof_unreceived, 'base64') with bytesFromBase64(proof_unreceived) successfully implements the PR's objective. This change ensures that the proof_unreceived is correctly converted from a base64 string to bytes, maintaining the method's functionality while eliminating the use of Buffer operations.


Line range hint 1-124: Summary: Successful implementation of Buffer replacement

The changes in this file effectively implement the PR objective of replacing Buffer operations with Uint8Array-based alternatives. The modifications include:

  1. Importing necessary polyfill utilities.
  2. Updating the fromProto method to use base64FromBytes.
  3. Updating the toProto method to use bytesFromBase64.

These changes maintain the functionality of the MsgTimeout class while enhancing compatibility and potentially improving performance. The implementation is clean, consistent, and aligns well with the project's goals.

src/core/celestia/msgs/MsgPayForBlobs.ts (4)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill module aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


76-78: LGTM: Replaced Buffer usage with polyfill function in fromProto method

The changes in the fromProto method effectively replace Buffer.from(...).toString('base64') with base64FromBytes. This modification:

  1. Removes the dependency on the Node.js Buffer class.
  2. Simplifies the code.
  3. Maintains the same functionality of converting byte arrays to base64 strings.

These changes are in line with the PR objective and improve cross-platform compatibility.


93-95: LGTM: Replaced Buffer usage with polyfill function in toProto method

The modifications in the toProto method effectively replace Buffer.from(..., 'base64') with bytesFromBase64. This change:

  1. Eliminates the dependency on the Node.js Buffer class.
  2. Simplifies the code.
  3. Preserves the same functionality of converting base64 strings to byte arrays.

These alterations align with the PR objective and enhance cross-platform compatibility.


Line range hint 1-124: Summary: Successful replacement of Buffer with polyfill functions

The changes in this file consistently replace Buffer usage with polyfill functions (base64FromBytes and bytesFromBase64) throughout the MsgPayForBlobs class. These modifications:

  1. Achieve the PR objective of replacing Buffer with Uint8Array-based solutions.
  2. Enhance cross-platform compatibility by removing Node.js-specific Buffer dependencies.
  3. Potentially improve performance through the use of specialized polyfill functions.
  4. Maintain the core functionality of the MsgPayForBlobs class.

The changes are well-implemented and align perfectly with the PR's goals. Great job on improving the codebase!

src/core/bech32.spec.ts (4)

8-8: LGTM: New import statement for polyfill function.

The addition of import { bytesFromUtf8 } from '../util/polyfill' is consistent with the PR objective of replacing Buffer with Uint8Array. This import provides the necessary function to convert UTF-8 strings to byte arrays without relying on the Node.js Buffer class.


45-45: LGTM: Consistent use of bytesFromUtf8.

The change from Buffer.from('foobar', 'utf8') to bytesFromUtf8('foobar') is consistent with the previous modification and correctly implements the PR objective.


Line range hint 1-118: Overall assessment: Changes successfully implement PR objective.

The modifications in this file consistently replace Buffer.from('foobar', 'utf8') with bytesFromUtf8('foobar') across all test cases. This change aligns with the PR objective of replacing the Buffer class with a polyfill implementation, likely using Uint8Array.

Key points:

  1. The new import statement for bytesFromUtf8 is correctly added.
  2. All instances of Buffer usage have been replaced with the new polyfill function.
  3. The overall structure and logic of the tests remain unchanged.

These changes should improve cross-platform compatibility while maintaining the same functionality. Consider the suggested improvements in the previous comments to further enhance the code quality.


70-70: LGTM: Consistent use of bytesFromUtf8. Verify polyfill implementation.

The change from Buffer.from('foobar', 'utf8') to bytesFromUtf8('foobar') is consistent with the previous modifications and correctly implements the PR objective.

To ensure the polyfill function behaves identically to the Buffer implementation across all test cases, run the following script:

This script will help verify that the bytesFromUtf8 function produces the same output as Buffer.from for the test string 'foobar'.

src/core/wasm/msgs/MsgStoreCode.ts (4)

2-2: Approve: Import of polyfill utilities enhances compatibility

The addition of base64FromBytes and bytesFromBytes imports from the polyfill utility is a positive change. This aligns with the PR objective of replacing Buffer with Uint8Array, which should improve cross-platform compatibility and reduce dependencies on Node.js-specific APIs.


75-75: Approve: Consistent use of polyfill utility for base64 encoding

The replacement of Buffer.from(data.wasmByteCode).toString('base64') with base64FromBytes(data.wasmByteCode) is a positive change. It's consistent with the PR objective of replacing Buffer usage and utilizes the newly imported polyfill utility. This change enhances code consistency and maintainability.


86-86: Approve: Consistent use of polyfill utility for base64 decoding

The replacement of Buffer.from(wasm_byte_code, 'base64') with bytesFromBase64(wasm_byte_code) is a positive change. It aligns with the PR objective of replacing Buffer usage and utilizes the newly imported polyfill utility. This change enhances code consistency and maintainability across the codebase.


Line range hint 1-124: Overall: Successful replacement of Buffer with polyfill utilities

The changes in this file successfully replace the usage of Node.js Buffer with polyfill utilities for base64 encoding and decoding. This aligns perfectly with the PR objective and should improve cross-platform compatibility. The functionality of the MsgStoreCode class remains unchanged, while the code becomes more consistent and potentially more readable.

While the impact on performance is likely minimal, it might be worth verifying that there's no significant performance regression, especially if these operations are performed frequently.

To ensure there's no significant performance impact, you may want to run the following performance test:

src/core/move/msgs/MsgGovPublish.ts (4)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


77-77: LGTM: Improved base64 encoding in fromProto method

The modification to use base64FromBytes with map is a good improvement. It aligns with the PR objective of replacing Buffer usage, potentially improving cross-platform compatibility and performance. The functionality remains unchanged, converting byte data to base64 strings for each element in codeBytes.


87-87: LGTM: Enhanced base64 decoding in toProto method

The update to use bytesFromBase64 with map is a solid improvement. It successfully removes the Buffer usage, aligning with the PR's goal and potentially enhancing cross-platform compatibility and performance. The core functionality remains intact, converting base64 strings back to byte data for each element in code_bytes.


Line range hint 1-124: Overall: Excellent implementation of Buffer replacement

The changes in this file consistently and effectively implement the PR objective of replacing Buffer with Uint8Array. The modifications to the fromProto and toProto methods, along with the new utility function imports, improve code consistency and potentially enhance cross-platform compatibility and performance. The core functionality of the MsgGovPublish class remains intact, and the changes are well-integrated into the existing codebase.

src/core/move/msgs/MsgGovScript.ts (4)

2-2: LGTM: Import statement for base64 utility functions added.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility is consistent with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and aligns with the overall goal of the pull request.


83-85: LGTM: Replaced Buffer usage with base64 utility functions in fromProto.

The changes in the fromProto method successfully replace the use of Buffer with the new base64FromBytes utility function. This modification is applied consistently to both code_bytes and args, maintaining the method's functionality while improving compatibility and aligning with the PR's objectives.


94-96: LGTM: Replaced Buffer usage with base64 utility functions in toProto.

The modifications in the toProto method successfully replace the use of Buffer with the new bytesFromBase64 utility function. This change is applied consistently to both code_bytes and args, maintaining the method's functionality while improving compatibility. The symmetry between these changes and those in the fromProto method ensures consistency in the serialization and deserialization process, aligning perfectly with the PR's objectives.


Line range hint 1-138: Overall assessment: Changes successfully implement the PR objectives.

The modifications in this file consistently replace the use of Buffer with new base64 utility functions (base64FromBytes and bytesFromBase64). These changes are well-implemented across the MsgGovScript class, particularly in the fromProto and toProto methods. The alterations maintain the class's functionality while improving compatibility, which aligns perfectly with the PR's goal of replacing the Buffer class with Uint8Array.

The consistency and symmetry of the changes in both serialization and deserialization methods ensure that the class's behavior remains intact. No issues or potential improvements were identified during this review.

src/core/ibc/core/client/msgs/tendermint/crypto.ts (5)

36-41: LGTM: Consistent property naming in fromData method.

The renaming of leafHash to leaf_hash in the destructuring assignment is consistent with the changes made in the constructor. The method implementation remains correct, with only the property name being updated.


46-51: LGTM: Consistent property naming in toData method.

The renaming of leafHash to leaf_hash in both the destructuring assignment and the returned object is consistent with the previous changes. The method implementation remains correct, with only the property name being updated.


60-61: LGTM: Improved base64 conversion using new utility function.

The use of base64FromBytes instead of Buffer.from(...).toString('base64') aligns with the PR objective of replacing Buffer with Uint8Array. This change results in a more concise implementation and leverages the imported utility function.

Let's verify that base64FromBytes is used consistently for similar conversions:

#!/bin/bash
# Description: Verify consistent usage of base64FromBytes for conversions from bytes to base64.

# Test: Search for any remaining usage of Buffer.from(...).toString('base64')
rg --type typescript 'Buffer\.from\(.*\)\.toString\(.(base64|ascii|utf8|utf-8|utf16le|ucs2|ucs-2|binary|latin1).\)' src/

# Test: Search for usage of base64FromBytes
rg --type typescript 'base64FromBytes' src/

66-71: LGTM: Improved base64 conversion and consistent property naming.

The changes in this method are twofold and both positive:

  1. The use of bytesFromBase64 instead of Buffer.from(..., 'base64') aligns with the PR objective of replacing Buffer with Uint8Array.
  2. The renaming of leafHash to leaf_hash maintains consistency with previous changes.

These modifications result in a more consistent and modern implementation.

Let's verify that bytesFromBase64 is used consistently for similar conversions:

#!/bin/bash
# Description: Verify consistent usage of bytesFromBase64 for conversions from base64 to bytes.

# Test: Search for any remaining usage of Buffer.from(..., 'base64')
rg --type typescript 'Buffer\.from\(.*,\s*.(base64|ascii|utf8|utf-8|utf16le|ucs2|ucs-2|binary|latin1).\)' src/

# Test: Search for usage of bytesFromBase64
rg --type typescript 'bytesFromBase64' src/

2-5: 💡 Codebase verification

LGTM: New utility functions imported for base64 conversions.

The addition of base64FromBytes and bytesFromBase64 imports aligns with the PR objective of replacing Buffer with Uint8Array. These utility functions are used consistently throughout the file for base64 conversions.

Let's verify the usage of these new imports:

✅ Verification successful

Please verify the usage of the new base64 conversion functions by running the updated shell script below:


LGTM: The new base64 conversion utilities are correctly imported and utilized throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new base64 conversion utility functions.

# Test: Search for usage of base64FromBytes and bytesFromBase64
rg --type typescript 'base64FromBytes|bytesFromBase64' src/

Length of output: 236


Script:

#!/bin/bash
# Description: Verify the usage of new base64 conversion utility functions using specific file extensions.

# Search for usage of base64FromBytes and bytesFromBase64 in .ts and .tsx files
rg 'base64FromBytes|bytesFromBase64' --glob '**/*.ts' --glob '**/*.tsx' src/

Length of output: 24257

src/core/move/msgs/MsgGovScriptJSON.ts (4)

2-2: LGTM: Import of base64 utility functions

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


83-83: LGTM: Replacement of Buffer with base64FromBytes

The change from Buffer.from(data.codeBytes).toString('base64') to base64FromBytes(data.codeBytes) successfully replaces the Buffer usage with the new utility function. This modification aligns with the PR objective and likely improves the efficiency of the base64 encoding process.


94-94: LGTM: Replacement of Buffer with bytesFromBase64

The change from Buffer.from(code_bytes, 'base64') to bytesFromBase64(code_bytes) successfully replaces the Buffer usage with the new utility function. This modification aligns with the PR objective and likely improves the efficiency of the base64 decoding process.


Line range hint 1-138: Summary: Successful replacement of Buffer with base64 utility functions

The changes in this file consistently replace Buffer usage with the newly imported base64FromBytes and bytesFromBase64 utility functions. These modifications align perfectly with the PR objective of replacing Buffer with Uint8Array for improved compatibility and performance.

Key improvements:

  1. Import of specialized base64 utility functions.
  2. Replacement of Buffer in fromProto method for encoding.
  3. Replacement of Buffer in toProto method for decoding.

These changes should result in more efficient base64 encoding and decoding operations while maintaining the existing functionality. The implementation is clean and consistent throughout the file.

src/core/ophost/msgs/MsgInitiateTokenDeposit.ts (4)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances cross-platform compatibility.


93-93: LGTM: Replaced Buffer usage with polyfill utility

The fromProto method now uses base64FromBytes(msgProto.data) instead of Buffer.from(msgProto.data).toString('base64'). This change aligns with the PR objective of replacing Buffer usage and maintains the same functionality of converting binary data to a base64 string.


104-104: LGTM: Replaced Buffer usage with polyfill utility

The toProto method now uses bytesFromBase64(data) instead of Buffer.from(data, 'base64'). This change aligns with the PR objective of replacing Buffer usage and maintains the same functionality of converting a base64 string to binary data.


Line range hint 1-150: Summary: Successfully replaced Buffer with polyfill utilities

The changes in this file successfully replace Buffer usage with polyfill utilities for base64 encoding and decoding. This improves cross-platform compatibility while maintaining the existing functionality. Great job on implementing these changes consistently throughout the file!

To ensure the polyfill implementations provide the same level of functionality and performance as the Buffer class, please run the following verification script:

This script will help verify the implementation of the polyfill utilities and ensure that Buffer is no longer used in this file.

✅ Verification successful

Verification Successful: Polyfill Utilities Implemented and Buffer Usage Eliminated

The polyfill functions base64FromBytes and bytesFromBase64 are correctly implemented in src/util/polyfill.ts. Additionally, there is no usage of Buffer in src/core/ophost/msgs/MsgInitiateTokenDeposit.ts, and no related TODOs or FIXMEs remain.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of base64 polyfill utilities

# Test 1: Check if the polyfill utilities are implemented
echo "Checking polyfill implementation..."
rg --type typescript "export function (base64FromBytes|bytesFromBase64)" src/util/polyfill.ts

# Test 2: Verify that Buffer is not used in this file
echo "Verifying Buffer is not used..."
rg --type typescript "Buffer\." src/core/ophost/msgs/MsgInitiateTokenDeposit.ts

# Test 3: Check for any remaining TODOs or FIXMEs related to this change
echo "Checking for remaining TODOs or FIXMEs..."
rg --type typescript "(TODO|FIXME).*Buffer" src/core/ophost/msgs/MsgInitiateTokenDeposit.ts

Length of output: 623


Script:

#!/bin/bash
# Description: Verify the implementation and usage of base64 polyfill utilities

# Test 1: Check if the polyfill utilities are implemented
echo "Checking polyfill implementation..."
rg --glob '*.ts' "export function (base64FromBytes|bytesFromBase64)" src/util/polyfill.ts

# Test 2: Verify that Buffer is not used in this file
echo "Verifying Buffer is not used..."
rg --glob '*.ts' "Buffer\." src/core/ophost/msgs/MsgInitiateTokenDeposit.ts

# Test 3: Check for any remaining TODOs or FIXMEs related to this change
echo "Checking for remaining TODOs or FIXMEs..."
rg --glob '*.ts' "(TODO|FIXME).*Buffer" src/core/ophost/msgs/MsgInitiateTokenDeposit.ts

Length of output: 624

src/util/polyfill.spec.ts (2)

1-41: LGTM: Imports and base64 tests are well-structured and comprehensive.

The imports align with the PR objectives of replacing Buffer with Uint8Array. The base64 tests cover essential scenarios:

  1. Converting base64 string to Uint8Array
  2. Handling empty base64 strings
  3. Converting Uint8Array to base64 string
  4. Handling empty Uint8Array

The test data and expected results are correct, ensuring robust coverage of the base64 utility functions.


1-121: Overall, excellent test coverage and structure.

This new test file provides comprehensive coverage for the polyfill utility functions, aligning well with the PR objectives of replacing Buffer with Uint8Array. The tests are well-structured, consistent across all three encoding types (base64, hex, and UTF-8), and cover both normal conversions and edge cases.

A few minor suggestions:

  1. Consider adding tests for error cases, such as invalid input strings.
  2. You might want to add a test case for a more complex UTF-8 string containing non-ASCII characters to ensure proper handling of multi-byte characters.

These additions would further strengthen the robustness of your test suite.

src/core/ibc/core/channel/msgs/MsgTimeoutClose.ts (4)

2-2: LGTM: Import of base64 utility functions

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer usage. This change enhances cross-platform compatibility.


87-88: LGTM: Replacement of Buffer with base64FromBytes

The use of base64FromBytes instead of Buffer for proofUnreceived and proofClose is consistent with the PR objective. This change enhances cross-platform compatibility while maintaining the method's functionality.


106-107: LGTM: Replacement of Buffer with bytesFromBase64

The use of bytesFromBase64 instead of Buffer for proofUnreceived and proofClose is consistent with the PR objective and symmetrical to the changes in fromProto. This change enhances cross-platform compatibility while maintaining the method's functionality.


Line range hint 1-150: Overall assessment: Changes successfully implement Buffer replacement

The modifications in this file consistently replace Buffer usage with new utility functions for base64 encoding and decoding. These changes align perfectly with the PR objective of replacing the Buffer class with Uint8Array, enhancing cross-platform compatibility without altering the MsgTimeoutOnClose class's functionality. The implementation is clean and maintains the existing structure of the code.

src/core/ibc/core/client/msgs/MsgUpgradeClient.ts (4)

2-2: LGTM: Import of base64 utility functions aligns with PR objectives.

The addition of base64FromBytes and bytesFromBase64 from the polyfill utility is in line with the PR's goal of replacing Buffer with Uint8Array. This change should enhance compatibility and potentially improve performance.


87-88: LGTM: Improved clarity in proof data conversion.

The use of base64FromBytes for converting proofUpgradeClient and proofUpgradeConsensusState enhances code clarity and aligns with the PR's objective of removing Buffer usage. This change ensures consistent handling of byte array to base64 string conversion.


106-108: LGTM: Consistent approach to base64 decoding.

The use of bytesFromBase64 for converting proof_upgrade_client and proof_upgrade_consensus_state ensures consistency with the PR's objective of removing Buffer usage. This change provides a clear and uniform approach to decoding base64 strings into byte arrays.

The multi-line formatting for the longer property name also improves code readability.


Line range hint 1-141: Overall assessment: Changes successfully implement PR objectives.

The modifications in this file consistently replace Buffer usage with the new utility functions base64FromBytes and bytesFromBase64. These changes:

  1. Enhance compatibility by removing Node.js-specific Buffer usage.
  2. Potentially improve performance through the use of Uint8Array.
  3. Maintain the original functionality of the MsgUpgradeClient class.
  4. Improve code clarity and consistency in handling base64 encoding and decoding.

The changes are well-implemented and align perfectly with the PR's objectives.

src/core/ibc/core/channel/msgs/MsgChannelOpenAck.ts (2)

95-95: LGTM! Verify the base64FromBytes implementation.

The replacement of Buffer.from(proto.proofTry).toString('base64') with base64FromBytes(proto.proofTry) aligns with the PR objective and should improve compatibility and performance.

To ensure the base64FromBytes function is correctly implemented, run the following script:

#!/bin/bash
# Description: Verify the implementation of base64FromBytes function

# Test: Check the implementation of base64FromBytes
rg -t typescript "function base64FromBytes" -A 10 -g "src/**/util/polyfill.ts"

116-116: LGTM! Verify the bytesFromBase64 implementation.

The replacement of Buffer.from(proof_try, 'base64') with bytesFromBase64(proof_try) aligns with the PR objective and should improve compatibility and performance.

To ensure the bytesFromBase64 function is correctly implemented, run the following script:

✅ Verification successful

Verified the bytesFromBase64 implementation.

The bytesFromBase64 function in src/util/polyfill.ts correctly replaces Buffer.from(proof_try, 'base64'), ensuring compatibility and performance improvements as intended by the PR.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of bytesFromBase64 function

# Test: Check the implementation of bytesFromBase64
rg -t typescript "function bytesFromBase64" -A 10 -g "src/**/util/polyfill.ts"

Length of output: 115


Script:

#!/bin/bash
# Description: Verify the implementation of bytesFromBase64 function

# Search for the bytesFromBase64 function in .ts files
rg "function bytesFromBase64" -A 10 -g "*.ts"

Length of output: 598

src/core/ophost/msgs/MsgProposeOutput.ts (3)

2-2: LGTM: Import of polyfill functions

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill module aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility across different JavaScript environments.


107-107: LGTM: Use of bytesFromBase64 in toProto method

The replacement of Buffer.from(output_root, 'base64') with bytesFromBase64(output_root) is consistent with the PR objective and improves cross-environment compatibility. The null check is properly maintained, ensuring that undefined values are handled correctly.


Line range hint 1-150: Summary: Successful replacement of Buffer with polyfill functions

The changes in this file successfully replace the usage of Buffer with polyfill functions base64FromBytes and bytesFromBase64. This aligns well with the PR objective of enhancing compatibility across different JavaScript environments.

Key points:

  1. The new import statement adds the necessary polyfill functions.
  2. Both fromProto and toProto methods have been updated to use these new functions.
  3. The overall functionality of the MsgProposeOutput class remains intact.

These changes improve the code's portability without introducing any apparent issues or regressions. The minor suggestion for handling potential undefined values in the fromProto method is the only point to consider for further improvement.

src/core/ibc/core/channel/msgs/MsgChannelOpenTry.ts (1)

2-2: LGTM: Import of polyfill utilities.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.

src/core/move/msgs/MsgExecute.ts (2)

2-2: Approved: New import aligns with PR objectives

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility is consistent with the PR's goal of replacing Buffer with Uint8Array for improved compatibility.


Line range hint 1-186: Overall assessment: Changes are consistent and align with PR objectives

The modifications in this file successfully replace Buffer usage with polyfill functions, enhancing compatibility as intended. The changes are consistent throughout the file and maintain the original functionality. Minor suggestions for improved clarity through comments have been provided.

src/core/wasm/msgs/MsgInstantiateContract.ts (3)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill module aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and potentially improves performance.


102-102: LGTM: Improved base64 decoding in fromProto method

The use of base64FromBytes(data.msg) simplifies the decoding process and aligns with the PR objective of replacing Buffer operations. This change enhances code readability and potentially improves performance.


Line range hint 1-164: Summary: Successful implementation of Buffer replacement

The changes in this file successfully replace Buffer operations with new polyfill functions for base64 encoding and decoding. These modifications align well with the PR objectives and improve code consistency. The implementation enhances compatibility and potentially improves performance.

Key points:

  1. New utility functions are imported from the polyfill module.
  2. Both fromProto and toProto methods now use these new functions for handling the msg property.
  3. The changes simplify the code by removing buffer manipulations.

Overall, the modifications achieve the intended goal while maintaining the class's functionality.

src/core/ibc/core/channel/Packet.ts (4)

2-2: LGTM: Import changes look good

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility is appropriate for the Buffer replacement changes. The reordering of the Packet import is a minor change that doesn't affect functionality.

Also applies to: 4-4


131-131: LGTM: Buffer replacement in fromProto method

The change from Buffer.from(proto.data).toString('base64') to base64FromBytes(proto.data) aligns with the PR objective of replacing Buffer usage. This new implementation should provide the same functionality.

To ensure the correctness of this change, please verify that base64FromBytes handles the input correctly for all possible data types that proto.data might contain. Consider adding unit tests to cover various scenarios if they don't already exist.


154-154: LGTM: Buffer replacement in toProto method

The change from Buffer.from(data, 'base64') to bytesFromBase64(data) aligns with the PR objective of replacing Buffer usage. This new implementation should provide the same functionality.

To ensure the correctness of this change, please verify that bytesFromBase64 handles the input correctly for all possible values of data. Consider adding unit tests to cover various scenarios if they don't already exist.


Line range hint 1-190: Overall assessment: Changes look good and align with PR objectives

The modifications in this file successfully replace Buffer usage with polyfill functions base64FromBytes and bytesFromBase64. These changes are consistent with the PR's objective of enhancing compatibility and performance.

To ensure the robustness of these changes:

  1. Verify that the new polyfill functions handle all possible input types correctly.
  2. Consider adding or updating unit tests to cover various scenarios for both fromProto and toProto methods.
  3. Ensure that these changes don't introduce any performance regressions, especially for large data sets.
src/core/move/msgs/MsgGovExecute.ts (4)

2-2: LGTM: New utility functions imported for base64 operations

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility across different JavaScript environments.


140-140: LGTM: Replaced Buffer usage with polyfill in fromProto method

The modification in the fromProto method replaces the use of Buffer.from(arg).toString('base64') with the imported base64FromBytes function. This change aligns with the PR objective and improves cross-environment compatibility while maintaining the same functionality.


162-162: LGTM: Replaced Buffer usage with polyfill in toProto method

The modification in the toProto method replaces the use of Buffer.from(arg, 'base64') with the imported bytesFromBase64 function. This change aligns with the PR objective and improves cross-environment compatibility while maintaining the same functionality.


Line range hint 1-205: Overall assessment: Changes successfully implement the PR objectives

The modifications in this file consistently replace Buffer usage with polyfill functions for base64 operations. These changes improve cross-environment compatibility without altering the core functionality of the MsgGovExecute class. The implementation aligns well with the PR objectives of replacing the Buffer class with Uint8Array.

src/core/wasm/msgs/MsgStoreAndMigrateContract.ts (2)

106-111: LGTM! Consistent use of new utility function.

The changes in the fromProto method effectively replace the use of Buffer with the new base64FromBytes utility function. This is applied consistently for both data.wasmByteCode and data.msg, aligning with the PR objective of enhancing compatibility and potentially improving performance.


121-124: LGTM! Consistent use of new utility function.

The changes in the toProto method effectively replace the use of Buffer with the new bytesFromBase64 utility function. This is applied consistently for both wasm_byte_code and msg, maintaining symmetry with the fromProto method and aligning with the PR objective.

src/core/wasm/msgs/MsgInstantiateContractV2.ts (2)

2-2: LGTM: Appropriate import for base64 conversion functions

The addition of this import statement aligns well with the PR objective of replacing Buffer with more compatible alternatives. Importing specific functions (base64FromBytes and bytesFromBase64) is a good practice for maintaining clean and efficient code.


Line range hint 1-180: Overall assessment: Changes successfully implement PR objective

The modifications in this file successfully replace Buffer usage with more compatible alternatives (base64FromBytes and bytesFromBase64). The changes maintain the original functionality of the MsgInstantiateContractV2 class while improving its compatibility and potentially its performance.

Key points:

  1. Appropriate imports have been added.
  2. Both fromProto and toProto methods have been updated consistently.
  3. The changes do not alter the class's public API, ensuring backward compatibility.

To ensure that all Buffer usages have been replaced in this file, you can run the following command:

If this command returns no results, it confirms that all Buffer usages have been successfully replaced.

src/core/auction/AuctionParams.ts (4)

2-2: LGTM: Import statement for polyfill utilities added.

The import of base64FromBytes and bytesFromBase64 from the polyfill utility is consistent with the PR objective of replacing Buffer with Uint8Array. This change supports the implementation of base64 encoding and decoding operations without relying on Node.js-specific APIs.


119-119: LGTM: Buffer replaced with polyfill in fromProto method.

The change from Buffer.from(...).toString('base64') to base64FromBytes(...) aligns with the PR objective. This modification maintains the same functionality while using a platform-agnostic approach, which enhances the portability of the code.


139-139: LGTM: Buffer replaced with polyfill in toProto method.

The change from Buffer.from(..., 'base64') to bytesFromBase64(...) is consistent with the PR objective and the previous change in the fromProto method. This modification ensures that the base64 to bytes conversion is handled in a platform-agnostic manner, improving the code's portability.


Line range hint 1-173: Overall assessment: Changes successfully implement Buffer replacement.

The modifications in this file consistently replace Buffer usage with polyfill utilities for base64 encoding and decoding operations. These changes align well with the PR objectives, maintaining the original functionality while improving cross-platform compatibility. The code structure and readability are preserved, and the implementation appears consistent and error-free.

src/core/tx/SignatureV2.ts (2)

1-1: LGTM: Import statement for bytesFromBase64

The import of bytesFromBase64 from the polyfill utility is consistent with the PR objective of replacing Buffer with Uint8Array. This change supports the goal of enhancing compatibility and performance within the codebase.


106-106: LGTM: Replacement of Buffer with bytesFromBase64

The change from Buffer.from(sigData.signature, 'base64') to bytesFromBase64(sigData.signature) aligns with the PR objective of replacing Buffer with Uint8Array. This modification enhances compatibility and potentially improves performance.

Please verify the following:

  1. Ensure that the return type of the toModeInfoAndSignature method is updated if it has changed from [ModeInfo, Buffer] to [ModeInfo, Uint8Array].
  2. Check for any other uses of Buffer in this file or related files that might need similar updates.

You can use the following script to check for other Buffer usages:

src/util/bcs.ts (3)

3-3: LGTM: New import aligns with PR objectives.

The addition of hexFromBytes and bytesFromHex imports from ./polyfill is in line with the PR's goal of replacing the Buffer class with Uint8Array. This change enhances compatibility and potentially improves performance.


Line range hint 3-24: Summary: Successfully replaced Buffer with polyfill functions.

The changes in this file effectively replace the Node.js Buffer class with polyfill functions (bytesFromHex and hexFromBytes). These modifications align perfectly with the PR's objective of enhancing compatibility and potentially improving performance. The changes are consistent and well-implemented.

Key improvements:

  1. Added import for polyfill functions.
  2. Updated input transformation to use bytesFromHex.
  3. Updated output transformation to use hexFromBytes.

These changes contribute to making the codebase more platform-agnostic and maintainable.


24-24: LGTM: Replaced Buffer with polyfill function in output transformation.

The change from `0x${Buffer.from(val).toString('hex')}` to `0x${hexFromBytes(val)}` is in line with the PR's objective of replacing the Buffer class. This modification improves cross-platform compatibility.

To ensure consistency, let's verify that all Buffer.from(...).toString('hex') calls have been replaced:

#!/bin/bash
# Search for any remaining Buffer.from(...).toString('hex') calls
rg --type typescript "Buffer\.from\(.*\)\.toString\(['|\"]hex['|\"]\)"
src/client/lcd/api/OphostAPI.ts (3)

9-9: LGTM: New import for polyfill utilities.

The addition of bytesFromHex and base64FromBytes imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility and performance.


154-154: LGTM: Replaced Buffer with polyfill utilities.

The change from Buffer.from(withdrawalHash, 'hex').toString('base64') to base64FromBytes(bytesFromHex(withdrawalHash)) successfully replaces the Buffer usage with the new polyfill utilities. This modification maintains the same functionality while improving compatibility and potentially performance.


Line range hint 1-190: Overall assessment: Changes align with PR objectives and improve code quality.

The modifications in this file successfully replace Buffer usage with polyfill utilities, aligning with the PR's main objective. The changes enhance compatibility and potentially improve performance. Additionally, the update to Number.parseInt() improves code consistency and adheres to modern JavaScript best practices.

All changes have been reviewed and approved. The code quality has been improved without introducing any apparent issues or concerns.

src/core/ibc/core/connection/msgs/MsgConnectionOpenAck.ts (4)

2-2: LGTM: Import of polyfill utilities.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility module aligns with the PR objective of replacing Buffer usage. This change enhances cross-platform compatibility.


119-121: LGTM: Consistent replacement of Buffer with base64FromBytes.

The changes in the fromProto method successfully replace Buffer usage with the base64FromBytes utility function for all proof data conversions. This modification aligns with the PR objective and maintains the existing logic while improving cross-platform compatibility.


148-150: LGTM: Consistent replacement of Buffer with bytesFromBase64.

The changes in the toProto method successfully replace Buffer usage with the bytesFromBase64 utility function for all proof data conversions. This modification aligns with the PR objective and maintains the existing logic while improving cross-platform compatibility.


Line range hint 1-190: Summary: Successful replacement of Buffer with polyfill utilities.

The changes in this file consistently replace Buffer usage with the new polyfill utility functions base64FromBytes and bytesFromBase64. These modifications:

  1. Align with the PR objective of replacing the Buffer class with Uint8Array.
  2. Enhance cross-platform compatibility.
  3. Maintain the existing logic and functionality of the MsgConnectionOpenAck class.
  4. Are minimal and focused, reducing the risk of introducing new bugs.

The implementation is clean and consistent throughout the file.

src/core/ophost/BridgeConfig.ts (1)

2-2: LGTM: Import statement for polyfill functions.

The import of base64FromBytes and bytesFromBase64 from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility across different JavaScript environments.

src/core/ibc/core/connection/msgs/MsgConnectionOpenTry.ts (4)

130-132: LGTM! Consistent use of polyfill function.

The replacement of Buffer.from() with base64FromBytes is consistent with the PR objective and the earlier import changes. This modification enhances cross-environment compatibility.


161-163: LGTM! Consider adding tests for the new implementation.

The use of bytesFromBase64 instead of Buffer.from() is consistent with the PR objective and earlier changes. This modification completes the transition away from the Buffer class in this file.

To ensure the new implementation works as expected, please run the following script to check for existing tests or suggest adding new ones:

#!/bin/bash
# Description: Check for tests covering the MsgConnectionOpenTry class and its methods.

# Test: Search for test files related to MsgConnectionOpenTry
fd -e test.ts -e spec.ts MsgConnectionOpenTry

# Test: If test files exist, check for specific test cases for toProto method
rg --type typescript 'describe.*MsgConnectionOpenTry.*toProto' $(fd -e test.ts -e spec.ts MsgConnectionOpenTry)

If no tests are found, consider adding unit tests to verify the correct functioning of the toProto method with the new bytesFromBase64 implementation.


80-82: LGTM! Consider data validation.

The simplification of proof assignments aligns with the PR objective and improves code readability. However, ensure that the input data is properly validated before reaching this point to maintain data integrity.

To verify the data validation, please run the following script:

#!/bin/bash
# Description: Check for data validation of proof fields before they reach the fromData method.

# Test: Search for validation of proof_init, proof_client, and proof_consensus
rg --type typescript -A 5 'proof_init|proof_client|proof_consensus.*validate'

2-2: LGTM! Verify polyfill implementation.

The addition of base64FromBytes and bytesFromBytes from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change enhances compatibility across different JavaScript environments.

To ensure the polyfill functions are correctly implemented, please run the following script:

src/key/Key.ts (7)

14-14: LGTM: New utility functions imported

The new import statement adds necessary utility functions for byte operations, aligning with the PR objective of replacing Buffer with Uint8Array.


91-91: LGTM: Updated createSignatureAmino implementation

The change replaces Buffer operations with new utility functions, maintaining the same logic while aligning with the use of Uint8Array. This is consistent with the PR objective.


120-120: LGTM: Updated createSignature implementation

The change replaces Buffer operations with the new utility function, maintaining the same logic while aligning with the use of Uint8Array. This is consistent with the PR objective.


147-151: LGTM: Updated createSignatureEIP191 implementation

The changes replace Buffer operations with new utility functions and concatBytes, maintaining the same logic while aligning with the use of Uint8Array. This is consistent with the PR objective and improves compatibility.

Also applies to: 160-160


Line range hint 1-214: Overall assessment: Changes are consistent and well-implemented

The modifications in this file successfully replace Buffer with Uint8Array and introduce appropriate utility functions. These changes align perfectly with the PR objective of enhancing compatibility and performance. The consistency in implementation across different methods is commendable.

However, it's crucial to ensure that these changes are reflected throughout the codebase, particularly in areas that interact with the modified methods. Consider running comprehensive tests to verify the integrity of the system after these changes.


38-38: LGTM: Updated method signature for signWithKeccak256

The change from Buffer to Uint8Array aligns with the PR objective. However, ensure that all calls to this method across the codebase have been updated accordingly.

To verify the usage of this method across the codebase, run the following script:

✅ Verification successful

The signWithKeccak256 method is only used within src/key/Key.ts, and all usages are consistent with the updated signature. No additional changes are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to the 'signWithKeccak256' method
rg --type typescript -e '\.signWithKeccak256\s*\(' -A 3

Length of output: 92


Script:

#!/bin/bash
# Search for calls to the 'signWithKeccak256' method using the correct TypeScript file type
rg --type ts -e '\.signWithKeccak256\s*\(' -A 3

Length of output: 213


30-30: LGTM: Updated method signature for sign

The change from Buffer to Uint8Array aligns with the PR objective. However, ensure that all calls to this method across the codebase have been updated accordingly.

To verify the usage of this method across the codebase, run the following script:

✅ Verification successful

Verification Complete: Method signature for sign is consistently updated

All usages of the sign method in src/key/Key.ts align with the updated signature. The this.app.sign call in src/key/ledger/LedgerKey.ts appears to reference a different method and is unaffected by this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to the 'sign' method
rg --type typescript -e '\.sign\s*\(' -A 3

Length of output: 79


Script:

#!/bin/bash
# Search for calls to the 'sign' method
rg --type ts -e '\.sign\s*\(' -A 3

Length of output: 763

src/core/ophost/msgs/MsgFinalizeTokenWithdrawal.ts (4)

2-2: LGTM: Import of base64 utility functions.

The addition of base64FromBytes and bytesFromBase64 imports aligns with the PR objective of replacing Buffer with Uint8Array. These utility functions will be used for base64 encoding and decoding operations throughout the class.


180-187: LGTM: Consistent use of base64FromBytes utility function.

The changes in the fromProto method successfully replace Buffer usage with the new base64FromBytes utility function. This modification:

  1. Aligns with the PR objective of replacing Buffer with Uint8Array.
  2. Improves code consistency across the class.
  3. Maintains the same logic while updating the implementation method.

The changes look good and achieve the intended goal.


210-217: LGTM: Consistent use of bytesFromBase64 utility function.

The changes in the toProto method successfully replace Buffer usage with the new bytesFromBase64 utility function. This modification:

  1. Aligns with the PR objective of replacing Buffer with Uint8Array.
  2. Improves code consistency across the class.
  3. Maintains the same logic while updating the implementation method.

The changes look good and achieve the intended goal.


Line range hint 1-287: Consider updating related tests and documentation.

The changes to MsgFinalizeTokenWithdrawal class look good and consistently implement the replacement of Buffer with Uint8Array using the new utility functions. To ensure completeness:

  1. Please update any unit tests related to this class to reflect the new implementation.
  2. If there's any documentation (e.g., JSDoc comments, README, or separate documentation files) mentioning the use of Buffer in this context, please update it to reflect the new implementation using Uint8Array and the utility functions.

This will help maintain consistency across the codebase and prevent confusion for other developers.

To help verify the test coverage, you can run the following command:

src/core/PublicKey.ts (6)

117-117: LGTM! Consistent with PR objective.

The change from Buffer.from(...).toString('base64') to base64FromBytes is in line with the PR objective of replacing Buffer with Uint8Array-based utilities. The added return type improves type safety.


122-122: LGTM! Consistent with PR objective.

The change from Buffer.from(..., 'base64') to bytesFromBase64 aligns with the PR objective of replacing Buffer with Uint8Array-based utilities. The added return type enhances type safety.


138-138: LGTM! Efficient use of concatBytes.

The change from Buffer.concat to concatBytes is consistent with the PR objective and provides an efficient way to combine Uint8Arrays. This change maintains the functionality while aligning with the new Uint8Array-based approach.


142-143: LGTM! Consistent use of bytesFromBase64.

The change from Buffer.from(..., 'base64') to bytesFromBase64 is in line with the PR objective and provides a consistent way to convert base64 strings to Uint8Array. This change maintains the functionality while aligning with the new Uint8Array-based approach.


325-325: LGTM! Consistent with PR objective.

The change from Buffer.from(...).toString('base64') to base64FromBytes aligns with the PR objective of replacing Buffer with Uint8Array-based utilities. The added return type improves type safety.


330-330: LGTM! Consistent use of bytesFromBase64.

The changes from Buffer.from(..., 'base64') to bytesFromBase64 in both toProto and rawAddress methods are in line with the PR objective. These changes provide a consistent way to convert base64 strings to Uint8Array while maintaining the original functionality.

Also applies to: 350-351

src/client/lcd/api/TxAPI.ts (4)

15-16: LGTM: Import changes align with PR objectives

The updated import for hashToHex and the new imports for base64 conversion functions are in line with the PR's goal of replacing Buffer with Uint8Array. These changes should improve compatibility and performance.


376-376: LGTM: Encode method updated to use polyfill

The encode method has been successfully updated to use the base64FromBytes polyfill function, replacing the previous Buffer-based implementation. This change aligns with the PR's objective and should improve cross-platform compatibility.


384-384: LGTM: Decode method updated to use polyfill

The decode method has been successfully updated to use the bytesFromBase64 polyfill function, replacing the previous Buffer-based implementation. This change is consistent with the PR's objective and should enhance cross-platform compatibility.


Line range hint 1-624: Overall assessment: Changes successfully implement PR objectives

The modifications in this file effectively replace Buffer usage with Uint8Array polyfills in the encode and decode methods. These changes align perfectly with the PR's objective of enhancing compatibility and performance. The public API remains unchanged, ensuring backward compatibility. No new issues or potential bugs were introduced. The implementation is clean and focused.

src/core/ibc/core/client/msgs/tendermint/types.ts (7)

297-301: Approve BlockID class changes.

The renaming of partSetHeader to part_set_header is consistent with the new naming convention applied throughout the file. The changes have been applied consistently across all methods of the BlockID class.

Also applies to: 316-319, 324-327, 334-345


387-387: Approve PartSetHeader class changes.

The updates to base64 handling in the PartSetHeader class, using the new utility functions base64FromBytes and bytesFromBase64, are consistent with changes made throughout the file and align with the PR objective.

Also applies to: 400-400, 407-407


426-432: Approve Commit class changes.

The renaming of blockId to block_id in the Commit class is consistent with the new naming convention applied throughout the file. The changes have been applied consistently across all methods of the Commit class.

Also applies to: 448-452, 458-462, 479-483


507-514: Approve CommitSig class changes.

The renaming of properties and the updates to base64 handling in the CommitSig class are consistent with the changes made throughout the file. These changes adhere to the new naming convention and align with the PR objective of replacing Buffer with Uint8Array.

Also applies to: 541-544, 555-557, 562-569


593-598: Approve ValidatorSet class changes.

The renaming of totalVotingPower to total_voting_power in the ValidatorSet class is consistent with the new naming convention applied throughout the file. The changes have been applied consistently across all methods of the ValidatorSet class.

Also applies to: 622-626, 641-645


667-675: Approve Validator class changes and suggest final verification.

The renaming of properties and the updates to base64 handling in the Validator class are consistent with the changes made throughout the file. These changes adhere to the new naming convention and align with the PR objective of replacing Buffer with Uint8Array.

To ensure all changes have been applied consistently, run the following script:

Also applies to: 690-695, 700-705, 713-726


153-161: Approve base64 handling changes and suggest performance testing.

The replacement of Buffer with base64FromBytes and bytesFromBase64 functions aligns with the PR objective and should improve cross-platform compatibility.

Consider running performance tests to compare the efficiency of the new implementation against the old one:

Also applies to: 188-196

src/core/tx/CompactBitArray.ts (7)

2-2: Imports updated to use polyfill functions

The base64FromBytes and bytesFromBase64 functions are correctly imported from ../../util/polyfill, replacing Node.js Buffer dependencies for base64 operations.


7-7: Updated 'elems' type to 'Uint8Array'

Changing elems type to Uint8Array aligns with the transition from Buffer, enhancing compatibility with browser environments and improving performance.


23-23: Initialized 'elems' with 'Uint8Array'

Replaced Buffer.alloc(num_elems) with new Uint8Array(num_elems), which effectively creates a zero-filled array of the required length.


42-42: Direct element access in 'getIndex' method

Accessing this.elems[i >> 3] directly is appropriate with Uint8Array, simplifying the code by eliminating the need for readUInt8.


86-86: Used 'bytesFromBase64' for base64 decoding

In the fromData method, replacing Buffer.from(data.elems, 'base64') with bytesFromBase64(data.elems) correctly decodes the base64 string into a Uint8Array.


92-92: Used 'base64FromBytes' for base64 encoding

Updated this.elems.toString('base64') to base64FromBytes(this.elems) in the toData method, ensuring proper encoding of Uint8Array to a base64 string without relying on Buffer.


98-98: Simplified 'fromProto' method

Directly assigning proto.elems to elems is appropriate since proto.elems is already a Uint8Array, streamlining the method and removing unnecessary conversions.

src/core/bech32.ts (3)

2-2: Importing polyfill functions enhances compatibility

Great job replacing the Node.js Buffer class with bytesFromHex and hexFromBytes from '../util/polyfill'. This improves cross-platform compatibility and aligns with the PR objectives.


86-88: Consistent use of Uint8Array in toBytes function

Renaming toBuffer to toBytes and changing the return type to Uint8Array aligns with modern JavaScript practices and enhances compatibility. This change is consistent with the PR's objective to replace Buffer usage.


62-62: Verify correctness of address conversion in toHex

The toHex function now converts the bech32 address to a hexadecimal string using hexFromBytes. Ensure that the vals.words correctly represent the original address bytes and that the conversion handles all edge cases appropriately.

To confirm the correctness, you can run the following script to test address conversions:

src/core/opchild/msgs/MsgFinalizeTokenDeposit.ts (2)

2-2: Approved: Replacing Buffer with base64 utility functions

The import of base64FromBytes and bytesFromBase64 from ../../../util/polyfill effectively replaces the use of Buffer, enhancing compatibility and aligning with the pull request objectives.


133-133: Approved: Correct conversion of data using bytesFromBase64

In the toProto method, the use of bytesFromBase64(data) properly replaces the previous Buffer implementation, ensuring data is accurately converted from a base64 string to bytes.

src/core/slashing/SlashingParams.ts (3)

2-2: Importing UTF-8 conversion utilities

The addition of utf8FromBytes and bytesFromUtf8 from '../../util/polyfill' correctly replaces the use of Buffer and enhances compatibility.


110-113: Updated deserialization using UTF-8 conversion

The use of Number.parseFloat(utf8FromBytes(...)) for minSignedPerWindow, slashFractionDoubleSign, and slashFractionDowntime in the fromProto method correctly decodes the byte arrays and parses them as floats. This change aligns with the removal of Buffer usage and ensures proper deserialization.


128-133: Updated serialization using UTF-8 conversion

Serializing min_signed_per_window, slash_fraction_double_sign, and slash_fraction_downtime using bytesFromUtf8 in the toProto method ensures these numerical values are correctly encoded as UTF-8 byte arrays. This modification appropriately replaces the previous Buffer implementation and maintains data integrity during serialization.

src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts (3)

184-184: Utilize base64FromBytes for base64 encoding in fromProto

Replacing Buffer methods with base64FromBytes for encoding data.wasmByteCode, data.msg, and data.codeHash ensures consistent base64 encoding without relying on Node.js-specific features.

Also applies to: 191-191, 195-195


216-216: Use bytesFromBase64 for base64 decoding in toProto

Substituting Buffer methods with bytesFromBase64 for decoding wasm_byte_code, msg, and code_hash maintains functionality while improving cross-platform compatibility.

Also applies to: 221-221, 225-225


Line range hint 2-225: Verify the robustness of base64 utility functions

Ensure that base64FromBytes and bytesFromBase64 correctly handle all edge cases, such as empty inputs, large data arrays, and invalid base64 strings, to prevent potential runtime errors.

src/core/tx/Tx.ts (4)

76-76: LGTM!

The use of base64FromBytes in the fromProto method correctly replaces the Node.js Buffer method, ensuring consistency in base64 encoding throughout the codebase.


84-84: LGTM!

The update to use bytesFromBase64 in the toProto method appropriately handles base64 decoding, aligning with the updated utility functions and removing the dependency on Buffer.


142-142: LGTM!

The use of base64FromBytes in the appendSignatures method ensures consistent base64 encoding of signatures and aligns with the updated encoding practices without relying on Node.js Buffer.


92-92: ⚠️ Potential issue

Update all references to fromBuffer

The static method fromBuffer has been renamed to fromBytes, and the parameter type has changed from Buffer to Uint8Array. Ensure that all references to Tx.fromBuffer in the codebase are updated to Tx.fromBytes to maintain consistency and prevent runtime errors.

Comment on lines 39 to 45
params
)
.then((d) => ({
num_of_accounts: parseInt(d.num_of_accounts),
num_of_forwards: parseInt(d.num_of_forwards),
num_of_accounts: Number.parseInt(d.num_of_accounts),
num_of_forwards: Number.parseInt(d.num_of_forwards),
total_forwarded: Coin.fromData(d.total_forwarded),
}))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding error handling for parsing operations.

While the current implementation works well for valid input, it might be beneficial to add error handling for cases where the parsed strings are not valid numbers. This would make the code more robust and prevent potential runtime errors.

Here's a suggested implementation with error handling:

public async stats(
  channel: string,
  params: APIParams = {}
): Promise<ForwardingStats> {
  return this.c
    .get<ForwardingStats.Data>(
      `/noble/forwarding/v1/stats/${channel}`,
      params
    )
    .then((d) => {
      const num_of_accounts = Number.parseInt(d.num_of_accounts, 10);
      const num_of_forwards = Number.parseInt(d.num_of_forwards, 10);
      
      if (isNaN(num_of_accounts) || isNaN(num_of_forwards)) {
        throw new Error('Invalid data: num_of_accounts or num_of_forwards is not a number');
      }

      return {
        num_of_accounts,
        num_of_forwards,
        total_forwarded: Coin.fromData(d.total_forwarded),
      };
    });
}

This implementation adds checks for NaN values after parsing and throws an error if invalid data is encountered.

}

public toProto(): AcceptedMessagesFilter.Proto {
return AcceptedMessagesFilter_pb.fromPartial({
messages: this.messages.map((msg) => Buffer.from(msg, 'base64')),
messages: this.messages.map(bytesFromBase64),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential issue: Incorrect utility function used for base64 encoding.

While the change aligns with the PR objective of removing Buffer usage, there appears to be a logical error in the implementation. The bytesFromBase64 function is being used where we expect base64 encoding to occur. This is likely to cause incorrect behavior.

Consider replacing bytesFromBase64 with base64FromBytes to maintain the correct encoding direction:

-      messages: this.messages.map(bytesFromBase64),
+      messages: this.messages.map(base64FromBytes),

Please verify if this change maintains the intended functionality of the toProto method.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
messages: this.messages.map(bytesFromBase64),
messages: this.messages.map(base64FromBytes),

@@ -1,4 +1,5 @@
import { JSONSerializable } from '../../../../../util/json'
import { base64FromBytes, bytesFromBase64 } from '../../../../../util/polyfill'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing Export: bytesFromBase64 in Polyfill Utility

The polyfill.ts file correctly exports base64FromBytes, aligning with the PR objective. However, the bytesFromBase64 function is not found among the exports, which may lead to runtime issues where this function is expected.

  • File: src/util/polyfill.ts
    • Missing Export: bytesFromBase64

Please ensure that bytesFromBase64 is properly exported in the polyfill.ts file.

🔗 Analysis chain

LGTM! Verify the import path.

The addition of base64FromBytes and bytesFromBase64 imports from the polyfill utility aligns with the PR objective of replacing Buffer with Uint8Array. This change should improve compatibility and potentially performance.

To ensure the import path is correct, run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the polyfill utility file

# Test: Check if the polyfill utility file exists
fd -p "src/.*util/polyfill.(ts|js)" --exec echo "Polyfill utility file found: {}"

# Test: Verify the exported functions in the polyfill utility
rg -t typescript "export.*(base64FromBytes|bytesFromBase64)" -g "src/**/util/polyfill.ts"

Length of output: 377


Script:

#!/bin/bash
# Description: Verify the existence of the polyfill utility file

# Test: Check if the polyfill utility file exists
fd "src/**/util/polyfill.(ts|js)" --exec echo "Polyfill utility file found: {}"

# Test: Verify the exported functions in the polyfill utility
rg --type=typescript "export.*(base64FromBytes|bytesFromBase64)" -g "src/**/util/polyfill.ts"

Length of output: 212


Script:

#!/bin/bash
# Description: Verify the existence of the polyfill utility file

# Test: Check if the polyfill utility file exists
fd "polyfill.ts" "polyfill.js" src/**/util/ --exec echo "Polyfill utility file found: {}"

# Test: Verify the exported functions in the polyfill utility
rg "export\s+(function\s+base64FromBytes|const\s+bytesFromBase64)" "src/**/util/polyfill.ts" "src/**/util/polyfill.js"

Length of output: 496


Script:

#!/bin/bash
# Description: Verify the existence of the polyfill utility file

# Test: Check if the polyfill utility file exists
fd -e ts -e js "polyfill\.(ts|js)$" src/core/ibc/core/channel/util/ --exec echo "Polyfill utility file found: {}"

# Test: Verify the exported functions in the polyfill utility
rg "export\s+(function\s+base64FromBytes|const\s+bytesFromBase64)" src/core/ibc/core/channel/util/polyfill.ts src/core/ibc/core/channel/util/polyfill.js

Length of output: 555


Script:

#!/bin/bash
# Description: Globally verify the existence of the polyfill utility files and their exports

# Test: Check if any polyfill utility file exists
fd "polyfill\.(ts|js)$" --type f --exec echo "Polyfill utility file found: {}"

# Capture the found files into a variable
polyfill_files=$(fd "polyfill\.(ts|js)$" --type f)

# Check if any polyfill files were found
if [ -z "$polyfill_files" ]; then
  echo "No polyfill utility files found."
  exit 1
fi

# Test: Verify the exported functions in each polyfill utility file
for file in $polyfill_files; do
  echo "Checking exports in $file"
  rg "export\s+(function\s+base64FromBytes|const\s+bytesFromBase64)" "$file"
done

Length of output: 510

@@ -18,9 +19,9 @@ const initiaAddress = (
throw new Error('invalid address')
}

return Buffer.from(val, 'hex')
return bytesFromHex(val)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remaining Buffer.from(..., 'hex') Call Found

One instance of Buffer.from(..., 'hex') remains in src/util/polyfill.ts:

  • return Uint8Array.from(gt.Buffer.from(hex, 'hex'))
🔗 Analysis chain

LGTM: Replaced Buffer with polyfill function.

The change from Buffer.from(val, 'hex') to bytesFromHex(val) aligns with the PR's goal of replacing the Buffer class. This modification enhances cross-platform compatibility.

To ensure consistency, let's verify that all Buffer.from(..., 'hex') calls have been replaced:


Action Required: Verify all instances of Buffer.from(..., 'hex') have been replaced.

The previous search command failed to recognize the typescript file type. Let's retry the search without specifying the file type to ensure all files are scanned:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining Buffer.from(..., 'hex') calls
rg --type typescript "Buffer\.from\(.*,\s*['|\"]hex['|\"]\)"

Length of output: 111


Script:

#!/bin/bash
# Search for any remaining Buffer.from(..., 'hex') calls without specifying file type
rg "Buffer\.from\(.*,\s*['|\"]hex['|\"]\)"

Length of output: 124

Comment on lines +33 to +45
public chain_id: string,
public height: string,
public time: Date | undefined,
public lastBlockId: BlockID | undefined,
public lastCommitHash: string,
public dataHash: string,
public validatorsHash: string,
public nextValidatorsHash: string,
public consensusHash: string,
public appHash: string,
public lastResultsHash: string,
public evidenceHash: string,
public proposerAddress: string
public last_block_id: BlockID | undefined,
public last_commit_hash: string,
public data_hash: string,
public validators_hash: string,
public next_validators_hash: string,
public consensus_hash: string,
public app_hash: string,
public last_results_hash: string,
public evidence_hash: string,
public proposer_address: string
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Property renaming incomplete; old camelCase usages found.

The renaming from camelCase to snake_case is not fully propagated. The old property names are still used in the following files:

  • src/core/ibc/core/client/msgs/tendermint/types.ts
  • src/client/lcd/LCDClient.ts
  • src/client/lcd/Wallet.ts
  • src/core/tx/SignDoc.ts
  • src/key/Key.ts
  • src/client/LocalInitia.ts

Please update these references to use the new snake_case property names to ensure consistency and prevent potential issues.

🔗 Analysis chain

Approve property renaming and suggest verification.

The consistent renaming of properties from camelCase to snake_case improves adherence to a more Python-like naming convention. This change enhances readability for developers familiar with this style.

To ensure this change doesn't break existing code, please run the following script to check for any remaining uses of the old property names:

Also applies to: 62-74, 78-90, 97-109, 113-125, 153-161, 168-180, 184-196

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining uses of the old camelCase property names
rg -t ts 'chainId|lastBlockId|lastCommitHash|dataHash|validatorsHash|nextValidatorsHash|consensusHash|appHash|lastResultsHash|evidenceHash|proposerAddress' src/

Length of output: 3802

Comment on lines +96 to +105
export function concatBytes(arrs: Uint8Array[]): Uint8Array {
if (gt.Buffer) {
return gt.Buffer.concat(arrs)
} else {
return arrs.reduce((acc, arr) => {
const combined = new Uint8Array(acc.length + arr.length)
combined.set(acc)
combined.set(arr, acc.length)
return combined
}, new Uint8Array())
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize array concatenation performance

The current implementation of concatBytes in the absence of gt.Buffer uses repeated array allocations, which can be inefficient for large arrays. Consider precomputing the total length and allocating a single Uint8Array to improve performance.

Refactor the code as follows:

const totalLength = arrs.reduce((sum, arr) => sum + arr.length, 0)
const combined = new Uint8Array(totalLength)
let offset = 0
arrs.forEach((arr) => {
  combined.set(arr, offset)
  offset += arr.length
})
return combined

if (typeof global !== 'undefined') {
return global
}
throw 'Unable to locate global object'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use Error object when throwing exceptions

Throwing a string literal does not provide a stack trace and is less informative. Replace the string with a new Error object to improve error handling and debugging.

Apply this diff to fix the issue:

- throw 'Unable to locate global object'
+ throw new Error('Unable to locate global object')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throw 'Unable to locate global object'
throw new Error('Unable to locate global object')

} else {
const bin: string[] = []
arr.forEach((byte) => {
bin.push(gt.String.fromCharCode(byte))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use String.fromCharCode directly instead of gt.String.fromCharCode

String is a global constructor and doesn't need to be accessed via gt. Using String.fromCharCode improves readability and avoids potential issues if gt.String is undefined.

Apply this diff to simplify the code:

- bin.push(gt.String.fromCharCode(byte))
+ bin.push(String.fromCharCode(byte))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bin.push(gt.String.fromCharCode(byte))
bin.push(String.fromCharCode(byte))

Comment on lines +76 to +81
bech32.toWords(bytesFromHex(hex.padStart(40, '0')))
)
} else {
return bech32.encode(
'init',
bech32.toWords(Buffer.from(hex.padStart(64, '0'), 'hex'))
bech32.toWords(bytesFromHex(hex.padStart(64, '0')))
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor fromHex to eliminate code duplication

The fromHex function contains duplicated logic for handling different hex lengths. Consider refactoring to simplify the code and improve maintainability.

Apply this diff to refactor the function:

 export function fromHex(hexAddress: string): AccAddress {
   const hex = hexAddress.replace(/^0x0+|^0x|^0+(?!x)/, '')
-  if (hex.length <= 40) {
-    return bech32.encode(
-      'init',
-      bech32.toWords(bytesFromHex(hex.padStart(40, '0')))
-    )
-  } else {
-    return bech32.encode(
-      'init',
-      bech32.toWords(bytesFromHex(hex.padStart(64, '0')))
-    )
-  }
+  const paddedHex = hex.padStart(hex.length <= 40 ? 40 : 64, '0')
+  return bech32.encode('init', bech32.toWords(bytesFromHex(paddedHex)))
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bech32.toWords(bytesFromHex(hex.padStart(40, '0')))
)
} else {
return bech32.encode(
'init',
bech32.toWords(Buffer.from(hex.padStart(64, '0'), 'hex'))
bech32.toWords(bytesFromHex(hex.padStart(64, '0')))
const paddedHex = hex.padStart(hex.length <= 40 ? 40 : 64, '0')
return bech32.encode('init', bech32.toWords(bytesFromHex(paddedHex)))
)
}

msgProto.data.length
? Buffer.from(msgProto.data).toString('base64')
: undefined
msgProto.data.length ? base64FromBytes(msgProto.data) : undefined
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle undefined msgProto.data before accessing length

In the fromProto method, the expression msgProto.data.length assumes that msgProto.data is always defined. If msgProto.data is undefined, accessing length will result in a runtime error. Please add a check to ensure msgProto.data is defined before accessing its length property.

Suggested change:

- msgProto.data.length ? base64FromBytes(msgProto.data) : undefined
+ msgProto.data && msgProto.data.length ? base64FromBytes(msgProto.data) : undefined
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
msgProto.data.length ? base64FromBytes(msgProto.data) : undefined
msgProto.data && msgProto.data.length ? base64FromBytes(msgProto.data) : undefined

@joon9823
Copy link
Collaborator Author

closing this as initia.js has many external dependencies that have issues with polyfill

@joon9823 joon9823 closed this Oct 30, 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