-
Notifications
You must be signed in to change notification settings - Fork 2
/
v4.go
36 lines (29 loc) · 1.09 KB
/
v4.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
package addresses
import (
"crypto/sha256"
"fmt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/hdkeychain"
)
// CreateAddressV4 returns a P2WSH WalletAddress from a user HD-pubkey and a Muun co-signing HD-pubkey.
func CreateAddressV4(userKey, muunKey *hdkeychain.ExtendedKey, path string, network *chaincfg.Params) (*WalletAddress, error) {
witnessScript, err := CreateWitnessScriptV4(userKey, muunKey, network)
if err != nil {
return nil, fmt.Errorf("failed to generate witness script v4: %w", err)
}
witnessScript256 := sha256.Sum256(witnessScript)
address, err := btcutil.NewAddressWitnessScriptHash(witnessScript256[:], network)
if err != nil {
return nil, err
}
return &WalletAddress{
address: address.EncodeAddress(),
version: V4,
derivationPath: path,
}, nil
}
func CreateWitnessScriptV4(userKey, muunKey *hdkeychain.ExtendedKey, network *chaincfg.Params) ([]byte, error) {
// createMultisigRedeemScript creates a valid script for V2, V3 and V4 schemes
return createMultisigRedeemScript(userKey, muunKey, network)
}