diff --git a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/WalletTest.kt b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/WalletTest.kt index 84057a3f..2c979324 100644 --- a/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/WalletTest.kt +++ b/bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/WalletTest.kt @@ -6,6 +6,7 @@ import kotlin.test.assertTrue import kotlin.test.assertFalse import androidx.test.ext.junit.runners.AndroidJUnit4 import org.junit.runner.RunWith +import kotlin.test.assertNotNull @RunWith(AndroidJUnit4::class) class WalletTest { @@ -65,4 +66,17 @@ class WalletTest { "Addresses should be the same" ) } + + @Test + fun getWalletSecpCtx() { + val wallet: Wallet = Wallet.createSingle( + descriptor = BIP84_DESCRIPTOR, + network = Network.TESTNET, + persister = conn + ) + val secp = wallet.secpCtx() + val stringSpec = secp.toString() + + assertNotNull(stringSpec, "SecpCtx should not be null") + } } diff --git a/bdk-ffi/src/types.rs b/bdk-ffi/src/types.rs index 0cfe874c..c3178344 100644 --- a/bdk-ffi/src/types.rs +++ b/bdk-ffi/src/types.rs @@ -43,6 +43,7 @@ use bdk_esplora::esplora_client::api::MerkleProof as BdkMerkleProof; use bdk_esplora::esplora_client::api::OutputStatus as BdkOutputStatus; use bdk_esplora::esplora_client::api::Tx as BdkTx; use bdk_esplora::esplora_client::api::TxStatus as BdkTxStatus; +use bdk_wallet::bitcoin::secp256k1::{All, Secp256k1}; pub(crate) type KeychainKind = bdk_wallet::KeychainKind; @@ -1438,6 +1439,30 @@ impl From for ChangeSet { } } +/// The secp256k1 engine, used to execute all signature operations. +#[derive(Debug, uniffi::Object)] +#[uniffi::export(Debug, Display)] +pub struct SecpCtx { + pub(crate) secp: Secp256k1, +} + +#[uniffi::export] +impl SecpCtx { + /// Create a new SecpCtx + #[uniffi::constructor] + pub fn new() -> Self { + SecpCtx { + secp: Secp256k1::new(), + } + } +} + +impl Display for SecpCtx { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.secp) + } +} + /// Details about a transaction affecting the wallet (relevant and canonical). #[derive(uniffi::Record, Debug, Clone)] pub struct TxDetails { diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 0a06ccd0..45e8e73c 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -7,10 +7,11 @@ use crate::error::{ use crate::store::{PersistenceType, Persister}; use crate::types::{ AddressInfo, Balance, BlockId, CanonicalTx, ChangeSet, EvictedTx, FullScanRequestBuilder, - KeychainAndIndex, KeychainKind, LocalOutput, Policy, SentAndReceivedValues, SignOptions, - SyncRequestBuilder, UnconfirmedTx, Update, WalletEvent, WalletKeychain, + KeychainAndIndex, KeychainKind, LocalOutput, Policy, SecpCtx, SentAndReceivedValues, + SignOptions, SyncRequestBuilder, UnconfirmedTx, Update, WalletEvent, WalletKeychain, }; +use bdk_wallet::bitcoin::secp256k1::{All, Secp256k1}; use bdk_wallet::bitcoin::Network; use bdk_wallet::keys::KeyMap; #[allow(deprecated)] @@ -770,6 +771,12 @@ impl Wallet { pub fn public_descriptor(&self, keychain: KeychainKind) -> String { self.get_wallet().public_descriptor(keychain).to_string() } + + /// Return the secp256k1 context used for all signing operations. + pub fn secp_ctx(&self) -> Arc { + let secp: Secp256k1 = self.get_wallet().secp_ctx().clone(); + Arc::new(SecpCtx { secp }) + } } impl Wallet {