1
1
use bitcoin:: blockdata:: script:: { Script , Builder } ;
2
2
use bitcoin:: blockdata:: opcodes;
3
- use bitcoin:: blockdata:: transaction:: { TxIn , TxOut , Transaction } ;
3
+ use bitcoin:: blockdata:: transaction:: { TxIn , TxOut , OutPoint , Transaction } ;
4
4
use bitcoin:: util:: hash:: { Hash160 , Sha256dHash } ;
5
5
6
6
use secp256k1:: key:: { PublicKey , SecretKey } ;
@@ -32,10 +32,10 @@ pub fn build_commitment_secret(commitment_seed: [u8; 32], idx: u64) -> [u8; 32]
32
32
res
33
33
}
34
34
35
- pub fn derive_private_key ( secp_ctx : & Secp256k1 , per_commitment_point : & PublicKey , base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
35
+ pub fn derive_private_key < T : secp256k1 :: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
36
36
let mut sha = Sha256 :: new ( ) ;
37
37
sha. input ( & per_commitment_point. serialize ( ) ) ;
38
- sha. input ( & PublicKey :: from_secret_key ( & secp_ctx, & base_secret) . unwrap ( ) . serialize ( ) ) ;
38
+ sha. input ( & PublicKey :: from_secret_key ( & secp_ctx, & base_secret) . serialize ( ) ) ;
39
39
let mut res = [ 0 ; 32 ] ;
40
40
sha. result ( & mut res) ;
41
41
@@ -44,21 +44,21 @@ pub fn derive_private_key(secp_ctx: &Secp256k1, per_commitment_point: &PublicKey
44
44
Ok ( key)
45
45
}
46
46
47
- pub fn derive_public_key ( secp_ctx : & Secp256k1 , per_commitment_point : & PublicKey , base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
47
+ pub fn derive_public_key < T : secp256k1 :: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
48
48
let mut sha = Sha256 :: new ( ) ;
49
49
sha. input ( & per_commitment_point. serialize ( ) ) ;
50
50
sha. input ( & base_point. serialize ( ) ) ;
51
51
let mut res = [ 0 ; 32 ] ;
52
52
sha. result ( & mut res) ;
53
53
54
- let hashkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & secp_ctx, & res) ?) . unwrap ( ) ;
54
+ let hashkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & secp_ctx, & res) ?) ;
55
55
base_point. combine ( & secp_ctx, & hashkey)
56
56
}
57
57
58
58
/// Derives a revocation key from its constituent parts
59
- pub fn derive_private_revocation_key ( secp_ctx : & Secp256k1 , per_commitment_secret : & SecretKey , revocation_base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
60
- let revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & revocation_base_secret) . unwrap ( ) ;
61
- let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) . unwrap ( ) ;
59
+ pub fn derive_private_revocation_key < T : secp256k1 :: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , revocation_base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
60
+ let revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & revocation_base_secret) ;
61
+ let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) ;
62
62
63
63
let rev_append_commit_hash_key = {
64
64
let mut sha = Sha256 :: new ( ) ;
@@ -87,7 +87,7 @@ pub fn derive_private_revocation_key(secp_ctx: &Secp256k1, per_commitment_secret
87
87
Ok ( part_a)
88
88
}
89
89
90
- pub fn derive_public_revocation_key ( secp_ctx : & Secp256k1 , per_commitment_point : & PublicKey , revocation_base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
90
+ pub fn derive_public_revocation_key < T : secp256k1 :: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , revocation_base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
91
91
let rev_append_commit_hash_key = {
92
92
let mut sha = Sha256 :: new ( ) ;
93
93
sha. input ( & revocation_base_point. serialize ( ) ) ;
@@ -124,7 +124,7 @@ pub struct TxCreationKeys {
124
124
}
125
125
126
126
impl TxCreationKeys {
127
- pub fn new ( secp_ctx : & Secp256k1 , per_commitment_point : & PublicKey , a_delayed_payment_base : & PublicKey , a_htlc_base : & PublicKey , b_revocation_base : & PublicKey , b_payment_base : & PublicKey , b_htlc_base : & PublicKey ) -> Result < TxCreationKeys , secp256k1:: Error > {
127
+ pub fn new < T : secp256k1 :: Signing + secp256k1 :: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , a_delayed_payment_base : & PublicKey , a_htlc_base : & PublicKey , b_revocation_base : & PublicKey , b_payment_base : & PublicKey , b_htlc_base : & PublicKey ) -> Result < TxCreationKeys , secp256k1:: Error > {
128
128
Ok ( TxCreationKeys {
129
129
per_commitment_point : per_commitment_point. clone ( ) ,
130
130
revocation_key : derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & b_revocation_base) ?,
@@ -241,8 +241,10 @@ pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKey
241
241
pub fn build_htlc_transaction ( prev_hash : & Sha256dHash , feerate_per_kw : u64 , to_self_delay : u16 , htlc : & HTLCOutputInCommitment , a_delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
242
242
let mut txins: Vec < TxIn > = Vec :: new ( ) ;
243
243
txins. push ( TxIn {
244
- prev_hash : prev_hash. clone ( ) ,
245
- prev_index : htlc. transaction_output_index ,
244
+ previous_output : OutPoint {
245
+ txid : prev_hash. clone ( ) ,
246
+ vout : htlc. transaction_output_index ,
247
+ } ,
246
248
script_sig : Script :: new ( ) ,
247
249
sequence : 0 ,
248
250
witness : Vec :: new ( ) ,
0 commit comments