Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user implemented signer. #495

Merged
merged 11 commits into from
Oct 20, 2024
Merged

Support user implemented signer. #495

merged 11 commits into from
Oct 20, 2024

Conversation

roeierez
Copy link
Member

This PR allows users o initialize the sdk via their own signer implementation instead of passing the mnemonic phrase to the sdk.
A new function was added connect_with_signer and the Signer trait should be implemented and passed to the function.
For now we excluded flutter and react native because of binding issues.

Copy link
Contributor

@ok300 ok300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK.

This doesn't touch BtcSwapTx::partial_sign, which we use in the context of refund_tx_wrapper.partial_sign(), which take as arg the swap's refund keypair and internally calls MusigSession::partial_sign.

However this doesn't depend on user keys, so indeed the user-supplied signer shouldn't play a role for partial_sign.

.to_keypair(&secp);
let s = msg.as_slice();

let double_hashed_msg: Message = Message::from_digest_slice(s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: variable name is misleading as we don't know it's double hashed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// Prefix and double hash message
let mut engine = sha256::HashEngine::default();
engine.write_all(LN_MESSAGE_PREFIX)?;
engine.write_all(message.as_bytes())?;
let hashed_msg = sha256::Hash::from_engine(engine);
let double_hashed_msg = Message::from(sha256::Hash::hash(&hashed_msg));
let double_hashed_msg = Message::from_digest(hashed_msg.into_inner());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be double hashing any more?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed calling sign-message / check-message with the CLI finds the signature as invalid.

Changing the line to

let double_hashed_msg = Message::from_digest(sha256::Hash::hash(&hashed_msg).into_inner());

fixes the problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch guys. I fixed that and added a test for this case.

Comment on lines 227 to 250
// The master xpub encoded as 78 bytes length as defined in bip32 specification.
// For reference: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#user-content-Serialization_format
fn xpub(&self) -> Result<Vec<u8>, SignerError>;

// The derived xpub encoded as 78 bytes length as defined in bip32 specification.
// The derivation path is a string represents the shorter notation of the key tree to derive. For example:
// m/49'/1'/0'/0/0
// m/48'/1'/0'/0/0
// For reference: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#user-content-The_key_tree
fn derive_xpub(&self, derivation_path: String) -> Result<Vec<u8>, SignerError>;

// Sign an ECDSA message using the private key derived from the given derivation path
fn sign_ecdsa(&self, msg: Vec<u8>, derivation_path: String) -> Result<Vec<u8>, SignerError>;

// Sign an ECDSA message using the private key derived from the master key
fn sign_ecdsa_recoverable(&self, msg: Vec<u8>) -> Result<Vec<u8>, SignerError>;

// Return the master blinding key for SLIP77: https://github.com/satoshilabs/slips/blob/master/slip-0077.md
fn slip77_master_blinding_key(&self) -> Result<Vec<u8>, SignerError>;

// HMAC-SHA256 using the private key derived from the given derivation path
// This is used to calculate the linking key of lnurl-auth specification: https://github.com/lnurl/luds/blob/luds/05.md
fn hmac_sha256(&self, msg: Vec<u8>, derivation_path: String) -> Result<Vec<u8>, SignerError>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you /// them for rustdocs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, those flutter example files just need removing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All commits to packages/flutter/example can be removed, the example app removed in PR #510

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@hydra-yse hydra-yse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK

@roeierez roeierez merged commit e928c3d into main Oct 20, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants