Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ builds:
- linux
goarch:
- amd64

env:
- CGO_ENABLED=0
- CC=gcc
ldflags:
- -s -w -X main.version={{.Tag}} -X main.commitHash={{.ShortCommit}}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning]https://semver.org/spec/v2.0.0.
## Releases

### Unreleased
- Added support for disabled CGO_ENABLED flag in EVM, TRON cryptography [DV-3641]

### [0.9.6] - 2025-09-29
- Added two-factor secret encryption [DV-2526]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.3.5-0.20250213152832-bb52d7d78d9c
github.com/btcsuite/btcd/btcutil v1.1.7-0.20250213152832-bb52d7d78d9c
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.1-0.20250213152832-bb52d7d78d9c
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/ethereum/go-ethereum v1.15.8
github.com/fbsobreira/gotron-sdk v0.0.0-20250427130616-96b87f5d2100
github.com/go-playground/validator/v10 v10.26.0
Expand Down
10 changes: 5 additions & 5 deletions internal/fsm/fsmevm/fsm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fsmevm

import (
"context"
"crypto/ecdsa"
"fmt"
"math/big"
"strings"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/dv-net/dv-processing/internal/store/repos/repo_transfer_transactions"
trxv2 "github.com/dv-net/dv-proto/gen/go/eproxy/transactions/v2"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/dv-net/dv-processing/internal/constants"
"github.com/dv-net/dv-processing/internal/services/webhooks"
"github.com/dv-net/dv-processing/internal/store/repos"
Expand Down Expand Up @@ -202,8 +202,8 @@ func (s *FSM) getAssetDecimals(ctx context.Context, assetIdentifier string) (int

type walletCreds struct {
Address string
PrivateKey *btcec.PrivateKey
PublicKey *btcec.PublicKey
PrivateKey *ecdsa.PrivateKey
PublicKey *ecdsa.PublicKey
}

// getWalletCreds
Expand Down Expand Up @@ -288,7 +288,7 @@ func (s *FSM) sendBaseAsset(ctx context.Context, wCreds *walletCreds, toAddress
Data: nil,
})

signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(chainID), wCreds.PrivateKey.ToECDSA())
signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(chainID), wCreds.PrivateKey)
if err != nil {
return nil, nil, fmt.Errorf("sign transaction: %w", err)
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *FSM) sendERC20(ctx context.Context, wCreds *walletCreds, contractAddres
}

// create auth
auth, err := bind.NewKeyedTransactorWithChainID(wCreds.PrivateKey.ToECDSA(), chainID)
auth, err := bind.NewKeyedTransactorWithChainID(wCreds.PrivateKey, chainID)
if err != nil {
return nil, nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions internal/fsm/fsmtron/fsm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package fsmtron

import (
"context"
"crypto/ecdsa"
"fmt"
"strings"
"time"

"connectrpc.com/connect"
"github.com/btcsuite/btcd/btcec/v2"
trxv2 "github.com/dv-net/dv-proto/gen/go/eproxy/transactions/v2"
"github.com/fbsobreira/gotron-sdk/pkg/common"
"github.com/fbsobreira/gotron-sdk/pkg/proto/api"
Expand Down Expand Up @@ -155,8 +155,8 @@ func (s *FSM) getAssetDecimals(ctx context.Context, assetIdentifier string) (int

type walletCreds struct {
Address string
PrivateKey *btcec.PrivateKey
PublicKey *btcec.PublicKey
PrivateKey *ecdsa.PrivateKey
PublicKey *ecdsa.PublicKey
}

// getWalletCreds
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *FSM) systemActivation(ctx context.Context, wCreds *walletCreds, toAddre
return nil, fmt.Errorf("create system activation tx error: %s", string(tx.Result.Message))
}

if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey.ToECDSA()); err != nil {
if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey); err != nil {
return nil, fmt.Errorf("sign transaction: %w", err)
}

Expand Down Expand Up @@ -252,7 +252,7 @@ func (s *FSM) sendTRX(ctx context.Context, wCreds *walletCreds, toAddress string
return nil, fmt.Errorf("create send trx tx error: %s", string(tx.Result.Message))
}

if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey.ToECDSA()); err != nil {
if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey); err != nil {
return nil, fmt.Errorf("sign transaction: %w", err)
}

Expand Down Expand Up @@ -319,7 +319,7 @@ func (s *FSM) sendTrc20(ctx context.Context, wCreds *walletCreds, contractAddres
return nil, fmt.Errorf("create send trc20 tx error: %s", string(tx.Result.Message))
}

if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey.ToECDSA()); err != nil {
if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey); err != nil {
return nil, fmt.Errorf("sign transaction: %w", err)
}

Expand Down Expand Up @@ -407,7 +407,7 @@ func (s *FSM) delegateResource(
return nil, nil, fmt.Errorf("create delegate tx error: %s", string(tx.Result.Message))
}

if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey.ToECDSA()); err != nil {
if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey); err != nil {
return nil, nil, fmt.Errorf("sign transaction: %w", err)
}

Expand Down Expand Up @@ -464,7 +464,7 @@ func (s *FSM) reclaimResource(ctx context.Context, wCreds *walletCreds, toAddres
return nil, nil, fmt.Errorf("create reclaim tx error: %s", string(tx.Result.Message))
}

if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey.ToECDSA()); err != nil {
if err := s.tron.SignTransaction(tx.GetTransaction(), wCreds.PrivateKey); err != nil {
return nil, nil, fmt.Errorf("sign transaction: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/fsm/fsmtron/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestFSM(t *testing.T) {
bc, err := blockchains.New(context.Background(), conf.Blockchain, sdk)
require.NoError(t, err)

sysSvc := system.New(st, "sysVersion", "sysCommit")
sysSvc := system.New(l, st, "sysVersion", "sysCommit")
bs, err := baseservices.New(appCtx, l, conf, st, explorerProxySvc, bc, sysSvc, dispatcher.New(), nil, sdk)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion internal/fsm/fsmtron/stage_before.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (s *FSM) activateWalletResources(ctx context.Context, _ *workflow.Workflow,
}

// sign transaction
if err = s.tron.SignTransaction(tx.Transaction, wcreds.PrivateKey.ToECDSA()); err != nil {
if err = s.tron.SignTransaction(tx.Transaction, wcreds.PrivateKey); err != nil {
return fmt.Errorf("sign activation transaction: %w", err)
}

Expand Down
21 changes: 12 additions & 9 deletions pkg/walletsdk/evm/wallet.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package evm

import (
"crypto/ecdsa"
"encoding/hex"
"errors"
"strconv"
"strings"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/dv-net/go-bip39"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/fbsobreira/gotron-sdk/pkg/keys/hd"
)
Expand All @@ -20,12 +20,12 @@ func NewWalletSDK() *WalletSDK {
return &WalletSDK{}
}

func WalletPubKeyHash(mnemonic string, passphrase string, sequence uint32) (string, *btcec.PrivateKey, *btcec.PublicKey, error) {
func WalletPubKeyHash(mnemonic string, passphrase string, sequence uint32) (string, *ecdsa.PrivateKey, *ecdsa.PublicKey, error) {
seed := bip39.NewSeed(mnemonic, passphrase)

secret, chainCode := hd.ComputeMastersFromSeed(seed, []byte("Bitcoin seed"))
secret, err := hd.DerivePrivateKeyForPath(
btcec.S256(),
crypto.S256(),
secret,
chainCode,
"44'/60'/0'/0/"+strconv.Itoa(int(sequence)),
Expand All @@ -34,10 +34,13 @@ func WalletPubKeyHash(mnemonic string, passphrase string, sequence uint32) (stri
return "", nil, nil, errors.New("failed to derive private key")
}

privateKey, publicKey := secp256k1.PrivKeyFromBytes(secret[:]), secp256k1.PrivKeyFromBytes(secret[:]).PubKey()
address := crypto.PubkeyToAddress(*publicKey.ToECDSA())
privateKey, err := crypto.ToECDSA(secret[:])
if err != nil {
return "", nil, nil, errors.New("failed to generate ECDSA from secret")
}
address := crypto.PubkeyToAddress(privateKey.PublicKey)

return strings.ToLower(address.String()), privateKey, publicKey, nil
return strings.ToLower(address.String()), privateKey, &privateKey.PublicKey, nil
}

func AddressWallet(mnemonic string, passphrase string, sequence uint32) (string, error) {
Expand All @@ -57,7 +60,7 @@ func AddressSecret(address string, mnemonic string, passphrase string, sequence
if !strings.EqualFold(address, wAddress) {
return "", errors.New("generate private key address")
}
return private.Key.String(), nil
return hexutil.Encode(crypto.FromECDSA(private)), nil
}

func AddressPublic(address string, mnemonic string, passphrase string, sequence uint32) (string, error) {
Expand All @@ -68,7 +71,7 @@ func AddressPublic(address string, mnemonic string, passphrase string, sequence
if !strings.EqualFold(address, wAddress) {
return "", errors.New("generate private key address")
}
return hex.EncodeToString(public.SerializeUncompressed()), nil
return hex.EncodeToString(crypto.FromECDSAPub(public)), nil
}

func (s WalletSDK) ValidateAddress(address string) bool {
Expand Down
25 changes: 12 additions & 13 deletions pkg/walletsdk/evm/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import (
"strconv"
"testing"

"github.com/btcsuite/btcd/btcec/v2"
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/dv-net/dv-processing/pkg/walletsdk/evm"
"github.com/dv-net/go-bip39"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/fbsobreira/gotron-sdk/pkg/keys/hd"
"github.com/stretchr/testify/require"
)

const (
mnemonic = "vague wool express sniff alley core hen symptom end rather month cave cross elder nest bright paddle use voice wife dolphin mosquito inside curve"
passphrase = "asdfasdfasdf" //nolint:gosec
defaultSequence = 1
passphrase = "" //nolint:gosec
defaultSequence = 0
)

func Test_GenerateAddresses(t *testing.T) {
Expand All @@ -27,33 +26,33 @@ func Test_GenerateAddresses(t *testing.T) {
t.Fatalf("failed to generate addresss: %v", err)
}

fmt.Println(addr, priv)
fmt.Println(addr, hexutil.Encode(crypto.FromECDSA(priv)))
}
}

func TestEthereumWalletPubKeyHash(t *testing.T) {
seed := bip39.NewSeed(mnemonic, passphrase)
require.NotEmpty(t, seed)
secret, chainCode := hd.ComputeMastersFromSeed(seed, []byte(passphrase))
secret, chainCode := hd.ComputeMastersFromSeed(seed, []byte("Bitcoin seed"))
require.NotEmpty(t, secret)
require.NotEmpty(t, chainCode)
secret, err := hd.DerivePrivateKeyForPath(
btcec.S256(),
crypto.S256(),
secret,
chainCode,
"44'/60'/0'/0/"+strconv.Itoa(defaultSequence),
)
require.NoError(t, err)
require.NotEmpty(t, secret)

privateKey, publicKey := secp.PrivKeyFromBytes(secret[:]), secp.PrivKeyFromBytes(secret[:]).PubKey()
privateKey, err := crypto.ToECDSA(secret[:])
require.NoError(t, err)
require.NotEmpty(t, privateKey)
require.NotEmpty(t, publicKey)

address := crypto.PubkeyToAddress(*publicKey.ToECDSA())
address := crypto.PubkeyToAddress(privateKey.PublicKey)
require.NotEmpty(t, address)
t.Log(address.String())

t.Log(publicKey.ToECDSA())
t.Log(privateKey.Key.String())
t.Log(address.String())
t.Log(hexutil.Encode(crypto.FromECDSA(privateKey)))
t.Log(hexutil.Encode(crypto.FromECDSAPub(&privateKey.PublicKey)))
}
2 changes: 1 addition & 1 deletion pkg/walletsdk/tron/reclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (t *Tron) ReclaimResource(ctx context.Context, params ReclaimResourceParams
return nil, fmt.Errorf("create reclaim tx error: %s", string(tx.Result.Message))
}

if err := t.SignTransaction(tx.GetTransaction(), priv.ToECDSA()); err != nil {
if err := t.SignTransaction(tx.GetTransaction(), priv); err != nil {
return nil, fmt.Errorf("sign transaction: %w", err)
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/walletsdk/tron/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"time"

"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/dv-net/dv-processing/pkg/retry"
"github.com/dv-net/dv-processing/rpccode"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -883,12 +882,12 @@ func (t *Tron) fillFakeTX(tx *core.Transaction) error {
return err
}

pk, err := secp256k1.GeneratePrivateKey()
pk, err := crypto.GenerateKey()
if err != nil {
return err
}

signature, err := crypto.Sign(h256h.Sum(nil), pk.ToECDSA())
signature, err := crypto.Sign(h256h.Sum(nil), pk)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/walletsdk/tron/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"
"time"

"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/fbsobreira/gotron-sdk/pkg/address"
Expand Down Expand Up @@ -295,10 +294,10 @@ func TestEstimateEnergyForTransfer(t *testing.T) {
_, err = h256h.Write(rawData)
require.NoError(t, err)

pk, err := secp256k1.GeneratePrivateKey()
pk, err := crypto.GenerateKey()
require.NoError(t, err)

signature, err := crypto.Sign(h256h.Sum(nil), pk.ToECDSA())
signature, err := crypto.Sign(h256h.Sum(nil), pk)
require.NoError(t, err)

tx.Signature = append(tx.Signature, signature)
Expand Down
Loading
Loading