message: add functionality to library
diff: +use crate::api::UnsignedMessageUserAPI;
  +use forest_encoding::{from_slice, to_vec};
  +use forest_message::UnsignedMessage;
  +use hex::{decode, encode};
  +
  mod api;
  pub fn key_generate() {
  @@ -9,14 +14,24 @@ pub fn key_derive() {
  // TODO: return keypair (pub/priv + address)
  }
  -pub fn transaction_create() {
  - // TODO: tx params as JSON
  - // TODO: return unsigned transaction serialized as CBOR
  +pub fn transaction_create(unsigned_message_api: UnsignedMessageUserAPI) -> anyhow::Result<String> {
  + // tx params as JSON
  + let message = UnsignedMessage::from(unsigned_message_api);
  + let message_cbor: Vec<u8> = to_vec(&message)?;
  + let message_cbor_hex = encode(message_cbor);
  +
  + // return unsigned transaction serialized as CBOR / hexstring
  + Ok(message_cbor_hex)
  }
  -pub fn transaction_parse() {
  - // TODO: serialized tx
  - // TODO: tx as JSON
  +pub fn transaction_parse(cbor_hexstring: String) -> anyhow::Result<UnsignedMessageUserAPI> {
  + // FIXME: Extend to both unsigned and sign txs
  +
  + let cbor_buffer = decode(cbor_hexstring)?;
  + let message: UnsignedMessage = from_slice(&cbor_buffer)?;
  + let message_user_api = UnsignedMessageUserAPI::from(message);
  +
  + Ok(message_user_api)
  }
  pub fn sign_transaction() {
  @@ -29,7 +44,7 @@ pub fn sign_message() {
  // TODO: return signature
  }
  -pub fn verify_signature() -> Result<bool, ()> {
  +pub fn verify_signature() -> anyhow::Result<bool> {
  // TODO: receive pubkey, signature, message
  // TODO: true is valid
  Ok(false)
  