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

feat: add ECDSA signature support #147

Merged
merged 3 commits into from
Sep 2, 2024

Conversation

appbak3r
Copy link
Contributor

This PR introduces a new RPC method to the Bitcoin Snap that allows for the signing of messages.

This feature enhances the BTC Snap by providing users with the ability to sign messages directly from the Snap, improving functionality and user control.

The added tests ensure that the feature is reliable and behaves as expected in various conditions.

  • The new method leverages the bitcoinjs-message library to sign messages using ECDSA.
  • BIP-322 Standard will be introduced shortly as soon as we agree on this PR.

);

const btcNetwork = getNetwork(snapNetwork);
const path = [...pathMap[ScriptType.P2SH_P2WPKH], "0'", '0', '0'];

Choose a reason for hiding this comment

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

Instead of hardcode the path here, it should be passed in as the parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please elaborate on this? How do you see it?

Copy link
Member

@aaronisme aaronisme Aug 14, 2024

Choose a reason for hiding this comment

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

Adding the path as the parameter to the signMessage function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to support the current API of the snap. neither btc_signPsbt and btc_signLNInvoice allow to change the path, should we do it here?

Copy link
Member

Choose a reason for hiding this comment

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

The PSBT data includes the BIP32 path in the inputs field to indicate which key to use for signing. For signMessage, this information should also be included to specify which key is being used for signing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'll do then next,

I'm going to remove scriptType from arguments, and will add derivePath argument so users can pass full derivation path, is it ok?

Also I'm going to test the path against request bip32 entropies supported by snap

network: btcNetwork,
}).address as string;

const result = await snap.request({

Choose a reason for hiding this comment

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

A warning should be included, if the message is not an hummable readable string, like a hex string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i've included warning for any message, the same way metamask does.

@appbak3r
Copy link
Contributor Author

image

@appbak3r
Copy link
Contributor Author

@aaronisme updated

@aaronisme aaronisme merged commit 6a30d1e into snapdao:master Sep 2, 2024
1 check passed
@appbak3r appbak3r deleted the feat/ecdsa-signature branch September 2, 2024 09:28
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.

3 participants