fix(useragent): unsafe, but working implementation of ml-dsa

This commit is contained in:
hdbg
2026-04-07 15:41:50 +02:00
parent 6b8da567dd
commit a4070e7df7
104 changed files with 11133 additions and 461 deletions

View File

@@ -0,0 +1,29 @@
use anyhow::anyhow;
use flutter_rust_bridge::frb;
use arbiter_crypto::authn::{self, USERAGENT_CONTEXT};
#[frb(opaque)]
pub struct MldsaKey(authn::SigningKey);
impl MldsaKey {
pub fn from_bytes(bytes: &[u8]) -> anyhow::Result<Self> {
let bytes: [u8; 32] = bytes.try_into().map_err(|_| anyhow!("Invalid key length"))?;
Ok(Self(authn::SigningKey::from_seed(bytes)))
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.to_seed().to_vec()
}
pub fn sign(&self, message: &[u8]) -> anyhow::Result<Vec<u8>> {
Ok(self.0.sign_message(message, USERAGENT_CONTEXT)?.to_bytes())
}
pub fn generate() -> Self {
Self(authn::SigningKey::generate())
}
pub fn get_public_key(&self) -> Vec<u8> {
self.0.public_key().to_bytes().to_vec()
}
}