Merge branch 'master' into channelid

This commit is contained in:
Gijs Van Laer 2019-10-17 18:48:20 -04:00
commit d6a131eedf
3 changed files with 31 additions and 21 deletions

View File

@ -175,12 +175,11 @@ The bidirectional payment channels can be used to construct third-party payments
To enable third-party payment support, initialize each payment channel as follows:
// create the channel state for each channel and indicate third-party support
let mut channel_a = bidirectional::ChannelState::<Bls12>::new(String::from("Channel A <-> I"), true);
let mut channel_b = bidirectional::ChannelState::<Bls12>::new(String::from("Channel B <-> I"), true);
let mut channel_state = bidirectional::ChannelState::<Bls12>::new(String::from("Third-party Channels"), true);
Moreover, the intermediary can set a channel fee as follows:
channel_a.set_channel_fee(5);
channel_state.set_channel_fee(5);
The channel establishment still works as described before and the pay protocol includes an additional step to verify that the payments on both channels cancel out or include a channel fee (if specified).
@ -188,22 +187,42 @@ The channel establishment still works as described before and the pay protocol i
...
let payment_amount = 20;
// get payment proof on first channel with party A (and I)
let (payment_proofA, new_cust_stateA) = bidirectional::generate_payment_proof(rng, &channel_a, // channel state
// get payment proof on first channel with party A and H
let (sender_payment, new_cust_stateA) = bidirectional::generate_payment_proof(rng, &channel_state, // channel state
&cust_stateA,
payment_amount); // bal inc
// get payment proof on second channel with party B (and I)
let (payment_proofB, new_cust_stateB) = bidirectional::generate_payment_proof(rng, &channel_b,
// get payment proof on second channel with party B and H
let (receiver_payment, new_cust_stateB) = bidirectional::generate_payment_proof(rng, &channel_state,
&cust_stateB,
-payment_amount); // bal dec
// verify that the payment proof is valid and cancels out or results in a fee
let tx_fee = channel_a.get_channel_fee() + channel_b.get_channel_fee();
assert!(bidirectional::verify_third_party_payment(&pp, tx_fee, &payment_proofA, &payment_proofB));
// intermediary executes the following on the two payment proofs
// verifies that the payment proof is valid & cancels out and results in hub's fee
let close_token_result = bidirectional::verify_multiple_payment_proofs(rng, &channel_state,
&sender_payment,
&receiver_payment,
&mut merch_state);
let (alice_close_token, bob_cond_close_token) = handle_bolt_result!(close_token_result).unwrap();
// both alice and bob generate a revoke token
let revoke_token_alice = bidirectional::generate_revoke_token(&channel_state,
&mut cust_stateA,
new_cust_stateA,
&alice_close_token);
let revoke_token_bob = bidirectional::generate_revoke_token(&channel_state,
&mut cust_stateB,
new_cust_stateB,
&bob_cond_close_token);
// send both revoke tokens to intermediary and receive pay-tokens (one for sender and another for receiver)
let new_pay_tokens: BoltResult<(cl::Signature<Bls12>,cl::Signature<Bls12>)> = \
bidirectional::verify_multiple_revoke_tokens(&revoke_token_sender,
&revoke_token_receiver,
&mut merch_state);
...
See the `third_party_payment_basics_work()` unit test in `src/lib.rs` for more details.
See the `intermediary_payment_basics_works()` unit test in `src/lib.rs` for more details.
# Documentation (TODO)

View File

@ -24,7 +24,6 @@ extern crate pairing;
extern crate rand;
extern crate rand_core;
//extern crate sodiumoxide;
extern crate secp256k1;
extern crate time;
extern crate sha2;
@ -38,7 +37,6 @@ extern crate libc;
extern crate rand_xorshift;
extern crate core;
//pub mod sym;
pub mod cl;
pub mod ccs08;
pub mod ped92;
@ -50,9 +48,6 @@ pub mod ffishim;
use std::fmt;
use std::str;
//use sodiumoxide::randombytes;
//use sodiumoxide::crypto::hash::sha512;
//use sha2::Sha512;
use std::collections::HashMap;
use ff::{Rand, Field};
@ -113,14 +108,11 @@ pub mod bidirectional {
use util;
use wallet;
use pairing::Engine;
//use sodiumoxide;
use cl;
// for blind signature
use secp256k1;
// for on-chain keys
use HashMap;
//use sodiumoxide::crypto::hash::sha512;
//use sha2::Sha512;
use serde::{Serialize, Deserialize};
use util::{RevokedMessage, hash_to_slice};

View File

@ -1,5 +1,4 @@
use super::*;
//use sodiumoxide::crypto::hash::sha512;
use pairing::Engine;
use ff::{PrimeField};
use rand::Rng;