Skip to content

Commit

Permalink
defines from_frost factory method on NativePublicKeyPackage (#5381)
Browse files Browse the repository at this point in the history
allows us to construct a PublicKeyPackage from the raw parts: the frost public
key package, the list of signer identities, and the minimum number of signers

following the round3_min changes to ironfish-frost the Ledger app will produce a
raw frost public key package at the end of DKG round3, so we will need to
construct the ironfish-frost PublicKeyPackage from its parts
  • Loading branch information
hughy authored Sep 17, 2024
1 parent 9263726 commit 7413250
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ export namespace multisig {
export type NativePublicKeyPackage = PublicKeyPackage
export class PublicKeyPackage {
constructor(value: string)
static fromFrost(frostPublicKeyPackage: Buffer, identities: Array<string>, minSigners: number): NativePublicKeyPackage
serialize(): Buffer
identities(): Array<Buffer>
frostPublicKeyPackage(): Buffer
minSigners(): number
}
export type NativeSigningCommitment = SigningCommitment
Expand Down
38 changes: 37 additions & 1 deletion ironfish-rust-nodejs/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use crate::{structs::NativeUnsignedTransaction, to_napi_err};
use ironfish::{
frost::{
frost::{round1::SigningCommitments, round2::SignatureShare as FrostSignatureShare},
frost::{
keys::PublicKeyPackage as FrostPublicKeyPackage, round1::SigningCommitments,
round2::SignatureShare as FrostSignatureShare,
},
keys::KeyPackage,
round2, Randomizer,
},
Expand Down Expand Up @@ -351,6 +354,28 @@ impl NativePublicKeyPackage {
Ok(NativePublicKeyPackage { public_key_package })
}

#[napi(factory)]
pub fn from_frost(
frost_public_key_package: JsBuffer,
identities: Vec<String>,
min_signers: u16,
) -> Result<NativePublicKeyPackage> {
let frost_public_key_package =
FrostPublicKeyPackage::deserialize(frost_public_key_package.into_value()?.as_ref())
.map_err(to_napi_err)?;
let identities = try_deserialize_identities(identities)?;

let public_key_package =
PublicKeyPackage::from_frost(frost_public_key_package, identities, min_signers);

Ok(NativePublicKeyPackage { public_key_package })
}

#[napi]
pub fn serialize(&self) -> Buffer {
Buffer::from(self.public_key_package.serialize())
}

#[napi]
pub fn identities(&self) -> Vec<Buffer> {
self.public_key_package
Expand All @@ -360,6 +385,17 @@ impl NativePublicKeyPackage {
.collect()
}

#[napi]
pub fn frost_public_key_package(&self) -> Result<Buffer> {
Ok(Buffer::from(
self.public_key_package
.frost_public_key_package()
.serialize()
.map_err(to_napi_err)?
.as_slice(),
))
}

#[napi]
pub fn min_signers(&self) -> u16 {
self.public_key_package.min_signers()
Expand Down
18 changes: 18 additions & 0 deletions ironfish/src/multisig.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ describe('multisig', () => {

const publicAddress = round3Packages[0].publicAddress

// Ensure that we can construct PublicKeyPackage from the raw frost public
// key package
for (const round3Package of round3Packages) {
const deserializedPublicKeyPackage = new multisig.PublicKeyPackage(
round3Package.publicKeyPackage,
)

const publicKeyPackage = multisig.PublicKeyPackage.fromFrost(
deserializedPublicKeyPackage.frostPublicKeyPackage(),
deserializedPublicKeyPackage.identities().map((i) => i.toString('hex')),
deserializedPublicKeyPackage.minSigners(),
)

expect(publicKeyPackage.serialize().toString('hex')).toEqual(
round3Package.publicKeyPackage,
)
}

const raw = new RawTransaction(TransactionVersion.V1)

const inNote = new NativeNote(
Expand Down

0 comments on commit 7413250

Please sign in to comment.