Skip to content

Commit

Permalink
Merge pull request #1 from NetSepio/meumonicwalletaddr
Browse files Browse the repository at this point in the history
meumonicwalletaddr
  • Loading branch information
Rushikeshnimkar authored May 30, 2024
2 parents a384a9e + 5f8b00f commit 02184b4
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 29 deletions.
59 changes: 59 additions & 0 deletions core/suiwallet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package core

import (
"crypto/ed25519"
"crypto/sha256"
"encoding/hex"
"log"
"os"

"github.com/tyler-smith/go-bip32"
"github.com/tyler-smith/go-bip39"
)

var WalletAddressSui string

// GenerateWalletAddress generates a wallet address from the mnemonic set in the environment
func GenerateWalletAddress() {
// Read mnemonic from environment variable
mnemonic := os.Getenv("MNEMONIC")
if mnemonic == "" {
log.Fatal("MNEMONIC environment variable is not set")
}

// 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, "")

// Generate a master key using BIP32
masterKey, err := bip32.NewMasterKey(seed)
if err != nil {
log.Fatal(err)
}

// Derive a child key
childKey, err := masterKey.NewChildKey(bip32.FirstHardenedChild)
if err != nil {
log.Fatal(err)
}

// Generate ED25519 keys from the child key
privateKey := ed25519.NewKeyFromSeed(childKey.Key)
publicKey := privateKey.Public().(ed25519.PublicKey)

log.Println("Private Key:", hex.EncodeToString(privateKey))
log.Println("Public Key:", hex.EncodeToString(publicKey))

// Generate wallet address
hash := sha256.Sum256(publicKey)
walletAddress := hex.EncodeToString(hash[:])
log.Println("Wallet Address:", walletAddress)

// Assign the wallet address to the global variable
WalletAddressSui = walletAddress
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ require (
)

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
Expand Down Expand Up @@ -131,6 +133,8 @@ require (
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/showwin/speedtest-go v1.6.10 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
go.opencensus.io v0.24.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
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=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
Expand All @@ -40,6 +44,7 @@ github.com/chelnak/ysmrr v0.2.1 h1:9xLbVcrgnvEFovFAPnDiTCtxHiuLmz03xCg5OUgdOfc=
github.com/chelnak/ysmrr v0.2.1/go.mod h1:9TEgLy2xDMGN62zJm9XZrEWY/fHoGoBslSVEkEpRCXk=
github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
Expand Down Expand Up @@ -457,6 +462,7 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand All @@ -468,6 +474,10 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
Expand Down Expand Up @@ -518,6 +528,7 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw=
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -714,6 +725,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func main() {
// dump wg config file
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()

go p2p.Init()
//running updater
Expand Down
75 changes: 46 additions & 29 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"os"
"time"

"github.com/NetSepio/erebrus/core"
"github.com/NetSepio/erebrus/util/pkg/node"
"github.com/docker/docker/pkg/namesgenerator"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/multiformats/go-multiaddr"
"github.com/sirupsen/logrus"
)

// DiscoveryInterval is how often we search for other peers via the DHT.
Expand Down Expand Up @@ -98,35 +100,50 @@ func Init() {
}
}()

// //Topic 2
// topicString2 := "client" // Change "UniversalPeer" to whatever you want!
// topic2, err := ps.Join(DiscoveryServiceTag + "/" + topicString2)
// if err != nil {
// panic(err)
// }
// // if err := topic2.Publish(ctx, []byte("sending data over client topic")); err != nil {
// // panic(err)
// // }
// sub2, err := topic2.Subscribe()
// if err != nil {
// panic(err)
// }

// go func() {
// for {
// // Block until we recieve a new message.
// msg, err := sub2.Next(ctx)

// if err != nil {
// panic(err)
// }
// // if msg.ReceivedFrom == ha.ID() {
// // continue
// // }
// fmt.Printf("[%s] %s", msg.ReceivedFrom, string(msg.Data))
// fmt.Println()
// }
// }()
//Topic 2
ClientTopicString := "client" // Change "UniversalPeer" to whatever you want!
ClientTopic, err := ps.Join(DiscoveryServiceTag + "/" + ClientTopicString)
if err != nil {
panic(err)
}
go func() {
time.Sleep(5 * time.Second)
fmt.Println("sending clients")
clients, err := core.ReadClients()
if err != nil {
logrus.WithFields(logrus.Fields{
"err": err,
}).Error("failed to list clients")
return
}

msgBytes, err := json.Marshal(clients)
if err != nil {
panic(err)
}
if err := topic.Publish(ctx, msgBytes); err != nil {
panic(err)
}
}()
//Subscribe to the topic.
ClientSub, err := ClientTopic.Subscribe()
if err != nil {
panic(err)
}
go func() {
for {
// Block until we recieve a new message.
msg, err := ClientSub.Next(ctx)
if err != nil {
panic(err)
}
if msg.ReceivedFrom == ha.ID() {
continue
}
fmt.Printf("[%s] %s", msg.ReceivedFrom, string(msg.Data))
fmt.Println()
}
}()

}

Expand Down
53 changes: 53 additions & 0 deletions util/meumonicsWalletAddr/meumonicWalletAddr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package meumonicswalletaddr

import (
"crypto/ed25519"
"crypto/sha256"
"encoding/hex"
"fmt"
"log"

"github.com/tyler-smith/go-bip32"
"github.com/tyler-smith/go-bip39"
)

func Meumonicswalletaddr() {
// Generate a mnemonic
entropy, err := bip39.NewEntropy(128)
if err != nil {
log.Fatal(err)
}

mnemonic, err := bip39.NewMnemonic(entropy)
if err != nil {
log.Fatal(err)
}
fmt.Println("Mnemonic:", mnemonic)

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

// Generate a master key using BIP32
masterKey, err := bip32.NewMasterKey(seed)
if err != nil {
log.Fatal(err)
}

// Derive a child key
childKey, err := masterKey.NewChildKey(bip32.FirstHardenedChild)
if err != nil {
log.Fatal(err)
}

// Generate ED25519 keys from the child key
privateKey := ed25519.NewKeyFromSeed(childKey.Key)
publicKey := privateKey.Public().(ed25519.PublicKey)

fmt.Println("Private Key:", hex.EncodeToString(privateKey))
fmt.Println("Public Key:", hex.EncodeToString(publicKey))

// Generate wallet address
hash := sha256.Sum256(publicKey)
address := hex.EncodeToString(hash[:])
fmt.Println("Wallet Address:", address)
}
3 changes: 3 additions & 0 deletions util/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package node
import (
"os"

"github.com/NetSepio/erebrus/core"
"github.com/NetSepio/erebrus/util/pkg/speedtest"
"github.com/sirupsen/logrus"
)
Expand All @@ -17,6 +18,7 @@ type NodeStatus struct {
UploadSpeed float64 `json:"uploadSpeed"`
StartTimeStamp int64 `json:"startTimeStamp"`
Name string `json:"name"`
WalletAddress string `json:"walletAddress"`
}

func CreateNodeStatus(address string, id string, startTimeStamp int64, name string) *NodeStatus {
Expand All @@ -34,6 +36,7 @@ func CreateNodeStatus(address string, id string, startTimeStamp int64, name stri
UploadSpeed: speedtestResult.UploadSpeed,
StartTimeStamp: startTimeStamp,
Name: name,
WalletAddress: core.WalletAddressSui,
}
return nodeStatus
}

0 comments on commit 02184b4

Please sign in to comment.