Weight.hs (1596B)
1 module Main where 2 3 import qualified Data.ByteString as BS 4 import Fixture 5 import qualified Lightning.Protocol.BOLT8 as BOLT8 6 import Weigh 7 8 -- note that 'weigh' doesn't work properly in a repl 9 main :: IO () 10 main = do 11 fx <- fixture 12 mainWith $ do 13 keys fx 14 handshake fx 15 transport fx 16 17 keys :: Fixture -> Weigh () 18 keys fx = wgroup "keys" $ do 19 func "keypair" BOLT8.keypair i_s_ent 20 func "parse_pub" BOLT8.parse_pub pub_bs 21 func "serialize_pub" BOLT8.serialize_pub pub 22 where 23 pub = BOLT8.keypair_pub (fx_r fx) 24 pub_bs = BOLT8.serialize_pub pub 25 26 handshake :: Fixture -> Weigh () 27 handshake fx = wgroup "handshake" $ do 28 func "act1" 29 (BOLT8.act1 (fx_i fx) (BOLT8.keypair_pub (fx_r fx))) i_e_ent 30 func "act2" (BOLT8.act2 (fx_r fx) r_e_ent) (fx_msg1 fx) 31 func "act3" (BOLT8.act3 (fx_i_hs fx)) (fx_msg2 fx) 32 func "finalize" (BOLT8.finalize (fx_r_hs fx)) (fx_msg3 fx) 33 34 transport :: Fixture -> Weigh () 35 transport fx = wgroup "transport" $ do 36 func "encrypt (32B)" (BOLT8.encrypt (fx_snd fx)) msg_32 37 func "encrypt (1KB)" (BOLT8.encrypt (fx_snd fx)) msg_1k 38 func "encrypt (64KB)" (BOLT8.encrypt (fx_snd fx)) msg_64k 39 func "encrypt (32B, rotating)" (BOLT8.encrypt (fx_snd_rot fx)) msg_32 40 func "decrypt (32B)" (BOLT8.decrypt (fx_rcv fx)) (fx_ct_32 fx) 41 func "decrypt (1KB)" (BOLT8.decrypt (fx_rcv fx)) (fx_ct_1k fx) 42 func "decrypt (64KB)" (BOLT8.decrypt (fx_rcv fx)) (fx_ct_64k fx) 43 func "decrypt_header" 44 (BOLT8.decrypt_header (fx_rcv fx)) (BS.take 18 (fx_ct_1k fx)) 45 func "decrypt_body (1KB)" 46 (BOLT8.decrypt_body (fx_pend_1k fx)) (BS.drop 18 (fx_ct_1k fx))