Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defines from_frost factory method on NativePublicKeyPackage #5381

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading