Add TrustedChannel
This commit is contained in:
parent
f59dc042b6
commit
b5881d63b0
@ -237,3 +237,52 @@ impl CachedMessage {
|
|||||||
aes_decrypt.decrypt_with_key()
|
aes_decrypt.decrypt_with_key()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Tsify, Default)]
|
||||||
|
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub struct TrustedChannel {
|
||||||
|
id: u32, // Just take the id of the cached message?
|
||||||
|
revokation_outpoint: OutPoint, // revokation output is locked by the shared_secret
|
||||||
|
shared_secret: [u8; 32],
|
||||||
|
revoked_in_block: [u8; 32],
|
||||||
|
with: String, // Silent payment address
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TrustedChannel {
|
||||||
|
pub fn new(with: String) -> Result<Self> {
|
||||||
|
// check that with is valid silent payment address
|
||||||
|
SilentPaymentAddress::try_from(with.as_str())?;
|
||||||
|
|
||||||
|
// Generating random id
|
||||||
|
let mut new = Self::default();
|
||||||
|
let mut buf = [0u8; 4];
|
||||||
|
thread_rng().fill_bytes(&mut buf);
|
||||||
|
new.id = u32::from_be_bytes(buf);
|
||||||
|
new.with = with;
|
||||||
|
|
||||||
|
Ok(new)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_revokation(
|
||||||
|
&mut self,
|
||||||
|
revokation_outpoint: String,
|
||||||
|
shared_secret: String,
|
||||||
|
) -> Result<()> {
|
||||||
|
let mut buf = [0u8; 32];
|
||||||
|
buf.copy_from_slice(&Vec::from_hex(&shared_secret)?);
|
||||||
|
self.revokation_outpoint = OutPoint::from_str(&revokation_outpoint)?;
|
||||||
|
self.shared_secret.copy_from_slice(&buf);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn revoke(&mut self, revoked_in_block: String) -> Result<()> {
|
||||||
|
let block_hash = BlockHash::from_str(&revoked_in_block)?;
|
||||||
|
let mut buf = [0u8; 32];
|
||||||
|
buf.copy_from_slice(&serialize::<BlockHash>(&block_hash));
|
||||||
|
self.revoked_in_block = buf;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user