@bennyblader/ddk-rn 0.3.12 → 0.3.14
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.
- package/cpp/ddk_ffi.cpp +42 -0
- package/cpp/ddk_ffi.hpp +2 -0
- package/ddk-ffi/Cargo.lock +1 -1
- package/ddk-ffi/Cargo.toml +1 -1
- package/ddk-ffi/src/ddk_ffi.udl +8 -0
- package/ddk-ffi/src/lib.rs +78 -29
- package/lib/commonjs/ddk_ffi-ffi.js.map +1 -1
- package/lib/commonjs/ddk_ffi.js +12 -0
- package/lib/commonjs/ddk_ffi.js.map +1 -1
- package/lib/module/ddk_ffi-ffi.js.map +1 -1
- package/lib/module/ddk_ffi.js +11 -0
- package/lib/module/ddk_ffi.js.map +1 -1
- package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts +2 -0
- package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ddk_ffi.d.ts +1 -0
- package/lib/typescript/commonjs/src/ddk_ffi.d.ts.map +1 -1
- package/lib/typescript/module/src/ddk_ffi-ffi.d.ts +2 -0
- package/lib/typescript/module/src/ddk_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/module/src/ddk_ffi.d.ts +1 -0
- package/lib/typescript/module/src/ddk_ffi.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ddk_ffi-ffi.ts +8 -0
- package/src/ddk_ffi.ts +36 -0
package/cpp/ddk_ffi.cpp
CHANGED
|
@@ -272,6 +272,13 @@ extern "C" {
|
|
|
272
272
|
uint64_t value,
|
|
273
273
|
RustCallStatus *uniffi_out_err
|
|
274
274
|
);
|
|
275
|
+
RustBuffer uniffi_ddk_ffi_fn_func_sign_multi_sig_input(
|
|
276
|
+
RustBuffer tx,
|
|
277
|
+
RustBuffer dlc_input,
|
|
278
|
+
RustBuffer local_privkey,
|
|
279
|
+
RustBuffer remote_signature,
|
|
280
|
+
RustCallStatus *uniffi_out_err
|
|
281
|
+
);
|
|
275
282
|
int8_t uniffi_ddk_ffi_fn_func_verify_cet_adaptor_sig_from_oracle_info(
|
|
276
283
|
RustBuffer adaptor_sig,
|
|
277
284
|
RustBuffer cet,
|
|
@@ -551,6 +558,8 @@ extern "C" {
|
|
|
551
558
|
);
|
|
552
559
|
uint16_t uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input(
|
|
553
560
|
);
|
|
561
|
+
uint16_t uniffi_ddk_ffi_checksum_func_sign_multi_sig_input(
|
|
562
|
+
);
|
|
554
563
|
uint16_t uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info(
|
|
555
564
|
);
|
|
556
565
|
uint16_t uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sigs_from_oracle_info(
|
|
@@ -2247,6 +2256,14 @@ NativeDdkFfi::NativeDdkFfi(
|
|
|
2247
2256
|
return this->cpp_uniffi_ddk_ffi_fn_func_sign_fund_transaction_input(rt, thisVal, args, count);
|
|
2248
2257
|
}
|
|
2249
2258
|
);
|
|
2259
|
+
props["ubrn_uniffi_ddk_ffi_fn_func_sign_multi_sig_input"] = jsi::Function::createFromHostFunction(
|
|
2260
|
+
rt,
|
|
2261
|
+
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_fn_func_sign_multi_sig_input"),
|
|
2262
|
+
4,
|
|
2263
|
+
[this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
2264
|
+
return this->cpp_uniffi_ddk_ffi_fn_func_sign_multi_sig_input(rt, thisVal, args, count);
|
|
2265
|
+
}
|
|
2266
|
+
);
|
|
2250
2267
|
props["ubrn_uniffi_ddk_ffi_fn_func_verify_cet_adaptor_sig_from_oracle_info"] = jsi::Function::createFromHostFunction(
|
|
2251
2268
|
rt,
|
|
2252
2269
|
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_fn_func_verify_cet_adaptor_sig_from_oracle_info"),
|
|
@@ -2423,6 +2440,14 @@ NativeDdkFfi::NativeDdkFfi(
|
|
|
2423
2440
|
return this->cpp_uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input(rt, thisVal, args, count);
|
|
2424
2441
|
}
|
|
2425
2442
|
);
|
|
2443
|
+
props["ubrn_uniffi_ddk_ffi_checksum_func_sign_multi_sig_input"] = jsi::Function::createFromHostFunction(
|
|
2444
|
+
rt,
|
|
2445
|
+
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_checksum_func_sign_multi_sig_input"),
|
|
2446
|
+
0,
|
|
2447
|
+
[this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
2448
|
+
return this->cpp_uniffi_ddk_ffi_checksum_func_sign_multi_sig_input(rt, thisVal, args, count);
|
|
2449
|
+
}
|
|
2450
|
+
);
|
|
2426
2451
|
props["ubrn_uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info"] = jsi::Function::createFromHostFunction(
|
|
2427
2452
|
rt,
|
|
2428
2453
|
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info"),
|
|
@@ -2696,6 +2721,16 @@ jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_fn_func_sign_fund_transaction_input(
|
|
|
2696
2721
|
uniffi::ddk_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
|
|
2697
2722
|
|
|
2698
2723
|
|
|
2724
|
+
return uniffi::ddk_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
|
|
2725
|
+
}
|
|
2726
|
+
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_fn_func_sign_multi_sig_input(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
2727
|
+
RustCallStatus status = uniffi::ddk_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
|
|
2728
|
+
auto value = uniffi_ddk_ffi_fn_func_sign_multi_sig_input(uniffi::ddk_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[0]), uniffi::ddk_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]), uniffi::ddk_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[2]), uniffi::ddk_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[3]),
|
|
2729
|
+
&status
|
|
2730
|
+
);
|
|
2731
|
+
uniffi::ddk_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
|
|
2732
|
+
|
|
2733
|
+
|
|
2699
2734
|
return uniffi::ddk_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
|
|
2700
2735
|
}
|
|
2701
2736
|
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_fn_func_verify_cet_adaptor_sig_from_oracle_info(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
@@ -2861,6 +2896,13 @@ jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_checksum_func_sign_fund_transaction_
|
|
|
2861
2896
|
);
|
|
2862
2897
|
|
|
2863
2898
|
|
|
2899
|
+
return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
|
|
2900
|
+
}
|
|
2901
|
+
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_checksum_func_sign_multi_sig_input(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
2902
|
+
auto value = uniffi_ddk_ffi_checksum_func_sign_multi_sig_input(
|
|
2903
|
+
);
|
|
2904
|
+
|
|
2905
|
+
|
|
2864
2906
|
return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
|
|
2865
2907
|
}
|
|
2866
2908
|
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
package/cpp/ddk_ffi.hpp
CHANGED
|
@@ -39,6 +39,7 @@ class NativeDdkFfi : public jsi::HostObject {
|
|
|
39
39
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_is_dust_output(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
40
40
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_sign_cet(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
41
41
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_sign_fund_transaction_input(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
42
|
+
jsi::Value cpp_uniffi_ddk_ffi_fn_func_sign_multi_sig_input(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
42
43
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_verify_cet_adaptor_sig_from_oracle_info(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
43
44
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_verify_cet_adaptor_sigs_from_oracle_info(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
44
45
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_verify_fund_tx_signature(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
@@ -61,6 +62,7 @@ class NativeDdkFfi : public jsi::HostObject {
|
|
|
61
62
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_is_dust_output(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
62
63
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_sign_cet(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
63
64
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
65
|
+
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_sign_multi_sig_input(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
64
66
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
65
67
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sigs_from_oracle_info(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
66
68
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_verify_fund_tx_signature(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
package/ddk-ffi/Cargo.lock
CHANGED
package/ddk-ffi/Cargo.toml
CHANGED
package/ddk-ffi/src/ddk_ffi.udl
CHANGED
|
@@ -107,6 +107,14 @@ namespace ddk_ffi {
|
|
|
107
107
|
u32 input_index
|
|
108
108
|
);
|
|
109
109
|
|
|
110
|
+
[Throws=DLCError]
|
|
111
|
+
Transaction sign_multi_sig_input(
|
|
112
|
+
Transaction tx,
|
|
113
|
+
DlcInputInfo dlc_input,
|
|
114
|
+
sequence<u8> local_privkey,
|
|
115
|
+
sequence<u8> remote_signature
|
|
116
|
+
);
|
|
117
|
+
|
|
110
118
|
[Throws=DLCError]
|
|
111
119
|
Transaction sign_cet(
|
|
112
120
|
Transaction cet,
|
package/ddk-ffi/src/lib.rs
CHANGED
|
@@ -4,7 +4,7 @@ use bitcoin::bip32::{DerivationPath, IntoDerivationPath, Xpriv, Xpub};
|
|
|
4
4
|
use bitcoin::hashes::Hash;
|
|
5
5
|
use bitcoin::sighash::EcdsaSighashType;
|
|
6
6
|
use bitcoin::{
|
|
7
|
-
Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction as BtcTransaction, TxIn,
|
|
7
|
+
Amount, Network, OutPoint, Psbt, ScriptBuf, Sequence, Transaction as BtcTransaction, TxIn,
|
|
8
8
|
TxOut as BtcTxOut, Txid, Witness,
|
|
9
9
|
};
|
|
10
10
|
use bitcoin::{Script, WPubkeyHash};
|
|
@@ -271,6 +271,19 @@ pub fn dlc_input_info_to_rust(input: &DlcInputInfo) -> Result<RustDlcInputInfo,
|
|
|
271
271
|
})
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
pub fn rust_to_dlc_input(input: &RustDlcInputInfo) -> Result<DlcInputInfo, DLCError> {
|
|
275
|
+
Ok(DlcInputInfo {
|
|
276
|
+
fund_tx: btc_tx_to_transaction(&input.fund_tx),
|
|
277
|
+
fund_vout: input.fund_vout,
|
|
278
|
+
local_fund_pubkey: input.local_fund_pubkey.serialize().to_vec(),
|
|
279
|
+
remote_fund_pubkey: input.remote_fund_pubkey.serialize().to_vec(),
|
|
280
|
+
fund_amount: input.fund_amount.to_sat(),
|
|
281
|
+
max_witness_len: input.max_witness_len as u32,
|
|
282
|
+
input_serial_id: input.input_serial_id,
|
|
283
|
+
contract_id: input.contract_id.to_vec(),
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
|
|
274
287
|
/// Convert UniFFI TxInputInfo to rust-dlc TxInputInfo
|
|
275
288
|
pub fn tx_input_info_to_rust(input: &TxInputInfo) -> Result<DlcTxInputInfo, DLCError> {
|
|
276
289
|
let txid = Txid::from_str(&input.txid)
|
|
@@ -607,8 +620,7 @@ pub fn verify_fund_tx_signature(
|
|
|
607
620
|
input.previous_output.txid == input_txid && input.previous_output.vout == vout
|
|
608
621
|
})
|
|
609
622
|
.ok_or(DLCError::InvalidArgument(format!(
|
|
610
|
-
"Input index not found in {}"
|
|
611
|
-
input_txid
|
|
623
|
+
"Input index not found in {input_txid}"
|
|
612
624
|
)))?;
|
|
613
625
|
|
|
614
626
|
// Create a simple P2WPKH script for verification
|
|
@@ -616,13 +628,7 @@ pub fn verify_fund_tx_signature(
|
|
|
616
628
|
let script = bitcoin::ScriptBuf::new_p2wpkh(&wpkh);
|
|
617
629
|
|
|
618
630
|
// Parse signature
|
|
619
|
-
let sig =
|
|
620
|
-
EcdsaSignature::from_compact(&signature).map_err(|_| DLCError::InvalidSignature)?
|
|
621
|
-
} else {
|
|
622
|
-
// Remove sighash type byte and parse DER
|
|
623
|
-
let sig_bytes = &signature[..signature.len() - 1];
|
|
624
|
-
EcdsaSignature::from_der(sig_bytes).map_err(|_| DLCError::InvalidSignature)?
|
|
625
|
-
};
|
|
631
|
+
let sig = EcdsaSignature::from_der(&signature).map_err(|_| DLCError::InvalidSignature)?;
|
|
626
632
|
|
|
627
633
|
let secp = Secp256k1::verification_only();
|
|
628
634
|
match dlc::verify_tx_input_sig(
|
|
@@ -665,8 +671,7 @@ pub fn get_raw_funding_transaction_input_signature(
|
|
|
665
671
|
input.previous_output.txid == prev_txid && input.previous_output.vout == prev_tx_vout
|
|
666
672
|
})
|
|
667
673
|
.ok_or(DLCError::InvalidArgument(format!(
|
|
668
|
-
"Input index not found in {}"
|
|
669
|
-
prev_txid
|
|
674
|
+
"Input index not found in {prev_txid}"
|
|
670
675
|
)))?;
|
|
671
676
|
|
|
672
677
|
let secp = get_secp_context();
|
|
@@ -685,7 +690,7 @@ pub fn get_raw_funding_transaction_input_signature(
|
|
|
685
690
|
)
|
|
686
691
|
.map_err(DLCError::from)?;
|
|
687
692
|
|
|
688
|
-
Ok(sig.
|
|
693
|
+
Ok(sig.serialize_der().to_vec())
|
|
689
694
|
}
|
|
690
695
|
|
|
691
696
|
/// Sign a funding transaction input
|
|
@@ -710,8 +715,7 @@ pub fn sign_fund_transaction_input(
|
|
|
710
715
|
input.previous_output.txid == prev_txid && input.previous_output.vout == prev_tx_vout
|
|
711
716
|
})
|
|
712
717
|
.ok_or(DLCError::InvalidArgument(format!(
|
|
713
|
-
"Input index not found in {}"
|
|
714
|
-
prev_txid
|
|
718
|
+
"Input index not found in {prev_txid}"
|
|
715
719
|
)))?;
|
|
716
720
|
|
|
717
721
|
let secp = Secp256k1::signing_only();
|
|
@@ -728,6 +732,55 @@ pub fn sign_fund_transaction_input(
|
|
|
728
732
|
Ok(btc_tx_to_transaction(&btc_tx))
|
|
729
733
|
}
|
|
730
734
|
|
|
735
|
+
pub fn sign_multi_sig_input(
|
|
736
|
+
txn: Transaction,
|
|
737
|
+
dlc_input: DlcInputInfo,
|
|
738
|
+
local_privkey: Vec<u8>,
|
|
739
|
+
remote_signature: Vec<u8>,
|
|
740
|
+
) -> Result<Transaction, DLCError> {
|
|
741
|
+
let secp = get_secp_context();
|
|
742
|
+
let btc_tx = transaction_to_btc_tx(&txn)?;
|
|
743
|
+
let sk = SecretKey::from_slice(&local_privkey)
|
|
744
|
+
.map_err(|_| DLCError::InvalidArgument("Invalid private key".to_string()))?;
|
|
745
|
+
|
|
746
|
+
let local_pk = PublicKey::from_slice(&dlc_input.local_fund_pubkey)
|
|
747
|
+
.map_err(|_| DLCError::InvalidPublicKey)?;
|
|
748
|
+
let remote_pk = PublicKey::from_slice(&dlc_input.remote_fund_pubkey)
|
|
749
|
+
.map_err(|_| DLCError::InvalidPublicKey)?;
|
|
750
|
+
|
|
751
|
+
let dlc_input = dlc_input_info_to_rust(&dlc_input)?;
|
|
752
|
+
|
|
753
|
+
let signature = dlc::dlc_input::create_dlc_funding_input_signature(
|
|
754
|
+
secp,
|
|
755
|
+
&btc_tx,
|
|
756
|
+
dlc_input.fund_vout as usize,
|
|
757
|
+
&dlc_input,
|
|
758
|
+
&sk,
|
|
759
|
+
)
|
|
760
|
+
.map_err(|_| DLCError::InvalidSignature)?;
|
|
761
|
+
|
|
762
|
+
let (first, second) = if local_pk < remote_pk {
|
|
763
|
+
(local_pk, remote_pk)
|
|
764
|
+
} else {
|
|
765
|
+
(remote_pk, local_pk)
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
let witness = dlc::dlc_input::combine_dlc_input_signatures(
|
|
769
|
+
&dlc_input,
|
|
770
|
+
&signature,
|
|
771
|
+
&remote_signature,
|
|
772
|
+
&first,
|
|
773
|
+
&second,
|
|
774
|
+
);
|
|
775
|
+
|
|
776
|
+
let mut fund_psbt = Psbt::from_unsigned_tx(btc_tx).map_err(|_| DLCError::InvalidTransaction)?;
|
|
777
|
+
fund_psbt.inputs[dlc_input.fund_vout as usize].final_script_witness = Some(witness);
|
|
778
|
+
|
|
779
|
+
Ok(btc_tx_to_transaction(
|
|
780
|
+
&fund_psbt.extract_tx_unchecked_fee_rate(),
|
|
781
|
+
))
|
|
782
|
+
}
|
|
783
|
+
|
|
731
784
|
pub fn sign_cet(
|
|
732
785
|
cet: Transaction,
|
|
733
786
|
adaptor_signature: Vec<u8>,
|
|
@@ -741,7 +794,7 @@ pub fn sign_cet(
|
|
|
741
794
|
let adaptor_sig = vec_to_ecdsa_adaptor_signature(adaptor_signature)?;
|
|
742
795
|
let oracle_sigs = oracle_signatures
|
|
743
796
|
.iter()
|
|
744
|
-
.map(|sig| vec_to_schnorr_signature(sig))
|
|
797
|
+
.map(|sig| vec_to_schnorr_signature(sig.as_slice()))
|
|
745
798
|
.collect::<Result<Vec<_>, _>>()?;
|
|
746
799
|
let funding_sk = SecretKey::from_slice(&funding_secret_key)
|
|
747
800
|
.map_err(|_| DLCError::InvalidArgument("Invalid funding secret key".to_string()))?;
|
|
@@ -756,7 +809,7 @@ pub fn sign_cet(
|
|
|
756
809
|
&[oracle_sigs],
|
|
757
810
|
&funding_sk,
|
|
758
811
|
&other_pk,
|
|
759
|
-
|
|
812
|
+
funding_script,
|
|
760
813
|
Amount::from_sat(fund_output_value),
|
|
761
814
|
)
|
|
762
815
|
.map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
|
|
@@ -764,7 +817,7 @@ pub fn sign_cet(
|
|
|
764
817
|
Ok(btc_tx_to_transaction(&btc_tx))
|
|
765
818
|
}
|
|
766
819
|
|
|
767
|
-
fn vec_to_schnorr_signature(signature: &
|
|
820
|
+
fn vec_to_schnorr_signature(signature: &[u8]) -> Result<SchnorrSignature, DLCError> {
|
|
768
821
|
let sig = SchnorrSignature::from_slice(signature).map_err(|_| DLCError::InvalidSignature)?;
|
|
769
822
|
Ok(sig)
|
|
770
823
|
}
|
|
@@ -783,7 +836,7 @@ pub fn create_cet_adaptor_sigs_from_oracle_info(
|
|
|
783
836
|
) -> Result<Vec<AdaptorSignature>, DLCError> {
|
|
784
837
|
let cets = cets
|
|
785
838
|
.iter()
|
|
786
|
-
.map(
|
|
839
|
+
.map(transaction_to_btc_tx)
|
|
787
840
|
.collect::<Result<Vec<_>, _>>()?;
|
|
788
841
|
let oracle_infos = oracle_info
|
|
789
842
|
.iter()
|
|
@@ -831,11 +884,11 @@ pub fn create_cet_adaptor_sigs_from_oracle_info(
|
|
|
831
884
|
&cets,
|
|
832
885
|
&oracle_infos,
|
|
833
886
|
&funding_sk,
|
|
834
|
-
|
|
887
|
+
funding_script,
|
|
835
888
|
Amount::from_sat(fund_output_value),
|
|
836
889
|
&msgs,
|
|
837
890
|
)
|
|
838
|
-
.map_err(|e| DLCError::
|
|
891
|
+
.map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
|
|
839
892
|
|
|
840
893
|
let adaptor_sigs = adaptor_sigs
|
|
841
894
|
.iter()
|
|
@@ -904,7 +957,7 @@ pub fn verify_cet_adaptor_sig_from_oracle_info(
|
|
|
904
957
|
&btc_tx,
|
|
905
958
|
&adaptor_point,
|
|
906
959
|
&pubkey,
|
|
907
|
-
|
|
960
|
+
funding_script,
|
|
908
961
|
Amount::from_sat(total_collateral),
|
|
909
962
|
) else {
|
|
910
963
|
return false;
|
|
@@ -923,7 +976,7 @@ pub fn verify_cet_adaptor_sigs_from_oracle_info(
|
|
|
923
976
|
msgs: Vec<Vec<Vec<Vec<u8>>>>,
|
|
924
977
|
) -> bool {
|
|
925
978
|
cets.into_iter()
|
|
926
|
-
.zip(adaptor_sigs
|
|
979
|
+
.zip(adaptor_sigs)
|
|
927
980
|
.enumerate()
|
|
928
981
|
.all(|(i, (cet, adaptor_sig))| {
|
|
929
982
|
verify_cet_adaptor_sig_from_oracle_info(
|
|
@@ -1540,11 +1593,7 @@ mod tests {
|
|
|
1540
1593
|
let script = ScriptBuf::from_bytes(script_pubkey);
|
|
1541
1594
|
let sig_hash_msg =
|
|
1542
1595
|
dlc::util::get_sig_hash_msg(&btc_txn, input_index, &script, Amount::from_sat(value))?;
|
|
1543
|
-
let sig =
|
|
1544
|
-
EcdsaSignature::from_compact(&signature).map_err(|_| DLCError::InvalidSignature)
|
|
1545
|
-
} else {
|
|
1546
|
-
EcdsaSignature::from_der(&signature).map_err(|_| DLCError::InvalidSignature)
|
|
1547
|
-
}?;
|
|
1596
|
+
let sig = EcdsaSignature::from_der(&signature).map_err(|_| DLCError::InvalidSignature)?;
|
|
1548
1597
|
let pk = PublicKey::from_slice(&pk).map_err(|_| DLCError::InvalidPublicKey)?;
|
|
1549
1598
|
secp.verify_ecdsa(&sig_hash_msg, &sig, &pk)
|
|
1550
1599
|
.map_err(|_| DLCError::InvalidSignature)?;
|
|
@@ -1700,7 +1749,7 @@ mod tests {
|
|
|
1700
1749
|
)));
|
|
1701
1750
|
sign_res.expect("Error signing CET");
|
|
1702
1751
|
verify_tx_input_sig(
|
|
1703
|
-
adapted_sig.
|
|
1752
|
+
adapted_sig.serialize_der().to_vec(),
|
|
1704
1753
|
cets[0].clone(),
|
|
1705
1754
|
0,
|
|
1706
1755
|
funding_script_pubkey.clone().into_bytes(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getter","globalThis","NativeDdkFfi","_default","exports","default","isRustFutureContinuationCallbackTypeCompatible","isUniffiForeignFutureTypeCompatible"],"sourceRoot":"../../src","sources":["ddk_ffi-ffi.ts"],"mappings":";;;;;;AAAA;AACA;;
|
|
1
|
+
{"version":3,"names":["getter","globalThis","NativeDdkFfi","_default","exports","default","isRustFutureContinuationCallbackTypeCompatible","isUniffiForeignFutureTypeCompatible"],"sourceRoot":"../../src","sources":["ddk_ffi-ffi.ts"],"mappings":";;;;;;AAAA;AACA;;AAoOA;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":[]}
|
package/lib/commonjs/ddk_ffi.js
CHANGED
|
@@ -23,6 +23,7 @@ exports.getXpubFromXpriv = getXpubFromXpriv;
|
|
|
23
23
|
exports.isDustOutput = isDustOutput;
|
|
24
24
|
exports.signCet = signCet;
|
|
25
25
|
exports.signFundTransactionInput = signFundTransactionInput;
|
|
26
|
+
exports.signMultiSigInput = signMultiSigInput;
|
|
26
27
|
exports.verifyCetAdaptorSigFromOracleInfo = verifyCetAdaptorSigFromOracleInfo;
|
|
27
28
|
exports.verifyCetAdaptorSigsFromOracleInfo = verifyCetAdaptorSigsFromOracleInfo;
|
|
28
29
|
exports.verifyFundTxSignature = verifyFundTxSignature;
|
|
@@ -188,6 +189,14 @@ function signFundTransactionInput(fundTransaction, privkey, prevTxId, prevTxVout
|
|
|
188
189
|
})()(FfiConverterTypeTransaction.lower(fundTransaction), FfiConverterArrayUInt8.lower(privkey), FfiConverterString.lower(prevTxId), _uniffiBindgenReactNative.FfiConverterUInt32.lower(prevTxVout), _uniffiBindgenReactNative.FfiConverterUInt64.lower(value), callStatus);
|
|
189
190
|
}, /*liftString:*/FfiConverterString.lift));
|
|
190
191
|
}
|
|
192
|
+
function signMultiSigInput(tx, dlcInput, localPrivkey, remoteSignature) /*throws*/{
|
|
193
|
+
return FfiConverterTypeTransaction.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
|
|
194
|
+
return (() => {
|
|
195
|
+
console.debug(`-- uniffi_ddk_ffi_fn_func_sign_multi_sig_input`);
|
|
196
|
+
return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_sign_multi_sig_input;
|
|
197
|
+
})()(FfiConverterTypeTransaction.lower(tx), FfiConverterTypeDlcInputInfo.lower(dlcInput), FfiConverterArrayUInt8.lower(localPrivkey), FfiConverterArrayUInt8.lower(remoteSignature), callStatus);
|
|
198
|
+
}, /*liftString:*/FfiConverterString.lift));
|
|
199
|
+
}
|
|
191
200
|
function verifyCetAdaptorSigFromOracleInfo(adaptorSig, cet, oracleInfo, pubkey, fundingScriptPubkey, totalCollateral, msgs) {
|
|
192
201
|
return _uniffiBindgenReactNative.FfiConverterBool.lift(uniffiCaller.rustCall(/*caller:*/callStatus => {
|
|
193
202
|
return (() => {
|
|
@@ -1259,6 +1268,9 @@ function uniffiEnsureInitialized() {
|
|
|
1259
1268
|
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input() !== 50531) {
|
|
1260
1269
|
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_sign_fund_transaction_input');
|
|
1261
1270
|
}
|
|
1271
|
+
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_sign_multi_sig_input() !== 14569) {
|
|
1272
|
+
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_sign_multi_sig_input');
|
|
1273
|
+
}
|
|
1262
1274
|
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info() !== 52232) {
|
|
1263
1275
|
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_verify_cet_adaptor_sig_from_oracle_info');
|
|
1264
1276
|
}
|