@bennyblader/ddk-rn 0.3.32 → 0.3.33
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 +84 -0
- package/cpp/ddk_ffi.hpp +4 -0
- package/ddk-ffi/Cargo.lock +131 -162
- package/ddk-ffi/Cargo.toml +1 -1
- package/ddk-ffi/src/ddk_ffi.udl +38 -0
- package/ddk-ffi/src/lib.rs +373 -0
- package/lib/commonjs/ddk_ffi-ffi.js.map +1 -1
- package/lib/commonjs/ddk_ffi.js +79 -1
- 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 +76 -0
- package/lib/module/ddk_ffi.js.map +1 -1
- package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts +4 -0
- package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ddk_ffi.d.ts +37 -0
- package/lib/typescript/commonjs/src/ddk_ffi.d.ts.map +1 -1
- package/lib/typescript/module/src/ddk_ffi-ffi.d.ts +4 -0
- package/lib/typescript/module/src/ddk_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/module/src/ddk_ffi.d.ts +37 -0
- package/lib/typescript/module/src/ddk_ffi.d.ts.map +1 -1
- package/package.json +18 -17
- package/scripts/apply-hotfix.js +0 -0
- package/scripts/postinstall.js +0 -0
- package/src/ddk_ffi-ffi.ts +16 -0
- package/src/ddk_ffi.ts +153 -0
package/ddk-ffi/Cargo.toml
CHANGED
package/ddk-ffi/src/ddk_ffi.udl
CHANGED
|
@@ -211,6 +211,25 @@ namespace ddk_ffi {
|
|
|
211
211
|
sequence<sequence<u8>> oracle_signatures,
|
|
212
212
|
sequence<u8> adaptor_signature
|
|
213
213
|
);
|
|
214
|
+
|
|
215
|
+
// Debug function to get all inputs for adaptor signature creation
|
|
216
|
+
// Use this to compare values with Fordefi
|
|
217
|
+
[Throws=DLCError]
|
|
218
|
+
CetAdaptorSignatureDebugInfo get_cet_adaptor_signature_inputs(
|
|
219
|
+
Transaction cet,
|
|
220
|
+
sequence<OracleInfo> oracle_info,
|
|
221
|
+
sequence<u8> funding_script_pubkey,
|
|
222
|
+
u64 fund_output_value,
|
|
223
|
+
sequence<sequence<sequence<u8>>> msgs
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
// Get sighash for a CET - the actual message that gets signed
|
|
227
|
+
[Throws=DLCError]
|
|
228
|
+
sequence<u8> get_cet_sighash(
|
|
229
|
+
Transaction cet,
|
|
230
|
+
sequence<u8> funding_script_pubkey,
|
|
231
|
+
u64 fund_output_value
|
|
232
|
+
);
|
|
214
233
|
};
|
|
215
234
|
|
|
216
235
|
// Transaction representation
|
|
@@ -303,6 +322,25 @@ dictionary OracleInfo {
|
|
|
303
322
|
sequence<sequence<u8>> nonces;
|
|
304
323
|
};
|
|
305
324
|
|
|
325
|
+
// Debug info for CET adaptor signature inputs
|
|
326
|
+
// All the values that go into creating an adaptor signature
|
|
327
|
+
dictionary CetAdaptorSignatureDebugInfo {
|
|
328
|
+
// The sighash (32 bytes) - this is the message that gets signed
|
|
329
|
+
sequence<u8> sighash;
|
|
330
|
+
// The adaptor point (33 bytes compressed public key)
|
|
331
|
+
sequence<u8> adaptor_point;
|
|
332
|
+
// Input index (always 0 for CETs)
|
|
333
|
+
u32 input_index;
|
|
334
|
+
// The funding script pubkey used for sighash
|
|
335
|
+
sequence<u8> script_pubkey;
|
|
336
|
+
// The fund output value used for sighash
|
|
337
|
+
u64 value;
|
|
338
|
+
// The CET txid
|
|
339
|
+
string cet_txid;
|
|
340
|
+
// Raw CET bytes for verification
|
|
341
|
+
sequence<u8> cet_raw;
|
|
342
|
+
};
|
|
343
|
+
|
|
306
344
|
// Error types for DLC operations
|
|
307
345
|
[Error]
|
|
308
346
|
enum DLCError {
|
package/ddk-ffi/src/lib.rs
CHANGED
|
@@ -193,6 +193,31 @@ pub struct OracleInfo {
|
|
|
193
193
|
pub nonces: Vec<Vec<u8>>,
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
/// Debug info for CET adaptor signature inputs.
|
|
197
|
+
///
|
|
198
|
+
/// Contains all the values that go into creating an adaptor signature,
|
|
199
|
+
/// useful for comparing with external signers during debugging.
|
|
200
|
+
///
|
|
201
|
+
/// This struct is intentionally always available (not feature-gated)
|
|
202
|
+
/// to support production debugging scenarios.
|
|
203
|
+
#[derive(Clone)]
|
|
204
|
+
pub struct CetAdaptorSignatureDebugInfo {
|
|
205
|
+
/// The sighash (32 bytes) - this is the message that gets signed
|
|
206
|
+
pub sighash: Vec<u8>,
|
|
207
|
+
/// The adaptor point (33 bytes compressed public key)
|
|
208
|
+
pub adaptor_point: Vec<u8>,
|
|
209
|
+
/// Input index (always 0 for CETs)
|
|
210
|
+
pub input_index: u32,
|
|
211
|
+
/// The funding script pubkey used for sighash
|
|
212
|
+
pub script_pubkey: Vec<u8>,
|
|
213
|
+
/// The fund output value used for sighash
|
|
214
|
+
pub value: u64,
|
|
215
|
+
/// The CET txid
|
|
216
|
+
pub cet_txid: String,
|
|
217
|
+
/// Raw CET bytes for verification
|
|
218
|
+
pub cet_raw: Vec<u8>,
|
|
219
|
+
}
|
|
220
|
+
|
|
196
221
|
// Conversion helpers
|
|
197
222
|
pub fn btc_tx_to_transaction(tx: &BtcTransaction) -> Transaction {
|
|
198
223
|
use bitcoin::consensus::Encodable;
|
|
@@ -1154,6 +1179,116 @@ pub fn extract_ecdsa_signature_from_oracle_signatures(
|
|
|
1154
1179
|
Ok(ecdsa_sig.serialize_der().to_vec())
|
|
1155
1180
|
}
|
|
1156
1181
|
|
|
1182
|
+
/// Get all the inputs that go into creating a CET adaptor signature.
|
|
1183
|
+
///
|
|
1184
|
+
/// This debug function is intentionally always available (not feature-gated)
|
|
1185
|
+
/// to enable debugging signature mismatches in production environments where
|
|
1186
|
+
/// rebuilding with debug features may not be feasible.
|
|
1187
|
+
///
|
|
1188
|
+
/// Use this to compare values with external signers (e.g., Fordefi) when
|
|
1189
|
+
/// debugging adaptor signature verification failures.
|
|
1190
|
+
///
|
|
1191
|
+
/// Returns:
|
|
1192
|
+
/// - `sighash`: The 32-byte BIP143 sighash message that gets signed
|
|
1193
|
+
/// - `adaptor_point`: The 33-byte compressed adaptor public key
|
|
1194
|
+
/// - `input_index`: Always 0 for CETs
|
|
1195
|
+
/// - `script_pubkey`: The funding script used for sighash calculation
|
|
1196
|
+
/// - `value`: The fund output value used for sighash calculation
|
|
1197
|
+
/// - `cet_txid`: The CET transaction ID
|
|
1198
|
+
/// - `cet_raw`: Raw serialized CET bytes
|
|
1199
|
+
pub fn get_cet_adaptor_signature_inputs(
|
|
1200
|
+
cet: Transaction,
|
|
1201
|
+
oracle_info: Vec<OracleInfo>,
|
|
1202
|
+
funding_script_pubkey: Vec<u8>,
|
|
1203
|
+
fund_output_value: u64,
|
|
1204
|
+
msgs: Vec<Vec<Vec<u8>>>,
|
|
1205
|
+
) -> Result<CetAdaptorSignatureDebugInfo, DLCError> {
|
|
1206
|
+
let btc_tx = transaction_to_btc_tx(&cet)?;
|
|
1207
|
+
let funding_script = Script::from_bytes(&funding_script_pubkey);
|
|
1208
|
+
|
|
1209
|
+
// Convert oracle info
|
|
1210
|
+
let oracle_infos: Vec<DlcOracleInfo> = oracle_info
|
|
1211
|
+
.iter()
|
|
1212
|
+
.map(|info| {
|
|
1213
|
+
let public_key = XOnlyPublicKey::from_slice(&info.public_key)
|
|
1214
|
+
.map_err(|_| DLCError::InvalidPublicKey)?;
|
|
1215
|
+
let nonces = info
|
|
1216
|
+
.nonces
|
|
1217
|
+
.iter()
|
|
1218
|
+
.map(|nonce| XOnlyPublicKey::from_slice(nonce))
|
|
1219
|
+
.collect::<Result<Vec<_>, _>>()
|
|
1220
|
+
.map_err(|_| DLCError::InvalidArgument("Invalid nonce pubkey".to_string()))?;
|
|
1221
|
+
Ok(DlcOracleInfo { public_key, nonces })
|
|
1222
|
+
})
|
|
1223
|
+
.collect::<Result<Vec<_>, DLCError>>()?;
|
|
1224
|
+
|
|
1225
|
+
// Convert messages
|
|
1226
|
+
let cet_msgs: Vec<Vec<Message>> = msgs
|
|
1227
|
+
.into_iter()
|
|
1228
|
+
.map(|outcome_msgs| {
|
|
1229
|
+
outcome_msgs
|
|
1230
|
+
.iter()
|
|
1231
|
+
.map(|m| {
|
|
1232
|
+
Message::from_digest_slice(m)
|
|
1233
|
+
.map_err(|_| DLCError::InvalidArgument("Invalid message".to_string()))
|
|
1234
|
+
})
|
|
1235
|
+
.collect::<Result<Vec<_>, _>>()
|
|
1236
|
+
})
|
|
1237
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
1238
|
+
|
|
1239
|
+
let secp = get_secp_context();
|
|
1240
|
+
|
|
1241
|
+
// Get the adaptor point
|
|
1242
|
+
let adaptor_point = ddk_dlc::get_adaptor_point_from_oracle_info(secp, &oracle_infos, &cet_msgs)
|
|
1243
|
+
.map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
|
|
1244
|
+
|
|
1245
|
+
// Get the sighash - this is the actual message being signed
|
|
1246
|
+
let sig_hash = ddk_dlc::util::get_sig_hash_msg(
|
|
1247
|
+
&btc_tx,
|
|
1248
|
+
0, // input_index is always 0 for CETs
|
|
1249
|
+
funding_script,
|
|
1250
|
+
Amount::from_sat(fund_output_value),
|
|
1251
|
+
)
|
|
1252
|
+
.map_err(DLCError::from)?;
|
|
1253
|
+
|
|
1254
|
+
Ok(CetAdaptorSignatureDebugInfo {
|
|
1255
|
+
sighash: sig_hash.as_ref().to_vec(),
|
|
1256
|
+
adaptor_point: adaptor_point.serialize().to_vec(),
|
|
1257
|
+
input_index: 0,
|
|
1258
|
+
script_pubkey: funding_script_pubkey,
|
|
1259
|
+
value: fund_output_value,
|
|
1260
|
+
cet_txid: btc_tx.compute_txid().to_string(),
|
|
1261
|
+
cet_raw: cet.raw_bytes,
|
|
1262
|
+
})
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
/// Get the sighash for a CET - the actual 32-byte message that gets signed.
|
|
1266
|
+
///
|
|
1267
|
+
/// This debug function is intentionally always available (not feature-gated)
|
|
1268
|
+
/// to enable debugging sighash mismatches in production environments where
|
|
1269
|
+
/// rebuilding with debug features may not be feasible.
|
|
1270
|
+
///
|
|
1271
|
+
/// Use this to compare sighash values with external signers (e.g., Fordefi)
|
|
1272
|
+
/// when debugging signature verification failures.
|
|
1273
|
+
pub fn get_cet_sighash(
|
|
1274
|
+
cet: Transaction,
|
|
1275
|
+
funding_script_pubkey: Vec<u8>,
|
|
1276
|
+
fund_output_value: u64,
|
|
1277
|
+
) -> Result<Vec<u8>, DLCError> {
|
|
1278
|
+
let btc_tx = transaction_to_btc_tx(&cet)?;
|
|
1279
|
+
let funding_script = Script::from_bytes(&funding_script_pubkey);
|
|
1280
|
+
|
|
1281
|
+
let sig_hash = ddk_dlc::util::get_sig_hash_msg(
|
|
1282
|
+
&btc_tx,
|
|
1283
|
+
0, // input_index is always 0 for CETs
|
|
1284
|
+
funding_script,
|
|
1285
|
+
Amount::from_sat(fund_output_value),
|
|
1286
|
+
)
|
|
1287
|
+
.map_err(DLCError::from)?;
|
|
1288
|
+
|
|
1289
|
+
Ok(sig_hash.as_ref().to_vec())
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1157
1292
|
pub fn convert_mnemonic_to_seed(
|
|
1158
1293
|
mnemonic: String,
|
|
1159
1294
|
passphrase: Option<String>,
|
|
@@ -2066,4 +2201,242 @@ mod tests {
|
|
|
2066
2201
|
let ecdsa_sig = EcdsaSignature::from_der(&ecdsa_sig_bytes);
|
|
2067
2202
|
assert!(ecdsa_sig.is_ok(), "Should be valid DER signature");
|
|
2068
2203
|
}
|
|
2204
|
+
|
|
2205
|
+
#[test]
|
|
2206
|
+
fn test_get_cet_sighash() {
|
|
2207
|
+
// Setup: Create DLC transactions to get a valid CET
|
|
2208
|
+
let (offer_party_params, _offer_fund_sk) =
|
|
2209
|
+
get_party_params(1_000_000_000, 100_000_000, None);
|
|
2210
|
+
let (accept_party_params, _accept_fund_sk) =
|
|
2211
|
+
get_party_params(1_000_000_000, 100_000_000, Some(2));
|
|
2212
|
+
|
|
2213
|
+
let dlc_txs = create_dlc_transactions(
|
|
2214
|
+
payouts_test(),
|
|
2215
|
+
offer_party_params.clone(),
|
|
2216
|
+
accept_party_params.clone(),
|
|
2217
|
+
100,
|
|
2218
|
+
4,
|
|
2219
|
+
10,
|
|
2220
|
+
10,
|
|
2221
|
+
0,
|
|
2222
|
+
)
|
|
2223
|
+
.unwrap();
|
|
2224
|
+
|
|
2225
|
+
let cet = dlc_txs.cets[0].clone();
|
|
2226
|
+
let funding_script_pubkey = ddk_dlc::make_funding_redeemscript(
|
|
2227
|
+
&PublicKey::from_slice(&offer_party_params.fund_pubkey).unwrap(),
|
|
2228
|
+
&PublicKey::from_slice(&accept_party_params.fund_pubkey).unwrap(),
|
|
2229
|
+
);
|
|
2230
|
+
let fund_output_value = dlc_txs.fund.outputs[0].value;
|
|
2231
|
+
|
|
2232
|
+
// Act: Get the sighash
|
|
2233
|
+
let result = get_cet_sighash(
|
|
2234
|
+
cet.clone(),
|
|
2235
|
+
funding_script_pubkey.clone().into_bytes(),
|
|
2236
|
+
fund_output_value,
|
|
2237
|
+
);
|
|
2238
|
+
|
|
2239
|
+
// Assert
|
|
2240
|
+
assert!(result.is_ok(), "get_cet_sighash should succeed");
|
|
2241
|
+
let sighash = result.unwrap();
|
|
2242
|
+
assert_eq!(sighash.len(), 32, "Sighash should be 32 bytes");
|
|
2243
|
+
|
|
2244
|
+
// Verify against direct ddk-dlc call
|
|
2245
|
+
let btc_tx = transaction_to_btc_tx(&cet).unwrap();
|
|
2246
|
+
let direct_sighash = ddk_dlc::util::get_sig_hash_msg(
|
|
2247
|
+
&btc_tx,
|
|
2248
|
+
0,
|
|
2249
|
+
Script::from_bytes(&funding_script_pubkey.clone().into_bytes()),
|
|
2250
|
+
Amount::from_sat(fund_output_value),
|
|
2251
|
+
)
|
|
2252
|
+
.unwrap();
|
|
2253
|
+
|
|
2254
|
+
assert_eq!(
|
|
2255
|
+
sighash,
|
|
2256
|
+
direct_sighash.as_ref().to_vec(),
|
|
2257
|
+
"Sighash should match direct ddk-dlc calculation"
|
|
2258
|
+
);
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
#[test]
|
|
2262
|
+
fn test_get_cet_adaptor_signature_inputs() {
|
|
2263
|
+
// Setup: Create DLC transactions and oracle info
|
|
2264
|
+
let secp = Secp256k1::new();
|
|
2265
|
+
let mut rng = secp256k1_zkp::rand::thread_rng();
|
|
2266
|
+
let (offer_party_params, _offer_fund_sk) =
|
|
2267
|
+
get_party_params(1_000_000_000, 100_000_000, None);
|
|
2268
|
+
let (accept_party_params, _accept_fund_sk) =
|
|
2269
|
+
get_party_params(1_000_000_000, 100_000_000, Some(2));
|
|
2270
|
+
|
|
2271
|
+
let dlc_txs = create_dlc_transactions(
|
|
2272
|
+
payouts_test(),
|
|
2273
|
+
offer_party_params.clone(),
|
|
2274
|
+
accept_party_params.clone(),
|
|
2275
|
+
100,
|
|
2276
|
+
4,
|
|
2277
|
+
10,
|
|
2278
|
+
10,
|
|
2279
|
+
0,
|
|
2280
|
+
)
|
|
2281
|
+
.unwrap();
|
|
2282
|
+
|
|
2283
|
+
let cet = dlc_txs.cets[0].clone();
|
|
2284
|
+
let funding_script_pubkey = ddk_dlc::make_funding_redeemscript(
|
|
2285
|
+
&PublicKey::from_slice(&offer_party_params.fund_pubkey).unwrap(),
|
|
2286
|
+
&PublicKey::from_slice(&accept_party_params.fund_pubkey).unwrap(),
|
|
2287
|
+
);
|
|
2288
|
+
let fund_output_value = dlc_txs.fund.outputs[0].value;
|
|
2289
|
+
|
|
2290
|
+
// Create oracle info (single oracle, single nonce for enumeration)
|
|
2291
|
+
let oracle_kp = Keypair::new(&secp, &mut rng);
|
|
2292
|
+
let oracle_pubkey = oracle_kp.x_only_public_key().0;
|
|
2293
|
+
let mut sk_nonce = [0u8; 32];
|
|
2294
|
+
rng.fill_bytes(&mut sk_nonce);
|
|
2295
|
+
let oracle_r_kp = Keypair::from_seckey_slice(&secp, &sk_nonce).unwrap();
|
|
2296
|
+
let nonce = XOnlyPublicKey::from_keypair(&oracle_r_kp).0;
|
|
2297
|
+
|
|
2298
|
+
let oracle_info = vec![OracleInfo {
|
|
2299
|
+
public_key: oracle_pubkey.serialize().to_vec(),
|
|
2300
|
+
nonces: vec![nonce.serialize().to_vec()],
|
|
2301
|
+
}];
|
|
2302
|
+
|
|
2303
|
+
// Create message (first outcome)
|
|
2304
|
+
let message = &[0u8];
|
|
2305
|
+
let hash = sha256::Hash::hash(message).to_byte_array();
|
|
2306
|
+
let msgs = vec![vec![hash.to_vec()]]; // Single oracle, single message
|
|
2307
|
+
|
|
2308
|
+
// Act: Get debug info
|
|
2309
|
+
let result = get_cet_adaptor_signature_inputs(
|
|
2310
|
+
cet.clone(),
|
|
2311
|
+
oracle_info.clone(),
|
|
2312
|
+
funding_script_pubkey.clone().into_bytes(),
|
|
2313
|
+
fund_output_value,
|
|
2314
|
+
msgs.clone(),
|
|
2315
|
+
);
|
|
2316
|
+
|
|
2317
|
+
// Assert
|
|
2318
|
+
assert!(
|
|
2319
|
+
result.is_ok(),
|
|
2320
|
+
"get_cet_adaptor_signature_inputs should succeed"
|
|
2321
|
+
);
|
|
2322
|
+
let debug_info = result.unwrap();
|
|
2323
|
+
|
|
2324
|
+
// Verify sighash
|
|
2325
|
+
assert_eq!(debug_info.sighash.len(), 32, "Sighash should be 32 bytes");
|
|
2326
|
+
let expected_sighash = get_cet_sighash(
|
|
2327
|
+
cet.clone(),
|
|
2328
|
+
funding_script_pubkey.clone().into_bytes(),
|
|
2329
|
+
fund_output_value,
|
|
2330
|
+
)
|
|
2331
|
+
.unwrap();
|
|
2332
|
+
assert_eq!(
|
|
2333
|
+
debug_info.sighash, expected_sighash,
|
|
2334
|
+
"Sighash should match get_cet_sighash result"
|
|
2335
|
+
);
|
|
2336
|
+
|
|
2337
|
+
// Verify adaptor point
|
|
2338
|
+
assert_eq!(
|
|
2339
|
+
debug_info.adaptor_point.len(),
|
|
2340
|
+
33,
|
|
2341
|
+
"Adaptor point should be 33 bytes (compressed pubkey)"
|
|
2342
|
+
);
|
|
2343
|
+
|
|
2344
|
+
// Verify input index is always 0 for CETs
|
|
2345
|
+
assert_eq!(
|
|
2346
|
+
debug_info.input_index, 0,
|
|
2347
|
+
"Input index should always be 0 for CETs"
|
|
2348
|
+
);
|
|
2349
|
+
|
|
2350
|
+
// Verify script_pubkey matches what we passed in
|
|
2351
|
+
assert_eq!(
|
|
2352
|
+
debug_info.script_pubkey,
|
|
2353
|
+
funding_script_pubkey.clone().into_bytes(),
|
|
2354
|
+
"Script pubkey should match input"
|
|
2355
|
+
);
|
|
2356
|
+
|
|
2357
|
+
// Verify value matches
|
|
2358
|
+
assert_eq!(
|
|
2359
|
+
debug_info.value, fund_output_value,
|
|
2360
|
+
"Value should match input"
|
|
2361
|
+
);
|
|
2362
|
+
|
|
2363
|
+
// Verify cet_txid is valid
|
|
2364
|
+
let btc_tx = transaction_to_btc_tx(&cet).unwrap();
|
|
2365
|
+
assert_eq!(
|
|
2366
|
+
debug_info.cet_txid,
|
|
2367
|
+
btc_tx.compute_txid().to_string(),
|
|
2368
|
+
"CET txid should match"
|
|
2369
|
+
);
|
|
2370
|
+
|
|
2371
|
+
// Verify cet_raw matches input
|
|
2372
|
+
assert_eq!(
|
|
2373
|
+
debug_info.cet_raw, cet.raw_bytes,
|
|
2374
|
+
"CET raw bytes should match input"
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
#[test]
|
|
2379
|
+
fn test_get_cet_sighash_invalid_transaction() {
|
|
2380
|
+
// Create an invalid transaction (empty raw_bytes)
|
|
2381
|
+
let invalid_tx = Transaction {
|
|
2382
|
+
version: 2,
|
|
2383
|
+
lock_time: 0,
|
|
2384
|
+
inputs: vec![],
|
|
2385
|
+
outputs: vec![],
|
|
2386
|
+
raw_bytes: vec![0x00], // Invalid serialization
|
|
2387
|
+
};
|
|
2388
|
+
|
|
2389
|
+
let result = get_cet_sighash(invalid_tx, vec![0x00, 0x14], 100_000);
|
|
2390
|
+
|
|
2391
|
+
assert!(
|
|
2392
|
+
result.is_err(),
|
|
2393
|
+
"Should fail with invalid transaction bytes"
|
|
2394
|
+
);
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
#[test]
|
|
2398
|
+
fn test_get_cet_adaptor_signature_inputs_invalid_oracle_pubkey() {
|
|
2399
|
+
// Setup valid CET
|
|
2400
|
+
let (offer_party_params, _) = get_party_params(1_000_000_000, 100_000_000, None);
|
|
2401
|
+
let (accept_party_params, _) = get_party_params(1_000_000_000, 100_000_000, Some(2));
|
|
2402
|
+
|
|
2403
|
+
let dlc_txs = create_dlc_transactions(
|
|
2404
|
+
payouts_test(),
|
|
2405
|
+
offer_party_params.clone(),
|
|
2406
|
+
accept_party_params.clone(),
|
|
2407
|
+
100,
|
|
2408
|
+
4,
|
|
2409
|
+
10,
|
|
2410
|
+
10,
|
|
2411
|
+
0,
|
|
2412
|
+
)
|
|
2413
|
+
.unwrap();
|
|
2414
|
+
|
|
2415
|
+
let cet = dlc_txs.cets[0].clone();
|
|
2416
|
+
let funding_script_pubkey = ddk_dlc::make_funding_redeemscript(
|
|
2417
|
+
&PublicKey::from_slice(&offer_party_params.fund_pubkey).unwrap(),
|
|
2418
|
+
&PublicKey::from_slice(&accept_party_params.fund_pubkey).unwrap(),
|
|
2419
|
+
);
|
|
2420
|
+
|
|
2421
|
+
// Invalid oracle info (wrong pubkey length)
|
|
2422
|
+
let invalid_oracle_info = vec![OracleInfo {
|
|
2423
|
+
public_key: vec![0x00; 20], // Invalid: should be 32 bytes for x-only
|
|
2424
|
+
nonces: vec![vec![0x00; 32]],
|
|
2425
|
+
}];
|
|
2426
|
+
|
|
2427
|
+
let msgs = vec![vec![vec![0u8; 32]]];
|
|
2428
|
+
|
|
2429
|
+
let result = get_cet_adaptor_signature_inputs(
|
|
2430
|
+
cet,
|
|
2431
|
+
invalid_oracle_info,
|
|
2432
|
+
funding_script_pubkey.into_bytes(),
|
|
2433
|
+
100_000,
|
|
2434
|
+
msgs,
|
|
2435
|
+
);
|
|
2436
|
+
|
|
2437
|
+
assert!(
|
|
2438
|
+
result.is_err(),
|
|
2439
|
+
"Should fail with invalid oracle public key"
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2069
2442
|
}
|
|
@@ -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;;AAkRA;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
|
@@ -3,7 +3,7 @@
|
|
|
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.ExtendedKey_Tags = exports.ExtendedKey = exports.DlcTransactions = 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.DlcInputInfo = exports.DlcError_Tags = exports.DlcError = exports.ChangeOutputAndFees = exports.CetAdaptorSignatureDebugInfo = exports.AdaptorSignature = void 0;
|
|
7
7
|
exports.addSignatureToTransaction = addSignatureToTransaction;
|
|
8
8
|
exports.convertMnemonicToSeed = convertMnemonicToSeed;
|
|
9
9
|
exports.createCet = createCet;
|
|
@@ -20,6 +20,8 @@ exports.createSplicedDlcTransactions = createSplicedDlcTransactions;
|
|
|
20
20
|
exports.createXprivFromParentPath = createXprivFromParentPath;
|
|
21
21
|
exports.default = void 0;
|
|
22
22
|
exports.extractEcdsaSignatureFromOracleSignatures = extractEcdsaSignatureFromOracleSignatures;
|
|
23
|
+
exports.getCetAdaptorSignatureInputs = getCetAdaptorSignatureInputs;
|
|
24
|
+
exports.getCetSighash = getCetSighash;
|
|
23
25
|
exports.getChangeOutputAndFees = getChangeOutputAndFees;
|
|
24
26
|
exports.getPubkeyFromExtkey = getPubkeyFromExtkey;
|
|
25
27
|
exports.getRawFundingTransactionInputSignature = getRawFundingTransactionInputSignature;
|
|
@@ -170,6 +172,22 @@ function extractEcdsaSignatureFromOracleSignatures(oracleSignatures, adaptorSign
|
|
|
170
172
|
})()(FfiConverterArrayArrayUInt8.lower(oracleSignatures), FfiConverterArrayUInt8.lower(adaptorSignature), callStatus);
|
|
171
173
|
}, /*liftString:*/FfiConverterString.lift));
|
|
172
174
|
}
|
|
175
|
+
function getCetAdaptorSignatureInputs(cet, oracleInfo, fundingScriptPubkey, fundOutputValue, msgs) /*throws*/{
|
|
176
|
+
return FfiConverterTypeCetAdaptorSignatureDebugInfo.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
|
|
177
|
+
return (() => {
|
|
178
|
+
console.debug(`-- uniffi_ddk_ffi_fn_func_get_cet_adaptor_signature_inputs`);
|
|
179
|
+
return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_get_cet_adaptor_signature_inputs;
|
|
180
|
+
})()(FfiConverterTypeTransaction.lower(cet), FfiConverterArrayTypeOracleInfo.lower(oracleInfo), FfiConverterArrayUInt8.lower(fundingScriptPubkey), _uniffiBindgenReactNative.FfiConverterUInt64.lower(fundOutputValue), FfiConverterArrayArrayArrayUInt8.lower(msgs), callStatus);
|
|
181
|
+
}, /*liftString:*/FfiConverterString.lift));
|
|
182
|
+
}
|
|
183
|
+
function getCetSighash(cet, fundingScriptPubkey, fundOutputValue) /*throws*/{
|
|
184
|
+
return FfiConverterArrayUInt8.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
|
|
185
|
+
return (() => {
|
|
186
|
+
console.debug(`-- uniffi_ddk_ffi_fn_func_get_cet_sighash`);
|
|
187
|
+
return (0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_fn_func_get_cet_sighash;
|
|
188
|
+
})()(FfiConverterTypeTransaction.lower(cet), FfiConverterArrayUInt8.lower(fundingScriptPubkey), _uniffiBindgenReactNative.FfiConverterUInt64.lower(fundOutputValue), callStatus);
|
|
189
|
+
}, /*liftString:*/FfiConverterString.lift));
|
|
190
|
+
}
|
|
173
191
|
function getChangeOutputAndFees(params, feeRate) /*throws*/{
|
|
174
192
|
return FfiConverterTypeChangeOutputAndFees.lift(uniffiCaller.rustCallWithError(/*liftError:*/FfiConverterTypeDLCError.lift.bind(FfiConverterTypeDLCError), /*caller:*/callStatus => {
|
|
175
193
|
return (() => {
|
|
@@ -317,6 +335,59 @@ const FfiConverterTypeAdaptorSignature = (() => {
|
|
|
317
335
|
}
|
|
318
336
|
return new FFIConverter();
|
|
319
337
|
})();
|
|
338
|
+
/**
|
|
339
|
+
* Generated factory for {@link CetAdaptorSignatureDebugInfo} record objects.
|
|
340
|
+
*/
|
|
341
|
+
const CetAdaptorSignatureDebugInfo = exports.CetAdaptorSignatureDebugInfo = (() => {
|
|
342
|
+
const defaults = () => ({});
|
|
343
|
+
const create = (() => {
|
|
344
|
+
return (0, _uniffiBindgenReactNative.uniffiCreateRecord)(defaults);
|
|
345
|
+
})();
|
|
346
|
+
return Object.freeze({
|
|
347
|
+
/**
|
|
348
|
+
* Create a frozen instance of {@link CetAdaptorSignatureDebugInfo}, with defaults specified
|
|
349
|
+
* in Rust, in the {@link ddk_ffi} crate.
|
|
350
|
+
*/
|
|
351
|
+
create,
|
|
352
|
+
/**
|
|
353
|
+
* Create a frozen instance of {@link CetAdaptorSignatureDebugInfo}, with defaults specified
|
|
354
|
+
* in Rust, in the {@link ddk_ffi} crate.
|
|
355
|
+
*/
|
|
356
|
+
new: create,
|
|
357
|
+
/**
|
|
358
|
+
* Defaults specified in the {@link ddk_ffi} crate.
|
|
359
|
+
*/
|
|
360
|
+
defaults: () => Object.freeze(defaults())
|
|
361
|
+
});
|
|
362
|
+
})();
|
|
363
|
+
const FfiConverterTypeCetAdaptorSignatureDebugInfo = (() => {
|
|
364
|
+
class FFIConverter extends _uniffiBindgenReactNative.AbstractFfiConverterByteArray {
|
|
365
|
+
read(from) {
|
|
366
|
+
return {
|
|
367
|
+
sighash: FfiConverterArrayUInt8.read(from),
|
|
368
|
+
adaptorPoint: FfiConverterArrayUInt8.read(from),
|
|
369
|
+
inputIndex: _uniffiBindgenReactNative.FfiConverterUInt32.read(from),
|
|
370
|
+
scriptPubkey: FfiConverterArrayUInt8.read(from),
|
|
371
|
+
value: _uniffiBindgenReactNative.FfiConverterUInt64.read(from),
|
|
372
|
+
cetTxid: FfiConverterString.read(from),
|
|
373
|
+
cetRaw: FfiConverterArrayUInt8.read(from)
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
write(value, into) {
|
|
377
|
+
FfiConverterArrayUInt8.write(value.sighash, into);
|
|
378
|
+
FfiConverterArrayUInt8.write(value.adaptorPoint, into);
|
|
379
|
+
_uniffiBindgenReactNative.FfiConverterUInt32.write(value.inputIndex, into);
|
|
380
|
+
FfiConverterArrayUInt8.write(value.scriptPubkey, into);
|
|
381
|
+
_uniffiBindgenReactNative.FfiConverterUInt64.write(value.value, into);
|
|
382
|
+
FfiConverterString.write(value.cetTxid, into);
|
|
383
|
+
FfiConverterArrayUInt8.write(value.cetRaw, into);
|
|
384
|
+
}
|
|
385
|
+
allocationSize(value) {
|
|
386
|
+
return FfiConverterArrayUInt8.allocationSize(value.sighash) + FfiConverterArrayUInt8.allocationSize(value.adaptorPoint) + _uniffiBindgenReactNative.FfiConverterUInt32.allocationSize(value.inputIndex) + FfiConverterArrayUInt8.allocationSize(value.scriptPubkey) + _uniffiBindgenReactNative.FfiConverterUInt64.allocationSize(value.value) + FfiConverterString.allocationSize(value.cetTxid) + FfiConverterArrayUInt8.allocationSize(value.cetRaw);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return new FFIConverter();
|
|
390
|
+
})();
|
|
320
391
|
/**
|
|
321
392
|
* Generated factory for {@link ChangeOutputAndFees} record objects.
|
|
322
393
|
*/
|
|
@@ -1304,6 +1375,12 @@ function uniffiEnsureInitialized() {
|
|
|
1304
1375
|
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures() !== 8006) {
|
|
1305
1376
|
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_extract_ecdsa_signature_from_oracle_signatures');
|
|
1306
1377
|
}
|
|
1378
|
+
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_cet_adaptor_signature_inputs() !== 14595) {
|
|
1379
|
+
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_cet_adaptor_signature_inputs');
|
|
1380
|
+
}
|
|
1381
|
+
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_cet_sighash() !== 10643) {
|
|
1382
|
+
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_cet_sighash');
|
|
1383
|
+
}
|
|
1307
1384
|
if ((0, _ddk_ffiFfi.default)().ubrn_uniffi_ddk_ffi_checksum_func_get_change_output_and_fees() !== 44150) {
|
|
1308
1385
|
throw new _uniffiBindgenReactNative.UniffiInternalError.ApiChecksumMismatch('uniffi_ddk_ffi_checksum_func_get_change_output_and_fees');
|
|
1309
1386
|
}
|
|
@@ -1348,6 +1425,7 @@ var _default = exports.default = Object.freeze({
|
|
|
1348
1425
|
initialize: uniffiEnsureInitialized,
|
|
1349
1426
|
converters: {
|
|
1350
1427
|
FfiConverterTypeAdaptorSignature,
|
|
1428
|
+
FfiConverterTypeCetAdaptorSignatureDebugInfo,
|
|
1351
1429
|
FfiConverterTypeChangeOutputAndFees,
|
|
1352
1430
|
FfiConverterTypeDLCError,
|
|
1353
1431
|
FfiConverterTypeDlcInputInfo,
|