Skip to content

Conversation

@hernan-clich
Copy link
Member

@hernan-clich hernan-clich commented Oct 31, 2025

Summary

Added browser-compatible Sui functionality by replacing Node.js-specific dependencies with browser-safe alternatives and creating a new prepareSuiDepositAndCall function for wallet adapter integration.

Key Changes

Browser-Safe Dependencies

  • Replaced bip39@scure/bip39
  • Replaced ethereum-cryptography/hdkey@scure/bip32
  • Moved getAccountData to separate file for better tree-shaking

New Browser-Compatible API

  • Created prepareSuiDepositAndCall - Returns unsigned transaction for browser wallet signing
  • Created suiBrowserOptionsSchema - Browser-friendly options without Ed25519Keypair requirement
  • Exported Sui types - Added ./chains/sui package export for browser imports

Refactored for DRY

  • Extracted shared transaction building logic into buildSuiDepositAndCallTransaction helper
  • Both CLI and browser functions use the same underlying transaction builder
  • Eliminated 60+ lines of code duplication

API Design

CLI (Node.js)

await suiDepositAndCall(params, { signer: Ed25519Keypair, chainId: "103" });

Browser (Wallet Adapters)

const { transaction, client } = await prepareSuiDepositAndCall(params, { chainId: "103" });
const signed = await wallet.signTransaction(transaction);
await client.executeTransactionBlock({ transactionBlock: signed.bytes, signature: signed.signature });

Benefits

  • Browser-safe - No Node.js dependencies, works in all browser environments
  • Wallet agnostic - Compatible with any Sui wallet (Slush, Sui Wallet, Dynamic Labs, etc.)
  • Follows Bitcoin pattern - Toolkit builds unsigned transactions, consumers handle wallet-specific signing
  • Maintainable - Shared transaction builder ensures consistency between CLI and browser APIs

Summary by CodeRabbit

Release Notes

  • New Features

    • Added comprehensive Sui blockchain network integration with full transaction support
    • Introduced browser-compatible transaction signing capabilities for improved accessibility
    • Extended deposit-and-call functionality to support both native SUI and non-native token transfers
  • Dependencies

    • Added cryptographic utility libraries for secure key derivation and management

@hernan-clich hernan-clich requested review from a team as code owners October 31, 2025 16:27
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

📝 Walkthrough

Walkthrough

This pull request adds Sui chain support with browser-based signing capabilities, refactors account data utility functions into a dedicated module, updates all corresponding imports across utility files, and adds BIP32/BIP39 cryptographic dependencies to the package configuration.

Changes

Cohort / File(s) Summary
Package Dependencies
package.json
Added new export entry for Sui chain at "./chains/sui" with distribution paths. Added "@scure/bip32" and "@scure/bip39" (v2.0.1) to both dependencies and devDependencies.
Sui Chain Implementation
src/chains/sui/depositAndCall.ts, src/chains/sui/index.ts
Introduced buildSuiDepositAndCallTransaction internal builder function and new prepareSuiDepositAndCall exported function for browser-based unsigned transaction preparation. Extended logic to handle native vs non-native token transfers, validating signerAddress for non-native tokens. Added new schema imports and browser options type. Re-exported suiBrowserOptionsSchema and suiDepositAndCallParamsSchema.
Sui Schema
src/schemas/sui.ts
Added new suiBrowserOptionsSchema export as a browser-friendly variant omitting Ed25519Keypair requirement while including optional signerAddress.
Account Data Utilities Refactoring
utils/getAccountData.ts
Created new utility module exporting accountExists and getAccountData functions with generic typing for account data retrieval and existence checking.
Account Data Module Cleanup
utils/accounts.ts
Removed public getAccountData function and account data type exports (BitcoinAccountData, EVMAccountData, SolanaAccountData, SuiAccountData, TONAccountData).
Import Path Updates
test/addressResolver.test.ts, utils/addressResolver.ts, utils/bitcoin.command.helpers.ts, utils/evm.command.helpers.ts, utils/solana.commands.helpers.ts, utils/solana.keypair.helpers.ts, utils/ton.command.helpers.ts, utils/zetachain.command.helpers.ts
Updated getAccountData import path from "./accounts" to "./getAccountData" across test and utility files.
Cryptographic Dependencies Update
utils/sui.ts
Replaced mnemonic and key derivation dependencies by switching from bech32/hdkey to @scure/bip32 and @scure/bip39. Updated getAccountData import path to "./getAccountData".

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant prepareSuiDepositAndCall as prepareSuiDepositAndCall
    participant buildSuiDepositAndCallTransaction as buildSuiDepositAndCallTransaction
    participant suiClient as Sui Client

    Browser->>prepareSuiDepositAndCall: Call with options (chainId, signerAddress, etc.)
    prepareSuiDepositAndCall->>prepareSuiDepositAndCall: Validate options against suiBrowserOptionsSchema
    prepareSuiDepositAndCall->>buildSuiDepositAndCallTransaction: Invoke builder with validated options
    
    alt Native SUI Transfer
        buildSuiDepositAndCallTransaction->>buildSuiDepositAndCallTransaction: Process without signerAddress requirement
    else Non-Native Token Transfer
        buildSuiDepositAndCallTransaction->>buildSuiDepositAndCallTransaction: Validate signerAddress present
        buildSuiDepositAndCallTransaction->>suiClient: Fetch coinObjectId using signerAddress
    end
    
    buildSuiDepositAndCallTransaction->>buildSuiDepositAndCallTransaction: Construct unsigned transaction
    buildSuiDepositAndCallTransaction-->>prepareSuiDepositAndCall: Return { client, transaction }
    prepareSuiDepositAndCall-->>Browser: Return unsigned transaction for browser signing
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • src/chains/sui/depositAndCall.ts: Review new builder function logic, native vs non-native token handling paths, and signerAddress validation requirements
  • Refactoring consistency: Verify all import path updates are consistent and no missing conversions in utils files
  • utils/getAccountData.ts: Confirm account data parsing logic, error handling, and generic type constraints match previous implementation
  • Schema compatibility: Ensure suiBrowserOptionsSchema and new Sui exports integrate properly with existing type system

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "feat: Export browser compatible Sui depositAndCall function" clearly and specifically references the main user-facing change in this PR: the introduction of the prepareSuiDepositAndCall exported function for browser wallet integration. While the PR encompasses supporting changes like dependency replacements (@scure/bip32, @scure/bip39), code refactoring (moving getAccountData), and schema additions, the title effectively captures the primary objective and most important user-facing change. The wording is concise, specific to the Sui chain, and clearly communicates browser compatibility without ambiguity or vague terms.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/export-sui-browser-compatible-function

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the feat label Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants