-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.go
More file actions
30 lines (25 loc) · 806 Bytes
/
convert.go
File metadata and controls
30 lines (25 loc) · 806 Bytes
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
// Copyright (c) 2018, Jonathan Chappelow
package pktopkhaddr
import (
"github.com/decred/dcrd/dcrec"
"github.com/decred/dcrd/dcrutil"
)
// PKAddr2PKHAddr converts a P2PK (pay-to-pubkey) address to a P2PKH
// (pay-to-pubkey-hash) address. The generated address specifies an ECDSA
// signature over the secp256k1 elliptic curve.
func PKAddr2PKHAddr(p2pk string) (p2pkh string, err error) {
// Attempt to decode the pay-to-pubkey address.
var addr dcrutil.Address
addr, err = dcrutil.DecodeAddress(p2pk)
if err != nil {
return
}
// Extract the pubkey hash.
addrHash := addr.Hash160()
// Create a new pay-to-pubkey-hash address.
addrPKH, err := dcrutil.NewAddressPubKeyHash(addrHash[:], addr.Net(), dcrec.STEcdsaSecp256k1)
if err != nil {
return
}
return addrPKH.EncodeAddress(), err
}