Skip to content

Commit

Permalink
Rahul/create signing commitment returns identifier with commitment (#…
Browse files Browse the repository at this point in the history
…4679)

* signing commitment now contains identifier

* removing identifiercommitment concept

* remove newline

* Reverting change to assert is signer

* fixing createSigningPackage test
  • Loading branch information
patnir authored Feb 5, 2024
1 parent a32b217 commit 4a73e1d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 76 deletions.
7 changes: 2 additions & 5 deletions ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
/* auto-generated by NAPI-RS */

export interface Commitment {
identifier: string
hiding: string
binding: string
}
export interface IdentifierCommitment {
identifier: string
commitment: Commitment
}
export function createSigningCommitment(keyPackage: string, seed: number): Commitment
export function createSigningShare(signingPackage: string, keyPackage: string, publicKeyRandomness: string, seed: number): string
export function splitSecret(coordinatorSaplingKey: string, minSigners: number, identifiers: Array<string>): TrustedDealerKeyPackages
Expand Down Expand Up @@ -250,7 +247,7 @@ export class UnsignedTransaction {
constructor(jsBytes: Buffer)
serialize(): Buffer
publicKeyRandomness(): string
signingPackage(nativeIdentiferCommitments: Array<IdentifierCommitment>): string
signingPackage(nativeIdentiferCommitments: Array<Commitment>): string
sign(spenderHexKey: string): Buffer
signFrost(publicKeyPackageStr: string, signingPackageStr: string, signatureSharesMap: Record<string, string>): Buffer
}
Expand Down
8 changes: 2 additions & 6 deletions ironfish-rust-nodejs/src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ use rand::thread_rng;

#[napi(object, js_name = "Commitment")]
pub struct NativeCommitment {
pub identifier: String,
pub hiding: String,
pub binding: String,
}

#[napi(object, js_name = "IdentifierCommitment")]
pub struct NativeIdentifierCommitment {
pub identifier: String,
pub commitment: NativeCommitment,
}

#[napi]
pub fn create_signing_commitment(key_package: String, seed: u32) -> Result<NativeCommitment> {
let key_package =
KeyPackage::deserialize(&hex_to_vec_bytes(&key_package).map_err(to_napi_err)?)
.map_err(to_napi_err)?;
let (_, commitment) = create_signing_commitment_rust(&key_package, seed as u64);
Ok(NativeCommitment {
identifier: bytes_to_hex(&key_package.identifier().serialize()),
hiding: bytes_to_hex(&commitment.hiding().serialize()),
binding: bytes_to_hex(&commitment.binding().serialize()),
})
Expand Down
8 changes: 4 additions & 4 deletions ironfish-rust-nodejs/src/structs/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use napi::{
};
use napi_derive::napi;

use crate::frost::NativeIdentifierCommitment;
use crate::frost::NativeCommitment;
use crate::to_napi_err;

use super::note::NativeNote;
Expand Down Expand Up @@ -414,7 +414,7 @@ impl NativeUnsignedTransaction {
#[napi]
pub fn signing_package(
&self,
native_identifer_commitments: Vec<NativeIdentifierCommitment>,
native_identifer_commitments: Vec<NativeCommitment>,
) -> Result<String> {
let mut commitments: BTreeMap<Identifier, SigningCommitments> = BTreeMap::new();

Expand All @@ -425,11 +425,11 @@ impl NativeUnsignedTransaction {

let commitment = SigningCommitments::new(
NonceCommitment::deserialize(
hex_to_bytes(&identifier_commitment.commitment.hiding).map_err(to_napi_err)?,
hex_to_bytes(&identifier_commitment.hiding).map_err(to_napi_err)?,
)
.map_err(to_napi_err)?,
NonceCommitment::deserialize(
hex_to_bytes(&identifier_commitment.commitment.binding).map_err(to_napi_err)?,
hex_to_bytes(&identifier_commitment.binding).map_err(to_napi_err)?,
)
.map_err(to_napi_err)?,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ routes.register<typeof CreateSigningCommitmentRequestSchema, CreateSigningCommit
const result = createSigningCommitment(request.data.keyPackage, request.data.seed)

request.end({
identifier: result.identifier,
hiding: result.hiding,
binding: result.binding,
})
Expand Down
12 changes: 4 additions & 8 deletions ironfish/src/rpc/routes/multisig/createSigningPackage.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
import { IdentifierCommitment, ParticipantSecret } from '@ironfish/rust-nodejs'
import { Commitment, ParticipantSecret } from '@ironfish/rust-nodejs'
import {
createNodeTest,
useAccountFixture,
Expand Down Expand Up @@ -29,17 +29,13 @@ describe('Route multisig/createSigningPackage', () => {

const trustedDealerPackage = response.content

const commitments: Array<IdentifierCommitment> = []
const commitments: Array<Commitment> = []
for (let i = 0; i < 3; i++) {
const commitment = await routeTest.client.multisig.createSigningCommitment({
const signingCommitment = await routeTest.client.multisig.createSigningCommitment({
keyPackage: trustedDealerPackage.keyPackages[i].keyPackage,
seed,
})

commitments.push({
identifier: trustedDealerPackage.keyPackages[i].identifier,
commitment: commitment.content,
})
commitments.push(signingCommitment.content)
}

const account = await useAccountFixture(nodeTest.wallet)
Expand Down
16 changes: 2 additions & 14 deletions ironfish/src/rpc/routes/multisig/createSigningPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { RpcSigningCommitments, RpcSigningCommitmentsSchema } from './types'

export type CreateSigningPackageRequest = {
unsignedTransaction: string
commitments: Array<{
identifier: string
commitment: RpcSigningCommitments
}>
commitments: Array<RpcSigningCommitments>
}

export type CreateSigningPackageResponse = {
Expand All @@ -23,16 +20,7 @@ export const CreateSigningPackageRequestSchema: yup.ObjectSchema<CreateSigningPa
yup
.object({
unsignedTransaction: yup.string().defined(),
commitments: yup
.array(
yup
.object({
identifier: yup.string().defined(),
commitment: RpcSigningCommitmentsSchema,
})
.defined(),
)
.defined(),
commitments: yup.array(RpcSigningCommitmentsSchema).defined(),
})
.defined()

Expand Down
2 changes: 2 additions & 0 deletions ironfish/src/rpc/routes/multisig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import * as yup from 'yup'

export type RpcSigningCommitments = {
identifier: string
hiding: string
binding: string
}

export const RpcSigningCommitmentsSchema: yup.ObjectSchema<RpcSigningCommitments> = yup
.object({
identifier: yup.string().defined(),
hiding: yup.string().defined(),
binding: yup.string().defined(),
})
Expand Down
60 changes: 21 additions & 39 deletions ironfish/src/wallet/wallet.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
Asset,
ASSET_ID_LENGTH,
Commitment,
createSigningCommitment,
createSigningShare,
generateKey,
Expand Down Expand Up @@ -1141,7 +1142,6 @@ describe('Wallet', () => {
it('can do a multisig transaction', async () => {
const seed = 420
const minSigners = 2
const participants = 3

const { node } = await nodeTest.createSetup()
const recipient = await useAccountFixture(node.wallet, 'recipient')
Expand All @@ -1150,7 +1150,7 @@ describe('Wallet', () => {

const identifiers: string[] = []

for (let i = 0; i < participants; i++) {
for (let i = 0; i < 3; i++) {
identifiers.push(ParticipantSecret.random().toIdentity().toFrostIdentifier())
}

Expand Down Expand Up @@ -1198,6 +1198,9 @@ describe('Wallet', () => {
multiSigKeys: getMultiSigKeys(2),
...trustedDealerPackage,
})

const participants = [participantA, participantB, participantC]

const coordinator = await node.wallet.importAccount({
version: 4,
id: uuid(),
Expand All @@ -1210,27 +1213,14 @@ describe('Wallet', () => {
...trustedDealerPackage,
})

Assert.isNotUndefined(participantA.multiSigKeys)
Assert.isNotUndefined(participantB.multiSigKeys)
Assert.isNotUndefined(participantC.multiSigKeys)
AssertIsSignerMultiSig(participantA.multiSigKeys)
AssertIsSignerMultiSig(participantB.multiSigKeys)
AssertIsSignerMultiSig(participantC.multiSigKeys)

const signingCommitments = [
{
identifier: participantA.multiSigKeys.identifier,
commitment: createSigningCommitment(participantA.multiSigKeys.keyPackage, seed),
},
{
identifier: participantB.multiSigKeys.identifier,
commitment: createSigningCommitment(participantB.multiSigKeys.keyPackage, seed),
},
{
identifier: participantC.multiSigKeys.identifier,
commitment: createSigningCommitment(participantC.multiSigKeys.keyPackage, seed),
},
]
const signingCommitments: Commitment[] = []
for (const participant of participants) {
Assert.isNotUndefined(participant.multiSigKeys)
AssertIsSignerMultiSig(participant.multiSigKeys)
signingCommitments.push(
createSigningCommitment(participant.multiSigKeys.keyPackage, seed),
)
}

// mine block to send IRON to multisig account
const miner = await useAccountFixture(node.wallet, 'miner')
Expand Down Expand Up @@ -1295,25 +1285,17 @@ describe('Wallet', () => {
const signingPackage = unsignedTransaction.signingPackage(signingCommitments)
const publicKeyRandomness = unsignedTransaction.publicKeyRandomness()

const signatureShares: Record<string, string> = {
[participantA.multiSigKeys.identifier]: createSigningShare(
signingPackage,
participantA.multiSigKeys.keyPackage,
publicKeyRandomness,
seed,
),
[participantB.multiSigKeys.identifier]: createSigningShare(
signingPackage,
participantB.multiSigKeys.keyPackage,
publicKeyRandomness,
seed,
),
[participantC.multiSigKeys.identifier]: createSigningShare(
const signatureShares: Record<string, string> = {}

for (const participant of participants) {
Assert.isNotUndefined(participant.multiSigKeys)
AssertIsSignerMultiSig(participant.multiSigKeys)
signatureShares[participant.multiSigKeys.identifier] = createSigningShare(
signingPackage,
participantC.multiSigKeys.keyPackage,
participant.multiSigKeys.keyPackage,
publicKeyRandomness,
seed,
),
)
}

Assert.isNotUndefined(coordinator.multiSigKeys)
Expand Down

0 comments on commit 4a73e1d

Please sign in to comment.