Skip to content

Commit

Permalink
Merge pull request #24 from NetSepio/bug_fix
Browse files Browse the repository at this point in the history
fix: wallet address generation for supported chains
  • Loading branch information
Shachindra authored Jan 27, 2025
2 parents bbf3b4a + e29babe commit c5d1b08
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 73 deletions.
54 changes: 28 additions & 26 deletions core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"os"
"strings"

"github.com/blocto/solana-go-sdk/pkg/hdwallet"
"github.com/blocto/solana-go-sdk/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/mr-tron/base58"
"github.com/tyler-smith/go-bip32"
"github.com/tyler-smith/go-bip39"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/sha3"
)

Expand All @@ -23,10 +23,13 @@ var (
CodeHash string
)

var NodeName string
var ChainName string
var NodeType string
var NodeConfig string
var (
NodeName string
ChainName string
NodeType string
NodeConfig string
)
var WalletAddress string

// Function to load the node details from the environment and save it to the global variable
func LoadNodeDetails() {
Expand All @@ -36,6 +39,17 @@ func LoadNodeDetails() {
ChainName = os.Getenv("CHAIN_NAME")
if ChainName == "" {
log.Fatalf("CHAIN_NAME environment variable is not set")
} else {
ChainName = strings.ToLower(ChainName)
if ChainName == "solana" || ChainName == "eclipse" {
GenerateWalletAddressSolanaAndEclipse(os.Getenv("MNEMONIC"))
} else if ChainName == "ethereum" {
GenerateEthereumWalletAddress(os.Getenv("MNEMONIC"))
} else if ChainName == "sui" {
GenerateWalletAddressSui(os.Getenv("MNEMONIC"))
} else if ChainName == "aptos" {
GenerateWalletAddressAptos(os.Getenv("MNEMONIC"))
}
}
fmt.Printf("Chain Name: %s\n", ChainName)

Expand All @@ -52,15 +66,12 @@ func LoadNodeDetails() {
fmt.Printf("Node Config: %s\n", NodeConfig)
}

var WalletAddress string

// GenerateEthereumWalletAddress generates an Ethereum wallet address from the given mnemonic
func GenerateEthereumWalletAddress(mnemonic string) {
// Validate the mnemonic
if !bip39.IsMnemonicValid(mnemonic) {
log.Fatal("Invalid mnemonic")
}
log.Println("Mnemonic:", mnemonic)

// Derive a seed from the mnemonic
seed := bip39.NewSeed(mnemonic, "")
Expand Down Expand Up @@ -142,30 +153,21 @@ func toChecksumAddress(address string) string {
}

// GenerateWalletAddressSolana generates a Solana wallet address from the given mnemonic
func GenerateWalletAddressSolana(mnemonic string) {
func GenerateWalletAddressSolanaAndEclipse(mnemonic string) {
// Validate the mnemonic
if !bip39.IsMnemonicValid(mnemonic) {
fmt.Println("Invalid mnemonic")
return
}
fmt.Printf("Mnemonic: %s\n", mnemonic)

// Derive a seed from the mnemonic
seed := bip39.NewSeed(mnemonic, "")

// Derive the keypair using PBKDF2 with the Solana-specific path
derivedKey := pbkdf2.Key(seed, []byte("ed25519 seed"), 2048, 64, sha3.New512)

// The first 32 bytes are the private key, the next 32 bytes are the chain code (unused here)
privateKey := derivedKey[:32]

// Generate the public key
publicKey := ed25519.NewKeyFromSeed(privateKey).Public().(ed25519.PublicKey)
// mnemonic := "curtain century depth trim slogan stay case human farm ivory case merge"
seed := bip39.NewSeed(mnemonic, "") // (mnemonic, password)
path := `m/44'/501'/0'/0'`
derivedKey, _ := hdwallet.Derived(path, seed)
account, _ := types.AccountFromSeed(derivedKey.PrivateKey)

// Encode the public key to Base58
WalletAddress = base58.Encode(publicKey)
WalletAddress = account.PublicKey.ToBase58()

fmt.Printf("Solona Wallet Address: %s\n", WalletAddress)
fmt.Printf("Solona OR Eclipse Wallet Address: %s\n", WalletAddress)
}

// GenerateWalletAddressSui generates a Sui wallet address from the given mnemonic
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.4

require (
aidanwoods.dev/go-paseto v1.5.3
github.com/blocto/solana-go-sdk v1.30.0
github.com/danielkov/gin-helmet v0.0.0-20171108135313-1387e224435e
github.com/docker/docker v27.5.0+incompatible
github.com/ethereum/go-ethereum v1.14.12
Expand Down Expand Up @@ -34,6 +35,7 @@ require (
require (
aidanwoods.dev/go-result v0.1.0 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl
dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU=
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
Expand All @@ -26,6 +28,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blocto/solana-go-sdk v1.30.0 h1:GEh4GDjYk1lMhV/hqJDCyuDeCuc5dianbN33yxL88NU=
github.com/blocto/solana-go-sdk v1.30.0/go.mod h1:Xoyhhb3hrGpEQ5rJps5a3OgMwDpmEhrd9bgzFKkkwMs=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/bytedance/sonic v1.12.6 h1:/isNmCUF2x3Sh8RAp/4mh4ZGkcFAX/hLrzrK3AvpRzk=
Expand Down Expand Up @@ -196,8 +200,6 @@ github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/ipfs/boxo v0.24.0 h1:D9gTU3QdxyjPMlJ6QfqhHTG3TIJPplKzjXLO2J30h9U=
github.com/ipfs/boxo v0.24.0/go.mod h1:iP7xUPpHq2QAmVAjwtQvsNBTxTwLpFuy6ZpiRFwmzDA=
github.com/ipfs/boxo v0.24.3 h1:gldDPOWdM3Rz0v5LkVLtZu7A7gFNvAlWcmxhCqlHR3c=
github.com/ipfs/boxo v0.24.3/go.mod h1:h0DRzOY1IBFDHp6KNvrJLMFdSXTYID0Zf+q7X05JsNg=
github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs=
github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down Expand Up @@ -269,8 +271,6 @@ github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl9
github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8=
github.com/libp2p/go-libp2p-kad-dht v0.25.2 h1:FOIk9gHoe4YRWXTu8SY9Z1d0RILol0TrtApsMDPjAVQ=
github.com/libp2p/go-libp2p-kad-dht v0.25.2/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo=
github.com/libp2p/go-libp2p-kad-dht v0.28.2 h1:/VivUl/Ru0tVgkWNhDDBy8pK6q+gRdI+z8VfqmSUJWo=
github.com/libp2p/go-libp2p-kad-dht v0.28.2/go.mod h1:sUR/qh4p/5+YFXBtwOiCmIBeBA2YD94ttmL+Xk8+pTE=
github.com/libp2p/go-libp2p-kbucket v0.6.4 h1:OjfiYxU42TKQSB8t8WYd8MKhYhMJeO2If+NiuKfb6iQ=
github.com/libp2p/go-libp2p-kbucket v0.6.4/go.mod h1:jp6w82sczYaBsAypt5ayACcRJi0lgsba7o4TzJKEfWA=
github.com/libp2p/go-libp2p-pubsub v0.12.0 h1:PENNZjSfk8KYxANRlpipdS7+BfLmOl3L2E/6vSNjbdI=
Expand Down
46 changes: 3 additions & 43 deletions util/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,6 @@ import (
"github.com/sirupsen/logrus"
)

// type NodeStatus struct {
// Id string `json:"id"`
// HttpPort string `json:"httpPort"`
// Domain string `json:"domain"`
// Address string `json:"address"`
// Region string `json:"region"`
// NodeName string `json:"nodename"`
// DownloadSpeed float64 `json:"downloadSpeed"`
// UploadSpeed float64 `json:"uploadSpeed"`
// StartTimeStamp int64 `json:"startTimeStamp"`
// Name string `json:"name"`
// WalletAddress string `json:"walletAddress"`
// ChainName string `json:"chainName"`
// IpInfoIP string `json:"ipinfoip"`
// IpInfoCity string `json:"ipinfocity"`
// IpInfoCountry string `json:"ipinfocountry"`
// IpInfoLocation string `json:"ipinfolocation"`
// IpInfoOrg string `json:"ipinfoorg"`
// IpInfoPostal string `json:"ipinfopostal"`
// IpInfoTimezone string `json:"ipinfotimezone"`
// }

// type NodeStatus struct {
// PeerId string `json:"peerId" gorm:"primaryKey"`
// Name string `json:"name"`
// HttpPort string `json:"httpPort"`
// Host string `json:"host"` //domain
// PeerAddress string `json:"peerAddress"`
// Region string `json:"region"`
// Status string `json:"status"` // offline 1, online 2, maintainance 3,block 4
// DownloadSpeed float64 `json:"downloadSpeed"`
// UploadSpeed float64 `json:"uploadSpeed"`
// RegistrationTime int64 `json:"registrationTime"` //StartTimeStamp
// LastPing int64 `json:"lastPing"`
// Chain string `json:"chain"`
// WalletAddress string `json:"walletAddress"`
// Version string `json:"version"`
// CodeHash string `json:"codeHash"`
// SystemInfo OSInfo `json:"systemInfo"`
// IpInfo IPInfo `json:"ipinfo"`
// }

type NodeStatus struct {
PeerId string `json:"peerId" gorm:"primaryKey"`
Name string `json:"name"`
Expand Down Expand Up @@ -128,7 +86,7 @@ func CreateNodeStatus(address string, id string, startTimeStamp int64, name stri
IpInfoPostal: core.GlobalIPInfo.Postal,
IpInfoTimezone: core.GlobalIPInfo.Timezone}
fmt.Println("Ip Geo : ", IpGeoAddress)

nodeStatus := &NodeStatus{
HttpPort: os.Getenv("HTTP_PORT"),
Host: os.Getenv("DOMAIN"),
Expand All @@ -150,6 +108,8 @@ func CreateNodeStatus(address string, id string, startTimeStamp int64, name stri
NodeConfig: core.NodeConfig,
}

fmt.Printf("%+v\n", nodeStatus)

return nodeStatus
}

Expand Down

0 comments on commit c5d1b08

Please sign in to comment.