Skip to content

Commit

Permalink
Merge pull request #8 from NetSepio/rushikesh-solona-wallet-address
Browse files Browse the repository at this point in the history
fix soloana wallet address
  • Loading branch information
Rushikeshnimkar authored Jun 3, 2024
2 parents f82d439 + a5c5896 commit 841ae57
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 48 deletions.
36 changes: 17 additions & 19 deletions core/solonawallet.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package core

import (
"bytes"
"crypto/sha256"
"fmt"
"os"

"github.com/mr-tron/base58"
"github.com/tyler-smith/go-bip39"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/sha3"
)

var WalletAddressSolana string

// GenerateWalletAddress generates a wallet address from the mnemonic set in the environment
func GenerateWalletAddresssolana() {
// GenerateWalletAddressSolana generates a Solana 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")
fmt.Println("MNEMONIC_SOL environment variable is not set")
return
}

Expand All @@ -32,19 +32,17 @@ func GenerateWalletAddresssolana() {
// 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
}
// 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)

// Generate wallet address
hash := sha256.Sum256(publicKey)
WalletAddresssol := base58.Encode(hash[:20])
fmt.Printf("Wallet Address: %s\n", WalletAddresssol)
// Encode the public key to Base58
WalletAddressSolana = base58.Encode(publicKey)

// Assign the wallet address to the variable (consider error handling)
WalletAddressSolana = WalletAddresssol
fmt.Printf("The final wallet address: %s\n", WalletAddressSolana)
}
fmt.Printf("Wallet Address: %s\n", WalletAddressSolana)
}
32 changes: 22 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.22.2
require (
aidanwoods.dev/go-paseto v1.2.0
github.com/danielkov/gin-helmet v0.0.0-20171108135313-1387e224435e
github.com/docker/docker v26.0.1+incompatible
github.com/ethereum/go-ethereum v1.10.26
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/static v0.0.1
Expand All @@ -17,10 +18,15 @@ require (
github.com/libp2p/go-libp2p v0.33.2
github.com/libp2p/go-libp2p-kad-dht v0.25.2
github.com/libp2p/go-libp2p-pubsub v0.10.0
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.12.3
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/showwin/speedtest-go v1.6.10
github.com/sirupsen/logrus v1.9.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/tyler-smith/go-bip32 v1.0.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.19.0
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20221104135756-97bc4ad4a1cb
google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.32.0
Expand All @@ -29,30 +35,34 @@ 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/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chelnak/ysmrr v0.2.1 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/docker/docker v26.0.1+incompatible // indirect
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dop251/goja v0.0.0-20220405120441-9037c2b61cbf // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
Expand All @@ -78,6 +88,7 @@ require (
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/josharian/native v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/karalabe/usb v0.0.2 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
Expand All @@ -97,6 +108,7 @@ require (
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mdlayher/genetlink v1.3.1 // indirect
github.com/mdlayher/netlink v1.7.1 // indirect
github.com/mdlayher/socket v0.4.0 // indirect
Expand All @@ -106,7 +118,6 @@ require (
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
Expand All @@ -121,6 +132,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
Expand All @@ -131,10 +143,11 @@ require (
github.com/quic-go/quic-go v0.42.0 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/showwin/speedtest-go v1.6.10 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // 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/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // 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 All @@ -146,7 +159,6 @@ require (
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
Expand All @@ -157,7 +169,7 @@ require (
golang.zx2c4.com/wireguard v0.0.0-20230209153558-1e2c3e5a3c14 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
Loading

0 comments on commit 841ae57

Please sign in to comment.