forked from vulpemventures/go-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
32 lines (27 loc) · 877 Bytes
/
example.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
package main
import (
"encoding/hex"
"github.com/btcsuite/btcd/btcec"
"github.com/yenkuanlee/go-elements/network"
"github.com/yenkuanlee/go-elements/payment"
"github.com/yenkuanlee/go-elements/pset"
)
func randomKey() (string, error) {
ecPrivateKey, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
return "", err
}
privateKeyBytes := ecPrivateKey.Serialize()
return hex.EncodeToString(privateKeyBytes), nil
}
func main() {
privKeyHex := "1cc080a4cd371eafcad489a29664af6a7276b362fe783443ce036552482b971d"
privateKeyBytes, _ := hex.DecodeString(privKeyHex)
_, publicKey := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes)
pay := payment.FromPublicKey(publicKey, &network.Regtest, nil)
legacyAddress, _ := pay.PubKeyHash()
segwitAddress, _ := pay.WitnessPubKeyHash()
println(legacyAddress)
println(segwitAddress)
pset.New(nil, nil, 2, 0)
}