You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement struct wrappers for channel key types to avoid confusion.
Currently all channel keys and their basepoints exist uniformly as
`PublicKey` type, which not only makes in harder for a developer to
distinguish those entities, but also does not engage the language
type system to check if the correct key is being used in any
particular function.
Having struct wrappers around keys also enables more nuanced
semantics allowing to express Lightning Protocol rules in language.
For example, the code allows to derive `HtlcKey` from
`HtlcBasepoint` and not from `PaymentBasepoint`.
This change is transparent for channel monitors that will use the
internal public key of a wrapper.
Payment, DelayedPayment, HTLC and Revocation basepoints and their
derived keys are now wrapped into a specific struct that make it
distinguishable for the Rust type system. Functions that require a
specific key or basepoint should not use generic Public Key, but
require a specific key wrapper struct to engage Rust type
verification system and make it more clear for developers which
key is used.
let secret = self.get_secret(commitment_number).unwrap();
2993
2991
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
2994
2992
let per_commitment_point = PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx,&per_commitment_key);
2995
-
let revocation_pubkey = chan_utils::derive_public_revocation_key(&self.onchain_tx_handler.secp_ctx,&per_commitment_point,&self.holder_revocation_basepoint);
2996
-
let delayed_key = chan_utils::derive_public_key(&self.onchain_tx_handler.secp_ctx,&PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx,&per_commitment_key),&self.counterparty_commitment_params.counterparty_delayed_payment_base_key);
2993
+
let revocation_pubkey = RevocationKey::from_basepoint(&self.onchain_tx_handler.secp_ctx,&self.holder_revocation_basepoint,&per_commitment_point,);
2994
+
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx,&self.counterparty_commitment_params.counterparty_delayed_payment_base_key,&PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx,&per_commitment_key));
2997
2995
2998
2996
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,self.counterparty_commitment_params.on_counterparty_tx_csv,&delayed_key);
2999
2997
let revokeable_p2wsh = revokeable_redeemscript.to_v0_p2wsh();
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx,&self.counterparty_commitment_params.counterparty_delayed_payment_base_key,&per_commitment_point);
3110
+
3113
3111
let revokeable_p2wsh = chan_utils::get_revokeable_redeemscript(&revocation_pubkey,
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
1196
1197
use bitcoin::blockdata::script::ScriptBuf;
@@ -1209,7 +1210,7 @@ mod tests {
1209
1210
{
1210
1211
let dumb_scalar = SecretKey::from_slice(&<Vec<u8>>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
1211
1212
let dumb_point = PublicKey::from_secret_key(&$secp_ctx,&dumb_scalar);
0 commit comments