lnwallet: publicly export several functions within script_utils.go
This commit is contained in:
2 files changed
+14
-13
No files matched your search
@@ -58,9 +58,9 @@ func genMultiSigScript(aPub, bPub []byte) ([]byte, error) {
|
|||||||
return bldr.Script()
|
return bldr.Script()
|
||||||
}
|
}
|
||||||
|
|
||||||
// genFundingPkScript creates a redeem script, and its matching p2wsh
|
// GenFundingPkScript creates a redeem script, and its matching p2wsh
|
||||||
// output for the funding transaction.
|
// output for the funding transaction.
|
||||||
func genFundingPkScript(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, error) {
|
func GenFundingPkScript(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, error) {
|
||||||
// As a sanity check, ensure that the passed amount is above zero.
|
// As a sanity check, ensure that the passed amount is above zero.
|
||||||
if amt <= 0 {
|
if amt <= 0 {
|
||||||
return nil, nil, fmt.Errorf("can't create FundTx script with " +
|
return nil, nil, fmt.Errorf("can't create FundTx script with " +
|
||||||
@@ -85,7 +85,7 @@ func genFundingPkScript(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, erro
|
|||||||
|
|
||||||
// spendMultiSig generates the witness stack required to redeem the 2-of-2 p2wsh
|
// spendMultiSig generates the witness stack required to redeem the 2-of-2 p2wsh
|
||||||
// multi-sig output.
|
// multi-sig output.
|
||||||
func spendMultiSig(redeemScript, pubA, sigA, pubB, sigB []byte) [][]byte {
|
func SpendMultiSig(redeemScript, pubA, sigA, pubB, sigB []byte) [][]byte {
|
||||||
witness := make([][]byte, 4)
|
witness := make([][]byte, 4)
|
||||||
|
|
||||||
// When spending a p2wsh multi-sig script, rather than an OP_0, we add
|
// When spending a p2wsh multi-sig script, rather than an OP_0, we add
|
||||||
@@ -114,7 +114,8 @@ func spendMultiSig(redeemScript, pubA, sigA, pubB, sigB []byte) [][]byte {
|
|||||||
// matching 'script'. Additionally, a boolean is returned indicating if
|
// matching 'script'. Additionally, a boolean is returned indicating if
|
||||||
// a matching output was found at all.
|
// a matching output was found at all.
|
||||||
// NOTE: The search stops after the first matching script is found.
|
// NOTE: The search stops after the first matching script is found.
|
||||||
func findScriptOutputIndex(tx *wire.MsgTx, script []byte) (bool, uint32) {
|
// TODO(roasbeef): shouldn't be public?
|
||||||
|
func FindScriptOutputIndex(tx *wire.MsgTx, script []byte) (bool, uint32) {
|
||||||
found := false
|
found := false
|
||||||
index := uint32(0)
|
index := uint32(0)
|
||||||
for i, txOut := range tx.TxOut {
|
for i, txOut := range tx.TxOut {
|
||||||
@@ -670,7 +671,7 @@ func commitSpendNoDelay(commitScript []byte, outputAmt btcutil.Amount,
|
|||||||
return wire.TxWitness(witness), nil
|
return wire.TxWitness(witness), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deriveRevocationPubkey derives the revocation public key given the
|
// DeriveRevocationPubkey derives the revocation public key given the
|
||||||
// counter-party's commitment key, and revocation pre-image derived via a
|
// counter-party's commitment key, and revocation pre-image derived via a
|
||||||
// pseudo-random-function. In the event that we (for some reason) broadcast a
|
// pseudo-random-function. In the event that we (for some reason) broadcast a
|
||||||
// revoked commitment transaction, then if the other party knows the revocation
|
// revoked commitment transaction, then if the other party knows the revocation
|
||||||
@@ -689,7 +690,7 @@ func commitSpendNoDelay(commitScript []byte, outputAmt btcutil.Amount,
|
|||||||
// revokePriv := commitPriv + revokePreimge mod N
|
// revokePriv := commitPriv + revokePreimge mod N
|
||||||
//
|
//
|
||||||
// Where N is the order of the sub-group.
|
// Where N is the order of the sub-group.
|
||||||
func deriveRevocationPubkey(commitPubKey *btcec.PublicKey,
|
func DeriveRevocationPubkey(commitPubKey *btcec.PublicKey,
|
||||||
revokePreimage []byte) *btcec.PublicKey {
|
revokePreimage []byte) *btcec.PublicKey {
|
||||||
|
|
||||||
// First we need to convert the revocation hash into a point on the
|
// First we need to convert the revocation hash into a point on the
|
||||||
@@ -703,7 +704,7 @@ func deriveRevocationPubkey(commitPubKey *btcec.PublicKey,
|
|||||||
return &btcec.PublicKey{X: revokeX, Y: revokeY}
|
return &btcec.PublicKey{X: revokeX, Y: revokeY}
|
||||||
}
|
}
|
||||||
|
|
||||||
// deriveRevocationPrivKey derives the revocation private key given a node's
|
// DeriveRevocationPrivKey derives the revocation private key given a node's
|
||||||
// commitment private key, and the pre-image to a previously seen revocation
|
// commitment private key, and the pre-image to a previously seen revocation
|
||||||
// hash. Using this derived private key, a node is able to claim the output
|
// hash. Using this derived private key, a node is able to claim the output
|
||||||
// within the commitment transaction of a node in the case that they broadcast
|
// within the commitment transaction of a node in the case that they broadcast
|
||||||
@@ -713,7 +714,7 @@ func deriveRevocationPubkey(commitPubKey *btcec.PublicKey,
|
|||||||
// revokePriv := commitPriv + revokePreimage mod N
|
// revokePriv := commitPriv + revokePreimage mod N
|
||||||
//
|
//
|
||||||
// Where N is the order of the sub-group.
|
// Where N is the order of the sub-group.
|
||||||
func deriveRevocationPrivKey(commitPrivKey *btcec.PrivateKey,
|
func DeriveRevocationPrivKey(commitPrivKey *btcec.PrivateKey,
|
||||||
revokePreimage []byte) *btcec.PrivateKey {
|
revokePreimage []byte) *btcec.PrivateKey {
|
||||||
|
|
||||||
// Convert the revocation pre-image into a scalar value so we can
|
// Convert the revocation pre-image into a scalar value so we can
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
|
|||||||
channelBalance := btcutil.Amount(1 * 10e8)
|
channelBalance := btcutil.Amount(1 * 10e8)
|
||||||
csvTimeout := uint32(5)
|
csvTimeout := uint32(5)
|
||||||
revocationPreimage := testHdSeed[:]
|
revocationPreimage := testHdSeed[:]
|
||||||
revokePubKey := deriveRevocationPubkey(bobKeyPub, revocationPreimage)
|
revokePubKey := DeriveRevocationPubkey(bobKeyPub, revocationPreimage)
|
||||||
|
|
||||||
// With all the test data set up, we create the commitment transaction.
|
// With all the test data set up, we create the commitment transaction.
|
||||||
// We only focus on a single party's transactions, as the scripts are
|
// We only focus on a single party's transactions, as the scripts are
|
||||||
@@ -50,7 +50,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
|
|||||||
// This is Alice's commitment transaction, so she must wait a CSV delay
|
// This is Alice's commitment transaction, so she must wait a CSV delay
|
||||||
// of 5 blocks before sweeping the output, while bob can spend
|
// of 5 blocks before sweeping the output, while bob can spend
|
||||||
// immediately with either the revocation key, or his regular key.
|
// immediately with either the revocation key, or his regular key.
|
||||||
commitmentTx, err := createCommitTx(fakeFundingTxIn, aliceKeyPub,
|
commitmentTx, err := CreateCommitTx(fakeFundingTxIn, aliceKeyPub,
|
||||||
bobKeyPub, revokePubKey, csvTimeout, channelBalance, channelBalance)
|
bobKeyPub, revokePubKey, csvTimeout, channelBalance, channelBalance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create commitment transaction: %v", nil)
|
t.Fatalf("unable to create commitment transaction: %v", nil)
|
||||||
@@ -96,7 +96,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
|
|||||||
// Next, we'll test bob spending with the derived revocation key to
|
// Next, we'll test bob spending with the derived revocation key to
|
||||||
// simulate the scenario when alice broadcasts this commitmen
|
// simulate the scenario when alice broadcasts this commitmen
|
||||||
// transaction after it's been revoked.
|
// transaction after it's been revoked.
|
||||||
revokePrivKey := deriveRevocationPrivKey(bobKeyPriv, revocationPreimage)
|
revokePrivKey := DeriveRevocationPrivKey(bobKeyPriv, revocationPreimage)
|
||||||
bobWitnessSpend, err := commitSpendRevoke(delayScript, channelBalance,
|
bobWitnessSpend, err := commitSpendRevoke(delayScript, channelBalance,
|
||||||
revokePrivKey, sweepTx)
|
revokePrivKey, sweepTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -144,9 +144,9 @@ func TestRevocationKeyDerivation(t *testing.T) {
|
|||||||
|
|
||||||
priv, pub := btcec.PrivKeyFromBytes(btcec.S256(), testWalletPrivKey)
|
priv, pub := btcec.PrivKeyFromBytes(btcec.S256(), testWalletPrivKey)
|
||||||
|
|
||||||
revocationPub := deriveRevocationPubkey(pub, revocationPreimage)
|
revocationPub := DeriveRevocationPubkey(pub, revocationPreimage)
|
||||||
|
|
||||||
revocationPriv := deriveRevocationPrivKey(priv, revocationPreimage)
|
revocationPriv := DeriveRevocationPrivKey(priv, revocationPreimage)
|
||||||
x, y := btcec.S256().ScalarBaseMult(revocationPriv.D.Bytes())
|
x, y := btcec.S256().ScalarBaseMult(revocationPriv.D.Bytes())
|
||||||
derivedRevPub := &btcec.PublicKey{
|
derivedRevPub := &btcec.PublicKey{
|
||||||
Curve: btcec.S256(),
|
Curve: btcec.S256(),
|
||||||
|
|||||||
Reference in new issue
Block a user