diff --git a/core/solonawallet.go b/core/solonawallet.go new file mode 100644 index 0000000..5984bd8 --- /dev/null +++ b/core/solonawallet.go @@ -0,0 +1,50 @@ +package core + +import ( + "bytes" + "crypto/sha256" + "fmt" + "os" + + "github.com/mr-tron/base58" + "github.com/tyler-smith/go-bip39" + "golang.org/x/crypto/ed25519" +) + +var WalletAddressSolana string + +// GenerateWalletAddress generates a wallet address from the mnemonic set in the environment +func GenerateWalletAddresssolana() { + // Read mnemonic from environment variable + mnemonic := os.Getenv("MNEMONIC_sol") + if mnemonic == "" { + fmt.Println("MNEMONIC environment variable is not set") + return + } + + // 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, "") + + // Generate a keypair + publicKey, _, err := ed25519.GenerateKey(bytes.NewReader(seed)) + if err != nil { + fmt.Println(err) + return + } + + // Generate wallet address + hash := sha256.Sum256(publicKey) + WalletAddresssol := base58.Encode(hash[:20]) + fmt.Printf("Wallet Address: %s\n", WalletAddresssol) + + // Assign the wallet address to the variable (consider error handling) + WalletAddressSolana = WalletAddresssol + fmt.Printf("The final wallet address: %s\n", WalletAddressSolana) +} \ No newline at end of file diff --git a/main.go b/main.go index fa05431..2e29888 100644 --- a/main.go +++ b/main.go @@ -127,7 +127,8 @@ func main() { err := core.UpdateServerConfigWg() util.CheckError("Error while creating WireGuard config file: ", err) // Call the function to generate the wallet address and store it in the global variable - core.GenerateWalletAddress() + core.GenerateWalletAddress(), + core.GenerateWalletAddresssol(), go p2p.Init() //running updater diff --git a/util/pkg/node/node.go b/util/pkg/node/node.go index 315d84d..bdbb823 100644 --- a/util/pkg/node/node.go +++ b/util/pkg/node/node.go @@ -19,6 +19,7 @@ type NodeStatus struct { StartTimeStamp int64 `json:"startTimeStamp"` Name string `json:"name"` WalletAddress string `json:"walletAddress"` + WalletAddresssol string `json:"walletAddressSol"` } func CreateNodeStatus(address string, id string, startTimeStamp int64, name string) *NodeStatus { @@ -27,16 +28,17 @@ func CreateNodeStatus(address string, id string, startTimeStamp int64, name stri logrus.Error("failed to fetch network speed: ", err.Error()) } nodeStatus := &NodeStatus{ - HttpPort: os.Getenv("HTTP_PORT"), - Domain: os.Getenv("DOMAIN"), - Address: address, - Region: os.Getenv("REGION"), - Id: id, - DownloadSpeed: speedtestResult.DownloadSpeed, - UploadSpeed: speedtestResult.UploadSpeed, - StartTimeStamp: startTimeStamp, - Name: name, - WalletAddress: core.WalletAddressSui, + HttpPort: os.Getenv("HTTP_PORT"), + Domain: os.Getenv("DOMAIN"), + Address: address, + Region: os.Getenv("REGION"), + Id: id, + DownloadSpeed: speedtestResult.DownloadSpeed, + UploadSpeed: speedtestResult.UploadSpeed, + StartTimeStamp: startTimeStamp, + Name: name, + WalletAddress: core.WalletAddressSui, + WalletAddresssol: core.WalletAddressSolana, } return nodeStatus }