Implement a Signer (TON / TRON)

Overview

This tutorial explains how to implement or extend a Signer for a chain (e.g. TON, TRON) in the Wallet service. Signers are stateless: they derive addresses and sign transactions given keys and payloads.


Signer contract

Location: services/wallet/internal/wallet/service/signer/interfaces.go

  • Deriver: FromMnemonic(mnemonic, path, curve) → (PrivKey, PubKey, error)
  • Signer: Address(pub, chain) → string, SignTx(chain, priv, payload) → ([]byte, error)

Implementations: ton_signer.go, tron_signer.go; optional TWC behind build tag.


Steps

1. Choose the chain

  • TON: ed25519, bounceable/non-bounceable address (tonutils-go).
  • TRON: secp256k1, keccak256, base58check with 0x41 prefix.

2. Implement Deriver (if new curve)

  • Use BIP32 path; derive private/public key for the chain’s curve.
  • Return PrivKey and PubKey byte slices.

3. Implement Signer

  • Address(pub, chain): From public key, compute the chain-specific address (string).
  • SignTx(chain, priv, payload): Decode payload (e.g. protobuf for TRON), sign, return serialized signed tx.

4. Register in factory

  • In signer/factory.go, map Chain to your implementation so the wallet service uses it for that chain.

5. Tests

  • Golden/vector tests: Known mnemonic + path → known address and (if possible) known signature for a sample tx.
  • Unit tests for Address and SignTx with fixed inputs.

Flow

flowchart LR
  A[Mnemonic] --> B[Deriver]
  B --> C[PrivKey, PubKey]
  C --> D[Signer.Address]
  C --> E[Signer.SignTx]
  D --> F[Address string]
  E --> G[Signed TX bytes]

References

© 2025 GitiNext - Enterprise Crypto Infrastructure | GitHub | Website