Skip to content

Conversation

nguyen-zung
Copy link
Collaborator

@nguyen-zung nguyen-zung commented Jun 23, 2025

  • Go wrapper for Stellar
  • Example code for test

Thank you!

Summary by CodeRabbit

  • New Features

    • Added support for Internet Computer Protocol (ICP) and Stellar coins.
    • Introduced sample functions to demonstrate creating, signing, and verifying ICP, NEAR, and Stellar transactions.
    • Added constants for Stellar and Kin network passphrases.
    • Provided a utility to display detailed wallet information.
  • Tests

    • Included new sample test functions for ICP, NEAR, and Stellar transaction flows.

Copy link

coderabbitai bot commented Jun 23, 2025

Walkthrough

This change adds support for Internet Computer Protocol (ICP) and Stellar coins to the Go wrapper. It introduces new coin type constants, sample transaction test functions for both coins, utility constants for Stellar passphrases, and a wallet information printing function. The main function is updated to invoke the new sample tests.

Changes

File(s) Change Summary
wrapper/go-wrapper/core/coin.go Added CoinTypeICP and CoinTypeStellar constants to the CoinType enum.
wrapper/go-wrapper/core/stellar.go Added constants for Stellar and Kin network passphrases.
wrapper/go-wrapper/core/utils.go Introduced WalletInfo function to print wallet details.
wrapper/go-wrapper/main.go Added calls to sample.TestICP() and sample.TestStellar() in main function.
wrapper/go-wrapper/sample/icp.go Added TestICP() function to demonstrate ICP transaction creation and signing.
wrapper/go-wrapper/sample/near.go Added TestNEAR() function to demonstrate NEAR transaction creation, signing, and verification.
wrapper/go-wrapper/sample/stellar.go Added TestStellar() function for Stellar transaction creation, signing, and verification.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant Sample
    participant Core
    participant Protobuf

    Main->>Sample: TestICP()
    Sample->>Core: Create ICP wallet from mnemonic
    Sample->>Core: Build ICP SigningInput (protobuf)
    Sample->>Protobuf: Marshal SigningInput
    Sample->>Core: PreImageHashes (get hash for signing)
    Core-->>Sample: PreSigningOutput (protobuf)
    Sample->>Protobuf: Unmarshal PreSigningOutput
    Sample->>Main: Print data hash
Loading
sequenceDiagram
    participant Main
    participant Sample
    participant Core
    participant Protobuf

    Main->>Sample: TestStellar()
    Sample->>Core: Build Stellar SigningInput (protobuf)
    Sample->>Protobuf: Marshal SigningInput
    Sample->>Core: PreImageHashes (get hash for signing)
    Core-->>Sample: PreSigningOutput (protobuf)
    Sample->>Protobuf: Unmarshal PreSigningOutput
    Sample->>Core: PublicKeyVerify (verify signature)
    Sample->>Core: CompileWithSignatures (assemble signed tx)
    Core-->>Sample: SigningOutput (protobuf)
    Sample->>Main: Print signed transaction
Loading

Possibly related PRs

  • Cramiumlabs/wallet-core#5: Adds Cosmos coin type and related sample code, directly related via modifications to CoinType enum and addition of coin-specific samples.

Suggested reviewers

  • seunghwalee-cramiumlabs
  • zkrypt-crossbar
  • sookyung-eom

Poem

In fields of code where wallets hop,
ICP and Stellar join the crop.
With passphrases bright and hashes clear,
New coins now dance, their time is here!
From mnemonic seeds to signed delight,
Rabbits cheer this crypto flight!
🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

@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: 2

🧹 Nitpick comments (3)
wrapper/go-wrapper/sample/icp.go (1)

18-18: Fix incorrect comment.

The comment says "bitcoin wallet" but the code creates an ICP wallet.

-	// bitcoin wallet
+	// ICP wallet
wrapper/go-wrapper/sample/stellar.go (1)

33-38: Improve error handling consistency.

The error handling is inconsistent - proto.Marshal error is ignored while proto.Unmarshal error is also ignored. Consider handling marshaling errors for robustness.

-	txInputData, _ := proto.Marshal(input)
+	txInputData, err := proto.Marshal(input)
+	if err != nil {
+		panic(fmt.Errorf("failed to marshal input: %w", err))
+	}
-	proto.Unmarshal(preimage, &preSigningOutput)
+	err = proto.Unmarshal(preimage, &preSigningOutput)
+	if err != nil {
+		panic(fmt.Errorf("failed to unmarshal preimage: %w", err))
+	}
wrapper/go-wrapper/sample/near.go (1)

40-46: Improve error handling consistency.

Similar to the stellar.go file, error handling is inconsistent. The marshaling error is ignored while unmarshaling error is also ignored.

-	txInputData, _ := proto.Marshal(&input)
+	txInputData, err := proto.Marshal(&input)
+	if err != nil {
+		panic(fmt.Errorf("failed to marshal input: %w", err))
+	}
-	proto.Unmarshal(msgForSign, &preSigningOutput)
+	err = proto.Unmarshal(msgForSign, &preSigningOutput)
+	if err != nil {
+		panic(fmt.Errorf("failed to unmarshal preimage: %w", err))
+	}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d42b875 and 3588c59.

📒 Files selected for processing (7)
  • wrapper/go-wrapper/core/coin.go (1 hunks)
  • wrapper/go-wrapper/core/stellar.go (1 hunks)
  • wrapper/go-wrapper/core/utils.go (1 hunks)
  • wrapper/go-wrapper/main.go (1 hunks)
  • wrapper/go-wrapper/sample/icp.go (1 hunks)
  • wrapper/go-wrapper/sample/near.go (1 hunks)
  • wrapper/go-wrapper/sample/stellar.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.64.8)
wrapper/go-wrapper/core/stellar.go

1-1: : # github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/core
wrapper/go-wrapper/core/utils.go:5:20: undefined: Wallet

(typecheck)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build
  • GitHub Check: test
  • GitHub Check: test-wasm
  • GitHub Check: build
  • GitHub Check: build-and-test
  • GitHub Check: build
🔇 Additional comments (13)
wrapper/go-wrapper/main.go (1)

58-59: LGTM! Consistent integration of new sample tests.

The addition of sample.TestICP() and sample.TestStellar() follows the established pattern and integrates well with the existing sample test calls.

wrapper/go-wrapper/core/coin.go (1)

24-25: LGTM! Proper coin type constant definitions.

The new CoinTypeICP and CoinTypeStellar constants are correctly defined following the established pattern and use appropriate Trust Wallet Core C constants.

wrapper/go-wrapper/core/stellar.go (1)

3-4: LGTM! Well-defined Stellar network constants.

The Stellar passphrase constants are properly defined with descriptive names and follow Go naming conventions. These appear to be standard Stellar network identifiers.

wrapper/go-wrapper/sample/icp.go (2)

23-23: Dependent on WalletInfo compilation fix.

This line calls core.WalletInfo() which has a compilation error due to the undefined Wallet type. This will need to be fixed once the issue in wrapper/go-wrapper/core/utils.go is resolved.


25-36: LGTM! Well-structured ICP transaction input.

The SigningInput construction for the ICP transfer transaction is well-structured and includes all necessary fields for a proper transfer operation.

wrapper/go-wrapper/sample/stellar.go (4)

1-12: LGTM! Clean package structure and imports.

The package declaration and imports are well-organized and appropriate for the functionality.


14-31: LGTM! Well-structured Stellar transaction input.

The SigningInput construction covers all essential fields for a Stellar payment transaction including passphrase, account details, operation, and memo. The hardcoded values are appropriate for a test function.


40-47: LGTM! Proper signature verification with appropriate error handling.

The signature verification logic is correct with proper error handling using panic for test failure, which is appropriate for a test function.


49-57: Good transaction compilation with proper error handling.

The transaction compilation and output handling demonstrate proper error checking and appropriate panic behavior for test scenarios.

wrapper/go-wrapper/sample/near.go (4)

1-12: LGTM! Consistent package structure.

The imports and package declaration are appropriate and consistent with the stellar.go implementation.


16-23: LGTM! Appropriate test data setup.

The hardcoded test data is well-organized, and the transfer amount initialization demonstrates proper byte array handling for NEAR's 128-bit amounts.


24-40: LGTM! Well-structured NEAR transaction input.

The SigningInput construction properly demonstrates a NEAR transfer transaction with all required fields including signer/receiver IDs, nonce, block hash, and transfer action.


48-63: LGTM! Proper signature verification and transaction compilation.

The signature verification and transaction compilation logic is correct with appropriate error handling. The output formatting with both signed transaction and hash provides good debugging information.

Comment on lines +5 to +10
func WalletInfo(w *Wallet) {
fmt.Printf("%s wallet: \n", w.CoinType.GetName())
fmt.Printf("\t address: %s \n", w.Address)
fmt.Printf("\t pri key: %s \n", w.PriKey)
fmt.Printf("\t pub key: %s \n", w.PubKey)
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix compilation error: undefined Wallet type.

The Wallet type is not defined or imported in this package, causing a compilation error as indicated by the static analysis tool.

The Wallet type needs to be imported or this function should be moved to a package where Wallet is defined. Looking at the codebase, Wallet appears to be defined in the same core package, so you may need to check if there's a missing file or if the Wallet struct definition needs to be added.

Additionally, this function duplicates the printWallet function from main.go. Consider consolidating this functionality.

+// Add the Wallet struct definition or import it from the appropriate location
 func WalletInfo(w *Wallet) {
 	fmt.Printf("%s wallet: \n", w.CoinType.GetName())
 	fmt.Printf("\t address: %s \n", w.Address)
 	fmt.Printf("\t pri key: %s \n", w.PriKey)
 	fmt.Printf("\t pub key: %s \n", w.PubKey)
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In wrapper/go-wrapper/core/utils.go around lines 5 to 10, the Wallet type is
undefined causing a compilation error. Verify if the Wallet struct is defined
elsewhere in the core package or if its definition is missing and add it here if
needed. Alternatively, move this WalletInfo function to the package where Wallet
is defined. Also, consider removing this duplicate function and consolidating
with the existing printWallet function in main.go to avoid redundancy.

Comment on lines +39 to +45
txInputData, _ := proto.Marshal(input)
msgForSign := core.PreImageHashes(core.CoinTypeICP, txInputData)

fmt.Println("msgForSign:", msgForSign)

var preSigningOutput transactioncompiler.PreSigningOutput
proto.Unmarshal(msgForSign, &preSigningOutput)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for protobuf operations.

The proto.Marshal and proto.Unmarshal operations can fail but errors are currently ignored, which could lead to runtime panics or unexpected behavior.

-	txInputData, _ := proto.Marshal(input)
+	txInputData, err := proto.Marshal(input)
+	if err != nil {
+		panic(err)
+	}
 	msgForSign := core.PreImageHashes(core.CoinTypeICP, txInputData)
 
 	fmt.Println("msgForSign:", msgForSign)
 
 	var preSigningOutput transactioncompiler.PreSigningOutput
-	proto.Unmarshal(msgForSign, &preSigningOutput)
+	err = proto.Unmarshal(msgForSign, &preSigningOutput)
+	if err != nil {
+		panic(err)
+	}
📝 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
txInputData, _ := proto.Marshal(input)
msgForSign := core.PreImageHashes(core.CoinTypeICP, txInputData)
fmt.Println("msgForSign:", msgForSign)
var preSigningOutput transactioncompiler.PreSigningOutput
proto.Unmarshal(msgForSign, &preSigningOutput)
txInputData, err := proto.Marshal(input)
if err != nil {
panic(err)
}
msgForSign := core.PreImageHashes(core.CoinTypeICP, txInputData)
fmt.Println("msgForSign:", msgForSign)
var preSigningOutput transactioncompiler.PreSigningOutput
err = proto.Unmarshal(msgForSign, &preSigningOutput)
if err != nil {
panic(err)
}
🤖 Prompt for AI Agents
In wrapper/go-wrapper/sample/icp.go around lines 39 to 45, the proto.Marshal and
proto.Unmarshal calls ignore errors, risking runtime panics or unexpected
behavior. Modify the code to capture and check the errors returned by
proto.Marshal and proto.Unmarshal. If an error occurs, handle it appropriately
by returning the error or logging it, ensuring the program does not proceed with
invalid data.

@nguyen-zung nguyen-zung merged commit a20cb74 into master Jun 24, 2025
8 of 13 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 11, 2025
5 tasks
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.

1 participant