github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/tools/type2next/type2next.go (about) 1 // This tool outpus Type-2 deterministic addresses, as described here: 2 // https://bitcointalk.org/index.php?topic=19137.0 3 // At input it takes "A_public_key" and "B_secret" - both values as hex encoded strings. 4 // Optionally, you can add a third parameter - number of public keys you want to calculate. 5 package main 6 7 import ( 8 "os" 9 "fmt" 10 "encoding/hex" 11 "github.com/piotrnar/gocoin/lib/btc" 12 ) 13 14 15 func main() { 16 if len(os.Args) < 3 { 17 fmt.Println("Specify secret and public_key to get the next Type-2 deterministic address") 18 fmt.Println("Add -t as the third argument to work with Testnet addresses.") 19 return 20 } 21 public_key, er := hex.DecodeString(os.Args[2]) 22 if er != nil { 23 println("Error parsing public_key:", er.Error()) 24 os.Exit(1) 25 } 26 27 if len(public_key)==33 && (public_key[0]==2 || public_key[0]==3) { 28 fmt.Println("Compressed") 29 } else if len(public_key)==65 && (public_key[0]==4) { 30 fmt.Println("Uncompressed") 31 } else { 32 println("Incorrect public key") 33 } 34 35 secret, er := hex.DecodeString(os.Args[1]) 36 if er != nil { 37 println("Error parsing secret:", er.Error()) 38 os.Exit(1) 39 } 40 41 testnet := len(os.Args) > 3 && os.Args[3]=="-t" 42 43 // Old address 44 public_key = btc.DeriveNextPublic(public_key, secret) 45 46 // New address 47 fmt.Println(btc.NewAddrFromPubkey(public_key, btc.AddrVerPubkey(testnet)).String()) 48 // New key 49 fmt.Println(hex.EncodeToString(public_key)) 50 51 }