mirror of
https://github.com/muun/recovery.git
synced 2025-11-10 22:10:14 -05:00
Release v0.1.0
This commit is contained in:
84
vendor/github.com/muun/libwallet/V3.go
generated
vendored
Normal file
84
vendor/github.com/muun/libwallet/V3.go
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
package libwallet
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
)
|
||||
|
||||
func CreateAddressV3(userKey, muunKey *HDPublicKey) (MuunAddress, error) {
|
||||
|
||||
redeemScript, err := createRedeemScriptV3(userKey, muunKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
address, err := btcutil.NewAddressScriptHash(redeemScript, userKey.Network.network)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &muunAddress{
|
||||
address: address.EncodeAddress(),
|
||||
version: addressV3,
|
||||
derivationPath: userKey.Path,
|
||||
redeemScript: redeemScript,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func createRedeemScriptV3(userKey, muunKey *HDPublicKey) ([]byte, error) {
|
||||
witnessScript, err := createWitnessScriptV3(userKey, muunKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to generate redeem script v3")
|
||||
}
|
||||
|
||||
return createNonNativeSegwitRedeemScript(witnessScript)
|
||||
}
|
||||
|
||||
func createWitnessScriptV3(userKey, muunKey *HDPublicKey) ([]byte, error) {
|
||||
// createRedeemScriptV2 creates a valid script for both V2 and V3 schemes
|
||||
return createRedeemScriptV2(userKey, muunKey)
|
||||
}
|
||||
|
||||
func addUserSignatureInputV3(input Input, index int, tx *wire.MsgTx, privateKey *HDPrivateKey, muunKey *HDPublicKey) (*wire.TxIn, error) {
|
||||
|
||||
if len(input.MuunSignature()) == 0 {
|
||||
return nil, errors.Errorf("muun signature must be present")
|
||||
}
|
||||
|
||||
|
||||
witnessScript, err := createWitnessScriptV3(privateKey.PublicKey(), muunKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sig, err := signInputV3(input, index, tx, privateKey.PublicKey(), muunKey, privateKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
zeroByteArray := []byte{}
|
||||
|
||||
txInput := tx.TxIn[index]
|
||||
txInput.Witness = wire.TxWitness{zeroByteArray, sig, input.MuunSignature(), witnessScript}
|
||||
|
||||
return txInput, nil
|
||||
}
|
||||
|
||||
func signInputV3(input Input, index int, tx *wire.MsgTx, userKey *HDPublicKey, muunKey *HDPublicKey,
|
||||
signingKey *HDPrivateKey) ([]byte, error) {
|
||||
|
||||
witnessScript, err := createWitnessScriptV3(userKey, muunKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
redeemScript, err := createRedeemScriptV3(userKey, muunKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to build reedem script for signing")
|
||||
}
|
||||
|
||||
return signNonNativeSegwitInput(input, index, tx, signingKey, redeemScript, witnessScript)
|
||||
}
|
||||
Reference in New Issue
Block a user