@bennyblader/ddk-rn 0.3.31 → 0.3.32
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 +40 -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 +6 -0
- package/ddk-ffi/src/lib.rs +183 -3
- 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 +17 -18
- package/scripts/apply-hotfix.js +0 -0
- package/scripts/postinstall.js +0 -0
- package/src/ddk_ffi-ffi.ts +6 -0
- package/src/ddk_ffi.ts +34 -0
package/cpp/ddk_ffi.cpp
CHANGED
|
@@ -243,6 +243,11 @@ extern "C" {
|
|
|
243
243
|
RustBuffer path,
|
|
244
244
|
RustCallStatus *uniffi_out_err
|
|
245
245
|
);
|
|
246
|
+
RustBuffer uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures(
|
|
247
|
+
RustBuffer oracle_signatures,
|
|
248
|
+
RustBuffer adaptor_signature,
|
|
249
|
+
RustCallStatus *uniffi_out_err
|
|
250
|
+
);
|
|
246
251
|
RustBuffer uniffi_ddk_ffi_fn_func_get_change_output_and_fees(
|
|
247
252
|
RustBuffer params,
|
|
248
253
|
uint64_t fee_rate,
|
|
@@ -570,6 +575,8 @@ extern "C" {
|
|
|
570
575
|
);
|
|
571
576
|
uint16_t uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path(
|
|
572
577
|
);
|
|
578
|
+
uint16_t uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures(
|
|
579
|
+
);
|
|
573
580
|
uint16_t uniffi_ddk_ffi_checksum_func_get_change_output_and_fees(
|
|
574
581
|
);
|
|
575
582
|
uint16_t uniffi_ddk_ffi_checksum_func_get_pubkey_from_extkey(
|
|
@@ -2252,6 +2259,14 @@ NativeDdkFfi::NativeDdkFfi(
|
|
|
2252
2259
|
return this->cpp_uniffi_ddk_ffi_fn_func_create_xpriv_from_parent_path(rt, thisVal, args, count);
|
|
2253
2260
|
}
|
|
2254
2261
|
);
|
|
2262
|
+
props["ubrn_uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures"] = jsi::Function::createFromHostFunction(
|
|
2263
|
+
rt,
|
|
2264
|
+
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures"),
|
|
2265
|
+
2,
|
|
2266
|
+
[this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
2267
|
+
return this->cpp_uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures(rt, thisVal, args, count);
|
|
2268
|
+
}
|
|
2269
|
+
);
|
|
2255
2270
|
props["ubrn_uniffi_ddk_ffi_fn_func_get_change_output_and_fees"] = jsi::Function::createFromHostFunction(
|
|
2256
2271
|
rt,
|
|
2257
2272
|
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_fn_func_get_change_output_and_fees"),
|
|
@@ -2468,6 +2483,14 @@ NativeDdkFfi::NativeDdkFfi(
|
|
|
2468
2483
|
return this->cpp_uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path(rt, thisVal, args, count);
|
|
2469
2484
|
}
|
|
2470
2485
|
);
|
|
2486
|
+
props["ubrn_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures"] = jsi::Function::createFromHostFunction(
|
|
2487
|
+
rt,
|
|
2488
|
+
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures"),
|
|
2489
|
+
0,
|
|
2490
|
+
[this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
2491
|
+
return this->cpp_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures(rt, thisVal, args, count);
|
|
2492
|
+
}
|
|
2493
|
+
);
|
|
2471
2494
|
props["ubrn_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees"] = jsi::Function::createFromHostFunction(
|
|
2472
2495
|
rt,
|
|
2473
2496
|
jsi::PropNameID::forAscii(rt, "ubrn_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees"),
|
|
@@ -2773,6 +2796,16 @@ jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_fn_func_create_xpriv_from_parent_pat
|
|
|
2773
2796
|
uniffi::ddk_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
|
|
2774
2797
|
|
|
2775
2798
|
|
|
2799
|
+
return uniffi::ddk_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
|
|
2800
|
+
}
|
|
2801
|
+
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
2802
|
+
RustCallStatus status = uniffi::ddk_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
|
|
2803
|
+
auto value = uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures(uniffi::ddk_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[0]), uniffi::ddk_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]),
|
|
2804
|
+
&status
|
|
2805
|
+
);
|
|
2806
|
+
uniffi::ddk_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
|
|
2807
|
+
|
|
2808
|
+
|
|
2776
2809
|
return uniffi::ddk_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
|
|
2777
2810
|
}
|
|
2778
2811
|
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_fn_func_get_change_output_and_fees(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
@@ -3000,6 +3033,13 @@ jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_checksum_func_create_xpriv_from_pare
|
|
|
3000
3033
|
);
|
|
3001
3034
|
|
|
3002
3035
|
|
|
3036
|
+
return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
|
|
3037
|
+
}
|
|
3038
|
+
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
3039
|
+
auto value = uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures(
|
|
3040
|
+
);
|
|
3041
|
+
|
|
3042
|
+
|
|
3003
3043
|
return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
|
|
3004
3044
|
}
|
|
3005
3045
|
jsi::Value NativeDdkFfi::cpp_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
package/cpp/ddk_ffi.hpp
CHANGED
|
@@ -35,6 +35,7 @@ class NativeDdkFfi : public jsi::HostObject {
|
|
|
35
35
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_create_refund_transaction(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
36
36
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_create_spliced_dlc_transactions(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
37
37
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_create_xpriv_from_parent_path(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
38
|
+
jsi::Value cpp_uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
38
39
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_get_change_output_and_fees(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
39
40
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_get_pubkey_from_extkey(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
40
41
|
jsi::Value cpp_uniffi_ddk_ffi_fn_func_get_raw_funding_transaction_input_signature(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
@@ -62,6 +63,7 @@ class NativeDdkFfi : public jsi::HostObject {
|
|
|
62
63
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_create_refund_transaction(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
63
64
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_create_spliced_dlc_transactions(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
64
65
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
66
|
+
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
65
67
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
66
68
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_get_pubkey_from_extkey(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count);
|
|
67
69
|
jsi::Value cpp_uniffi_ddk_ffi_checksum_func_get_raw_funding_transaction_input_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
|
@@ -205,6 +205,12 @@ namespace ddk_ffi {
|
|
|
205
205
|
sequence<OracleInfo> oracle_info,
|
|
206
206
|
sequence<sequence<sequence<sequence<u8>>>> msgs
|
|
207
207
|
);
|
|
208
|
+
|
|
209
|
+
[Throws=DLCError]
|
|
210
|
+
sequence<u8> extract_ecdsa_signature_from_oracle_signatures(
|
|
211
|
+
sequence<sequence<u8>> oracle_signatures,
|
|
212
|
+
sequence<u8> adaptor_signature
|
|
213
|
+
);
|
|
208
214
|
};
|
|
209
215
|
|
|
210
216
|
// Transaction representation
|
package/ddk-ffi/src/lib.rs
CHANGED
|
@@ -9,13 +9,15 @@ use bitcoin::{
|
|
|
9
9
|
TxOut as BtcTxOut, Txid, Witness,
|
|
10
10
|
};
|
|
11
11
|
use bitcoin::{Script, WPubkeyHash};
|
|
12
|
+
use ddk_dlc::secp_utils;
|
|
12
13
|
use ddk_dlc::{
|
|
13
14
|
self, dlc_input::DlcInputInfo as RustDlcInputInfo, DlcTransactions as RustDlcTransactions,
|
|
14
15
|
OracleInfo as DlcOracleInfo, PartyParams as DlcPartyParams, Payout as DlcPayout,
|
|
15
16
|
TxInputInfo as DlcTxInputInfo,
|
|
16
17
|
};
|
|
17
18
|
use secp256k1_zkp::{
|
|
18
|
-
ecdsa::Signature as EcdsaSignature, Message, PublicKey, Secp256k1, SecretKey,
|
|
19
|
+
ecdsa::Signature as EcdsaSignature, Message, PublicKey, Scalar, Secp256k1, SecretKey,
|
|
20
|
+
XOnlyPublicKey,
|
|
19
21
|
};
|
|
20
22
|
use secp256k1_zkp::{schnorr::Signature as SchnorrSignature, All, EcdsaAdaptorSignature};
|
|
21
23
|
use std::str::FromStr;
|
|
@@ -828,6 +830,33 @@ fn vec_to_ecdsa_adaptor_signature(signature: Vec<u8>) -> Result<EcdsaAdaptorSign
|
|
|
828
830
|
EcdsaAdaptorSignature::from_slice(&signature).map_err(|_| DLCError::InvalidSignature)
|
|
829
831
|
}
|
|
830
832
|
|
|
833
|
+
fn signatures_to_secret(signatures: &[Vec<SchnorrSignature>]) -> Result<SecretKey, DLCError> {
|
|
834
|
+
let s_values = signatures
|
|
835
|
+
.iter()
|
|
836
|
+
.flatten()
|
|
837
|
+
.map(|x| match secp_utils::schnorrsig_decompose(x) {
|
|
838
|
+
Ok(v) => Ok(v.1),
|
|
839
|
+
Err(err) => Err(DLCError::Secp256k1Error(err.to_string())),
|
|
840
|
+
})
|
|
841
|
+
.collect::<Result<Vec<&[u8]>, DLCError>>()?;
|
|
842
|
+
|
|
843
|
+
if s_values.is_empty() {
|
|
844
|
+
return Err(DLCError::InvalidArgument(
|
|
845
|
+
"No signatures provided".to_string(),
|
|
846
|
+
));
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
let secret = SecretKey::from_slice(s_values[0])
|
|
850
|
+
.map_err(|_| DLCError::InvalidArgument("Invalid signature".to_string()))?;
|
|
851
|
+
|
|
852
|
+
let result = s_values.iter().skip(1).fold(secret, |accum, s| {
|
|
853
|
+
let sec = SecretKey::from_slice(s).unwrap();
|
|
854
|
+
accum.add_tweak(&Scalar::from(sec)).unwrap()
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
Ok(result)
|
|
858
|
+
}
|
|
859
|
+
|
|
831
860
|
pub fn create_cet_adaptor_sigs_from_oracle_info(
|
|
832
861
|
cets: Vec<Transaction>,
|
|
833
862
|
oracle_info: Vec<OracleInfo>,
|
|
@@ -1100,6 +1129,31 @@ pub fn create_cet_adaptor_points_from_oracle_info(
|
|
|
1100
1129
|
Ok(adaptor_points)
|
|
1101
1130
|
}
|
|
1102
1131
|
|
|
1132
|
+
pub fn extract_ecdsa_signature_from_oracle_signatures(
|
|
1133
|
+
oracle_signatures: Vec<Vec<u8>>,
|
|
1134
|
+
adaptor_signature: Vec<u8>,
|
|
1135
|
+
) -> Result<Vec<u8>, DLCError> {
|
|
1136
|
+
// Convert oracle signatures to Schnorr signatures
|
|
1137
|
+
let oracle_sigs = oracle_signatures
|
|
1138
|
+
.iter()
|
|
1139
|
+
.map(|sig| vec_to_schnorr_signature(sig.as_slice()))
|
|
1140
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
1141
|
+
|
|
1142
|
+
// Extract the secret key from oracle signatures
|
|
1143
|
+
let adaptor_secret = signatures_to_secret(&[oracle_sigs])?;
|
|
1144
|
+
|
|
1145
|
+
// Convert adaptor signature to EcdsaAdaptorSignature
|
|
1146
|
+
let adaptor_sig = vec_to_ecdsa_adaptor_signature(adaptor_signature)?;
|
|
1147
|
+
|
|
1148
|
+
// Decrypt the adaptor signature to get the final ECDSA signature
|
|
1149
|
+
let ecdsa_sig = adaptor_sig
|
|
1150
|
+
.decrypt(&adaptor_secret)
|
|
1151
|
+
.map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
|
|
1152
|
+
|
|
1153
|
+
// Return the DER-encoded signature
|
|
1154
|
+
Ok(ecdsa_sig.serialize_der().to_vec())
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1103
1157
|
pub fn convert_mnemonic_to_seed(
|
|
1104
1158
|
mnemonic: String,
|
|
1105
1159
|
passphrase: Option<String>,
|
|
@@ -1735,7 +1789,7 @@ mod tests {
|
|
|
1735
1789
|
let mut rng = secp256k1_zkp::rand::thread_rng();
|
|
1736
1790
|
let (offer_party_params, offer_fund_sk) =
|
|
1737
1791
|
get_party_params(1_000_000_000, 100_000_000, None);
|
|
1738
|
-
let (accept_party_params,
|
|
1792
|
+
let (accept_party_params, _accept_fund_sk) =
|
|
1739
1793
|
get_party_params(1_000_000_000, 100_000_000, None);
|
|
1740
1794
|
|
|
1741
1795
|
let dlc_txs = create_dlc_transactions(
|
|
@@ -1837,7 +1891,7 @@ mod tests {
|
|
|
1837
1891
|
cets[0].clone(),
|
|
1838
1892
|
cet_sigs[0].signature.clone(),
|
|
1839
1893
|
oracle_signatures[0].clone(),
|
|
1840
|
-
|
|
1894
|
+
_accept_fund_sk.secret_bytes().to_vec(),
|
|
1841
1895
|
offer_party_params.fund_pubkey.clone(),
|
|
1842
1896
|
accept_party_params.fund_pubkey.clone(),
|
|
1843
1897
|
fund_output_value,
|
|
@@ -1886,4 +1940,130 @@ mod tests {
|
|
|
1886
1940
|
)
|
|
1887
1941
|
.expect("Invalid decrypted adaptor signature");
|
|
1888
1942
|
}
|
|
1943
|
+
|
|
1944
|
+
#[test]
|
|
1945
|
+
fn test_extract_ecdsa_signature_from_oracle_signatures() {
|
|
1946
|
+
// Setup test data (similar to the main test)
|
|
1947
|
+
let secp = Secp256k1::new();
|
|
1948
|
+
let mut rng = secp256k1_zkp::rand::thread_rng();
|
|
1949
|
+
let (offer_party_params, offer_fund_sk) =
|
|
1950
|
+
get_party_params(1_000_000_000, 100_000_000, None);
|
|
1951
|
+
let (accept_party_params, _accept_fund_sk) =
|
|
1952
|
+
get_party_params(1_000_000_000, 100_000_000, None);
|
|
1953
|
+
|
|
1954
|
+
let dlc_txs = create_dlc_transactions(
|
|
1955
|
+
payouts_test(),
|
|
1956
|
+
offer_party_params.clone(),
|
|
1957
|
+
accept_party_params.clone(),
|
|
1958
|
+
100,
|
|
1959
|
+
4,
|
|
1960
|
+
10,
|
|
1961
|
+
10,
|
|
1962
|
+
0, // Add missing fund_output_serial_id parameter
|
|
1963
|
+
)
|
|
1964
|
+
.unwrap();
|
|
1965
|
+
|
|
1966
|
+
let cets = dlc_txs.cets;
|
|
1967
|
+
const NB_ORACLES: usize = 1; // 1 oracle
|
|
1968
|
+
const NB_OUTCOMES: usize = 3; // 3 outcomes (enumeration)
|
|
1969
|
+
const NB_DIGITS: usize = 1; // 1 nonce for enumeration contract
|
|
1970
|
+
|
|
1971
|
+
let mut oracle_infos: Vec<OracleInfo> = Vec::with_capacity(NB_ORACLES);
|
|
1972
|
+
let mut oracle_sks: Vec<Keypair> = Vec::with_capacity(NB_ORACLES);
|
|
1973
|
+
let mut oracle_sk_nonce: Vec<Vec<[u8; 32]>> = Vec::with_capacity(NB_ORACLES);
|
|
1974
|
+
let mut oracle_sigs: Vec<Vec<SchnorrSignature>> = Vec::with_capacity(NB_ORACLES);
|
|
1975
|
+
|
|
1976
|
+
// Messages: 3 outcomes × 1 oracle × 1 message per outcome
|
|
1977
|
+
let messages: Vec<Vec<Vec<_>>> = (0..NB_OUTCOMES)
|
|
1978
|
+
.map(|outcome_idx| {
|
|
1979
|
+
vec![
|
|
1980
|
+
// Single oracle
|
|
1981
|
+
vec![
|
|
1982
|
+
// Single message for this outcome
|
|
1983
|
+
{
|
|
1984
|
+
let message = &[outcome_idx as u8]; // Different message per outcome
|
|
1985
|
+
let hash = sha256::Hash::hash(message).to_byte_array();
|
|
1986
|
+
hash.to_vec()
|
|
1987
|
+
},
|
|
1988
|
+
],
|
|
1989
|
+
]
|
|
1990
|
+
})
|
|
1991
|
+
.collect();
|
|
1992
|
+
|
|
1993
|
+
// Setup single oracle with single nonce
|
|
1994
|
+
for i in 0..NB_ORACLES {
|
|
1995
|
+
// Runs once
|
|
1996
|
+
let oracle_kp = Keypair::new(&secp, &mut rng);
|
|
1997
|
+
let oracle_pubkey = oracle_kp.x_only_public_key().0;
|
|
1998
|
+
let mut nonces: Vec<XOnlyPublicKey> = Vec::with_capacity(NB_DIGITS);
|
|
1999
|
+
let mut sk_nonces: Vec<[u8; 32]> = Vec::with_capacity(NB_DIGITS);
|
|
2000
|
+
oracle_sigs.push(Vec::with_capacity(NB_DIGITS));
|
|
2001
|
+
|
|
2002
|
+
// Single nonce for enumeration
|
|
2003
|
+
let mut sk_nonce = [0u8; 32];
|
|
2004
|
+
rng.fill_bytes(&mut sk_nonce);
|
|
2005
|
+
let oracle_r_kp = Keypair::from_seckey_slice(&secp, &sk_nonce).unwrap();
|
|
2006
|
+
let nonce = XOnlyPublicKey::from_keypair(&oracle_r_kp).0;
|
|
2007
|
+
|
|
2008
|
+
// Sign the first outcome's message with the single nonce
|
|
2009
|
+
let sig = secp_utils::schnorrsig_sign_with_nonce(
|
|
2010
|
+
&secp,
|
|
2011
|
+
&Message::from_digest_slice(&messages[0][0][0]).unwrap(), // First outcome, first oracle, first message
|
|
2012
|
+
&oracle_kp,
|
|
2013
|
+
&sk_nonce,
|
|
2014
|
+
);
|
|
2015
|
+
|
|
2016
|
+
oracle_sigs[i].push(sig);
|
|
2017
|
+
nonces.push(nonce);
|
|
2018
|
+
sk_nonces.push(sk_nonce);
|
|
2019
|
+
|
|
2020
|
+
oracle_infos.push(OracleInfo {
|
|
2021
|
+
public_key: oracle_pubkey.serialize().to_vec(),
|
|
2022
|
+
nonces: nonces.iter().map(|n| n.serialize().to_vec()).collect(), // Just 1 nonce
|
|
2023
|
+
});
|
|
2024
|
+
oracle_sk_nonce.push(sk_nonces);
|
|
2025
|
+
oracle_sks.push(oracle_kp);
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
let funding_script_pubkey = ddk_dlc::make_funding_redeemscript(
|
|
2029
|
+
&PublicKey::from_slice(&offer_party_params.fund_pubkey.clone()).unwrap(),
|
|
2030
|
+
&PublicKey::from_slice(&accept_party_params.fund_pubkey.clone()).unwrap(),
|
|
2031
|
+
);
|
|
2032
|
+
let fund_output_value = dlc_txs.fund.outputs[0].value;
|
|
2033
|
+
|
|
2034
|
+
// Create adaptor signatures
|
|
2035
|
+
let cet_sigs = create_cet_adaptor_sigs_from_oracle_info(
|
|
2036
|
+
cets.clone(),
|
|
2037
|
+
oracle_infos.clone(),
|
|
2038
|
+
offer_fund_sk.secret_bytes().to_vec(),
|
|
2039
|
+
funding_script_pubkey.clone().into_bytes(),
|
|
2040
|
+
fund_output_value,
|
|
2041
|
+
messages.clone(),
|
|
2042
|
+
)
|
|
2043
|
+
.unwrap();
|
|
2044
|
+
|
|
2045
|
+
// Convert oracle signatures to the format expected by our function
|
|
2046
|
+
let oracle_signatures = oracle_sigs
|
|
2047
|
+
.iter()
|
|
2048
|
+
.map(|s| s.iter().map(|s| s.serialize().to_vec()).collect::<Vec<_>>())
|
|
2049
|
+
.collect::<Vec<_>>();
|
|
2050
|
+
|
|
2051
|
+
// Test our new function
|
|
2052
|
+
let result = extract_ecdsa_signature_from_oracle_signatures(
|
|
2053
|
+
oracle_signatures[0].clone(),
|
|
2054
|
+
cet_sigs[0].signature.clone(),
|
|
2055
|
+
);
|
|
2056
|
+
|
|
2057
|
+
assert!(result.is_ok(), "Function should succeed");
|
|
2058
|
+
|
|
2059
|
+
let ecdsa_sig_bytes = result.unwrap();
|
|
2060
|
+
assert!(
|
|
2061
|
+
!ecdsa_sig_bytes.is_empty(),
|
|
2062
|
+
"Should return non-empty signature"
|
|
2063
|
+
);
|
|
2064
|
+
|
|
2065
|
+
// Verify the signature is valid DER format
|
|
2066
|
+
let ecdsa_sig = EcdsaSignature::from_der(&ecdsa_sig_bytes);
|
|
2067
|
+
assert!(ecdsa_sig.is_ok(), "Should be valid DER signature");
|
|
2068
|
+
}
|
|
1889
2069
|
}
|
|
@@ -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;;AAkQA;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
|
@@ -19,6 +19,7 @@ exports.createRefundTransaction = createRefundTransaction;
|
|
|
19
19
|
exports.createSplicedDlcTransactions = createSplicedDlcTransactions;
|
|
20
20
|
exports.createXprivFromParentPath = createXprivFromParentPath;
|
|
21
21
|
exports.default = void 0;
|
|
22
|
+
exports.extractEcdsaSignatureFromOracleSignatures = extractEcdsaSignatureFromOracleSignatures;
|
|
22
23
|
exports.getChangeOutputAndFees = getChangeOutputAndFees;
|
|
23
24
|
exports.getPubkeyFromExtkey = getPubkeyFromExtkey;
|
|
24
25
|
exports.getRawFundingTransactionInputSignature = getRawFundingTransactionInputSignature;
|
|
@@ -161,6 +162,14 @@ function createXprivFromParentPath(seedOrXpriv, baseDerivationPath, network, pat
|
|
|
161
162
|
})()(FfiConverterArrayUInt8.lower(seedOrXpriv), FfiConverterString.lower(baseDerivationPath), FfiConverterString.lower(network), FfiConverterString.lower(path), callStatus);
|
|
162
163
|
}, /*liftString:*/FfiConverterString.lift));
|
|
163
164
|
}
|
|
165
|
+
function extractEcdsaSignatureFromOracleSignatures(oracleSignatures, adaptorSignature) /*throws*/{
|
|
166
|
+
return FfiConverterArrayUInt8.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
|
|
167
|
+
return (() => {
|
|
168
|
+
console.debug(`-- uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures`);
|
|
169
|
+
return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_extract_ecdsa_signature_from_oracle_signatures;
|
|
170
|
+
})()(FfiConverterArrayArrayUInt8.lower(oracleSignatures), FfiConverterArrayUInt8.lower(adaptorSignature), callStatus);
|
|
171
|
+
}, /*liftString:*/FfiConverterString.lift));
|
|
172
|
+
}
|
|
164
173
|
function getChangeOutputAndFees(params, feeRate) /*throws*/{
|
|
165
174
|
return FfiConverterTypeChangeOutputAndFees.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
|
|
166
175
|
return (() => {
|
|
@@ -1292,6 +1301,9 @@ function uniffiEnsureInitialized() {
|
|
|
1292
1301
|
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path() !== 34808) {
|
|
1293
1302
|
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_create_xpriv_from_parent_path');
|
|
1294
1303
|
}
|
|
1304
|
+
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures() !== 8006) {
|
|
1305
|
+
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures');
|
|
1306
|
+
}
|
|
1295
1307
|
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees() !== 44150) {
|
|
1296
1308
|
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_change_output_and_fees');
|
|
1297
1309
|
}
|