github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/tools/type2determ/type2determ.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 "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 "strconv" 11 "encoding/hex" 12 "github.com/piotrnar/gocoin/lib/btc" 13 ) 14 15 16 func main() { 17 var testnet bool 18 19 if len(os.Args) < 3 { 20 fmt.Println("Specify secret, public_key and optionaly number of addresses you want.") 21 fmt.Println("Use a negative value for number of addresses, to work with Testnet addresses.") 22 return 23 } 24 public_key, er := hex.DecodeString(os.Args[2]) 25 if er != nil { 26 println("Error parsing public_key:", er.Error()) 27 os.Exit(1) 28 } 29 30 if len(public_key)==33 && (public_key[0]==2 || public_key[0]==3) { 31 fmt.Println("Compressed") 32 } else if len(public_key)==65 && (public_key[0]==4) { 33 fmt.Println("Uncompressed") 34 } else { 35 println("Incorrect public key") 36 } 37 38 secret, er := hex.DecodeString(os.Args[1]) 39 if er != nil { 40 println("Error parsing secret:", er.Error()) 41 os.Exit(1) 42 } 43 44 n := int64(25) 45 46 if len(os.Args) > 3 { 47 n, er = strconv.ParseInt(os.Args[3], 10, 32) 48 if er != nil { 49 println("Error parsing number of keys value:", er.Error()) 50 os.Exit(1) 51 } 52 if n == 0 { 53 return 54 } 55 56 if n < 0 { 57 n = -n 58 testnet = true 59 } 60 } 61 62 fmt.Println("# Type-2") 63 fmt.Println("#", hex.EncodeToString(public_key)) 64 fmt.Println("#", hex.EncodeToString(secret)) 65 66 for i:=1; i<=int(n); i++ { 67 fmt.Println(btc.NewAddrFromPubkey(public_key, btc.AddrVerPubkey(testnet)).String(), "TypB", i) 68 if i >= int(n) { 69 break 70 } 71 72 public_key = btc.DeriveNextPublic(public_key, secret) 73 } 74 }