@bennyblader/ddk-rn 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,13 @@
1
- #![allow(unused_imports, unused_variables)]
2
1
  #![allow(clippy::too_many_arguments)]
3
- use bitcoin::consensus::{Decodable, Encodable};
2
+ use bip39::{Language, Mnemonic};
3
+ use bitcoin::bip32::{DerivationPath, IntoDerivationPath, Xpriv, Xpub};
4
4
  use bitcoin::hashes::Hash;
5
- use bitcoin::sighash::{EcdsaSighashType, SighashCache};
6
- use bitcoin::transaction::Version;
5
+ use bitcoin::sighash::EcdsaSighashType;
7
6
  use bitcoin::{
8
- Amount, OutPoint, ScriptBuf, Sequence, Transaction as BtcTransaction, TxIn, TxOut as BtcTxOut,
9
- Txid, Witness,
7
+ Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction as BtcTransaction, TxIn,
8
+ TxOut as BtcTxOut, Txid, Witness,
10
9
  };
11
- use bitcoin::{PubkeyHash, WPubkeyHash};
10
+ use bitcoin::{Script, WPubkeyHash};
12
11
  use dlc::{
13
12
  self, dlc_input::DlcInputInfo as RustDlcInputInfo, DlcTransactions as RustDlcTransactions,
14
13
  OracleInfo as DlcOracleInfo, PartyParams as DlcPartyParams, Payout as DlcPayout,
@@ -17,11 +16,18 @@ use dlc::{
17
16
  use secp256k1_zkp::{
18
17
  ecdsa::Signature as EcdsaSignature, Message, PublicKey, Secp256k1, SecretKey, XOnlyPublicKey,
19
18
  };
20
- use secp256k1_zkp::{schnorr::Signature as SchnorrSignature, EcdsaAdaptorSignature};
19
+ use secp256k1_zkp::{schnorr::Signature as SchnorrSignature, All, EcdsaAdaptorSignature};
21
20
  use std::str::FromStr;
21
+ use std::sync::OnceLock;
22
22
 
23
23
  uniffi::include_scaffolding!("ddk_ffi");
24
24
 
25
+ static SECP_CONTEXT: OnceLock<Secp256k1<All>> = OnceLock::new();
26
+
27
+ pub fn get_secp_context() -> &'static Secp256k1<All> {
28
+ SECP_CONTEXT.get_or_init(Secp256k1::new)
29
+ }
30
+
25
31
  pub fn version() -> String {
26
32
  env!("CARGO_PKG_VERSION").to_string()
27
33
  }
@@ -54,8 +60,22 @@ pub enum DLCError {
54
60
  Secp256k1Error(String),
55
61
  #[error("Miniscript error")]
56
62
  MiniscriptError,
57
- #[error("Network error")]
58
- NetworkError,
63
+ #[error("Invalid network")]
64
+ InvalidNetwork,
65
+ #[error("Extended key error: {0}")]
66
+ KeyError(ExtendedKey),
67
+ }
68
+
69
+ #[derive(Debug, thiserror::Error)]
70
+ pub enum ExtendedKey {
71
+ #[error("Invalid mnemonic")]
72
+ InvalidMnemonic,
73
+ #[error("Invalid xpriv")]
74
+ InvalidXpriv,
75
+ #[error("Invalid xpub")]
76
+ InvalidXpub,
77
+ #[error("Invalid derivation path")]
78
+ InvalidDerivationPath,
59
79
  }
60
80
 
61
81
  impl From<dlc::Error> for DLCError {
@@ -452,8 +472,8 @@ pub fn create_cets(
452
472
  witness: Witness::new(),
453
473
  };
454
474
 
455
- let local_script = bitcoin::Script::from_bytes(&local_final_script_pubkey);
456
- let remote_script = bitcoin::Script::from_bytes(&remote_final_script_pubkey);
475
+ let local_script = Script::from_bytes(&local_final_script_pubkey);
476
+ let remote_script = Script::from_bytes(&remote_final_script_pubkey);
457
477
 
458
478
  let payouts: Vec<DlcPayout> = outcomes
459
479
  .iter()
@@ -624,14 +644,14 @@ pub fn get_raw_funding_transaction_input_signature(
624
644
  })
625
645
  .ok_or(DLCError::InvalidArgument)?;
626
646
 
647
+ let secp = get_secp_context();
627
648
  // Create P2WPKH script for signing
628
- let pk = PublicKey::from_secret_key(&Secp256k1::new(), &sk);
649
+ let pk = PublicKey::from_secret_key(secp, &sk);
629
650
  let wpkh = WPubkeyHash::hash(&pk.serialize());
630
651
  let script = bitcoin::ScriptBuf::new_p2wpkh(&wpkh);
631
652
 
632
- let secp = Secp256k1::signing_only();
633
653
  let sig = dlc::util::get_raw_sig_for_tx_input(
634
- &secp,
654
+ secp,
635
655
  &btc_tx,
636
656
  input_index,
637
657
  &script,
@@ -678,6 +698,51 @@ pub fn sign_fund_transaction_input(
678
698
  Ok(btc_tx_to_transaction(&btc_tx))
679
699
  }
680
700
 
701
+ pub fn sign_cet(
702
+ cet: Transaction,
703
+ adaptor_signature: Vec<u8>,
704
+ oracle_signatures: Vec<Vec<u8>>,
705
+ funding_secret_key: Vec<u8>,
706
+ other_pubkey: Vec<u8>,
707
+ funding_script_pubkey: Vec<u8>,
708
+ fund_output_value: u64,
709
+ ) -> Result<Transaction, DLCError> {
710
+ let mut btc_tx = transaction_to_btc_tx(&cet)?;
711
+ let adaptor_sig = vec_to_ecdsa_adaptor_signature(adaptor_signature)?;
712
+ let oracle_sigs = oracle_signatures
713
+ .iter()
714
+ .map(|sig| vec_to_schnorr_signature(sig))
715
+ .collect::<Result<Vec<_>, _>>()?;
716
+ let funding_sk =
717
+ SecretKey::from_slice(&funding_secret_key).map_err(|_| DLCError::InvalidArgument)?;
718
+ let other_pk = PublicKey::from_slice(&other_pubkey).map_err(|_| DLCError::InvalidPublicKey)?;
719
+ let funding_script = Script::from_bytes(&funding_script_pubkey);
720
+ let secp = get_secp_context();
721
+
722
+ dlc::sign_cet(
723
+ secp,
724
+ &mut btc_tx,
725
+ &adaptor_sig,
726
+ &[oracle_sigs],
727
+ &funding_sk,
728
+ &other_pk,
729
+ &funding_script,
730
+ Amount::from_sat(fund_output_value),
731
+ )
732
+ .map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
733
+
734
+ Ok(btc_tx_to_transaction(&btc_tx))
735
+ }
736
+
737
+ fn vec_to_schnorr_signature(signature: &Vec<u8>) -> Result<SchnorrSignature, DLCError> {
738
+ let sig = SchnorrSignature::from_slice(signature).map_err(|_| DLCError::InvalidSignature)?;
739
+ Ok(sig)
740
+ }
741
+
742
+ fn vec_to_ecdsa_adaptor_signature(signature: Vec<u8>) -> Result<EcdsaAdaptorSignature, DLCError> {
743
+ EcdsaAdaptorSignature::from_slice(&signature).map_err(|_| DLCError::InvalidSignature)
744
+ }
745
+
681
746
  /// Create CET adaptor signature from oracle info
682
747
  pub fn create_cet_adaptor_signature_from_oracle_info(
683
748
  cet: Transaction,
@@ -689,7 +754,7 @@ pub fn create_cet_adaptor_signature_from_oracle_info(
689
754
  ) -> Result<AdaptorSignature, DLCError> {
690
755
  let btc_tx = transaction_to_btc_tx(&cet)?;
691
756
  let sk = SecretKey::from_slice(&funding_sk).map_err(|_| DLCError::InvalidArgument)?;
692
- let funding_script = bitcoin::Script::from_bytes(&funding_script_pubkey);
757
+ let funding_script = Script::from_bytes(&funding_script_pubkey);
693
758
 
694
759
  // Convert oracle info
695
760
  let oracle_pk = XOnlyPublicKey::from_slice(&oracle_info.public_key)
@@ -714,9 +779,9 @@ pub fn create_cet_adaptor_signature_from_oracle_info(
714
779
  let msg_vec = messages.map_err(|_| DLCError::InvalidArgument)?;
715
780
  let nested_msgs = vec![msg_vec]; // Wrap in vector for single oracle
716
781
 
717
- let secp = Secp256k1::new();
782
+ let secp = get_secp_context();
718
783
  let adaptor_sig = dlc::create_cet_adaptor_sig_from_oracle_info(
719
- &secp,
784
+ secp,
720
785
  &btc_tx,
721
786
  &[dlc_oracle_info],
722
787
  &sk,
@@ -732,6 +797,57 @@ pub fn create_cet_adaptor_signature_from_oracle_info(
732
797
  })
733
798
  }
734
799
 
800
+ pub fn convert_mnemonic_to_seed(
801
+ mnemonic: String,
802
+ passphrase: Option<String>,
803
+ ) -> Result<Vec<u8>, DLCError> {
804
+ let seed_mnemonic = Mnemonic::parse_in_normalized(Language::English, &mnemonic)
805
+ .map_err(|_| DLCError::KeyError(ExtendedKey::InvalidMnemonic))?;
806
+ let passphrase = passphrase.unwrap_or("".to_string());
807
+ let seed = seed_mnemonic.to_seed(&passphrase);
808
+ Ok(seed.to_vec())
809
+ }
810
+
811
+ pub fn create_xpriv_from_parent_path(
812
+ xpriv: Vec<u8>,
813
+ base_derivation_path: String,
814
+ network: String,
815
+ path: String,
816
+ ) -> Result<Vec<u8>, DLCError> {
817
+ if xpriv.len() != 64 {
818
+ return Err(DLCError::KeyError(ExtendedKey::InvalidXpriv));
819
+ }
820
+ let secp = get_secp_context();
821
+ let network = Network::from_str(&network).map_err(|_| DLCError::InvalidNetwork)?;
822
+ let xpriv = Xpriv::new_master(network, &xpriv)
823
+ .map_err(|_| DLCError::KeyError(ExtendedKey::InvalidXpriv))?;
824
+ // Base path: 84'/0'/0'
825
+ let base_path = DerivationPath::from_str(&base_derivation_path)
826
+ .map_err(|_| DLCError::KeyError(ExtendedKey::InvalidDerivationPath))?;
827
+
828
+ // App path: {0 || 1}/{child_number}
829
+ let app_path = path
830
+ .into_derivation_path()
831
+ .map_err(|_| DLCError::KeyError(ExtendedKey::InvalidDerivationPath))?;
832
+
833
+ let full_path = base_path.extend(app_path);
834
+
835
+ let derived_xpriv = xpriv
836
+ .derive_priv(secp, &full_path)
837
+ .map_err(|_| DLCError::KeyError(ExtendedKey::InvalidXpriv))?;
838
+
839
+ Ok(derived_xpriv.encode().to_vec())
840
+ }
841
+
842
+ pub fn get_xpub_from_xpriv(xpriv: Vec<u8>, network: String) -> Result<Vec<u8>, DLCError> {
843
+ let secp = get_secp_context();
844
+ let network = Network::from_str(&network).map_err(|_| DLCError::InvalidNetwork)?;
845
+ let xpriv = Xpriv::new_master(network, &xpriv)
846
+ .map_err(|_| DLCError::KeyError(ExtendedKey::InvalidXpriv))?;
847
+ let xpub = Xpub::from_priv(secp, &xpriv);
848
+ Ok(xpub.encode().to_vec())
849
+ }
850
+
735
851
  #[cfg(test)]
736
852
  mod tests {
737
853
  use super::*;
@@ -760,7 +876,6 @@ mod tests {
760
876
  fund_pubkey: Vec<u8>,
761
877
  serial_id: u64,
762
878
  ) -> PartyParams {
763
- let secp = Secp256k1::new();
764
879
  let mut rng = thread_rng();
765
880
 
766
881
  // Create a realistic P2WPKH script
@@ -793,6 +908,50 @@ mod tests {
793
908
  }
794
909
  }
795
910
 
911
+ #[test]
912
+ fn mnemonic_to_seed_test() {
913
+ let mnemonic = Mnemonic::generate(24).unwrap();
914
+ let rust_seed = mnemonic.to_seed_normalized("").to_vec();
915
+ let ffi_seed = convert_mnemonic_to_seed(mnemonic.to_string(), None).unwrap();
916
+ assert_eq!(rust_seed, ffi_seed);
917
+ }
918
+
919
+ #[test]
920
+ fn xpriv_to_xpub_test() {
921
+ let mnemonic = Mnemonic::generate(24).unwrap();
922
+ let rust_xpriv =
923
+ Xpriv::new_master(Network::Bitcoin, &mnemonic.to_seed_normalized("").to_vec()).unwrap();
924
+ let ffi_xpriv = convert_mnemonic_to_seed(mnemonic.to_string(), None).unwrap();
925
+ let rust_xpub = Xpub::from_priv(get_secp_context(), &rust_xpriv);
926
+ let ffi_xpub = get_xpub_from_xpriv(ffi_xpriv, "bitcoin".to_string()).unwrap();
927
+ assert_eq!(rust_xpub.encode().to_vec(), ffi_xpub);
928
+ }
929
+
930
+ #[test]
931
+ fn xpriv_to_path() {
932
+ let base_derivation_path = "84'/0'/0'";
933
+ let app_path = "0/1";
934
+ let network = "bitcoin";
935
+ let secp = get_secp_context();
936
+
937
+ let mnemonic = Mnemonic::generate(24).unwrap();
938
+ let rust_xpriv =
939
+ Xpriv::new_master(Network::Bitcoin, &mnemonic.to_seed_normalized("")).unwrap();
940
+ let rust_path =
941
+ DerivationPath::from_str(&format!("{}/{}", base_derivation_path, app_path)).unwrap();
942
+ let rust_xpriv = rust_xpriv.derive_priv(&secp, &rust_path).unwrap();
943
+
944
+ let ffi_xpriv_bytes = convert_mnemonic_to_seed(mnemonic.to_string(), None).unwrap();
945
+ let ffi_xpub = create_xpriv_from_parent_path(
946
+ ffi_xpriv_bytes,
947
+ base_derivation_path.to_string(),
948
+ network.to_string(),
949
+ app_path.to_string(),
950
+ )
951
+ .unwrap();
952
+ assert_eq!(rust_xpriv.encode().to_vec(), ffi_xpub);
953
+ }
954
+
796
955
  #[test]
797
956
  fn test_create_fund_tx_locking_script_matches_rust_dlc() {
798
957
  let (_offer_sk, offer_pk, _accept_sk, accept_pk) = create_test_keys();
@@ -997,7 +1156,7 @@ mod tests {
997
1156
 
998
1157
  #[test]
999
1158
  fn test_conversion_functions() {
1000
- let (_offer_sk, offer_pk, _accept_sk, accept_pk) = create_test_keys();
1159
+ let (_offer_sk, offer_pk, _accept_sk, _accept_pk) = create_test_keys();
1001
1160
 
1002
1161
  // Test party params conversion
1003
1162
  let params =
@@ -1 +1 @@
1
- {"version":3,"names":["getter","globalThis","NativeDdkFfi","_default","exports","default","isRustFutureContinuationCallbackTypeCompatible","isUniffiForeignFutureTypeCompatible"],"sourceRoot":"../../src","sources":["ddk_ffi-ffi.ts"],"mappings":";;;;;;AAAA;AACA;;AAyJA;AACA;AACA;AACA;AACA;AACA,MAAMA,MAAmC,GAAGA,CAAA,KACzCC,UAAU,CAASC,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACpBL,MAAM,EAErB;AAmHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,8CAGL,GAAG,IAAI;AACR,MAAMC,mCAGL,GAAG,IAAI","ignoreList":[]}
1
+ {"version":3,"names":["getter","globalThis","NativeDdkFfi","_default","exports","default","isRustFutureContinuationCallbackTypeCompatible","isUniffiForeignFutureTypeCompatible"],"sourceRoot":"../../src","sources":["ddk_ffi-ffi.ts"],"mappings":";;;;;;AAAA;AACA;;AAoLA;AACA;AACA;AACA;AACA;AACA,MAAMA,MAAmC,GAAGA,CAAA,KACzCC,UAAU,CAASC,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACpBL,MAAM,EAErB;AAmHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,8CAGL,GAAG,IAAI;AACR,MAAMC,mCAGL,GAAG,IAAI","ignoreList":[]}
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TxOutput = exports.TxInputInfo = exports.TxInput = exports.Transaction = exports.Payout = exports.PartyParams = exports.OracleInfo = exports.DlcTransactions = exports.DlcOutcome = exports.DlcInputInfo = exports.DlcError_Tags = exports.DlcError = exports.ChangeOutputAndFees = exports.AdaptorSignature = void 0;
6
+ exports.TxOutput = exports.TxInputInfo = exports.TxInput = exports.Transaction = exports.Payout = exports.PartyParams = exports.OracleInfo = exports.ExtendedKey_Tags = exports.ExtendedKey = exports.DlcTransactions = exports.DlcOutcome = exports.DlcInputInfo = exports.DlcError_Tags = exports.DlcError = exports.ChangeOutputAndFees = exports.AdaptorSignature = void 0;
7
+ exports.convertMnemonicToSeed = convertMnemonicToSeed;
7
8
  exports.createCet = createCet;
8
9
  exports.createCetAdaptorSignatureFromOracleInfo = createCetAdaptorSignatureFromOracleInfo;
9
10
  exports.createCets = createCets;
@@ -11,12 +12,14 @@ exports.createDlcTransactions = createDlcTransactions;
11
12
  exports.createFundTxLockingScript = createFundTxLockingScript;
12
13
  exports.createRefundTransaction = createRefundTransaction;
13
14
  exports.createSplicedDlcTransactions = createSplicedDlcTransactions;
15
+ exports.createXprivFromParentPath = createXprivFromParentPath;
14
16
  exports.default = void 0;
15
17
  exports.getChangeOutputAndFees = getChangeOutputAndFees;
16
18
  exports.getRawFundingTransactionInputSignature = getRawFundingTransactionInputSignature;
17
19
  exports.getTotalInputVsize = getTotalInputVsize;
20
+ exports.getXpubFromXpriv = getXpubFromXpriv;
18
21
  exports.isDustOutput = isDustOutput;
19
- exports.plzWork = plzWork;
22
+ exports.signCet = signCet;
20
23
  exports.signFundTransactionInput = signFundTransactionInput;
21
24
  exports.verifyFundTxSignature = verifyFundTxSignature;
22
25
  exports.version = version;
@@ -37,6 +40,14 @@ typeof process !== 'object' ||
37
40
  process?.env?.NODE_ENV !== 'production' || true;
38
41
  // Public interface members begin here.
39
42
 
43
+ function convertMnemonicToSeed(mnemonic, passphrase) /*throws*/{
44
+ return FfiConverterArrayUInt8.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
45
+ return (() => {
46
+ console.debug(`-- uniffi_ddk_ffi_fn_func_convert_mnemonic_to_seed`);
47
+ return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_convert_mnemonic_to_seed;
48
+ })()(FfiConverterString.lower(mnemonic), FfiConverterOptionalString.lower(passphrase), callStatus);
49
+ }, /*liftString:*/FfiConverterString.lift));
50
+ }
40
51
  function createCet(localOutput, localPayoutSerialId, remoteOutput, remotePayoutSerialId, fundTxId, fundVout, lockTime) /*throws*/{
41
52
  return FfiConverterTypeTransaction.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
42
53
  return (() => {
@@ -93,6 +104,14 @@ function createSplicedDlcTransactions(outcomes, localParams, remoteParams, refun
93
104
  })()(FfiConverterArrayTypeDlcOutcome.lower(outcomes), FfiConverterTypePartyParams.lower(localParams), FfiConverterTypePartyParams.lower(remoteParams), _uniffiBindgenReactNative.FfiConverterUInt32.lower(refundLocktime), _uniffiBindgenReactNative.FfiConverterUInt64.lower(feeRate), _uniffiBindgenReactNative.FfiConverterUInt32.lower(fundLockTime), _uniffiBindgenReactNative.FfiConverterUInt32.lower(cetLockTime), _uniffiBindgenReactNative.FfiConverterUInt64.lower(fundOutputSerialId), callStatus);
94
105
  }, /*liftString:*/FfiConverterString.lift));
95
106
  }
107
+ function createXprivFromParentPath(xpriv, baseDerivationPath, network, path) /*throws*/{
108
+ return FfiConverterArrayUInt8.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
109
+ return (() => {
110
+ console.debug(`-- uniffi_ddk_ffi_fn_func_create_xpriv_from_parent_path`);
111
+ return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_create_xpriv_from_parent_path;
112
+ })()(FfiConverterArrayUInt8.lower(xpriv), FfiConverterString.lower(baseDerivationPath), FfiConverterString.lower(network), FfiConverterString.lower(path), callStatus);
113
+ }, /*liftString:*/FfiConverterString.lift));
114
+ }
96
115
  function getChangeOutputAndFees(params, feeRate) /*throws*/{
97
116
  return FfiConverterTypeChangeOutputAndFees.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
98
117
  return (() => {
@@ -117,6 +136,14 @@ function getTotalInputVsize(inputs) {
117
136
  })()(FfiConverterArrayTypeTxInputInfo.lower(inputs), callStatus);
118
137
  }, /*liftString:*/FfiConverterString.lift));
119
138
  }
139
+ function getXpubFromXpriv(xpriv, network) /*throws*/{
140
+ return FfiConverterArrayUInt8.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
141
+ return (() => {
142
+ console.debug(`-- uniffi_ddk_ffi_fn_func_get_xpub_from_xpriv`);
143
+ return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_get_xpub_from_xpriv;
144
+ })()(FfiConverterArrayUInt8.lower(xpriv), FfiConverterString.lower(network), callStatus);
145
+ }, /*liftString:*/FfiConverterString.lift));
146
+ }
120
147
  function isDustOutput(output) {
121
148
  return _uniffiBindgenReactNative.FfiConverterBool.lift(uniffiCaller.rustCall(/*caller:*/callStatus => {
122
149
  return (() => {
@@ -125,12 +152,12 @@ function isDustOutput(output) {
125
152
  })()(FfiConverterTypeTxOutput.lower(output), callStatus);
126
153
  }, /*liftString:*/FfiConverterString.lift));
127
154
  }
128
- function plzWork() {
129
- return FfiConverterString.lift(uniffiCaller.rustCall(/*caller:*/callStatus => {
155
+ function signCet(cet, adaptorSignature, oracleSignatures, fundingSecretKey, otherPubkey, fundingScriptPubkey, fundOutputValue) /*throws*/{
156
+ return FfiConverterTypeTransaction.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
130
157
  return (() => {
131
- console.debug(`-- uniffi_ddk_ffi_fn_func_plz_work`);
132
- return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_plz_work;
133
- })()(callStatus);
158
+ console.debug(`-- uniffi_ddk_ffi_fn_func_sign_cet`);
159
+ return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_sign_cet;
160
+ })()(FfiConverterTypeTransaction.lower(cet), FfiConverterArrayUInt8.lower(adaptorSignature), FfiConverterArrayArrayUInt8.lower(oracleSignatures), FfiConverterArrayUInt8.lower(fundingSecretKey), FfiConverterArrayUInt8.lower(otherPubkey), FfiConverterArrayUInt8.lower(fundingScriptPubkey), _uniffiBindgenReactNative.FfiConverterUInt64.lower(fundOutputValue), callStatus);
134
161
  }, /*liftString:*/FfiConverterString.lift));
135
162
  }
136
163
  function signFundTransactionInput(fundTransaction, privkey, prevTxId, prevTxVout, value) /*throws*/{
@@ -740,7 +767,8 @@ let DlcError_Tags = exports.DlcError_Tags = /*#__PURE__*/function (DlcError_Tags
740
767
  DlcError_Tags["SerializationError"] = "SerializationError";
741
768
  DlcError_Tags["Secp256k1Error"] = "Secp256k1Error";
742
769
  DlcError_Tags["MiniscriptError"] = "MiniscriptError";
743
- DlcError_Tags["NetworkError"] = "NetworkError";
770
+ DlcError_Tags["InvalidNetwork"] = "InvalidNetwork";
771
+ DlcError_Tags["KeyError"] = "KeyError";
744
772
  return DlcError_Tags;
745
773
  }({});
746
774
  const DlcError = exports.DlcError = (() => {
@@ -896,7 +924,7 @@ const DlcError = exports.DlcError = (() => {
896
924
  return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 8;
897
925
  }
898
926
  }
899
- class NetworkError extends _uniffiBindgenReactNative.UniffiError {
927
+ class InvalidNetwork extends _uniffiBindgenReactNative.UniffiError {
900
928
  /**
901
929
  * @private
902
930
  * This field is private and should not be used.
@@ -907,14 +935,33 @@ const DlcError = exports.DlcError = (() => {
907
935
  * This field is private and should not be used.
908
936
  */
909
937
  [_uniffiBindgenReactNative.variantOrdinalSymbol] = 9;
910
- tag = DlcError_Tags.NetworkError;
938
+ tag = DlcError_Tags.InvalidNetwork;
911
939
  constructor(message) {
912
- super('DlcError', 'NetworkError', message);
940
+ super('DlcError', 'InvalidNetwork', message);
913
941
  }
914
942
  static instanceOf(e) {
915
943
  return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 9;
916
944
  }
917
945
  }
946
+ class KeyError extends _uniffiBindgenReactNative.UniffiError {
947
+ /**
948
+ * @private
949
+ * This field is private and should not be used.
950
+ */
951
+ [_uniffiBindgenReactNative.uniffiTypeNameSymbol] = 'DlcError';
952
+ /**
953
+ * @private
954
+ * This field is private and should not be used.
955
+ */
956
+ [_uniffiBindgenReactNative.variantOrdinalSymbol] = 10;
957
+ tag = DlcError_Tags.KeyError;
958
+ constructor(message) {
959
+ super('DlcError', 'KeyError', message);
960
+ }
961
+ static instanceOf(e) {
962
+ return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 10;
963
+ }
964
+ }
918
965
 
919
966
  // Utility function which does not rely on instanceof.
920
967
  function instanceOf(e) {
@@ -929,7 +976,8 @@ const DlcError = exports.DlcError = (() => {
929
976
  SerializationError,
930
977
  Secp256k1Error,
931
978
  MiniscriptError,
932
- NetworkError,
979
+ InvalidNetwork,
980
+ KeyError,
933
981
  instanceOf
934
982
  };
935
983
  })();
@@ -958,7 +1006,139 @@ const FfiConverterTypeDLCError = (() => {
958
1006
  case 8:
959
1007
  return new DlcError.MiniscriptError(FfiConverterString.read(from));
960
1008
  case 9:
961
- return new DlcError.NetworkError(FfiConverterString.read(from));
1009
+ return new DlcError.InvalidNetwork(FfiConverterString.read(from));
1010
+ case 10:
1011
+ return new DlcError.KeyError(FfiConverterString.read(from));
1012
+ default:
1013
+ throw new _uniffiBindgenReactNative.UniffiInternalError.UnexpectedEnumCase();
1014
+ }
1015
+ }
1016
+ write(value, into) {
1017
+ const obj = value;
1018
+ const index = obj[_uniffiBindgenReactNative.variantOrdinalSymbol];
1019
+ intConverter.write(index, into);
1020
+ }
1021
+ allocationSize(value) {
1022
+ return intConverter.allocationSize(0);
1023
+ }
1024
+ }
1025
+ return new FfiConverter();
1026
+ })();
1027
+
1028
+ // Flat error type: ExtendedKey
1029
+ let ExtendedKey_Tags = exports.ExtendedKey_Tags = /*#__PURE__*/function (ExtendedKey_Tags) {
1030
+ ExtendedKey_Tags["InvalidMnemonic"] = "InvalidMnemonic";
1031
+ ExtendedKey_Tags["InvalidXpriv"] = "InvalidXpriv";
1032
+ ExtendedKey_Tags["InvalidXpub"] = "InvalidXpub";
1033
+ ExtendedKey_Tags["InvalidDerivationPath"] = "InvalidDerivationPath";
1034
+ return ExtendedKey_Tags;
1035
+ }({});
1036
+ const ExtendedKey = exports.ExtendedKey = (() => {
1037
+ class InvalidMnemonic extends _uniffiBindgenReactNative.UniffiError {
1038
+ /**
1039
+ * @private
1040
+ * This field is private and should not be used.
1041
+ */
1042
+ [_uniffiBindgenReactNative.uniffiTypeNameSymbol] = 'ExtendedKey';
1043
+ /**
1044
+ * @private
1045
+ * This field is private and should not be used.
1046
+ */
1047
+ [_uniffiBindgenReactNative.variantOrdinalSymbol] = 1;
1048
+ tag = ExtendedKey_Tags.InvalidMnemonic;
1049
+ constructor(message) {
1050
+ super('ExtendedKey', 'InvalidMnemonic', message);
1051
+ }
1052
+ static instanceOf(e) {
1053
+ return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 1;
1054
+ }
1055
+ }
1056
+ class InvalidXpriv extends _uniffiBindgenReactNative.UniffiError {
1057
+ /**
1058
+ * @private
1059
+ * This field is private and should not be used.
1060
+ */
1061
+ [_uniffiBindgenReactNative.uniffiTypeNameSymbol] = 'ExtendedKey';
1062
+ /**
1063
+ * @private
1064
+ * This field is private and should not be used.
1065
+ */
1066
+ [_uniffiBindgenReactNative.variantOrdinalSymbol] = 2;
1067
+ tag = ExtendedKey_Tags.InvalidXpriv;
1068
+ constructor(message) {
1069
+ super('ExtendedKey', 'InvalidXpriv', message);
1070
+ }
1071
+ static instanceOf(e) {
1072
+ return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 2;
1073
+ }
1074
+ }
1075
+ class InvalidXpub extends _uniffiBindgenReactNative.UniffiError {
1076
+ /**
1077
+ * @private
1078
+ * This field is private and should not be used.
1079
+ */
1080
+ [_uniffiBindgenReactNative.uniffiTypeNameSymbol] = 'ExtendedKey';
1081
+ /**
1082
+ * @private
1083
+ * This field is private and should not be used.
1084
+ */
1085
+ [_uniffiBindgenReactNative.variantOrdinalSymbol] = 3;
1086
+ tag = ExtendedKey_Tags.InvalidXpub;
1087
+ constructor(message) {
1088
+ super('ExtendedKey', 'InvalidXpub', message);
1089
+ }
1090
+ static instanceOf(e) {
1091
+ return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 3;
1092
+ }
1093
+ }
1094
+ class InvalidDerivationPath extends _uniffiBindgenReactNative.UniffiError {
1095
+ /**
1096
+ * @private
1097
+ * This field is private and should not be used.
1098
+ */
1099
+ [_uniffiBindgenReactNative.uniffiTypeNameSymbol] = 'ExtendedKey';
1100
+ /**
1101
+ * @private
1102
+ * This field is private and should not be used.
1103
+ */
1104
+ [_uniffiBindgenReactNative.variantOrdinalSymbol] = 4;
1105
+ tag = ExtendedKey_Tags.InvalidDerivationPath;
1106
+ constructor(message) {
1107
+ super('ExtendedKey', 'InvalidDerivationPath', message);
1108
+ }
1109
+ static instanceOf(e) {
1110
+ return instanceOf(e) && e[_uniffiBindgenReactNative.variantOrdinalSymbol] === 4;
1111
+ }
1112
+ }
1113
+
1114
+ // Utility function which does not rely on instanceof.
1115
+ function instanceOf(e) {
1116
+ return e[_uniffiBindgenReactNative.uniffiTypeNameSymbol] === 'ExtendedKey';
1117
+ }
1118
+ return {
1119
+ InvalidMnemonic,
1120
+ InvalidXpriv,
1121
+ InvalidXpub,
1122
+ InvalidDerivationPath,
1123
+ instanceOf
1124
+ };
1125
+ })();
1126
+
1127
+ // Union type for ExtendedKey error type.
1128
+
1129
+ const FfiConverterTypeExtendedKey = (() => {
1130
+ const intConverter = _uniffiBindgenReactNative.FfiConverterInt32;
1131
+ class FfiConverter extends _uniffiBindgenReactNative.AbstractFfiConverterByteArray {
1132
+ read(from) {
1133
+ switch (intConverter.read(from)) {
1134
+ case 1:
1135
+ return new ExtendedKey.InvalidMnemonic(FfiConverterString.read(from));
1136
+ case 2:
1137
+ return new ExtendedKey.InvalidXpriv(FfiConverterString.read(from));
1138
+ case 3:
1139
+ return new ExtendedKey.InvalidXpub(FfiConverterString.read(from));
1140
+ case 4:
1141
+ return new ExtendedKey.InvalidDerivationPath(FfiConverterString.read(from));
962
1142
  default:
963
1143
  throw new _uniffiBindgenReactNative.UniffiInternalError.UnexpectedEnumCase();
964
1144
  }
@@ -975,6 +1155,9 @@ const FfiConverterTypeDLCError = (() => {
975
1155
  return new FfiConverter();
976
1156
  })();
977
1157
 
1158
+ // FfiConverter for string | undefined
1159
+ const FfiConverterOptionalString = new _uniffiBindgenReactNative.FfiConverterOptional(FfiConverterString);
1160
+
978
1161
  // FfiConverter for Array<DlcInputInfo>
979
1162
  const FfiConverterArrayTypeDlcInputInfo = new _uniffiBindgenReactNative.FfiConverterArray(FfiConverterTypeDlcInputInfo);
980
1163
 
@@ -1017,6 +1200,9 @@ function uniffiEnsureInitialized() {
1017
1200
  if (bindingsContractVersion !== scaffoldingContractVersion) {
1018
1201
  throw new _uniffiBindgenReactNative.UniffiInternalError.ContractVersionMismatch(scaffoldingContractVersion, bindingsContractVersion);
1019
1202
  }
1203
+ if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_convert_mnemonic_to_seed() !== 65049) {
1204
+ throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_convert_mnemonic_to_seed');
1205
+ }
1020
1206
  if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_create_cet() !== 23081) {
1021
1207
  throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_create_cet');
1022
1208
  }
@@ -1038,6 +1224,9 @@ function uniffiEnsureInitialized() {
1038
1224
  if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_create_spliced_dlc_transactions() !== 51059) {
1039
1225
  throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_create_spliced_dlc_transactions');
1040
1226
  }
1227
+ if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path() !== 50010) {
1228
+ throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path');
1229
+ }
1041
1230
  if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees() !== 44150) {
1042
1231
  throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_change_output_and_fees');
1043
1232
  }
@@ -1047,11 +1236,14 @@ function uniffiEnsureInitialized() {
1047
1236
  if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_total_input_vsize() !== 38213) {
1048
1237
  throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_total_input_vsize');
1049
1238
  }
1239
+ if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_xpub_from_xpriv() !== 44344) {
1240
+ throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_xpub_from_xpriv');
1241
+ }
1050
1242
  if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_is_dust_output() !== 64174) {
1051
1243
  throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_is_dust_output');
1052
1244
  }
1053
- if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_plz_work() !== 32972) {
1054
- throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_plz_work');
1245
+ if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_sign_cet() !== 43957) {
1246
+ throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_sign_cet');
1055
1247
  }
1056
1248
  if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input() !== 50531) {
1057
1249
  throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input');
@@ -1072,6 +1264,7 @@ var _default = exports.default = Object.freeze({
1072
1264
  FfiConverterTypeDlcInputInfo,
1073
1265
  FfiConverterTypeDlcOutcome,
1074
1266
  FfiConverterTypeDlcTransactions,
1267
+ FfiConverterTypeExtendedKey,
1075
1268
  FfiConverterTypeOracleInfo,
1076
1269
  FfiConverterTypePartyParams,
1077
1270
  FfiConverterTypePayout,