Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
}
25 changes: 25 additions & 0 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1438,6 +1439,30 @@ impl From<bdk_wallet::ChangeSet> 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<All>,
}

#[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 {
Expand Down
11 changes: 9 additions & 2 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<SecpCtx> {
let secp: Secp256k1<All> = self.get_wallet().secp_ctx().clone();
Arc::new(SecpCtx { secp })
}
}

impl Wallet {
Expand Down
Loading