diff --git a/packages/launchpad-ledger/src/launchpadledger.ts b/packages/launchpad-ledger/src/launchpadledger.ts index 78e43947..cf7a75e0 100644 --- a/packages/launchpad-ledger/src/launchpadledger.ts +++ b/packages/launchpad-ledger/src/launchpadledger.ts @@ -1,5 +1,6 @@ -import { Secp256k1Signature } from "@cosmjs/crypto"; +import { Secp256k1Signature, Slip10RawIndex } from "@cosmjs/crypto"; import { fromUtf8 } from "@cosmjs/encoding"; +import { makeCosmoshubPath } from "@cosmjs/launchpad"; import { assert } from "@cosmjs/utils"; import Transport from "@ledgerhq/hw-transport"; import TransportWebUsb from "@ledgerhq/hw-transport-webusb"; @@ -58,12 +59,16 @@ async function createTransport(timeout: number): Promise { } } -const cosmosHdPath = [44, 118, 0, 0, 0]; +function unharden(hdPath: readonly Slip10RawIndex[]): number[] { + return hdPath.map((n) => (n.isHardened() ? n.toNumber() - 2 ** 31 : n.toNumber())); +} + +const cosmosHdPath = makeCosmoshubPath(0); const cosmosBech32Prefix = "cosmos"; export class LaunchpadLedger { private readonly testModeAllowed: boolean; - private readonly hdPath: number[]; + private readonly hdPath: readonly Slip10RawIndex[]; private readonly prefix: string; private cosmosApp: CosmosApp | null; public readonly platform: string; @@ -71,7 +76,7 @@ export class LaunchpadLedger { constructor( { testModeAllowed }: { testModeAllowed: boolean } = { testModeAllowed: false }, - hdPath: number[] = cosmosHdPath, + hdPath: readonly Slip10RawIndex[] = cosmosHdPath, prefix: string = cosmosBech32Prefix, ) { this.testModeAllowed = testModeAllowed; @@ -123,7 +128,8 @@ export class LaunchpadLedger { await this.connect(); assert(this.cosmosApp, "Cosmos Ledger App is not connected"); - const response = await this.cosmosApp.publicKey(this.hdPath); + // ledger-cosmos-js hardens the first three indices + const response = await this.cosmosApp.publicKey(unharden(this.hdPath)); this.handleLedgerErrors(response); return (response as PublicKeyResponse).compressed_pk; } @@ -147,7 +153,8 @@ export class LaunchpadLedger { await this.connect(); assert(this.cosmosApp, "Cosmos Ledger App is not connected"); - const response = await this.cosmosApp.sign(this.hdPath, fromUtf8(message)); + // ledger-cosmos-js hardens the first three indices + const response = await this.cosmosApp.sign(unharden(this.hdPath), fromUtf8(message)); this.handleLedgerErrors(response, { rejectionMessage: "Transaction signing request was rejected by the user", }); diff --git a/packages/launchpad-ledger/types/launchpadledger.d.ts b/packages/launchpad-ledger/types/launchpadledger.d.ts index 323bcecc..4dbf3064 100644 --- a/packages/launchpad-ledger/types/launchpadledger.d.ts +++ b/packages/launchpad-ledger/types/launchpadledger.d.ts @@ -1,4 +1,5 @@ /// +import { Slip10RawIndex } from "@cosmjs/crypto"; export declare class LaunchpadLedger { private readonly testModeAllowed; private readonly hdPath; @@ -12,7 +13,7 @@ export declare class LaunchpadLedger { }?: { testModeAllowed: boolean; }, - hdPath?: number[], + hdPath?: readonly Slip10RawIndex[], prefix?: string, ); connect(timeout?: number): Promise;