forked from saracen/bitcoin-all-key-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.go
40 lines (30 loc) · 1.05 KB
/
generate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"math/big"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
)
func main() {
// Print header
fmt.Printf("%64s %34s %34s\n", "Private", "Public", "Public Compressed")
// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(1)
// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)
// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)
// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())
// Get public key
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)
// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), &chaincfg.MainNetParams)
uaddr, _ := btcutil.NewAddressPubKey(public.SerializeUncompressed(), &chaincfg.MainNetParams)
// Print keys
fmt.Printf("%x %34s %34s\n", padded, uaddr.EncodeAddress(), caddr.EncodeAddress())
}
}