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

renames secretName to participantName #4927

Merged
merged 5 commits into from
Apr 23, 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
15 changes: 8 additions & 7 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export class DkgRound1Command extends IronfishCommand {

static flags = {
...RemoteFlags,
secretName: Flags.string({
char: 's',
participantName: Flags.string({
char: 'n',
description: 'The name of the secret to use for encryption during DKG',
aliases: ['name'],
}),
identity: Flags.string({
char: 'i',
description:
'The identity of the participants will generate the group keys (may be specified multiple times to add multiple participants). Must include the identity for secretName',
'The identity of the participants will generate the group keys (may be specified multiple times to add multiple participants)',
multiple: true,
}),
minSigners: Flags.integer({
Expand All @@ -34,9 +35,9 @@ export class DkgRound1Command extends IronfishCommand {

const client = await this.sdk.connectRpc()

let secretName = flags.secretName
if (!secretName) {
secretName = await selectSecret(client)
let participantName = flags.participantName
if (!participantName) {
participantName = await selectSecret(client)
}

let identities = flags.identity
Expand Down Expand Up @@ -64,7 +65,7 @@ export class DkgRound1Command extends IronfishCommand {
}

const response = await client.wallet.multisig.dkg.round1({
secretName: secretName,
participantName,
participants: identities.map((identity) => ({ identity })),
minSigners: minSigners,
})
Expand Down
15 changes: 8 additions & 7 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export class DkgRound2Command extends IronfishCommand {

static flags = {
...RemoteFlags,
secretName: Flags.string({
char: 's',
participantName: Flags.string({
char: 'n',
description: 'The name of the secret to use for encryption during DKG',
aliases: ['name'],
}),
round1SecretPackage: Flags.string({
char: 'e',
Expand All @@ -34,15 +35,15 @@ export class DkgRound2Command extends IronfishCommand {

const client = await this.sdk.connectRpc()

let secretName = flags.secretName
if (!secretName) {
secretName = await selectSecret(client)
let participantName = flags.participantName
if (!participantName) {
participantName = await selectSecret(client)
}

let round1SecretPackage = flags.round1SecretPackage
if (!round1SecretPackage) {
round1SecretPackage = await CliUx.ux.prompt(
`Enter the round 1 secret package for secret ${secretName}`,
`Enter the round 1 secret package for participant ${participantName}`,
{ required: true },
)
}
Expand All @@ -64,7 +65,7 @@ export class DkgRound2Command extends IronfishCommand {
round1PublicPackages = round1PublicPackages.map((i) => i.trim())

const response = await client.wallet.multisig.dkg.round2({
secretName,
participantName,
round1SecretPackage,
round1PublicPackages,
})
Expand Down
17 changes: 9 additions & 8 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export class DkgRound3Command extends IronfishCommand {

static flags = {
...RemoteFlags,
secretName: Flags.string({
char: 's',
participantName: Flags.string({
char: 'n',
description: 'The name of the secret to use for decryption during DKG',
aliases: ['name'],
}),
accountName: Flags.string({
char: 'n',
char: 'a',
description: 'The name to set for the imported account',
}),
round2SecretPackage: Flags.string({
Expand All @@ -44,15 +45,15 @@ export class DkgRound3Command extends IronfishCommand {

const client = await this.sdk.connectRpc()

let secretName = flags.secretName
if (!secretName) {
secretName = await selectSecret(client)
let participantName = flags.participantName
if (!participantName) {
participantName = await selectSecret(client)
}

let round2SecretPackage = flags.round2SecretPackage
if (!round2SecretPackage) {
round2SecretPackage = await CliUx.ux.prompt(
`Enter the encrypted round 2 secret package for secret ${secretName}`,
`Enter the encrypted secret package for participant ${participantName}`,
{
required: true,
},
Expand Down Expand Up @@ -103,7 +104,7 @@ export class DkgRound3Command extends IronfishCommand {
round2PublicPackages = round2PublicPackages.map((i) => i.trim())

const response = await client.wallet.multisig.dkg.round3({
secretName: secretName,
participantName,
accountName: flags.accountName,
round2SecretPackage,
round1PublicPackages,
Expand Down
56 changes: 31 additions & 25 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,47 @@ describe('Route multisig/dkg/round1', () => {
const routeTest = createRouteTest()

it('should create round 1 packages', async () => {
const secretName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName })
const participantName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName })

const identity = (await routeTest.client.wallet.multisig.getIdentity({ name: secretName }))
.content.identity
const identity = (
await routeTest.client.wallet.multisig.getIdentity({ name: participantName })
).content.identity
const otherParticipants = Array.from({ length: 2 }, () => ({
identity: multisig.ParticipantSecret.random().toIdentity().serialize().toString('hex'),
}))
const participants = [{ identity }, ...otherParticipants]

const request = { secretName, minSigners: 2, participants }
const request = { participantName, minSigners: 2, participants }
const response = await routeTest.client.wallet.multisig.dkg.round1(request)

expect(response.content).toMatchObject({
round1SecretPackage: expect.any(String),
round1PublicPackage: expect.any(String),
})

// Ensure that the round 1 secret package can be decrypted
const secretValue = await routeTest.node.wallet.walletDb.getMultisigSecretByName(secretName)
// Ensure that the encrypted secret package can be decrypted
const secretValue = await routeTest.node.wallet.walletDb.getMultisigSecretByName(
participantName,
)
Assert.isNotUndefined(secretValue)
const secret = new multisig.ParticipantSecret(secretValue.secret)
secret.decryptData(Buffer.from(response.content.round1SecretPackage, 'hex'))
})

it('should fail if the named secret does not exist', async () => {
const secretName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName })
const participantName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName })

const identity = (await routeTest.client.wallet.multisig.getIdentity({ name: secretName }))
.content.identity
const identity = (
await routeTest.client.wallet.multisig.getIdentity({ name: participantName })
).content.identity
const otherParticipants = Array.from({ length: 2 }, () => ({
identity: multisig.ParticipantSecret.random().toIdentity().serialize().toString('hex'),
}))
const participants = [{ identity }, ...otherParticipants]

const request = { secretName: 'otherName', minSigners: 2, participants }
const request = { participantName: 'otherName', minSigners: 2, participants }

await expect(routeTest.client.wallet.multisig.dkg.round1(request)).rejects.toThrow(
expect.objectContaining({
Expand All @@ -56,8 +60,8 @@ describe('Route multisig/dkg/round1', () => {
})

it('should add the named identity if it is not in the list of participants', async () => {
const secretName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName })
const participantName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName })

// only pass in one participant
const participants = [
Expand All @@ -66,7 +70,7 @@ describe('Route multisig/dkg/round1', () => {
},
]

const request = { secretName, minSigners: 2, participants }
const request = { participantName, minSigners: 2, participants }

const response = await routeTest.client.wallet.multisig.dkg.round1(request)

Expand All @@ -77,17 +81,18 @@ describe('Route multisig/dkg/round1', () => {
})

it('should fail if minSigners is too low', async () => {
const secretName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName })
const participantName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName })

const identity = (await routeTest.client.wallet.multisig.getIdentity({ name: secretName }))
.content.identity
const identity = (
await routeTest.client.wallet.multisig.getIdentity({ name: participantName })
).content.identity
const otherParticipants = Array.from({ length: 2 }, () => ({
identity: multisig.ParticipantSecret.random().toIdentity().serialize().toString('hex'),
}))
const participants = [{ identity }, ...otherParticipants]

const request = { secretName, minSigners: 1, participants }
const request = { participantName, minSigners: 1, participants }

await expect(routeTest.client.wallet.multisig.dkg.round1(request)).rejects.toThrow(
expect.objectContaining({
Expand All @@ -98,17 +103,18 @@ describe('Route multisig/dkg/round1', () => {
})

it('should fail if minSigners exceeds the number of participants', async () => {
const secretName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName })
const participantName = 'name'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName })

const identity = (await routeTest.client.wallet.multisig.getIdentity({ name: secretName }))
.content.identity
const identity = (
await routeTest.client.wallet.multisig.getIdentity({ name: participantName })
).content.identity
const otherParticipants = Array.from({ length: 2 }, () => ({
identity: multisig.ParticipantSecret.random().toIdentity().serialize().toString('hex'),
}))
const participants = [{ identity }, ...otherParticipants]

const request = { secretName, minSigners: 4, participants }
const request = { participantName, minSigners: 4, participants }

await expect(routeTest.client.wallet.multisig.dkg.round1(request)).rejects.toThrow(
expect.objectContaining({
Expand Down
10 changes: 5 additions & 5 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { routes } from '../../../router'
import { AssertHasRpcContext } from '../../../rpcContext'

export type DkgRound1Request = {
secretName: string
participantName: string
minSigners: number
participants: Array<{ identity: string }>
}
Expand All @@ -21,7 +21,7 @@ export type DkgRound1Response = {

export const DkgRound1RequestSchema: yup.ObjectSchema<DkgRound1Request> = yup
.object({
secretName: yup.string().defined(),
participantName: yup.string().defined(),
minSigners: yup.number().defined(),
participants: yup
.array()
Expand All @@ -43,12 +43,12 @@ routes.register<typeof DkgRound1RequestSchema, DkgRound1Response>(
async (request, node): Promise<void> => {
AssertHasRpcContext(request, node, 'wallet')

const { secretName, minSigners, participants } = request.data
const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(secretName)
const { participantName, minSigners, participants } = request.data
const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(participantName)

if (!multisigSecret) {
throw new RpcValidationError(
`Multisig secret with name '${secretName}' not found`,
`Multisig secret with name '${participantName}' not found`,
400,
RPC_ERROR_CODES.MULTISIG_SECRET_NOT_FOUND,
)
Expand Down
20 changes: 10 additions & 10 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ describe('Route multisig/dkg/round2', () => {
const routeTest = createRouteTest()

it('should create round 2 packages', async () => {
const secretName1 = 'name1'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName1 })
const secretName2 = 'name2'
await routeTest.client.wallet.multisig.createParticipant({ name: secretName2 })
const participantName1 = 'name1'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName1 })
const participantName2 = 'name2'
await routeTest.client.wallet.multisig.createParticipant({ name: participantName2 })

const identity1 = (
await routeTest.client.wallet.multisig.getIdentity({ name: secretName1 })
await routeTest.client.wallet.multisig.getIdentity({ name: participantName1 })
).content.identity
const identity2 = (
await routeTest.client.wallet.multisig.getIdentity({ name: secretName2 })
await routeTest.client.wallet.multisig.getIdentity({ name: participantName2 })
).content.identity
const participants = [{ identity: identity1 }, { identity: identity2 }]

const round1Request1 = { secretName: secretName1, minSigners: 2, participants }
const round1Request1 = { participantName: participantName1, minSigners: 2, participants }
const round1Response1 = await routeTest.client.wallet.multisig.dkg.round1(round1Request1)

const round1Request2 = { secretName: secretName2, minSigners: 2, participants }
const round1Request2 = { participantName: participantName2, minSigners: 2, participants }
const round1Response2 = await routeTest.client.wallet.multisig.dkg.round1(round1Request2)

const round2Request = {
secretName: secretName1,
participantName: participantName1,
round1SecretPackage: round1Response1.content.round1SecretPackage,
round1PublicPackages: [
round1Response1.content.round1PublicPackage,
Expand All @@ -44,7 +44,7 @@ describe('Route multisig/dkg/round2', () => {

it('should fail if the named secret does not exist', async () => {
const request = {
secretName: 'fakeName',
participantName: 'fakeName',
round1SecretPackage: 'foo',
round1PublicPackages: ['bar', 'baz'],
}
Expand Down
10 changes: 5 additions & 5 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { routes } from '../../../router'
import { AssertHasRpcContext } from '../../../rpcContext'

export type DkgRound2Request = {
secretName: string
participantName: string
round1SecretPackage: string
round1PublicPackages: Array<string>
}
Expand All @@ -21,7 +21,7 @@ export type DkgRound2Response = {

export const DkgRound2RequestSchema: yup.ObjectSchema<DkgRound2Request> = yup
.object({
secretName: yup.string().defined(),
participantName: yup.string().defined(),
round1SecretPackage: yup.string().defined(),
round1PublicPackages: yup.array().of(yup.string().defined()).defined(),
})
Expand All @@ -40,12 +40,12 @@ routes.register<typeof DkgRound2RequestSchema, DkgRound2Response>(
async (request, node): Promise<void> => {
AssertHasRpcContext(request, node, 'wallet')

const { secretName, round1SecretPackage, round1PublicPackages } = request.data
const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(secretName)
const { participantName, round1SecretPackage, round1PublicPackages } = request.data
const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(participantName)

if (!multisigSecret) {
throw new RpcValidationError(
`Multisig secret with name '${secretName}' not found`,
`Multisig secret with name '${participantName}' not found`,
400,
RPC_ERROR_CODES.MULTISIG_SECRET_NOT_FOUND,
)
Expand Down
Loading
Loading