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 btc in wallet #11

Merged
merged 3 commits into from
Feb 10, 2025
Merged

Support btc in wallet #11

merged 3 commits into from
Feb 10, 2025

Conversation

OrestisAlpos
Copy link
Collaborator

@OrestisAlpos OrestisAlpos commented Jan 29, 2025

Closes #9.

The ipc-cli wallet command can now generate keys that are compatible with bitcoin. A new value btc was added for parameter --wallet-type. The created key is similar to the evm wallet type (secp256k1 keypair), with the only difference that the public key is even (as defined in libsecp256k1), as required by bitcoin's taproot.

Here is how to use the new functionalities of the wallet:

  • ipc-cli wallet new --wallet-type btc
  • ipc-cli wallet list --wallet-type btc
    output:
Address: 0x303d9fb576971313ebefd0afc085a21dd43de79d     Secret key: 45d08401bfa93d6f8ef8f489f0f0f7cccc6baaa7a46ba680eb3ae165df5f291d
        PubKey: 04b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5d1440c977c3faf1b52ef58b5b0960309734364a3e577608db5717709d910c690
        XonlyPubKey: b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5
  • ipc-cli wallet pub-key --wallet-type btc --address 0x303d9fb576971313ebefd0afc085a21dd43de79d
    output: 04b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5d1440c977c3faf1b52ef58b5b0960309734364a3e577608db5717709d910c690
  • ipc-cli wallet set-default --wallet-type btc --address 0x303d9fb576971313ebefd0afc085a21dd43de79d
  • ipc-cli wallet get-default --wallet-type btc
  • ipc-cli wallet export --wallet-type btc --address 0x303d9fb576971313ebefd0afc085a21dd43de79d --hex
    output: 45d08401bfa93d6f8ef8f489f0f0f7cccc6baaa7a46ba680eb3ae165df5f291d
    -ipc-cli wallet import --wallet-type btc --private-key 4c75ecd89d223417f7d46631ee1144ac16067be2de72801c5613e23a4d03f3dd
    output: 0x23df81f399387e8972b5286489378f139088ea85
  • ipc-cli wallet remove --wallet-type btc --address 0x23df81f399387e8972b5286489378f139088ea85
  • The command ipc-cli wallet balancesis not supported yet.

To create and join a subnet using the ipc wallet:

  • Make 4 wallets using ipc-cli wallet new --wallet-type btc
  • List the keys using ipc-cli wallet list --wallet-type btc:
Address: 0xff3cb3a95b4592651bee182e438b340ad7bdb0da	Secret key: c9cfab36297973170b3303b8c7114d8b2e0c887e81152a34fc9027e7a55d17eb
	PubKey: 0439e2f2d8da7fc908442a2d114af6e888d419f482ecd09a093c3310b0d0bd2315b1313dce746fa1a5f89f7be89cd886648bc4813cccb30d6e2f558fa0e90af158
	XonlyPubKey: 39e2f2d8da7fc908442a2d114af6e888d419f482ecd09a093c3310b0d0bd2315
Address: 0xd9de7930810060e59156c213cb9abba81fde1dfd	Secret key: acdc805fc49c437fc3d90ed84a90833b3c2717ee24a49b475b0bb4136dac26cb
	PubKey: 0402c44b5cb925062742b91f6af7b2b493ed4ea4adb753153010a2a8584980c0ce6dd5a13792d307787738744bd4ed961256660e114b7f94dce8f96beedf171a20
	XonlyPubKey: 02c44b5cb925062742b91f6af7b2b493ed4ea4adb753153010a2a8584980c0ce
Address: 0x303d9fb576971313ebefd0afc085a21dd43de79d	Secret key: 45d08401bfa93d6f8ef8f489f0f0f7cccc6baaa7a46ba680eb3ae165df5f291d
	PubKey: 04b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5d1440c977c3faf1b52ef58b5b0960309734364a3e577608db5717709d910c690
	XonlyPubKey: b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5
Address: 0xd1e354d7b88f7e15aa63a04e6707fb7aff5b4e3c	Secret key: 0bc244d4c211610c31e96a8f36a7e7c359819874d7035988c6597823a3830259
	PubKey: 04c3bca1185923a02d09fc17ffd52edc65c26dd5a100144b37b11d0cba14212c092e8a7fd614deae5e337ed3036ef712ac77c93e345758e6bfe23e061553518436
	XonlyPubKey: c3bca1185923a02d09fc17ffd52edc65c26dd5a100144b37b11d0cba14212c09
  • Construct the whitelist using the XOnlyPublicKey values. It will look like this:
39e2f2d8da7fc908442a2d114af6e888d419f482ecd09a093c3310b0d0bd2315, 02c44b5cb925062742b91f6af7b2b493ed4ea4adb753153010a2a8584980c0ce, b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5,
c3bca1185923a02d09fc17ffd52edc65c26dd5a100144b37b11d0cba14212c09
  • Use this whitelist in the create subcommand:
ipc-cli subnet create --parent /bip122:0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 --min-validators 4 --bottomup-check-period 300 btc --min-validator-stake 10000000 --min-cross-msg-fee 10 --validator-whitelist 39e2f2d8da7fc908442a2d114af6e888d419f482ecd09a093c3310b0d0bd2315,02c44b5cb925062742b91f6af7b2b493ed4ea4adb753153010a2a8584980c0ce,b7a6d2916cf35d7c69e31e9bf169138d09536495f64e6bb84abc009b72a3b0d5,c3bca1185923a02d09fc17ffd52edc65c26dd5a100144b37b11d0cba14212c09
  • Write down the returned subnet id.
  • Use the join subcommand 4 times, specifying each time one of the outputs of wallet list in the --from argument. For example:
ipc-cli subnet join --from 0xff3cb3a95b4592651bee182e438b340ad7bdb0da --subnet=/bip122:0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206/2008096c93208ab6e1283b166044d271704ba95f288db1fc81b1588b74d21538 btc --collateral=20000000 --ip 66.222.44.55:8080 --backup-address bcrt1q3fznspr3e02artm9df7tk827a2xhny2m4zzr6n

@rista404 rista404 force-pushed the join-subnet-usid branch 2 times, most recently from 8a3d6a2 to 47492a7 Compare January 30, 2025 13:22
Base automatically changed from join-subnet-usid to bitcoin January 30, 2025 13:24
@rista404 rista404 force-pushed the support-btc-in-wallet branch from 2a72fc1 to c7265ef Compare January 30, 2025 13:27
Copy link
Collaborator

@rista404 rista404 left a comment

Choose a reason for hiding this comment

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

everything works from my testing — we can also add wallet balance support in another PR!

/// Generate a random secp256k1 private key, subject to the constraint that the
/// public key partity is even.
pub fn random_btc_secret_key() -> KeyInfo {
let secret_key = loop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can negate the secret key to negate its parity, instead of looping. But the libsecp256k1 doesn't provide the negate method (the underlying Scalar does but it's not public, annoying). So let's keep it this way.

@@ -99,6 +99,9 @@ impl CommandLineHandler for WalletBalances {
println!("{:?} - Balance: {}", addr, balance);
}
}
WalletType::Btc => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this use the same (except the wallet name) implementation as the evm wallet type? It looks like it forwards the request to the manager

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To handle in #16

@OrestisAlpos OrestisAlpos merged commit 8554715 into bitcoin Feb 10, 2025
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.

2 participants