Skip to content

Commit

Permalink
ironfish-rust-nodejs: move the multisig structs to the frost submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
andiflabs committed Mar 1, 2024
1 parent 1edd157 commit 130ca84
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 52 deletions.
26 changes: 13 additions & 13 deletions ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ export const IDENTITY_LEN: number
export function createSigningCommitment(identity: string, keyPackage: string, transactionHash: Buffer, signers: Array<string>): string
export function createSignatureShare(identity: string, keyPackage: string, signingPackage: string): string
export function splitSecret(spendingKey: string, minSigners: number, identities: Array<string>): TrustedDealerKeyPackages
export interface ParticipantKeyPackage {
identity: string
keyPackage: string
}
export interface TrustedDealerKeyPackages {
publicAddress: string
publicKeyPackage: string
viewKey: string
incomingViewKey: string
outgoingViewKey: string
proofAuthorizingKey: string
keyPackages: Array<ParticipantKeyPackage>
}
export function contribute(inputPath: string, outputPath: string, seed?: string | undefined | null): Promise<string>
export function verifyTransform(paramsPath: string, newParamsPath: string): Promise<string>
export const KEY_LENGTH: number
Expand Down Expand Up @@ -54,19 +67,6 @@ export const TRANSACTION_FEE_LENGTH: number
export const LATEST_TRANSACTION_VERSION: number
export function verifyTransactions(serializedTransactions: Array<Buffer>): boolean
export function aggregateSignatureShares(publicKeyPackageStr: string, signingPackageStr: string, signatureSharesArr: Array<string>): Buffer
export interface IdentityKeyPackage {
identity: string
keyPackage: string
}
export interface TrustedDealerKeyPackages {
proofAuthorizingKey: string
viewKey: string
incomingViewKey: string
outgoingViewKey: string
publicAddress: string
keyPackages: Array<IdentityKeyPackage>
publicKeyPackage: string
}
export const enum LanguageCode {
English = 0,
ChineseSimplified = 1,
Expand Down
34 changes: 26 additions & 8 deletions ironfish-rust-nodejs/src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::{
structs::{IdentityKeyPackage, TrustedDealerKeyPackages},
to_napi_err,
};
use crate::to_napi_err;
use ironfish::{
frost::{keys::KeyPackage, round1::SigningCommitments, round2, Randomizer},
frost_utils::{signing_package::SigningPackage, split_spender_key::split_spender_key},
Expand Down Expand Up @@ -212,7 +209,7 @@ pub fn split_secret(

let mut key_packages = Vec::with_capacity(packages.key_packages.len());
for (identity, key_package) in packages.key_packages.iter() {
key_packages.push(IdentityKeyPackage {
key_packages.push(ParticipantKeyPackage {
identity: bytes_to_hex(&identity.serialize()),
key_package: bytes_to_hex(&key_package.serialize().map_err(to_napi_err)?),
});
Expand All @@ -224,16 +221,37 @@ pub fn split_secret(
.map_err(to_napi_err)?;

Ok(TrustedDealerKeyPackages {
proof_authorizing_key: packages.proof_authorizing_key.hex_key(),
public_address: packages.public_address.hex_public_address(),
public_key_package: bytes_to_hex(&public_key_package),
view_key: packages.view_key.hex_key(),
incoming_view_key: packages.incoming_view_key.hex_key(),
outgoing_view_key: packages.outgoing_view_key.hex_key(),
public_address: packages.public_address.hex_public_address(),
proof_authorizing_key: packages.proof_authorizing_key.hex_key(),
key_packages,
public_key_package: bytes_to_hex(&public_key_package),
})
}

#[napi(object)]
pub struct ParticipantKeyPackage {
pub identity: String,
// TODO: this should contain the spender_key only, there's no need to return (and later store)
// the entire key package, as all other information can be either derived or is stored
// elsewhere (with the exception of min_signers, but that can be easily moved to
// TrustedDealerKeyPackages)
pub key_package: String,
}

#[napi(object)]
pub struct TrustedDealerKeyPackages {
pub public_address: String,
pub public_key_package: String,
pub view_key: String,
pub incoming_view_key: String,
pub outgoing_view_key: String,
pub proof_authorizing_key: String,
pub key_packages: Vec<ParticipantKeyPackage>,
}

#[napi(js_name = "PublicKeyPackage")]
pub struct NativePublicKeyPackage {
public_key_package: PublicKeyPackage,
Expand Down
22 changes: 0 additions & 22 deletions ironfish-rust-nodejs/src/structs/key_packages.rs

This file was deleted.

3 changes: 0 additions & 3 deletions ironfish-rust-nodejs/src/structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ pub use transaction::*;

mod witness;
pub use witness::*;

mod key_packages;
pub use key_packages::*;
12 changes: 6 additions & 6 deletions ironfish-rust/src/frost_utils/split_spender_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use crate::{
use super::split_secret::{split_secret, SecretShareConfig};

pub struct TrustedDealerKeyPackages {
pub proof_authorizing_key: jubjub::Fr,
pub public_address: PublicAddress,
pub public_key_package: PublicKeyPackage,
pub view_key: ViewKey,
pub incoming_view_key: IncomingViewKey,
pub outgoing_view_key: OutgoingViewKey,
pub public_address: PublicAddress,
pub proof_authorizing_key: jubjub::Fr,
pub key_packages: HashMap<Identity, KeyPackage>,
pub public_key_package: PublicKeyPackage,
}

pub fn split_spender_key(
Expand Down Expand Up @@ -61,13 +61,13 @@ pub fn split_spender_key(
let public_address = incoming_view_key.public_address();

Ok(TrustedDealerKeyPackages {
proof_authorizing_key,
public_address,
public_key_package,
view_key,
incoming_view_key,
outgoing_view_key,
public_address,
proof_authorizing_key,
key_packages,
public_key_package,
})
}

Expand Down

0 comments on commit 130ca84

Please sign in to comment.