go-wrapper

command module
v0.0.1-gowrapper-test Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README ยถ

Go Wrapper for Wallet Core

This is a Go wrapper for Trust Wallet Core, providing native Go bindings and a Chain Abstraction system for building multi-chain wallet applications.

๐Ÿš€ Features

  • Multi-Chain Support: Bitcoin, Ethereum, Cosmos, Cardano, Algorand, and 13+ more chains
  • Unified API: Single interface for all blockchain operations
  • Chain Abstraction: Abstract away chain-specific complexities
  • Wallet Management: Create wallets from mnemonic or private keys
  • Transaction Signing: Direct and external signing modes
  • Address Validation: Cross-chain address validation
  • Production Ready: Used in real-world applications

๐Ÿ“‹ Prerequisites

  • Go 1.23 or later
  • CMake
  • Ninja build system
  • C++ compiler

๐Ÿ› ๏ธ Setup

  1. Build native libraries:

    ./prepare.sh
    
  2. Install dependencies:

    go mod tidy
    
  3. Test the integration:

    cd cmd/wallet-cli
    go build .
    ./wallet-cli -command examples
    

๐Ÿ—๏ธ Project Structure

wrapper/go-wrapper/
โ”œโ”€โ”€ chain_abstraction/     # Chain abstraction system
โ”‚   โ”œโ”€โ”€ chains/           # Unified chain implementations
โ”‚   โ”‚   โ”œโ”€โ”€ chains.go     # All chains registration
โ”‚   โ”‚   โ”œโ”€โ”€ bitcoin_compatible/  # Bitcoin, Litecoin, BCH, Dogecoin
โ”‚   โ”‚   โ”œโ”€โ”€ ethereum_compatible/ # Ethereum, BSC, Polygon, etc.
โ”‚   โ”‚   โ””โ”€โ”€ ...           # Other chain implementations
โ”‚   โ”œโ”€โ”€ interfaces.go     # Core interfaces
โ”‚   โ””โ”€โ”€ factory.go        # Chain factory
โ”œโ”€โ”€ cmd/wallet-cli/       # CLI example application
โ”‚   โ”œโ”€โ”€ main.go          # Main CLI with init() registration
โ”‚   โ””โ”€โ”€ examples.go      # Complete integration examples
โ”œโ”€โ”€ core/                # Core wallet functionality
โ”œโ”€โ”€ native/              # Native library files
โ””โ”€โ”€ go.mod              # Go module file

๐ŸŽฏ Quick Start

1. Initialize Chain Abstraction
package main

import (
    "github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/chain_abstraction"
    "github.com/Cramiumlabs/wallet-core/wrapper/go-wrapper/chain_abstraction/chains"
)

// Global registry instance
var globalRegistry *chain_abstraction.ChainRegistry

// init function to register all chains when package is imported
func init() {
    globalRegistry = chain_abstraction.NewChainRegistry()
    chains.RegisterAll(globalRegistry)
}

func main() {
    // All chains are now registered and ready to use!
    availableChains := globalRegistry.ListChains()
    fmt.Printf("Registered %d chains\n", len(availableChains))
}
2. Create Multi-Chain Wallets
func createWallets(mnemonic string) {
    for _, chain := range globalRegistry.ListChains() {
        wallet, err := chain.CreateWallet(mnemonic)
        if err != nil {
            log.Printf("Failed to create %s wallet: %v", chain.GetName(), err)
            continue
        }
        
        fmt.Printf("โœ… %s: %s\n", chain.GetName(), wallet.Address)
    }
}
3. Validate Addresses
func validateAddress(address string) {
    for _, chain := range globalRegistry.ListChains() {
        if chain.ValidateAddress(address) {
            fmt.Printf("โœ… %s: Valid\n", chain.GetName())
        } else {
            fmt.Printf("โŒ %s: Invalid\n", chain.GetName())
        }
    }
}

๐Ÿ”— Supported Chains

Bitcoin Compatible (4 chains)
  • Bitcoin (BTC) - Coin Type: 0
  • Litecoin (LTC) - Coin Type: 2
  • Bitcoin Cash (BCH) - Coin Type: 145
  • Dogecoin (DOGE) - Coin Type: 3
Ethereum Compatible (5 chains)
  • Ethereum (ETH) - Coin Type: 60
  • Binance Smart Chain (BSC) - Coin Type: 20000714
  • Polygon (MATIC) - Coin Type: 966
  • Avalanche C-Chain (AVAX) - Coin Type: 10009000
  • Arbitrum (ARB) - Coin Type: 10042221
Other Chains (9 chains)
  • Cosmos (ATOM) - Coin Type: 118
  • Cardano (ADA) - Coin Type: 1815
  • Algorand (ALGO) - Coin Type: 283
  • Hedera (HBAR) - Coin Type: 3030
  • NEAR (NEAR) - Coin Type: 397
  • XRP (XRP) - Coin Type: 144
  • EOS (EOS) - Coin Type: 194
  • VeChain (VET) - Coin Type: 818
  • Internet Computer (ICP) - Coin Type: 223

๐ŸŽฎ CLI Examples

The cmd/wallet-cli provides a complete example application:

# List all available chains
./wallet-cli -command list-chains

# Create wallet from mnemonic
./wallet-cli -command create-wallet -chain Bitcoin -mnemonic "your mnemonic here"

# Create wallet from private key
./wallet-cli -command create-wallet -chain Ethereum -private-key "your_private_key_hex"

# Create transaction
./wallet-cli -command create-tx -chain Bitcoin -to "recipient_address" -amount "1000" -private-key "your_private_key_hex"

# Run complete integration demo
./wallet-cli -command examples

๐Ÿ”ง Development

Adding a New Chain
  1. Create chain implementation in chain_abstraction/chains/
  2. Register in chains.go:
    var AllChains = map[core.CoinType]chain_abstraction.Chain{
        // ... existing chains
        core.CoinTypeNewChain: newchain.NewNewChain(),
    }
    
  3. Test with CLI:
    ./wallet-cli -command examples
    
Building
# Build the CLI
cd cmd/wallet-cli
go build .

# Run tests
go test ./...

๐Ÿ“š Documentation

๐Ÿ”’ Security

  • Private keys are never stored in plain text
  • Supports hardware wallet integration via external signing
  • Built on Trust Wallet Core's security foundation
  • Comprehensive input validation and error handling

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all examples pass
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL