I cannot generate public keys in sequence.

59 views
Skip to first unread message

ass sds

unread,
Apr 6, 2022, 2:30:35 PM4/6/22
to golang-nuts
func Public(PrivateKey string) (publicKey string) { var e ecdsa.PrivateKey e.D, _ = new(big.Int).SetString(PrivateKey, 16) e.PublicKey.Curve = secp256k1.S256() e.PublicKey.X, e.PublicKey.Y = e.PublicKey.Curve.ScalarBaseMult(e.D.Bytes()) return fmt.Sprintf("%x", elliptic.MarshalCompressed(secp256k1.S256(), e.X, e.Y))
_________________________________________________________________________________________
i tried this

package main
  import
( "crypto/ecdsa" "crypto/elliptic" "fmt" "math/big" "github.com/ethereum/go-ethereum/crypto/secp256k1" )
  func Public(PrivateKey string) (publicKey string) { var e ecdsa.PrivateKey e.D, _ = new(big.Int).SetString(PrivateKey, 16) e.PublicKey.Curve = secp256k1.S256() e.PublicKey.X, e.PublicKey.Y = e.PublicKey.Curve.ScalarBaseMult(e.D.Bytes()) return fmt.Sprintf("%x", elliptic.MarshalCompressed(secp256k1.S256(), e.X, e.Y)) }
  func main() { count, one := big.NewInt(1), big.NewInt(1) count.SetString("9404625697166532776746648320380374280100293470930272690489102837043110636674",10) PrivateKey := make([]byte, 32)
  for { count.Add(count, one) copy(PrivateKey[32-len(count.Bytes()):], count.Bytes()) fmt.Printf("%x\n",Public(PrivateKey)) } }   
_______________________________________________________________________________________
output: ./ keysgo.go: 33: 33: unable to use PrivateKey (type [] byte) as type string in argument in Public
_______________________________________________________________________________________

I hope for your help. A thousand thanks

Brian Candler

unread,
Apr 6, 2022, 2:59:09 PM4/6/22
to golang-nuts
If you have a problem using the go-ethereum library then you're probably best asking at the tracker or discussion group for that software.

However, the error message seems pretty clear: you're trying to pass a value of type []byte to a function which takes a string.  You can convert one to the other, but it has to be requested explicitly:
https://go.dev/play/p/67C3mySRegN

Note also that your code posted is badly formatted (it's missing line breaks) which means it won't compile.  Using go.dev/play/ to make a self-contained program which demonstrates the problem is always a good idea, since it can be edited in-situ to fix.

Reply all
Reply to author
Forward
0 new messages