mirror of
https://github.com/muun/recovery.git
synced 2025-02-23 19:42:30 -05:00
25 lines
672 B
Go
25 lines
672 B
Go
|
package addresses
|
||
|
|
||
|
import (
|
||
|
"github.com/btcsuite/btcd/chaincfg"
|
||
|
"github.com/btcsuite/btcutil"
|
||
|
"github.com/btcsuite/btcutil/hdkeychain"
|
||
|
)
|
||
|
|
||
|
// CreateAddressV1 returns a P2PKH WalletAddress from a publicKey for use in TransactionSchemeV1
|
||
|
func CreateAddressV1(userKey *hdkeychain.ExtendedKey, path string, network *chaincfg.Params) (*WalletAddress, error) {
|
||
|
pubKey, err := userKey.ECPubKey()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
address, err := btcutil.NewAddressPubKey(pubKey.SerializeCompressed(), network)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &WalletAddress{
|
||
|
address: address.EncodeAddress(),
|
||
|
version: V1,
|
||
|
derivationPath: path,
|
||
|
}, nil
|
||
|
}
|