-
Notifications
You must be signed in to change notification settings - Fork 0
/
bt.go
52 lines (44 loc) · 1.03 KB
/
bt.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
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bufio"
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/hdkeychain"
)
func main() {
// Set the parameters for the main network.
params := &chaincfg.MainNetParams
// Prompt the user for a password.
fmt.Print("Enter password: ")
password, err := readPassword()
if err != nil {
fmt.Println(err)
return
}
// Generate a new master key using the password and the desired parameters.
masterKey, err := hdkeychain.GenerateMasterKey([]byte(password), params)
if err != nil {
fmt.Println(err)
return
}
// Generate a new address from the master key.
address, err := masterKey.Address(params)
if err != nil {
fmt.Println(err)
return
}
// Print the address.
fmt.Println(address)
}
// readPassword reads a password from the user's input.
func readPassword() (string, error) {
password, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return "", err
}
return password[:len(password)-1], nil
}