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

Rahul/ifl 3115 add ledger flag to account store #5685

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions ironfish-cli/src/commands/wallet/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class AccountsCommand extends IronfishCommand {
Scanning: response.content.account.scanningEnabled ? chalk.green('✓') : '',
Sequence: response.content.account.head?.sequence,
Head: response.content.account.head?.hash,
Ledger: response.content.account.isLedger ? chalk.green('✓') : '',
}

this.log(ui.card(status))
Expand Down
7 changes: 2 additions & 5 deletions ironfish-cli/src/commands/wallet/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ This will destroy tokens and decrease supply for a given asset.`
default: false,
description: 'Wait for the transaction to be confirmed',
}),
ledger: Flags.boolean({
default: false,
description: 'Burn a transaction using a Ledger device',
}),
}

async start(): Promise<void> {
Expand All @@ -109,6 +105,7 @@ This will destroy tokens and decrease supply for a given asset.`
}

const account = await useAccount(client, flags.account)
const accountStatus = (await client.wallet.getAccountStatus({ account })).content.account

let assetId = flags.assetId

Expand Down Expand Up @@ -225,7 +222,7 @@ This will destroy tokens and decrease supply for a given asset.`

await this.confirm(assetData, amount, raw.fee, account, flags.confirm)

if (flags.ledger) {
if (accountStatus.isLedger) {
await ui.sendTransactionWithLedger(
client,
raw,
Expand Down
23 changes: 16 additions & 7 deletions ironfish-cli/src/commands/wallet/chainport/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ export class BridgeCommand extends IronfishCommand {
description:
'Return a serialized UnsignedTransaction. Use it to create a transaction and build proofs but not post to the network',
}),
ledger: Flags.boolean({
default: false,
description: 'Send a transaction using a Ledger device',
}),
}

async start(): Promise<void> {
Expand All @@ -107,7 +103,7 @@ export class BridgeCommand extends IronfishCommand {
}
}

const { targetToken, from, to, amount, asset, assetData, expiration } =
const { targetToken, from, to, amount, asset, assetData, expiration, isLedger } =
await this.getAndValidateInputs(client, networkId)

const rawTransaction = await this.constructBridgeTransaction(
Expand All @@ -132,7 +128,7 @@ export class BridgeCommand extends IronfishCommand {
this.exit(0)
}

if (flags.ledger) {
if (isLedger) {
await ui.sendTransactionWithLedger(
client,
rawTransaction,
Expand Down Expand Up @@ -305,7 +301,20 @@ export class BridgeCommand extends IronfishCommand {
},
})
}
return { targetToken, from, to, amount, asset, assetData, expiration }

const accountStatus = (await client.wallet.getAccountStatus({ account: from })).content
.account

return {
targetToken,
from,
to,
amount,
asset,
assetData,
expiration,
isLedger: accountStatus.isLedger,
}
}

private async constructBridgeTransaction(
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/wallet/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Args, Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
import { LedgerError, LedgerMultiSigner, LedgerSingleSigner } from '../../ledger'
import { checkWalletUnlocked, inputPrompt } from '../../ui'
import * as ui from '../../ui'
import { checkWalletUnlocked, inputPrompt } from '../../ui'
import { importFile, importPipe, longPrompt } from '../../ui/longPrompt'
import { importAccount } from '../../utils'

Expand Down
5 changes: 5 additions & 0 deletions ironfish-cli/src/commands/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export class AccountsCommand extends IronfishCommand {
header: 'Head',
extended: true,
},
isLedger: {
get: (row) => (row.isLedger ? chalk.green('✓') : ''),
header: 'Ledger',
extended: true,
},
},
{
...flags,
Expand Down
7 changes: 2 additions & 5 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ This will create tokens and increase supply for a given asset.`
'Return a serialized UnsignedTransaction. Use it to create a transaction and build proofs but not post to the network',
exclusive: ['rawTransaction'],
}),
ledger: Flags.boolean({
default: false,
description: 'Mint a transaction using a Ledger device',
}),
}

async start(): Promise<void> {
Expand All @@ -130,6 +126,7 @@ This will create tokens and increase supply for a given asset.`
}

const account = await useAccount(client, flags.account)
const accountStatus = (await client.wallet.getAccountStatus({ account })).content.account

const publicKeyResponse = await client.wallet.getAccountPublicKey({ account })
const accountPublicKey = publicKeyResponse.content.publicKey
Expand Down Expand Up @@ -311,7 +308,7 @@ This will create tokens and increase supply for a given asset.`
assetData,
)

if (flags.ledger) {
if (accountStatus.isLedger) {
await ui.sendTransactionWithLedger(
client,
raw,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
path: Flags.string({
description: 'Path to a JSON file containing multisig transaction data',
}),
ledger: Flags.boolean({
default: false,
description: 'Create signing commitment using a Ledger device',
}),
}

async start(): Promise<void> {
Expand All @@ -58,6 +54,9 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
participantName = await ui.multisigSecretPrompt(client)
}

const accountStatus = (await client.wallet.getAccountStatus({ account: participantName }))
.content.account

let identities = options.identity
if (!identities || identities.length < 2) {
const input = await ui.longPrompt(
Expand Down Expand Up @@ -94,7 +93,7 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {

await ui.confirmOrQuit('Confirm signing commitment creation', flags.confirm)

if (flags.ledger) {
if (accountStatus.isLedger) {
await this.createSigningCommitmentWithLedger(
client,
participantName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class MultisigCreateDealer extends IronfishCommand {
multisigKeys: {
publicKeyPackage: response.content.publicKeyPackage,
},
isLedger: false,
}

await client.wallet.importAccount({
Expand Down
1 change: 1 addition & 0 deletions ironfish-cli/src/commands/wallet/multisig/dkg/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ export class DkgCreateCommand extends IronfishCommand {
},
version: ACCOUNT_SCHEMA_VERSION,
name: accountName,
isLedger: true,
createdAt: null,
spendingKey: null,
}
Expand Down
1 change: 1 addition & 0 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export class DkgRound3Command extends IronfishCommand {
},
version: ACCOUNT_SCHEMA_VERSION,
name: participantName,
isLedger: true,
spendingKey: null,
createdAt: null,
}
Expand Down
27 changes: 16 additions & 11 deletions ironfish-cli/src/commands/wallet/multisig/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export class SignMultisigTransactionCommand extends IronfishCommand {
char: 'a',
description: 'Name of the account to use for signing the transaction',
}),
ledger: Flags.boolean({
default: false,
description: 'Perform operation with a ledger device',
}),
server: Flags.boolean({
description: 'connect to a multisig broker server',
}),
Expand Down Expand Up @@ -78,12 +74,6 @@ export class SignMultisigTransactionCommand extends IronfishCommand {
const client = await this.connectRpc()
await ui.checkWalletUnlocked(client)

let ledger: LedgerMultiSigner | undefined = undefined

if (flags.ledger) {
ledger = new LedgerMultiSigner()
}

let multisigAccountName: string
if (!flags.account) {
multisigAccountName = await ui.accountPrompt(client)
Expand All @@ -97,6 +87,18 @@ export class SignMultisigTransactionCommand extends IronfishCommand {
}
}

const accountStatus = (
await client.wallet.getAccountStatus({
account: multisigAccountName,
})
).content.account

let ledger: LedgerMultiSigner | undefined = undefined

if (accountStatus.isLedger) {
ledger = new LedgerMultiSigner()
}

const accountIdentities = (
await client.wallet.multisig.getAccountIdentities({ account: multisigAccountName })
).content.identities
Expand Down Expand Up @@ -149,7 +151,10 @@ export class SignMultisigTransactionCommand extends IronfishCommand {
)

// Prompt for confirmation before broker automates signing
if (!flags.ledger && sessionManager instanceof MultisigClientSigningSessionManager) {
if (
!accountStatus.isLedger &&
sessionManager instanceof MultisigClientSigningSessionManager
) {
await ui.confirmOrQuit('Sign this transaction?')
}

Expand Down
8 changes: 3 additions & 5 deletions ironfish-cli/src/commands/wallet/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ export class Send extends IronfishCommand {
description: 'The note hashes to include in the transaction',
multiple: true,
}),
ledger: Flags.boolean({
default: false,
description: 'Send a transaction using a Ledger device',
}),
}

async start(): Promise<void> {
Expand All @@ -128,6 +124,8 @@ export class Send extends IronfishCommand {
}

const from = await useAccount(client, flags.account, 'Select an account to send from')
const accountStatus = (await client.wallet.getAccountStatus({ account: from })).content
.account

if (assetId == null) {
const asset = await ui.assetPrompt(client, from, {
Expand Down Expand Up @@ -255,7 +253,7 @@ export class Send extends IronfishCommand {
this.exit(0)
}

if (flags.ledger) {
if (accountStatus.isLedger) {
await ui.sendTransactionWithLedger(
client,
raw,
Expand Down
1 change: 1 addition & 0 deletions ironfish-cli/src/ledger/ledgerMultiSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class LedgerMultiSigner extends Ledger {
publicKeyPackage: publicKeyPackage.toString('hex'),
identity: identity.toString('hex'),
},
isLedger: true,
version: ACCOUNT_SCHEMA_VERSION,
spendingKey: null,
createdAt: null,
Expand Down
1 change: 1 addition & 0 deletions ironfish-cli/src/ledger/ledgerSingleSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class LedgerSingleSigner extends Ledger {
outgoingViewKey: responseViewKey.ovk.toString('hex'),
proofAuthorizingKey: responsePGK.nsk.toString('hex'),
spendingKey: null,
isLedger: true,
createdAt: null,
}

Expand Down
9 changes: 9 additions & 0 deletions ironfish/src/rpc/routes/wallet/importAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Route wallet/importAccount', () => {
proofAuthorizingKey: null,
version: 1,
createdAt: null,
isLedger: false,
}

const response = await routeTest.client.wallet.importAccount({
Expand All @@ -69,6 +70,7 @@ describe('Route wallet/importAccount', () => {
publicAddress: trustedDealerPackages.publicAddress,
spendingKey: null,
createdAt: null,
isLedger: false,
proofAuthorizingKey: trustedDealerPackages.proofAuthorizingKey,
multisigKeys: {
publicKeyPackage: trustedDealerPackages.publicKeyPackage,
Expand Down Expand Up @@ -102,6 +104,7 @@ describe('Route wallet/importAccount', () => {
proofAuthorizingKey: null,
version: 1,
createdAt: null,
isLedger: false,
}),
rescan: false,
})
Expand Down Expand Up @@ -129,6 +132,7 @@ describe('Route wallet/importAccount', () => {
proofAuthorizingKey: null,
version: 1,
createdAt: null,
isLedger: false,
}),
name: overriddenAccountName,
rescan: false,
Expand Down Expand Up @@ -172,6 +176,7 @@ describe('Route wallet/importAccount', () => {
proofAuthorizingKey: null,
version: 1,
createdAt: null,
isLedger: false,
}

const response = await routeTest.client.wallet.importAccount({
Expand Down Expand Up @@ -203,6 +208,7 @@ describe('Route wallet/importAccount', () => {
version: 1,
createdAt: null,
proofAuthorizingKey: key.proofAuthorizingKey,
isLedger: false,
}
}

Expand Down Expand Up @@ -500,6 +506,7 @@ describe('Route wallet/importAccount', () => {
keyPackage: trustedDealerPackages.keyPackages[1].keyPackage.toString(),
secret: secrets[1].serialize().toString('hex'),
},
isLedger: false,
}

try {
Expand Down Expand Up @@ -582,6 +589,7 @@ describe('Route wallet/importAccount', () => {
publicKeyPackage: trustedDealerPackages.publicKeyPackage,
identity: nextIdentity,
},
isLedger: false,
}

try {
Expand Down Expand Up @@ -625,6 +633,7 @@ describe('Route wallet/importAccount', () => {
publicKeyPackage: trustedDealerPackages.publicKeyPackage,
identity: identity,
},
isLedger: false,
}

const response = await routeTest.client.wallet.importAccount({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('Route wallt/multisig/createSignatureShare', () => {
version: ACCOUNT_SCHEMA_VERSION,
spendingKey: null,
createdAt: null,
isLedger: false,
}

const account = await routeTest.wallet.importAccount(accountImport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('Route wallet/multisig/createSigningCommitment', () => {
publicKeyPackage: trustedDealerPackage.publicKeyPackage,
},
proofAuthorizingKey: null,
isLedger: false,
}

const importAccountRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ routes.register<
keyPackage,
publicKeyPackage,
},
isLedger: false,
}

const encoder = new JsonEncoder()
Expand Down
1 change: 1 addition & 0 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ routes.register<typeof DkgRound3RequestSchema, DkgRound3Response>(
keyPackage,
publicKeyPackage,
},
isLedger: false,
}

const account = await node.wallet.importAccount(accountImport, {
Expand Down
Loading
Loading