@@ -407,9 +407,54 @@ fn create_blind_auth_secret(
407407}
408408
409409#[ cfg( test) ]
410+ #[ cfg( not( target_arch = "wasm32" ) ) ]
410411mod test {
411- use crate :: blindauth:: { ServicePlanIndex , SignedToken , TokenStorage } ;
412- use tbs:: { BlindedMessage , BlindedSignature } ;
412+ use crate :: auth:: MutinyAuthClient ;
413+ use crate :: blindauth:: { BlindAuthClient , ServicePlanIndex , SignedToken , TokenStorage } ;
414+ use crate :: generate_seed;
415+ use crate :: logging:: MutinyLogger ;
416+ use crate :: storage:: MemoryStorage ;
417+ use crate :: test_utils:: create_manager;
418+ use bitcoin:: bip32:: ExtendedPrivKey ;
419+ use bitcoin:: Network ;
420+ use nostr:: prelude:: hex;
421+ use std:: sync:: Arc ;
422+ use tbs:: {
423+ unblind_signature, AggregatePublicKey , BlindedMessage , BlindedSignature , PubKeyPoint ,
424+ } ;
425+
426+ const FREE_PK : & str = "a5596b43416c17dcd331a64d4a5f60ab3a470fc03f83a3d834910903ee78f5ade33da927b86481d6edd3de08e89455d6115f5c5e642f4a47d24c85a458369e736cfc410b984cf7e4bf97853a40632f26ca9ad65008bfbe27f40ab8aa7bdffe9f" ;
427+
428+ fn create_client ( ) -> BlindAuthClient < MemoryStorage > {
429+ let storage = MemoryStorage :: default ( ) ;
430+ let logger = Arc :: new ( MutinyLogger :: default ( ) ) ;
431+ let mnemonic = generate_seed ( 12 ) . unwrap ( ) ;
432+ let xpriv = ExtendedPrivKey :: new_master ( Network :: Regtest , & mnemonic. to_seed ( "" ) ) . unwrap ( ) ;
433+
434+ // Set up test auth client
435+ let auth_manager = create_manager ( ) ;
436+ let lnurl_client = Arc :: new (
437+ lnurl:: Builder :: default ( )
438+ . build_async ( )
439+ . expect ( "failed to make lnurl client" ) ,
440+ ) ;
441+ let auth_client = MutinyAuthClient :: new (
442+ auth_manager,
443+ lnurl_client,
444+ logger. clone ( ) ,
445+ "https://auth-staging.mutinywallet.com" . to_string ( ) ,
446+ ) ;
447+
448+ BlindAuthClient :: new (
449+ xpriv,
450+ Arc :: new ( auth_client) ,
451+ Network :: Regtest ,
452+ "https://blind-auth-staging.mutinywallet.com" . to_string ( ) ,
453+ & storage,
454+ logger,
455+ )
456+ . unwrap ( )
457+ }
413458
414459 #[ test]
415460 fn test_token_storage_serialization ( ) {
@@ -447,4 +492,32 @@ mod test {
447492 let deserialized: TokenStorage = serde_json:: from_str ( string) . unwrap ( ) ;
448493 assert_eq ! ( storage, deserialized) ;
449494 }
495+
496+ #[ tokio:: test]
497+ async fn test_blind_auth_client ( ) {
498+ let client = create_client ( ) ;
499+ assert ! ( client. available_tokens( ) . await . is_empty( ) ) ;
500+
501+ client. redeem_available_tokens ( ) . await . unwrap ( ) ;
502+
503+ let tokens = client. available_tokens ( ) . await ;
504+ assert ! ( !tokens. is_empty( ) ) ;
505+
506+ let token = tokens. first ( ) . unwrap ( ) ;
507+
508+ // do the unblinding
509+ let ( nonce, blinding_key) = client. get_unblinded_info_from_token ( token) ;
510+ let unblinded_sig = unblind_signature ( blinding_key, token. blind_sig ) ;
511+
512+ // check that the signature is valid
513+ let free_pk: AggregatePublicKey = AggregatePublicKey (
514+ PubKeyPoint :: from_compressed (
515+ hex:: decode ( FREE_PK ) . expect ( "Invalid key hex" ) [ ..]
516+ . try_into ( )
517+ . expect ( "Invalid key byte key" ) ,
518+ )
519+ . expect ( "Invalid FREE_PK" ) ,
520+ ) ;
521+ assert ! ( tbs:: verify( nonce. to_message( ) , unblinded_sig, free_pk) ) ;
522+ }
450523}
0 commit comments