diff --git a/packages-ts/gauntlet-terra/src/commands/ledgerKey.ts b/packages-ts/gauntlet-terra/src/commands/ledgerKey.ts index f4578510..482a8706 100644 --- a/packages-ts/gauntlet-terra/src/commands/ledgerKey.ts +++ b/packages-ts/gauntlet-terra/src/commands/ledgerKey.ts @@ -4,6 +4,8 @@ import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' import { logger } from '@chainlink/gauntlet-core/dist/utils' import { signatureImport } from 'secp256k1' +const BIP44_REGEX = /^(44)\'\s*\/\s*(\d+)\'\s*\/\s*([0,1]+)\'\s*\/\s*(\d+)\s*\/\s*(\d+)$/ + export class LedgerKey extends Key { private path: Array @@ -23,7 +25,7 @@ export class LedgerKey extends Key { } public static async create(path: string): Promise { - const pathArr = this.pathStringToArray(path) + const pathArr = this.bip44PathtoArray(path) const ledgerKey = new LedgerKey(pathArr) await ledgerKey.initialize() @@ -59,8 +61,12 @@ export class LedgerKey extends Key { } } - private static pathStringToArray(path: string): Array { - return path.split("'/").map((item) => parseInt(item)) + private static bip44PathtoArray(path: string): Array { + const match = BIP44_REGEX.exec(path) + if (!match) + throw new Error('Invalid BIP44 path!') + + return match.slice(1).map(Number) } private checkForErrors(response: CommonResponse) { diff --git a/packages-ts/gauntlet-terra/src/commands/middlewares.ts b/packages-ts/gauntlet-terra/src/commands/middlewares.ts index f448312b..06366984 100644 --- a/packages-ts/gauntlet-terra/src/commands/middlewares.ts +++ b/packages-ts/gauntlet-terra/src/commands/middlewares.ts @@ -5,7 +5,7 @@ import { assertions, io, logger } from '@chainlink/gauntlet-core/dist/utils' import TerraCommand from './internal/terra' import path from 'path' import { existsSync } from 'fs' -import { LEDGER_ULUNA_PATH } from '../lib/constants' +import { BIP44_LUNA_PATH } from '../lib/constants' const isValidURL = (a) => true export const withProvider: Middleware = (c: TerraCommand, next: Next) => { @@ -25,7 +25,7 @@ export const withProvider: Middleware = (c: TerraCommand, next: Next) => { export const withWallet: Middleware = async (c: TerraCommand, next: Next) => { let key: Key if (c.flags.withLedger || !!process.env.WITH_LEDGER) { - const path = c.flags.ledgerPath || LEDGER_ULUNA_PATH + const path = c.flags.ledgerPath || BIP44_LUNA_PATH key = await LedgerKey.create(path) } else { const mnemonic = process.env.MNEMONIC diff --git a/packages-ts/gauntlet-terra/src/lib/constants.ts b/packages-ts/gauntlet-terra/src/lib/constants.ts index 0a232b3b..36107cb0 100644 --- a/packages-ts/gauntlet-terra/src/lib/constants.ts +++ b/packages-ts/gauntlet-terra/src/lib/constants.ts @@ -1,2 +1,2 @@ export const ADDRESS_ZERO = 'terra000000000000000000000000000000000000000' -export const LEDGER_ULUNA_PATH = "44'/330'/0'/0'/0" +export const BIP44_LUNA_PATH = "44'/330'/0'/0/0"