Skip to content

Commit

Permalink
Add Babbage nonce/leader vrf extension
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewWestberg committed Jun 20, 2022
1 parent 7f8b384 commit 7375f81
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
1 change: 0 additions & 1 deletion pallas-multiplexer/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
Arc,
},
thread::{spawn, JoinHandle},
time::Duration,
};

pub type StdIngress = Receiver<Payload>;
Expand Down
2 changes: 1 addition & 1 deletion pallas-traverse/src/era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl TryFrom<u16> for Era {
4 => Ok(Era::Mary),
5 => Ok(Era::Alonzo),
6 => Ok(Era::Babbage),
x => Err(crate::Error::UnkownEra(x)),
x => Err(crate::Error::UnknownEra(x)),
}
}
}
Expand Down
34 changes: 32 additions & 2 deletions pallas-traverse/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pallas_codec::minicbor;
use pallas_crypto::hash::Hash;
use pallas_crypto::hash::{Hash, Hasher};
use pallas_primitives::ToHash;

use crate::{Error, MultiEraHeader};
Expand Down Expand Up @@ -45,4 +45,34 @@ impl<'b> MultiEraHeader<'b> {
MultiEraHeader::Byron(x) => x.to_hash(),
}
}
}

pub fn leader_vrf_output(&self) -> Result<Vec<u8>, Error> {
match self {
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(0)),
MultiEraHeader::AlonzoCompatible(x) => {
Ok(x.header_body.leader_vrf.0.to_vec())
}
MultiEraHeader::Babbage(x) => {
let mut leader_tagged_vrf: Vec<u8> = vec![0x4C_u8]; /* "L" */
leader_tagged_vrf.extend(&*x.header_body.vrf_result.0);
Ok(Hasher::<256>::hash(&leader_tagged_vrf).to_vec())
}
MultiEraHeader::Byron(_) => Err(Error::InvalidEra(1)),
}
}

pub fn nonce_vrf_output(&self) -> Result<Vec<u8>, Error> {
match self {
MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(0)),
MultiEraHeader::AlonzoCompatible(x) => {
Ok(x.header_body.nonce_vrf.0.to_vec())
}
MultiEraHeader::Babbage(x) => {
let mut nonce_tagged_vrf: Vec<u8> = vec![0x4E_u8]; /* "N" */
nonce_tagged_vrf.extend(&*x.header_body.vrf_result.0);
Ok(Hasher::<256>::hash(&nonce_tagged_vrf).to_vec())
}
MultiEraHeader::Byron(_) => Err(Error::InvalidEra(1)),
}
}
}
5 changes: 4 additions & 1 deletion pallas-traverse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ pub enum Error {
UnknownCbor(String),

#[error("Unknown era tag: {0}")]
UnkownEra(u16),
UnknownEra(u16),

#[error("Invalid era for request: {0}")]
InvalidEra(u16),
}

impl Error {
Expand Down

0 comments on commit 7375f81

Please sign in to comment.