A Go module for calling cryptocurrency transaction signing functions from a Rust library through CGO.
π Normal Workflow: First try importing the package normally (
go mod tidy
,go build
). If you get architecture or linking errors, then clone the repository and use manual build (./build_manual.sh
).
// In your Go project
import signer "github.com/sidan-lab/cardano-golang-signing-module"
// Try to use the library
func main() {
signer, err := signer.NewMnemonicSigner(mnemonic, derivationPath)
// ... your code
}
# Install dependencies
go mod tidy
go build # or go run main.go
If you get errors like "no prebuilt library for your architecture" or linking errors, follow these steps:
git clone https://github.com/sidan-lab/cardano-golang-signing-module.git
cd cardano-golang-signing-module
./build_manual.sh
# In your project directory
go mod edit -replace github.com/sidan-lab/cardano-golang-signing-module=/path/to/cardano-golang-signing-module
go mod tidy
go build
./build_prebuilt.sh
- First try importing the package normally (
go mod tidy
,go build
) - If that fails with architecture or linking errors β use manual build
- β No prebuilt library for your architecture (ARM, exotic platforms, etc.)
- β Linking errors with prebuilt libraries
- β CGO compilation issues with distributed binaries
- β Development - you're modifying the Rust code
- β Custom optimizations - need specific build flags
- β Latest features - using unreleased Rust code changes
- β Security - want to build from source yourself
Use ./build_prebuilt.sh
only when:
- π§ Publishing new version - creating libraries for distribution
- π§ Cross-platform builds - building for all supported platforms
- π§ Release preparation - updating prebuilt binaries for users
-
Install Rust (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env
-
Install Go (1.19+):
# macOS brew install go # Linux sudo apt install golang-go # Ubuntu/Debian sudo yum install golang # CentOS/RHEL # Windows - download from https://golang.org/dl/
-
C Compiler:
# macOS - Xcode Command Line Tools xcode-select --install # Linux sudo apt install build-essential # Ubuntu/Debian sudo yum groupinstall "Development Tools" # CentOS/RHEL # Windows - Visual Studio Build Tools or MinGW
-
Clone the repository:
git clone <repository-url> cd cardano-golang-signing-module
-
Run the complete manual build:
./build_manual.sh
This script will:
- Switch to manual build configuration
- Build Rust library from source
- Build Go project
- Run tests
-
Verify the build:
go test -v
If you prefer to run steps manually:
-
Switch to manual build configuration:
./switch_to_manual_build.sh
-
Build Rust library:
cargo build --release
-
Build Go project:
go build
-
Run tests:
go test -v
Complete manual build pipeline
- β Switches to manual build mode
- β
Builds Rust library from source (
cargo build --release
) - β Builds Go project using your compiled library
- β Runs tests
Multi-platform build for publishing
- π§ Switches to prebuilt library mode
- π§ Builds Rust libraries for all platforms (via
build_rust.sh
) - π§ Updates prebuilt binaries in
prebuilt/
directory - π§ Builds Go project using prebuilt libraries
- π§ Runs tests
- Switches
signer.go
to use platform-specific prebuilt libraries - Only changes configuration, doesn't build
- Switches
signer.go
to use unified manual build library - Only changes configuration, doesn't build
- Builds Rust libraries for all supported platforms
- Creates prebuilt binaries in
prebuilt/
directory - Used internally by
build_prebuilt.sh
- Only needed when publishing new versions
# In your Go project
go mod init myproject
go mod tidy
# Write your Go code with the import
# import "github.com/sidan-lab/cardano-golang-signing-module"
go build # Should work with prebuilt libraries
# Step 1: Clone and build manually
git clone https://github.com/sidan-lab/cardano-golang-signing-module.git
cd cardano-golang-signing-module
./build_manual.sh
# Step 2: Use in your project
cd /path/to/your/project
go mod edit -replace github.com/sidan-lab/cardano-golang-signing-module=/path/to/cardano-golang-signing-module
go mod tidy
go build
# When ready to publish new version
./build_prebuilt.sh # Creates binaries for all platforms
git add prebuilt/ # Commit updated prebuilt libraries
git commit -m "Update prebuilt libraries for v1.x.x"
git tag v1.x.x
git push origin main --tags
- Linux:
x86_64
,aarch64
(ARM64) - macOS:
x86_64
(Intel),aarch64
(Apple Silicon) - Windows:
x86_64
- Linux/macOS: Static libraries (
.a
) - Windows: Dynamic libraries (
.dll
)
Uses platform-specific libraries:
- Linux:
prebuilt/linux_{amd64,arm64}/libsigner_go.a
- macOS:
prebuilt/darwin_{amd64,arm64}/libsigner_go.a
- Windows:
prebuilt/windows_amd64/signer_go.dll
Uses your compiled library:
- Unix (Linux/macOS):
target/release/libsigner_go.a
- Windows:
target/release/signer_go.dll
orlibsigner_go.a
- Create a new Go project:
mkdir myproject
cd myproject
go mod init myproject
- Create main.go:
package main
import (
"fmt"
"log"
signer "github.com/sidan-lab/cardano-golang-signing-module"
)
func main() {
// Create signer from mnemonic phrase
mnemonic := "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
derivationPath := "m/44'/118'/0'/0/0"
signer, err := signer.NewMnemonicSigner(mnemonic, derivationPath)
if err != nil {
log.Fatalf("Failed to create signer: %v", err)
}
defer signer.Close() // Important to free resources!
// Get public key
publicKey, err := signer.GetPublicKey()
if err != nil {
log.Fatalf("Failed to get public key: %v", err)
}
fmt.Printf("Public Key: %s\n", publicKey)
// Sign transaction
txHex := "your_transaction_hex_here"
signature, err := signer.SignTransaction(txHex)
if err != nil {
log.Fatalf("Failed to sign transaction: %v", err)
}
fmt.Printf("Signature: %s\n", signature)
}
- Try to build normally first:
go mod tidy
go build
- If that fails β follow manual build instructions above
### Available Signer Types
#### 1. Mnemonic Signer
```go
signer, err := signer.NewMnemonicSigner(mnemonicPhrase, derivationPath)
signer, err := signer.NewBech32Signer(rootPrivateKey, derivationPath)
signer, err := signer.NewCLISigner(ed25519Key)
signature, err := signer.SignTransaction(txHex)
publicKey, err := signer.GetPublicKey()
signer.Close() // Always call this!
go mod tidy
go clean -modcache
go mod download
Your platform may not have prebuilt libraries. β Go to Manual Build (Step 2)
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install Go
# Download from https://golang.org/dl/
# Install C compiler
# macOS: xcode-select --install
# Linux: sudo apt install build-essential
# Clean everything and rebuild
go clean
cargo clean
./build_manual.sh
Make sure the path is absolute:
# Get absolute path
pwd # Note the full path
# Use absolute path in replace
go mod edit -replace github.com/sidan-lab/cardano-golang-signing-module=/full/absolute/path/to/cardano-golang-signing-module
go mod tidy
Install Rust toolchain:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Install Go from https://golang.org/dl/
- Make sure you have a C compiler installed
- Try clean rebuild:
go clean ./build_manual.sh # or ./build_prebuilt.sh
- Check that the library was built successfully
- Try switching build modes:
./build_prebuilt.sh # if manual fails # or ./build_manual.sh # if prebuilt fails
- β Check that
signer.Close()
wasn't called before use - β Verify input data (mnemonic phrases, keys) is valid
- β Make sure error handling is proper
βββ src/ # Rust source code
β βββ lib.rs # Main Rust library
β βββ c_interface.rs # C-compatible interface
βββ include/
β βββ signer.h # C header file
βββ prebuilt/ # Prebuilt libraries
β βββ linux_amd64/
β βββ linux_arm64/
β βββ darwin_amd64/
β βββ darwin_arm64/
β βββ windows_amd64/
βββ examples/ # Go examples
βββ signer.go # Go interface
βββ signer_test.go # Go tests
βββ build_manual.sh # Manual build script
βββ build_prebuilt.sh # Prebuilt build script
βββ build_rust.sh # Multi-platform Rust build
βββ switch_to_manual_build.sh
βββ switch_to_prebuilt.sh
βββ Cargo.toml # Rust configuration
βββ .cargo/config.toml # Cargo build config
- Memory Management: Always call
signer.Close()
to free Rust resources - Production Safety: Never use test mnemonic phrases in production
- Error Handling: Always check returned errors
- Build Verification: Manual builds allow you to verify the code yourself
[Add your license information here]
[Add contributing guidelines here]