Clean up libbolt customer interface and ffi shim re: refund token and wallet

This commit is contained in:
J. Ayo Akinyele 2019-03-24 03:06:47 -04:00
parent ce52d01371
commit e2dc5adc06
4 changed files with 44 additions and 27 deletions

View File

@ -116,7 +116,7 @@ fn main() {
let (new_wallet_sig, pay_merch_time2) = measure!(bidirectional::pay_by_merchant_phase2(&pp, &mut channel, &pay_proof, &mut merch_data, &rv_w));
println!(">> TIME for pay_by_merchant_phase2: {}", pay_merch_time2);
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keypair.pk, &mut cust_data, t_c, new_wallet, new_wallet_sig));
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keypair.pk, &mut cust_data, t_c, new_wallet, rt_w, new_wallet_sig));
{
// scope localizes the immutable borrow here (for debug purposes only)
@ -141,7 +141,7 @@ fn main() {
// get the new wallet sig (new_wallet_sig) on the new wallet
let new_wallet_sig1 = bidirectional::pay_by_merchant_phase2(&pp, &mut channel, &pay_proof1, &mut merch_data, &rv_w1);
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keypair.pk, &mut cust_data, t_c1, new_wallet1, new_wallet_sig1));
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keypair.pk, &mut cust_data, t_c1, new_wallet1, rt_w1, new_wallet_sig1));
{
let cust_wallet = &cust_data.csk;
@ -170,7 +170,7 @@ fn main() {
println!("Merchant has refuted the refund request!");
let (new_b0_cust, new_b0_merch) = bidirectional::resolve(&pp, &cust_data, &merch_data,
Some(rc_c), Some(rc_m), Some(rt_w1));
Some(rc_c), Some(rc_m));
println!("Resolved! Customer = {}, Merchant = {}", new_b0_cust, new_b0_merch);
}

View File

@ -943,6 +943,7 @@ pub mod bidirectional {
assert!(clsigs::verify_d(&pp.cl_mpk, &pk_m, &x, &sig));
}
w.signature = Some(sig);
// TODO: add a refund token here to the wallet
//println!("establish_customer_final - verified merchant signature on initial wallet with {}", w.balance);
return true;
}
@ -1321,7 +1322,7 @@ pub mod bidirectional {
///
pub fn pay_by_customer_final(pp: &PublicParams, pk_m: &clsigs::PublicKeyD,
c_data: &mut InitCustomerData, mut new_t: ChannelToken,
mut new_w: CustomerWallet, sig: clsigs::SignatureD) -> bool {
mut new_w: CustomerWallet, rt_w: clsigs::SignatureD, sig: clsigs::SignatureD) -> bool {
if new_w.signature.is_none() {
if pp.extra_verify {
let bal = convert_int_to_fr(new_w.balance);
@ -1331,6 +1332,8 @@ pub mod bidirectional {
}
// update signature in new wallet
new_w.signature = Some(sig);
// update refund token in new wallet
new_w.refund_token = Some(rt_w);
// update csk in new wallet
c_data.csk = new_w;
// update the channel token
@ -1434,8 +1437,7 @@ pub mod bidirectional {
/// to each party based on provided inputs.
///
pub fn resolve(pp: &PublicParams, c: &InitCustomerData, m: &InitMerchantData,
rc_c: Option<ChannelclosureC>, rc_m: Option<ChannelclosureM>,
rt_w: Option<clsigs::SignatureD>) -> (i32, i32) {
rc_c: Option<ChannelclosureC>, rc_m: Option<ChannelclosureM>) -> (i32, i32) {
let total_balance = c.csk.balance + m.csk.balance;
if rc_c.is_none() && rc_m.is_none() {
panic!("resolve1 - Did not specify channel closure messages for either customer or merchant!");
@ -1480,7 +1482,8 @@ pub mod bidirectional {
let refund = convert_str_to_fr("refund");
let mut x: Vec<Fr> = vec![c.csk.r.clone(), c.csk.cid.clone(), bal, h_wpk, refund];
let is_rt_valid = clsigs::verify_d(&pp.cl_mpk, &pk_m, &x, &rt_w.unwrap());
let refund_token = msg.rt.clone();
let is_rt_valid = clsigs::verify_d(&pp.cl_mpk, &pk_m, &x, &refund_token.unwrap());
if !is_rt_valid {
// refund token signature not valid, so pay full channel balance to merchant
return (0, total_balance)
@ -1801,7 +1804,13 @@ pub mod ffishim {
}
#[no_mangle]
pub extern fn ffishim_bidirectional_pay_by_customer_final(serialized_pp: *mut c_char, serialized_merchant_public_key: *mut c_char, serialized_customer_data: /* make mut */ *mut c_char, serialized_channel_token: *mut c_char, serialized_new_wallet: *mut c_char, serialized_new_wallet_sig: *mut c_char) -> *mut c_char {
pub extern fn ffishim_bidirectional_pay_by_customer_final(serialized_pp: *mut c_char,
serialized_merchant_public_key: *mut c_char,
serialized_customer_data: /* make mut */ *mut c_char,
serialized_channel_token: *mut c_char,
serialized_new_wallet: *mut c_char,
serialized_refund_token: *mut c_char,
serialized_new_wallet_sig: *mut c_char) -> *mut c_char {
// Deserialize the pp
let deserialized_pp: bidirectional::PublicParams = deserialize_object(serialized_pp);
@ -1817,17 +1826,25 @@ pub mod ffishim {
// Deserialize the new wallet
let deserialized_new_wallet: bidirectional::CustomerWallet = deserialize_object(serialized_new_wallet);
// Deserialize the refund token
let deserialized_refund_token: clsigs::SignatureD = deserialize_object(serialized_refund_token);
// Deserialize the new wallet sig
let deserialized_new_wallet_sig: clsigs::SignatureD = deserialize_object(serialized_new_wallet_sig);
bidirectional::pay_by_customer_final(&deserialized_pp, &deserialized_merchant_public_key, &mut deserialized_customer_data, deserialized_channel_token, deserialized_new_wallet, deserialized_new_wallet_sig);
bidirectional::pay_by_customer_final(&deserialized_pp, &deserialized_merchant_public_key,
&mut deserialized_customer_data, deserialized_channel_token,
deserialized_new_wallet, deserialized_refund_token, deserialized_new_wallet_sig);
let ser = ["{\'customer_data\':\'", serde_json::to_string(&deserialized_customer_data).unwrap().as_str(), "\'}"].concat();
let cser = CString::new(ser).unwrap();
cser.into_raw()
}
#[no_mangle]
pub extern fn ffishim_bidirectional_customer_refund(serialized_pp: *mut c_char, serialized_channel: *mut c_char, serialized_merchant_public_key: *mut c_char, serialized_wallet: *mut c_char) -> *mut c_char {
pub extern fn ffishim_bidirectional_customer_refund(serialized_pp: *mut c_char,
serialized_channel: *mut c_char,
serialized_merchant_public_key: *mut c_char,
serialized_wallet: *mut c_char) -> *mut c_char {
// Deserialize the pp
let deserialized_pp: bidirectional::PublicParams = deserialize_object(serialized_pp);
@ -1874,7 +1891,7 @@ pub mod ffishim {
}
#[no_mangle]
pub extern fn ffishim_bidirectional_resolve(serialized_pp: *mut c_char, serialized_customer_data: *mut c_char, serialized_merchant_data: *mut c_char, serialized_closure_customer: *mut c_char, serialized_closure_merchant: *mut c_char, serialized_revoke_token: *mut c_char) -> *mut c_char {
pub extern fn ffishim_bidirectional_resolve(serialized_pp: *mut c_char, serialized_customer_data: *mut c_char, serialized_merchant_data: *mut c_char, serialized_closure_customer: *mut c_char, serialized_closure_merchant: *mut c_char) -> *mut c_char {
// Deserialize the pp
let deserialized_pp: bidirectional::PublicParams = deserialize_object(serialized_pp);
@ -1892,10 +1909,7 @@ pub mod ffishim {
// Deserialize the merchant closure
let deserialized_closure_merchant: bidirectional::ChannelclosureM = deserialize_object(serialized_closure_merchant);
// Deserialize the revoke_token
let deserialized_revoke_token: clsigs::SignatureD = deserialize_object(serialized_revoke_token);
let (new_b0_cust, new_b0_merch) = bidirectional::resolve(&deserialized_pp, &deserialized_customer_data, &deserialized_merchant_data, Some(deserialized_closure_customer), Some(deserialized_closure_merchant), Some(deserialized_revoke_token));
let (new_b0_cust, new_b0_merch) = bidirectional::resolve(&deserialized_pp, &deserialized_customer_data, &deserialized_merchant_data, Some(deserialized_closure_customer), Some(deserialized_closure_merchant));
let ser = ["{\'new_b0_cust\':\'", new_b0_cust.to_string().as_str(), "\', \'new_b0_merch\':\'", new_b0_merch.to_string().as_str(), "\'}"].concat();
let cser = CString::new(ser).unwrap();
cser.into_raw()
@ -2096,7 +2110,7 @@ mod tests {
// get the new wallet sig (new_wallet_sig) on the new wallet
let new_wallet_sig = bidirectional::pay_by_merchant_phase2(&pp, channel, &pay_proof, merch_data, &rv_w);
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keys.pk, cust_data, t_c, new_wallet, new_wallet_sig));
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keys.pk, cust_data, t_c, new_wallet, rt_w, new_wallet_sig));
}
#[test]
@ -2227,9 +2241,9 @@ mod tests {
// get the new wallet sig (new_wallet_sig) on the new wallet
let new_wallet_sig2 = bidirectional::pay_by_merchant_phase2(&pp, channel2, &pay_proof2, merch2_data, &rv_w2);
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keys.pk, cust1_data, t_c1, new_wallet1, new_wallet_sig1));
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keys.pk, cust1_data, t_c1, new_wallet1, rt_w1, new_wallet_sig1));
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keys.pk, cust2_data, t_c2, new_wallet2, new_wallet_sig2));
assert!(bidirectional::pay_by_customer_final(&pp, &merch_keys.pk, cust2_data, t_c2, new_wallet2, rt_w2, new_wallet_sig2));
}
#[test]

View File

@ -6,6 +6,7 @@ int main()
{
// Testing the validate channel open rust functionality
// DONE
std::string cm_csp = "{\"com\":{\"c\":[4,6,218,95,139,44,142,86,18,60,32,17,124,114,153,176,117,107,149,252,98,255,181,197,174,160,86,110,81,105,51,77,181,55,71,7,212,158,186,21,222,49,52,130,71,55,9,235,222,210,12,89,8,105,234,180,59,26,56,148,10,6,62,227,181,6,191,19,186,105,204,13,115,223,178,254,125,28,121,249,158,241,183,226,83,176,101,200,169,244,15,158,101,37,234,206,203,94,236,126,59,185,182,23,110,145,61,248,111,89,8,154,247,196,10,21,211,21,58,243,204,238,209,180,185,95,71,173,178],\"r\":[3,57,194,144,135,110,163,182,35,213,188,149,61,173,116,213,111,211,127,132,12,49,29,249,63,164,255,128,237,122,122,250]},\"params\":{\"pub_bases\":[[4,1,14,26,235,250,26,53,41,48,246,128,250,138,198,42,127,176,89,18,83,27,63,84,144,174,53,251,77,39,204,14,34,65,224,51,186,23,137,26,133,168,167,124,55,49,236,75,65,46,113,117,160,53,34,44,99,242,95,208,18,69,243,56,108,7,242,93,92,76,235,87,201,218,89,123,104,66,251,101,214,54,3,71,148,142,66,134,180,124,182,222,133,154,143,38,239,43,91,124,174,158,138,61,87,80,140,113,223,69,13,9,64,76,3,204,56,244,38,68,150,4,113,43,87,194,8,113,28],[4,2,164,175,155,94,92,88,213,227,215,2,185,79,106,93,189,118,221,173,178,118,246,143,136,55,8,203,129,11,152,31,166,60,40,18,140,140,237,206,16,62,80,88,88,7,231,225,165,57,227,65,51,42,250,171,90,73,158,215,87,72,40,23,29,2,98,229,146,246,96,87,199,240,192,219,193,233,137,123,220,127,222,117,24,127,253,132,124,57,47,64,58,136,85,255,215,180,153,91,194,6,147,111,46,114,115,107,206,185,86,233,10,175,245,217,152,59,191,191,244,28,228,157,136,172,176,106,143],[4,7,100,134,2,189,120,60,93,161,40,229,122,180,60,122,183,86,177,35,195,6,194,113,124,89,11,152,125,207,87,230,215,189,149,148,10,127,166,18,182,77,106,123,172,193,236,63,245,193,168,41,130,80,57,204,41,199,218,53,241,52,102,174,207,2,185,122,127,124,103,36,5,87,45,44,79,197,211,233,214,42,3,182,30,54,189,172,71,253,218,186,76,132,96,24,161,255,170,18,143,27,170,237,219,254,44,197,149,220,1,177,162,76,108,107,92,122,70,205,199,234,101,51,104,220,119,118,82],[4,8,84,32,244,94,100,81,246,1,89,31,204,135,132,61,151,185,243,84,204,135,251,123,193,93,120,176,235,52,193,50,7,120,220,148,153,29,65,141,107,17,145,156,230,195,96,109,117,53,219,21,49,121,99,233,156,158,158,29,58,93,167,63,121,0,230,167,109,129,92,51,112,254,17,88,217,102,122,69,169,17,137,195,163,179,190,3,138,3,129,4,237,245,170,171,58,95,165,201,85,122,193,115,182,9,66,39,21,54,182,58,236,128,230,7,170,64,169,87,95,218,32,238,199,79,107,106,243],[4,4,182,17,88,147,5,132,115,60,119,27,138,166,101,204,217,156,238,108,255,30,164,148,39,4,33,195,152,212,27,196,127,43,88,102,118,76,237,179,40,97,124,142,162,0,44,20,143,55,165,230,238,16,48,248,224,219,251,46,14,60,116,215,142,0,101,173,151,113,250,77,198,49,106,144,28,170,18,106,80,145,6,72,54,186,22,55,205,218,117,45,167,171,248,25,179,176,76,216,253,113,208,26,29,87,157,39,225,231,198,202,8,144,69,152,11,18,2,242,55,227,93,27,207,4,99,185,157]]}}";
std::string x = "[[3,57,194,144,135,110,163,182,35,213,188,149,61,173,116,213,111,211,127,132,12,49,29,249,63,164,255,128,237,122,122,250],[47,197,153,89,35,28,236,71,233,146,254,194,211,208,146,152,208,30,74,147,115,64,57,141,31,199,112,188,113,193,196,232],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50],[24,79,61,24,253,183,252,253,186,39,65,174,36,49,35,125,138,69,241,75,91,12,141,247,191,173,213,219,246,133,136,217]]";
@ -18,6 +19,7 @@ int main()
std::string rc_c = "{\"message\":{\"msgtype\":\"refundToken\",\"wpk\":[3,108,79,169,238,98,15,205,191,239,241,150,119,148,90,203,86,252,237,149,89,7,247,192,212,155,193,140,185,96,29,57,89],\"balance\":55,\"r\":null,\"rt\":null},\"signature\":{\"a\":[4,5,142,169,217,62,3,199,143,201,139,153,125,216,94,196,221,70,207,13,163,53,70,170,99,147,174,195,168,232,78,194,59,247,246,7,91,253,123,72,105,41,235,72,196,201,36,245,255,57,71,24,28,116,194,166,119,82,165,119,2,142,119,180,197,3,67,163,240,182,166,26,153,166,62,37,214,150,14,201,60,140,130,123,140,163,214,99,217,187,187,158,171,10,22,238,40,254,197,39,27,217,141,227,222,56,127,38,122,167,81,21,193,98,109,244,111,160,195,119,197,139,120,66,20,190,147,176,205],\"A\":[[4,2,91,149,133,222,23,20,110,96,126,120,36,211,163,65,117,191,26,82,232,14,118,172,247,230,150,101,122,56,71,98,190,227,238,181,7,244,151,212,167,132,193,192,223,117,100,178,122,98,10,201,32,48,117,229,39,94,171,34,91,68,176,162,202,8,22,99,186,5,146,203,96,146,194,159,49,232,88,178,0,219,46,51,60,160,37,176,49,200,104,82,244,22,171,89,187,96,236,195,58,215,71,230,22,214,106,59,7,196,200,182,132,220,15,132,57,240,151,108,25,198,167,6,67,47,36,248,140],[4,8,78,130,250,169,175,146,89,195,13,210,32,9,249,182,198,50,243,110,255,17,16,77,1,232,61,163,94,118,129,183,46,115,152,254,159,204,181,178,21,20,88,35,174,62,164,174,218,45,33,254,178,164,243,247,19,128,215,60,25,34,46,180,217,5,39,207,214,90,204,138,61,9,202,169,118,104,24,51,241,132,125,70,113,132,98,204,185,212,217,54,4,92,254,106,224,99,131,129,249,250,65,148,17,212,45,21,152,203,240,218,53,50,221,99,162,83,10,162,189,110,226,75,148,3,101,123,193]],\"b\":[4,1,134,135,212,216,228,229,23,253,60,1,142,26,103,184,34,184,115,145,222,50,223,65,91,183,1,149,68,78,117,149,120,62,153,255,54,247,65,151,16,56,142,135,193,190,59,98,66,82,233,127,141,103,14,51,123,90,137,117,99,181,12,160,63,4,83,6,164,10,23,114,153,21,140,149,199,192,130,159,237,150,87,44,109,126,57,15,137,238,152,233,242,64,127,226,202,181,96,57,142,166,2,77,15,207,153,57,9,202,71,61,182,105,112,78,6,92,76,25,38,192,145,32,22,77,12,6,221],\"B\":[[4,7,121,196,34,23,36,149,205,231,235,206,43,11,194,215,204,79,43,14,178,97,46,91,219,200,35,57,18,0,136,106,114,69,75,147,255,45,220,70,186,89,27,7,91,187,45,10,218,106,18,175,185,119,187,125,0,7,48,142,130,25,227,146,40,7,31,113,75,206,134,81,255,127,164,0,131,39,89,90,25,119,162,105,181,138,144,44,132,214,236,52,222,104,93,102,24,74,95,120,62,247,171,143,81,237,195,111,50,91,233,124,183,45,106,230,54,196,105,139,215,208,153,132,126,173,116,144,127],[4,1,138,202,227,92,118,155,3,128,147,248,77,130,166,161,112,142,247,92,154,226,83,41,228,89,8,189,250,2,39,111,104,54,0,208,112,35,80,232,33,28,212,12,154,197,179,190,72,51,71,224,76,155,169,246,181,133,37,86,208,142,131,121,224,1,39,18,19,165,221,56,64,251,79,227,154,93,13,226,79,119,46,42,169,63,46,229,195,60,117,66,60,60,28,37,161,168,177,37,72,138,25,8,237,80,233,209,210,165,181,118,197,129,23,77,11,117,190,176,38,53,48,2,33,211,24,242,31]],\"c\":[4,1,96,179,188,105,157,175,152,101,255,91,199,136,105,157,237,98,143,215,73,178,116,82,216,20,70,6,79,254,100,217,251,179,41,195,60,2,138,69,87,79,6,12,94,175,81,187,227,125,177,91,107,38,148,175,84,217,25,189,177,42,64,23,102,6,26,182,123,162,220,55,168,5,94,132,123,168,109,43,162,22,177,113,211,194,116,23,49,37,97,33,182,174,198,247,114,163,28,211,199,233,101,174,211,233,142,100,209,222,152,179,134,255,11,189,132,248,160,35,121,123,151,166,27,226,241,242,44]}}";
// DONE
std::string pk_m = "{\"X\":[4,11,212,237,26,243,240,138,8,177,209,226,107,248,36,201,223,126,56,194,246,160,2,147,28,79,38,238,161,106,85,209,85,32,162,79,255,213,15,35,214,217,129,81,129,91,115,152,145,55,199,182,20,136,217,59,146,221,142,172,3,66,134,147,170],\"Y\":[4,13,143,248,55,31,110,150,169,97,222,5,62,113,117,110,224,148,76,164,73,197,211,222,97,116,142,84,241,124,135,5,52,3,255,73,76,91,182,83,193,49,188,214,60,8,232,98,185,9,92,164,89,94,252,123,26,179,220,245,131,91,73,108,177],\"Z\":[[4,11,195,77,142,142,41,122,88,140,236,130,168,59,251,84,31,236,241,241,36,211,109,185,12,231,47,158,229,67,34,88,12,39,191,42,236,216,87,207,79,91,101,236,189,82,246,220,228,99,185,171,133,230,80,73,17,230,182,72,184,122,199,84,211],[4,12,198,224,37,137,88,183,146,90,41,137,78,238,122,208,136,246,129,131,219,234,20,123,180,166,91,155,58,170,215,192,218,44,254,23,209,164,165,4,123,0,123,10,91,170,91,69,157,107,196,66,201,137,211,251,32,25,163,198,219,155,125,22,179],[4,15,48,5,87,171,60,247,234,141,11,124,141,166,201,160,205,212,161,227,62,113,70,211,4,115,23,199,63,222,2,146,83,43,76,129,95,89,89,170,101,128,13,118,138,203,163,60,92,18,78,72,0,57,175,14,170,72,46,52,14,46,199,9,228],[4,15,81,170,186,165,58,163,108,57,67,10,24,204,99,8,62,86,242,34,182,45,4,158,249,46,132,231,213,34,177,40,220,36,42,7,153,234,162,79,245,94,105,243,66,116,87,97,128,209,136,194,178,4,45,226,135,27,166,6,82,182,10,31,89]],\"Z2\":[[4,1,46,225,176,211,182,101,246,158,220,186,80,190,22,147,66,139,118,254,254,17,230,201,250,11,103,141,131,177,214,254,43,111,43,150,174,130,34,45,223,46,231,191,97,78,227,180,236,194,27,12,100,3,237,236,120,242,212,59,103,231,59,24,47,7,79,230,192,171,2,165,91,123,154,145,108,42,73,34,150,104,46,183,190,232,59,139,109,122,57,105,50,188,115,33,174,186,249,19,128,219,214,31,144,94,166,71,121,69,8,82,148,105,100,196,15,171,168,99,0,126,35,150,39,2,91,83,22],[4,8,78,227,114,68,33,144,142,20,114,63,203,228,156,104,239,206,153,172,17,48,5,235,24,164,206,3,83,181,254,105,136,141,95,30,167,26,46,250,241,218,128,86,33,214,50,103,153,225,23,235,40,55,152,215,101,21,254,108,23,105,181,249,157,0,12,106,4,151,137,74,249,161,172,215,177,91,99,27,19,134,238,223,82,77,237,175,163,192,210,149,147,155,164,23,226,253,42,10,133,16,8,242,235,242,231,22,46,216,226,84,72,125,74,153,145,191,239,39,36,55,10,128,17,171,149,179,99],[4,0,167,34,129,220,171,64,129,108,37,106,9,107,130,228,139,78,182,207,43,19,83,212,167,152,23,125,148,146,143,220,197,44,187,131,234,16,230,110,92,244,50,162,114,155,31,136,44,41,98,149,233,135,228,224,82,225,12,182,94,19,26,244,153,3,217,90,143,29,46,9,64,52,232,149,193,11,214,196,38,165,120,205,218,82,221,70,15,109,68,213,233,27,7,215,81,155,126,31,154,121,19,2,25,156,11,89,40,36,69,231,165,29,123,87,158,166,105,242,34,179,39,142,164,251,93,124,109],[4,3,175,119,174,99,244,192,184,229,87,231,64,87,171,19,95,228,179,203,178,92,176,14,242,131,251,226,199,36,180,69,241,217,63,95,210,234,3,122,32,42,154,9,87,131,222,86,49,92,62,220,24,147,3,192,114,160,93,120,111,98,32,93,6,7,65,19,23,182,23,36,124,46,87,2,67,156,193,176,128,111,33,236,84,176,125,1,193,175,138,250,241,46,157,154,183,41,254,210,154,224,103,92,236,12,179,190,7,242,165,127,79,250,119,95,220,93,81,148,113,191,107,3,150,200,72,91,87]],\"W\":[[4,22,229,244,131,241,7,130,217,228,193,167,191,168,98,145,15,160,159,82,185,195,131,238,27,80,18,176,171,183,83,100,161,38,213,179,117,33,5,124,233,163,140,96,192,172,252,185,17,99,234,176,99,91,236,122,230,13,126,73,120,240,30,70,25],[4,40,162,110,228,225,44,134,41,29,218,120,144,45,213,165,83,15,176,195,38,213,88,99,140,122,55,32,237,117,184,43,90,12,158,169,51,215,128,37,18,183,220,252,176,51,125,177,8,246,43,193,6,148,192,195,198,254,229,38,165,21,107,128,50],[4,39,73,110,208,252,249,11,106,99,70,177,105,156,130,115,164,41,223,213,248,116,43,30,136,82,15,27,77,151,40,128,155,34,15,207,216,16,38,213,222,237,233,7,181,175,173,3,21,134,201,81,83,124,51,130,144,30,159,102,158,106,14,198,125],[4,26,117,67,67,125,46,218,51,255,20,59,59,42,20,73,41,220,198,192,5,39,45,207,3,31,170,124,89,40,140,22,123,20,125,19,152,203,241,176,5,72,141,50,252,110,67,110,119,29,229,76,136,104,103,0,82,162,76,161,153,208,225,242,125]]}";
assert(validate_channel_close(pp.c_str(), rc_c.c_str(), pk_m.c_str()));

View File

@ -57,7 +57,7 @@ class Libbolt(object):
self.lib.ffishim_bidirectional_pay_by_merchant_phase2.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_void_p)
self.lib.ffishim_bidirectional_pay_by_merchant_phase2.restype = c_void_p
self.lib.ffishim_bidirectional_pay_by_customer_final.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p)
self.lib.ffishim_bidirectional_pay_by_customer_final.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p)
self.lib.ffishim_bidirectional_pay_by_customer_final.restype = c_void_p
self.lib.ffishim_bidirectional_customer_refund.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p)
@ -66,7 +66,7 @@ class Libbolt(object):
self.lib.ffishim_bidirectional_merchant_refund.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p)
self.lib.ffishim_bidirectional_merchant_refund.restype = c_void_p
self.lib.ffishim_bidirectional_resolve.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p)
self.lib.ffishim_bidirectional_resolve.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_void_p)
self.lib.ffishim_bidirectional_resolve.restype = c_void_p
# Exposing the decommitment functionality
@ -150,8 +150,9 @@ class Libbolt(object):
output_dictionary = ast.literal_eval(ctypes.cast(output_string, ctypes.c_char_p).value.decode('utf-8'))
return (output_dictionary['new_wallet_sig'],output_dictionary['state'], output_dictionary['merch_data'])
def bidirectional_pay_by_customer_final(self, pp, merch_public_key, cust_data, channel_token, new_wallet, new_wallet_sig):
output_string = self.lib.ffishim_bidirectional_pay_by_customer_final(pp.encode(), merch_public_key.encode(), cust_data.encode(), channel_token.encode(), new_wallet.encode(), new_wallet_sig.encode())
def bidirectional_pay_by_customer_final(self, pp, merch_public_key, cust_data, channel_token, new_wallet, refund_token, new_wallet_sig):
output_string = self.lib.ffishim_bidirectional_pay_by_customer_final(pp.encode(), merch_public_key.encode(), cust_data.encode(), channel_token.encode(),
new_wallet.encode(), refund_token.encode(), new_wallet_sig.encode())
output_dictionary = ast.literal_eval(ctypes.cast(output_string, ctypes.c_char_p).value.decode('utf-8'))
return output_dictionary['customer_data']
@ -165,8 +166,8 @@ class Libbolt(object):
output_dictionary = ast.literal_eval(ctypes.cast(output_string, ctypes.c_char_p).value.decode('utf-8'))
return (output_dictionary['rc_m'], output_dictionary['state'])
def bidirectional_resolve(self, pp, cust_data, merch_data, cust_closure, merch_closure, revoke_token):
output_string = self.lib.ffishim_bidirectional_resolve( pp.encode(), cust_data.encode(), merch_data.encode(), cust_closure.encode(), merch_closure.encode(), revoke_token.encode())
def bidirectional_resolve(self, pp, cust_data, merch_data, cust_closure, merch_closure):
output_string = self.lib.ffishim_bidirectional_resolve( pp.encode(), cust_data.encode(), merch_data.encode(), cust_closure.encode(), merch_closure.encode())
output_dictionary = ast.literal_eval(ctypes.cast(output_string, ctypes.c_char_p).value.decode('utf-8'))
return (int(output_dictionary['new_b0_cust']), int(output_dictionary['new_b0_merch']))
@ -203,8 +204,8 @@ releaseordebug = 'debug'
libbolt = Libbolt('target/{}/{}bolt.{}'.format(releaseordebug, prefix, ext))
b0_cust = 50;
b0_merch = 50;
b0_cust = 50
b0_merch = 50
pp = libbolt.bidirectional_setup(False)
@ -236,7 +237,7 @@ rv_w = libbolt.bidirectional_pay_by_customer_phase2(pp, cust_data, new_wallet, l
(new_wallet_sig, state, merch_data) = libbolt.bidirectional_pay_by_merchant_phase2(pp, channel_state, pay_proof, merch_data, rv_w)
cust_data = libbolt.bidirectional_pay_by_customer_final(pp, libbolt.util_extract_public_key_from_keypair(merch_keys), cust_data, channel_token, new_wallet, new_wallet_sig)
cust_data = libbolt.bidirectional_pay_by_customer_final(pp, libbolt.util_extract_public_key_from_keypair(merch_keys), cust_data, channel_token, new_wallet, rt_w, new_wallet_sig)
print("--------------------")