pub fn sign_voucher(
    voucher_string: String,
    private_key: &PrivateKey,
) -> Result<String, SignerError> {
    let decoded_voucher = base64::decode(voucher_string)?;
    let mut voucher: paych::SignedVoucher = from_slice(&decoded_voucher)?;

    let secret_key = libsecp256k1::SecretKey::parse_slice(&private_key.0)?;

    let svb = voucher
        .signing_bytes()
        .map_err(|err| SignerError::GenericString(err.to_string()))?;
    let digest = utils::get_digest_voucher(&svb)?;

    let blob_to_sign = libsecp256k1::Message::parse_slice(&digest)?;

    let (signature_rs, recovery_id) = libsecp256k1::sign(&blob_to_sign, &secret_key);

    let mut sig = [0; 65];
    sig[..64].copy_from_slice(&signature_rs.serialize()[..]);
    sig[64] = recovery_id.serialize();

    voucher.signature = Some(Signature::new_secp256k1(sig.to_vec()));

    let binary_voucher = to_vec(&voucher)?;
    let cbor_voucher = base64::encode(binary_voucher);

    Ok(cbor_voucher)
}
/// Sign a voucher for payment channel
///
/// # Arguments
///
/// * `voucher_string` - Voucher as base64 string;
/// * `private_key` - Private key as base64 string;
///
Sign a voucher for payment channel
Sign a voucher for payment channel
pub fn sign_voucher(
    voucher_string: String,
    private_key: &PrivateKey,
) -> Result<String, SignerError> {
    let decoded_voucher = base64::decode(voucher_string)?;
    let mut voucher: paych::SignedVoucher = from_slice(&decoded_voucher)?;
    let secret_key = libsecp256k1::SecretKey::parse_slice(&private_key.0)?;
    let svb = voucher
        .signing_bytes()
        .map_err(|err| SignerError::GenericString(err.to_string()))?;
    let digest = utils::get_digest_voucher(&svb)?;
    let blob_to_sign = libsecp256k1::Message::parse_slice(&digest)?;
    let (signature_rs, recovery_id) = libsecp256k1::sign(&blob_to_sign, &secret_key);
    let mut sig = [0; 65];
    sig[..64].copy_from_slice(&signature_rs.serialize()[..]);
    sig[64] = recovery_id.serialize();
    voucher.signature = Some(Signature::new_secp256k1(sig.to_vec()));
    let binary_voucher = to_vec(&voucher)?;
    let cbor_voucher = base64::encode(binary_voucher);
    Ok(cbor_voucher)
}
pub fn sign_voucher ( voucher_string : String , private_key : & PrivateKey , ) -> Result < String , SignerError > { let decoded_voucher = base64 :: decode ( voucher_string ) ? ; let mut voucher : paych :: SignedVoucher = from_slice ( & decoded_voucher ) ? ; let secret_key = libsecp256k1 :: SecretKey :: parse_slice ( & private_key . 0 ) ? ; let svb = voucher . signing_bytes ( ) . map_err ( | err | SignerError :: GenericString ( err . to_string ( ) ) ) ? ; let digest = utils :: get_digest_voucher ( & svb ) ? ; let blob_to_sign = libsecp256k1 :: Message :: parse_slice ( & digest ) ? ; let ( signature_rs , recovery_id ) = libsecp256k1 :: sign ( & blob_to_sign , & secret_key ) ; let mut sig = [ 0 ; 65 ] ; sig [ .. 64 ] . copy_from_slice ( & signature_rs . serialize ( ) [ .. ] ) ; sig [ 64 ] = recovery_id . serialize ( ) ; voucher . signature = Some ( Signature :: new_secp256k1 ( sig . to_vec ( ) ) ) ; let binary_voucher = to_vec ( & voucher ) ? ; let cbor_voucher = base64 :: encode ( binary_voucher ) ; Ok ( cbor_voucher ) }
Sign a voucher for payment channel
Sign a voucher for payment channel
voucher_string
String
private_key
&PrivateKey
voucher_string
String
private_key
&PrivateKey