lnwallet: publicly export several functions within script_utils.go

This commit is contained in:
Olaoluwa Osuntokun 2016-08-12 15:37:35 -07:00
parent 044b65317a
commit 564316a846
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 14 additions and 13 deletions

View File

@ -58,9 +58,9 @@ func genMultiSigScript(aPub, bPub []byte) ([]byte, error) {
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.
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.
if amt <= 0 {
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
// 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)
// 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
// a matching output was found at all.
// 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
index := uint32(0)
for i, txOut := range tx.TxOut {
@ -670,7 +671,7 @@ func commitSpendNoDelay(commitScript []byte, outputAmt btcutil.Amount,
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
// pseudo-random-function. In the event that we (for some reason) broadcast a
// 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
//
// Where N is the order of the sub-group.
func deriveRevocationPubkey(commitPubKey *btcec.PublicKey,
func DeriveRevocationPubkey(commitPubKey *btcec.PublicKey,
revokePreimage []byte) *btcec.PublicKey {
// 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}
}
// 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
// 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
@ -713,7 +714,7 @@ func deriveRevocationPubkey(commitPubKey *btcec.PublicKey,
// revokePriv := commitPriv + revokePreimage mod N
//
// Where N is the order of the sub-group.
func deriveRevocationPrivKey(commitPrivKey *btcec.PrivateKey,
func DeriveRevocationPrivKey(commitPrivKey *btcec.PrivateKey,
revokePreimage []byte) *btcec.PrivateKey {
// Convert the revocation pre-image into a scalar value so we can

View File

@ -41,7 +41,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
channelBalance := btcutil.Amount(1 * 10e8)
csvTimeout := uint32(5)
revocationPreimage := testHdSeed[:]
revokePubKey := deriveRevocationPubkey(bobKeyPub, revocationPreimage)
revokePubKey := DeriveRevocationPubkey(bobKeyPub, revocationPreimage)
// 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
@ -50,7 +50,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
// This is Alice's commitment transaction, so she must wait a CSV delay
// of 5 blocks before sweeping the output, while bob can spend
// 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)
if err != 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
// simulate the scenario when alice broadcasts this commitmen
// transaction after it's been revoked.
revokePrivKey := deriveRevocationPrivKey(bobKeyPriv, revocationPreimage)
revokePrivKey := DeriveRevocationPrivKey(bobKeyPriv, revocationPreimage)
bobWitnessSpend, err := commitSpendRevoke(delayScript, channelBalance,
revokePrivKey, sweepTx)
if err != nil {
@ -144,9 +144,9 @@ func TestRevocationKeyDerivation(t *testing.T) {
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())
derivedRevPub := &btcec.PublicKey{
Curve: btcec.S256(),