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

adds cli command to import multisig account from ledger #5409

Merged
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
9 changes: 7 additions & 2 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
deserializePublicPackage,
deserializeRound2CombinedPublicPackage,
} from '@ironfish/rust-nodejs'
import { AccountFormat, encodeAccountImport, RpcClient } from '@ironfish/sdk'
import {
ACCOUNT_SCHEMA_VERSION,
AccountFormat,
encodeAccountImport,
RpcClient,
} from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
Expand Down Expand Up @@ -210,7 +215,7 @@ export class DkgRound3Command extends IronfishCommand {
publicKeyPackage: publicKeyPackage.toString('hex'),
identity,
},
version: 4,
version: ACCOUNT_SCHEMA_VERSION,
name: participantName,
spendingKey: null,
createdAt: null,
Expand Down
67 changes: 67 additions & 0 deletions ironfish-cli/src/commands/wallet/multisig/ledger/import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* 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 { ACCOUNT_SCHEMA_VERSION, AccountFormat, encodeAccountImport } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import * as ui from '../../../../ui'
import { importAccount } from '../../../../utils'
import { Ledger } from '../../../../utils/ledger'

export class MultisigLedgerImport extends IronfishCommand {
static description = `import a multisig account from a Ledger device`

static flags = {
...RemoteFlags,
name: Flags.string({
description: 'Name to use for the account',
char: 'n',
}),
}

async start(): Promise<void> {
const { flags } = await this.parse(MultisigLedgerImport)

const client = await this.connectRpc()
await ui.checkWalletUnlocked(client)

const name = flags.name ?? (await ui.inputPrompt('Enter a name for the account', true))

const ledger = new Ledger(this.logger)
try {
await ledger.connect(true)
} catch (e) {
if (e instanceof Error) {
this.error(e.message)
} else {
throw e
}
}

const identity = await ledger.dkgGetIdentity(0)
const dkgKeys = await ledger.dkgRetrieveKeys()
const publicKeyPackage = await ledger.dkgGetPublicPackage()

const accountImport = {
...dkgKeys,
multisigKeys: {
publicKeyPackage: publicKeyPackage.toString('hex'),
identity: identity.toString('hex'),
},
version: ACCOUNT_SCHEMA_VERSION,
name,
spendingKey: null,
createdAt: null,
}

const { name: accountName } = await importAccount(
client,
encodeAccountImport(accountImport, AccountFormat.Base64Json),
this.logger,
)

this.log()
this.log(`Account ${accountName} imported with public address: ${dkgKeys.publicAddress}`)
}
}
4 changes: 2 additions & 2 deletions ironfish-cli/src/utils/ledger.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 { AccountImport, createRootLogger, Logger } from '@ironfish/sdk'
import { ACCOUNT_SCHEMA_VERSION, AccountImport, createRootLogger, Logger } from '@ironfish/sdk'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import IronfishApp, {
IronfishKeys,
Expand Down Expand Up @@ -123,7 +123,7 @@ export class Ledger {
}

const accountImport: AccountImport = {
version: 4, // ACCOUNT_SCHEMA_VERSION as of 2024-05
version: ACCOUNT_SCHEMA_VERSION,
name: 'ledger',
viewKey: responseViewKey.viewKey.toString('hex'),
incomingViewKey: responseViewKey.ivk.toString('hex'),
Expand Down