Skip to content

Commit

Permalink
adds multisig/aggregateSigningShares RPC (#4677)
Browse files Browse the repository at this point in the history
* adds multisig/aggregateSignatureShares RPC

takes a publicKeyPackage, an unsignedTransaction, a signingPackage for that
transaction, and a list of signatureShares for that signingPackage

uses UnsignedTransaction.signFrost to aggregate the signatureShares, sign the
transaction, and produce a signed transaction

returns a signed transaction serialized as hex

* fixes typo in RpcClient

s/Signature/Signing/

* fixes second typo
  • Loading branch information
hughy authored Feb 5, 2024
1 parent ea7d061 commit a32b217
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ironfish/src/rpc/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
AddPeerResponse,
AddTransactionRequest,
AddTransactionResponse,
AggregateSigningSharesRequest,
AggregateSigningSharesResponse,
BlockTemplateStreamRequest,
BlockTemplateStreamResponse,
BroadcastTransactionRequest,
Expand Down Expand Up @@ -821,6 +823,15 @@ export abstract class RpcClient {
},
}
multisig = {
aggregateSigningShares: (
params: AggregateSigningSharesRequest,
): Promise<RpcResponseEnded<AggregateSigningSharesResponse>> => {
return this.request<AggregateSigningSharesResponse>(
`${ApiNamespace.multisig}/aggregateSigningShares`,
params,
).waitForEnd()
},

createTrustedDealerKeyPackage: (
params: CreateTrustedDealerKeyPackageRequest,
): Promise<RpcResponseEnded<CreateTrustedDealerKeyPackageResponse>> => {
Expand Down
73 changes: 73 additions & 0 deletions ironfish/src/rpc/routes/multisig/aggregateSigningShares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* 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 { UnsignedTransaction } from '@ironfish/rust-nodejs'
import * as yup from 'yup'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type AggregateSigningSharesRequest = {
publicKeyPackage: string
unsignedTransaction: string
signingPackage: string
signingShares: Array<{
identifier: string
signingShare: string
}>
}

export type AggregateSigningSharesResponse = {
transaction: string
}

export const AggregateSigningSharesRequestSchema: yup.ObjectSchema<AggregateSigningSharesRequest> =
yup
.object({
publicKeyPackage: yup.string().defined(),
unsignedTransaction: yup.string().defined(),
signingPackage: yup.string().defined(),
signingShares: yup
.array(
yup
.object({
identifier: yup.string().defined(),
signingShare: yup.string().defined(),
})
.defined(),
)
.defined(),
})
.defined()

export const AggregateSigningSharesResponseSchema: yup.ObjectSchema<AggregateSigningSharesResponse> =
yup
.object({
transaction: yup.string().defined(),
})
.defined()

routes.register<typeof AggregateSigningSharesRequestSchema, AggregateSigningSharesResponse>(
`${ApiNamespace.multisig}/aggregateSigningShares`,
AggregateSigningSharesRequestSchema,
(request, _context): void => {
const unsigned = new UnsignedTransaction(
Buffer.from(request.data.unsignedTransaction, 'hex'),
)

// TODO(hughy): change interface of signFrost to take Array of shares instead of Record
const signingShares: Record<string, string> = {}
for (const { identifier, signingShare } of request.data.signingShares) {
signingShares[identifier] = signingShare
}

const transaction = unsigned.signFrost(
request.data.publicKeyPackage,
request.data.signingPackage,
signingShares,
)

request.end({
transaction: transaction.toString('hex'),
})
},
)
1 change: 1 addition & 0 deletions ironfish/src/rpc/routes/multisig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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/. */

export * from './aggregateSigningShares'
export * from './createSigningCommitment'
export * from './createSigningPackage'
export * from './createTrustedDealerKeyPackage'
Expand Down

0 comments on commit a32b217

Please sign in to comment.