Skip to content

Commit

Permalink
Threshold Custody: Add Follower Round 2 domain type
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Nov 17, 2023
1 parent e8e6fcf commit 37e2d90
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions crates/custody/src/threshold/sign.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::anyhow;
use decaf377_frost::round1;
use decaf377_frost as frost;
use ed25519_consensus::{Signature, VerificationKey};
use penumbra_proto::{penumbra::custody::threshold::v1alpha1 as pb, DomainType, TypeUrl};
use penumbra_transaction::plan::TransactionPlan;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl DomainType for CoordinatorRound1 {
#[derive(Debug, Clone)]
pub struct FollowerRound1 {
/// A commitment for each spend we need to authorize.
commitments: Vec<round1::SigningCommitments>,
commitments: Vec<frost::round1::SigningCommitments>,
/// A verification key identifying who the sender is.
pk: VerificationKey,
/// The signature over the protobuf encoding of the commitments.
Expand Down Expand Up @@ -107,3 +107,65 @@ impl TypeUrl for FollowerRound1 {
impl DomainType for FollowerRound1 {
type Proto = pb::FollowerRound1;
}

#[derive(Debug, Clone)]
struct FollowerRound2 {
/// One share of the signature for each authorization we need
shares: Vec<frost::round2::SignatureShare>,
/// The verification key identifying the sender.
pk: VerificationKey,
/// The signature over the proto-encoded shares.
sig: Signature,
}

impl From<FollowerRound2> for pb::FollowerRound2 {
fn from(value: FollowerRound2) -> Self {
Self {
inner: Some(pb::follower_round2::Inner {
shares: value.shares.into_iter().map(|x| x.into()).collect(),
}),
pk: Some(pb::VerificationKey {
inner: value.pk.to_bytes().to_vec(),
}),
sig: Some(pb::Signature {
inner: value.sig.to_bytes().to_vec(),
}),
}
}
}

impl TryFrom<pb::FollowerRound2> for FollowerRound2 {
type Error = anyhow::Error;

fn try_from(value: pb::FollowerRound2) -> Result<Self, Self::Error> {
Ok(Self {
shares: value
.inner
.ok_or(anyhow!("missing inner"))?
.shares
.into_iter()
.map(|x| x.try_into())
.collect::<Result<Vec<_>, _>>()?,
pk: value
.pk
.ok_or(anyhow!("missing pk"))?
.inner
.as_slice()
.try_into()?,
sig: value
.sig
.ok_or(anyhow!("missing sig"))?
.inner
.as_slice()
.try_into()?,
})
}
}

impl TypeUrl for FollowerRound2 {
const TYPE_URL: &'static str = "/penumbra.custody.threshold.v1alpha1.FollowerRound2";
}

impl DomainType for FollowerRound2 {
type Proto = pb::FollowerRound2;
}

0 comments on commit 37e2d90

Please sign in to comment.