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

feat(IFL-2206): large prompt signature share #4716

Merged
merged 1 commit into from
Feb 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../command'
import { RemoteFlags } from '../../../flags'
import { largePrompt } from '../../../utils/longPrompt'

export class CreateSignatureShareCommand extends IronfishCommand {
static description = `Creates a signature share for a participant for a given transaction`
Expand All @@ -20,25 +21,35 @@ export class CreateSignatureShareCommand extends IronfishCommand {
unsignedTransaction: Flags.string({
char: 'u',
description: 'The unsigned transaction for which the signature share will be created',
required: true,
required: false,
}),
signingPackage: Flags.string({
char: 's',
description: 'The signing package for which the signature share will be created',
required: true,
required: false,
}),
}

async start(): Promise<void> {
const { flags } = await this.parse(CreateSignatureShareCommand)
let unsignedTransaction = flags.unsignedTransaction?.trim()
let signingPackage = flags.signingPackage?.trim()

if (!unsignedTransaction) {
unsignedTransaction = await largePrompt('Enter the unsigned transaction: ')
}

if (!signingPackage) {
signingPackage = await largePrompt('Enter the signing package: ')
}

const client = await this.sdk.connectRpc()
// TODO(andrea): use flags.transaction to create commiment when we incorportate deterministic nonces
// set required to true as well
const signatureShareResponse = await client.wallet.multisig.createSignatureShare({
account: flags.account,
unsignedTransaction: flags.unsignedTransaction,
signingPackage: flags.signingPackage,
unsignedTransaction,
signingPackage,
seed: 0,
})

Expand Down
19 changes: 19 additions & 0 deletions ironfish-cli/src/utils/longPrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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 readline from 'readline'

// Most effective way to take in a large textual prompt input without affecting UX
jowparks marked this conversation as resolved.
Show resolved Hide resolved
export function largePrompt(question: string): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})

return new Promise((resolve) => {
rl.question(question, (answer) => {
rl.close()
resolve(answer.trim())
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type CreateSignatureShareResponse = {
export const CreateSignatureShareRequestSchema: yup.ObjectSchema<CreateSignatureShareRequest> =
yup
.object({
account: yup.string().defined(),
account: yup.string().optional(),
signingPackage: yup.string().defined(),
unsignedTransaction: yup.string().defined(),
seed: yup.number().defined(),
Expand Down
Loading