Skip to content

Commit

Permalink
Seq as seconds and also MAX_V_LEN
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane Huxley committed May 14, 2024
1 parent b3cb1e5 commit e318447
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/dids/src/method/dht/bep44.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use crypto::CryptoError;
use keys::key::{KeyError, PublicKey};

/// Minimum size of a bep44 encoded message
/// Signature is 64 bytes and seq is 8 byets
const MIN_MESSAGE_LEN: usize = 72;
const MAX_MESSAGE_LEN: usize = 1072;
/// Maximum size of a bep44 v field
const MAX_V_LEN: usize = 1000;
/// Maximum size a bep44 encoded message
const MAX_MESSAGE_LEN: usize = MAX_V_LEN + MIN_MESSAGE_LEN;

/// Errors that can occur when working with Bep44 messages for did:dht.
#[derive(thiserror::Error, Debug)]
pub enum Bep44EncodingError {
#[error(transparent)]
SystemTimeError(#[from] SystemTimeError),
#[error("Could not coerce microseconds since epoch into u64")]
TimeError,
#[error(transparent)]
CryptoError(#[from] CryptoError),
#[error("Failure creating DID: {0}")]
Expand Down Expand Up @@ -78,11 +81,7 @@ impl Bep44Message {
where
F: Fn(Vec<u8>) -> Result<Vec<u8>, KeyError>,
{
let seq: u64 = SystemTime::now()
.duration_since(UNIX_EPOCH)?
.as_micros()
.try_into()
.map_err(|_| Bep44EncodingError::TimeError)?;
let seq = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();

let signable = signable(seq, message);
let sig = sign(signable)?;
Expand Down

0 comments on commit e318447

Please sign in to comment.