Skip to content

Commit 44c1e2b

Browse files
hughypatnir
andauthored
separates Ledger DKG logic from single signer (#5425)
* separates Ledger DKG logic from single signer defines a separate class, LedgerDkg, for interacting with the Ledger Ironfish DKG app updates all DKG and multisig commands to use LedgerDkg adds aliased dependencies @zondax/ledger-js-dkg and @zondax/ledger-ironfish-dkg to use the versions of these packages that we need for the DKG app restores the previous version of the Ledger class for use with the single signer Ledger app uses v0.1.2 of @zondax/ledger-ironfish for compatibility with the single signer app * Update ironfish-cli/src/utils/ledger.ts Co-authored-by: Rahul Patni <[email protected]> --------- Co-authored-by: Rahul Patni <[email protected]>
1 parent d91aef6 commit 44c1e2b

File tree

14 files changed

+256
-170
lines changed

14 files changed

+256
-170
lines changed

ironfish-cli/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
"@oclif/plugin-warn-if-update-available": "3.1.8",
6969
"@types/keccak": "3.0.4",
7070
"@types/tar": "6.1.1",
71-
"@zondax/ledger-ironfish": "0.4.0",
71+
"@zondax/ledger-ironfish": "0.1.2",
72+
"@zondax/ledger-ironfish-dkg": "npm:@zondax/[email protected]",
73+
"@zondax/ledger-js-dkg": "npm:@zondax/[email protected]",
7274
"axios": "1.7.2",
7375
"bech32": "2.0.0",
7476
"blessed": "0.1.81",
@@ -148,4 +150,4 @@
148150
"url": "https://github.com/iron-fish/ironfish/issues"
149151
},
150152
"homepage": "https://ironfish.network"
151-
}
153+
}

ironfish-cli/src/commands/wallet/multisig/commitment/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Flags } from '@oclif/core'
77
import { IronfishCommand } from '../../../../command'
88
import { RemoteFlags } from '../../../../flags'
99
import * as ui from '../../../../ui'
10-
import { Ledger } from '../../../../utils/ledger'
10+
import { LedgerDkg } from '../../../../utils/ledger'
1111
import { MultisigTransactionJson } from '../../../../utils/multisig'
1212
import { renderUnsignedTransactionDetails } from '../../../../utils/transaction'
1313

@@ -124,9 +124,9 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
124124
unsignedTransaction: UnsignedTransaction,
125125
signers: string[],
126126
): Promise<void> {
127-
const ledger = new Ledger(this.logger)
127+
const ledger = new LedgerDkg(this.logger)
128128
try {
129-
await ledger.connect(true)
129+
await ledger.connect()
130130
} catch (e) {
131131
if (e instanceof Error) {
132132
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/dkg/create.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Flags } from '@oclif/core'
1111
import { IronfishCommand } from '../../../../command'
1212
import { RemoteFlags } from '../../../../flags'
1313
import * as ui from '../../../../ui'
14-
import { Ledger } from '../../../../utils/ledger'
14+
import { LedgerDkg } from '../../../../utils/ledger'
1515

1616
export class DkgCreateCommand extends IronfishCommand {
1717
static description = 'Interactive command to create a multisignature account using DKG'
@@ -37,12 +37,12 @@ export class DkgCreateCommand extends IronfishCommand {
3737
const client = await this.connectRpc()
3838
await ui.checkWalletUnlocked(client)
3939

40-
let ledger: Ledger | undefined = undefined
40+
let ledger: LedgerDkg | undefined = undefined
4141

4242
if (flags.ledger) {
43-
ledger = new Ledger(this.logger)
43+
ledger = new LedgerDkg(this.logger)
4444
try {
45-
await ledger.connect(true)
45+
await ledger.connect()
4646
} catch (e) {
4747
if (e instanceof Error) {
4848
this.error(e.message)
@@ -170,7 +170,7 @@ export class DkgCreateCommand extends IronfishCommand {
170170
}
171171

172172
async getIdentityFromLedger(
173-
ledger: Ledger,
173+
ledger: LedgerDkg,
174174
client: RpcClient,
175175
name?: string,
176176
): Promise<{
@@ -226,7 +226,7 @@ export class DkgCreateCommand extends IronfishCommand {
226226
}
227227

228228
async performRound1WithLedger(
229-
ledger: Ledger,
229+
ledger: LedgerDkg,
230230
client: RpcClient,
231231
participantName: string,
232232
identities: string[],
@@ -256,7 +256,7 @@ export class DkgCreateCommand extends IronfishCommand {
256256
client: RpcClient,
257257
participantName: string,
258258
currentIdentity: string,
259-
ledger: Ledger | undefined,
259+
ledger: LedgerDkg | undefined,
260260
): Promise<{
261261
round1: { secretPackage: string; publicPackage: string }
262262
totalParticipants: number
@@ -316,7 +316,7 @@ export class DkgCreateCommand extends IronfishCommand {
316316
}
317317

318318
async performRound2WithLedger(
319-
ledger: Ledger,
319+
ledger: LedgerDkg,
320320
round1PublicPackages: string[],
321321
round1SecretPackage: string,
322322
): Promise<{
@@ -342,7 +342,7 @@ export class DkgCreateCommand extends IronfishCommand {
342342
participantName: string,
343343
round1Result: { secretPackage: string; publicPackage: string },
344344
totalParticipants: number,
345-
ledger: Ledger | undefined,
345+
ledger: LedgerDkg | undefined,
346346
): Promise<{
347347
round2: { secretPackage: string; publicPackage: string }
348348
round1PublicPackages: string[]
@@ -388,7 +388,7 @@ export class DkgCreateCommand extends IronfishCommand {
388388
}
389389

390390
async performRound3WithLedger(
391-
ledger: Ledger,
391+
ledger: LedgerDkg,
392392
client: RpcClient,
393393
accountName: string,
394394
participantName: string,
@@ -490,7 +490,7 @@ export class DkgCreateCommand extends IronfishCommand {
490490
round2Result: { secretPackage: string; publicPackage: string },
491491
round1PublicPackages: string[],
492492
totalParticipants: number,
493-
ledger: Ledger | undefined,
493+
ledger: LedgerDkg | undefined,
494494
): Promise<void> {
495495
this.log(`\nEnter ${totalParticipants - 1} Round 2 Public Packages (excluding yours) `)
496496

ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Flags } from '@oclif/core'
66
import { IronfishCommand } from '../../../../command'
77
import { RemoteFlags } from '../../../../flags'
88
import * as ui from '../../../../ui'
9-
import { Ledger } from '../../../../utils/ledger'
9+
import { LedgerDkg } from '../../../../utils/ledger'
1010

1111
export class DkgRound1Command extends IronfishCommand {
1212
static description = 'Perform round1 of the DKG protocol for multisig account creation'
@@ -100,9 +100,9 @@ export class DkgRound1Command extends IronfishCommand {
100100
identities: string[],
101101
minSigners: number,
102102
): Promise<void> {
103-
const ledger = new Ledger(this.logger)
103+
const ledger = new LedgerDkg(this.logger)
104104
try {
105-
await ledger.connect(true)
105+
await ledger.connect()
106106
} catch (e) {
107107
if (e instanceof Error) {
108108
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/dkg/round2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Flags } from '@oclif/core'
55
import { IronfishCommand } from '../../../../command'
66
import { RemoteFlags } from '../../../../flags'
77
import * as ui from '../../../../ui'
8-
import { Ledger } from '../../../../utils/ledger'
8+
import { LedgerDkg } from '../../../../utils/ledger'
99

1010
export class DkgRound2Command extends IronfishCommand {
1111
static description = 'Perform round2 of the DKG protocol for multisig account creation'
@@ -97,9 +97,9 @@ export class DkgRound2Command extends IronfishCommand {
9797
round1PublicPackages: string[],
9898
round1SecretPackage: string,
9999
): Promise<void> {
100-
const ledger = new Ledger(this.logger)
100+
const ledger = new LedgerDkg(this.logger)
101101
try {
102-
await ledger.connect(true)
102+
await ledger.connect()
103103
} catch (e) {
104104
if (e instanceof Error) {
105105
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { IronfishCommand } from '../../../../command'
1616
import { RemoteFlags } from '../../../../flags'
1717
import * as ui from '../../../../ui'
1818
import { importAccount } from '../../../../utils'
19-
import { Ledger } from '../../../../utils/ledger'
19+
import { LedgerDkg } from '../../../../utils/ledger'
2020

2121
export class DkgRound3Command extends IronfishCommand {
2222
static description = 'Perform round3 of the DKG protocol for multisig account creation'
@@ -149,9 +149,9 @@ export class DkgRound3Command extends IronfishCommand {
149149
round2PublicPackagesStr: string[],
150150
round2SecretPackage: string,
151151
): Promise<void> {
152-
const ledger = new Ledger(this.logger)
152+
const ledger = new LedgerDkg(this.logger)
153153
try {
154-
await ledger.connect(true)
154+
await ledger.connect()
155155
} catch (e) {
156156
if (e instanceof Error) {
157157
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/ledger/backup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44
import { IronfishCommand } from '../../../../command'
5-
import { Ledger } from '../../../../utils/ledger'
5+
import { LedgerDkg } from '../../../../utils/ledger'
66

77
export class MultisigLedgerBackup extends IronfishCommand {
88
static description = `show encrypted multisig keys from a Ledger device`
99

1010
async start(): Promise<void> {
11-
const ledger = new Ledger(this.logger)
11+
const ledger = new LedgerDkg(this.logger)
1212
try {
13-
await ledger.connect(true)
13+
await ledger.connect()
1414
} catch (e) {
1515
if (e instanceof Error) {
1616
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/ledger/import.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IronfishCommand } from '../../../../command'
77
import { RemoteFlags } from '../../../../flags'
88
import * as ui from '../../../../ui'
99
import { importAccount } from '../../../../utils'
10-
import { Ledger } from '../../../../utils/ledger'
10+
import { LedgerDkg } from '../../../../utils/ledger'
1111

1212
export class MultisigLedgerImport extends IronfishCommand {
1313
static description = `import a multisig account from a Ledger device`
@@ -28,9 +28,9 @@ export class MultisigLedgerImport extends IronfishCommand {
2828

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

31-
const ledger = new Ledger(this.logger)
31+
const ledger = new LedgerDkg(this.logger)
3232
try {
33-
await ledger.connect(true)
33+
await ledger.connect()
3434
} catch (e) {
3535
if (e instanceof Error) {
3636
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/ledger/restore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { Flags } from '@oclif/core'
55
import { IronfishCommand } from '../../../../command'
66
import * as ui from '../../../../ui'
7-
import { Ledger } from '../../../../utils/ledger'
7+
import { LedgerDkg } from '../../../../utils/ledger'
88

99
export class MultisigLedgerRestore extends IronfishCommand {
1010
static description = `restore encrypted multisig keys to a Ledger device`
@@ -26,9 +26,9 @@ export class MultisigLedgerRestore extends IronfishCommand {
2626
)
2727
}
2828

29-
const ledger = new Ledger(this.logger)
29+
const ledger = new LedgerDkg(this.logger)
3030
try {
31-
await ledger.connect(true)
31+
await ledger.connect()
3232
} catch (e) {
3333
if (e instanceof Error) {
3434
this.error(e.message)

ironfish-cli/src/commands/wallet/multisig/participant/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Flags } from '@oclif/core'
66
import { IronfishCommand } from '../../../../command'
77
import { RemoteFlags } from '../../../../flags'
88
import * as ui from '../../../../ui'
9-
import { Ledger } from '../../../../utils/ledger'
9+
import { LedgerDkg } from '../../../../utils/ledger'
1010

1111
export class MultisigIdentityCreate extends IronfishCommand {
1212
static description = `Create a multisig participant identity`
@@ -71,9 +71,9 @@ export class MultisigIdentityCreate extends IronfishCommand {
7171
}
7272

7373
async getIdentityFromLedger(): Promise<Buffer> {
74-
const ledger = new Ledger(this.logger)
74+
const ledger = new LedgerDkg(this.logger)
7575
try {
76-
await ledger.connect(true)
76+
await ledger.connect()
7777
} catch (e) {
7878
if (e instanceof Error) {
7979
this.error(e.message)

0 commit comments

Comments
 (0)