diff --git a/packages/ui-keyring/src/ledger-polkadot.d.ts b/packages/ui-keyring/src/ledger-polkadot.d.ts index 8722cd38..28352b95 100644 --- a/packages/ui-keyring/src/ledger-polkadot.d.ts +++ b/packages/ui-keyring/src/ledger-polkadot.d.ts @@ -20,7 +20,7 @@ declare module 'ledger-polkadot' { } export interface ResponseSign extends ResponseBase { - signature: string; + signature: Buffer; } declare class LedgerApp { diff --git a/packages/ui-keyring/src/ledger.ts b/packages/ui-keyring/src/ledger.ts index 6d93b7b4..8ddd13bf 100644 --- a/packages/ui-keyring/src/ledger.ts +++ b/packages/ui-keyring/src/ledger.ts @@ -8,7 +8,7 @@ import LedgerHid from '@ledgerhq/hw-transport-node-hid'; import LedgerU2F from '@ledgerhq/hw-transport-u2f'; import LedgerWebUSB from '@ledgerhq/hw-transport-webusb'; import LedgerApp, { ResponseBase } from 'ledger-polkadot'; -import { assert, u8aToBuffer } from '@polkadot/util'; +import { assert, bufferToU8a, u8aToBuffer, u8aToHex } from '@polkadot/util'; export type LedgerTypes = 'hid' | 'u2f' | 'webusb'; @@ -24,9 +24,7 @@ export interface LedgerSignature { export interface LedgerVersion { isLocked: boolean; isTestMode: boolean; - major: number; - minor: number; - patch: number; + version: [number, number, number]; } export const LEDGER_DEFAULT_ACCOUNT = 0x80000000; @@ -70,7 +68,7 @@ export default class Ledger { return this.app; } - private async wrapResult (fn: (app: LedgerApp) => Promise): Promise { + private async withApp (fn: (app: LedgerApp) => Promise): Promise { try { const app = await this.getApp(); @@ -93,7 +91,7 @@ export default class Ledger { } public async getAddress (confirm = false, account = LEDGER_DEFAULT_ACCOUNT, change = LEDGER_DEFAULT_CHANGE, addressIndex = LEDGER_DEFAULT_INDEX): Promise { - return this.wrapResult(async (app: LedgerApp): Promise => { + return this.withApp(async (app: LedgerApp): Promise => { const { address, pubKey } = await this.wrapError(app.getAddress(account, change, addressIndex, confirm)); return { @@ -104,26 +102,24 @@ export default class Ledger { } public async getVersion (): Promise { - return this.wrapResult(async (app: LedgerApp): Promise => { + return this.withApp(async (app: LedgerApp): Promise => { const { device_locked, major, minor, patch, test_mode } = await this.wrapError(app.getVersion()); return { isLocked: device_locked, isTestMode: test_mode, - major, - minor, - patch + version: [major, minor, patch] }; }); } public async sign (message: Uint8Array, account = LEDGER_DEFAULT_ACCOUNT, change = LEDGER_DEFAULT_CHANGE, addressIndex = LEDGER_DEFAULT_INDEX): Promise { - return this.wrapResult(async (app: LedgerApp): Promise => { + return this.withApp(async (app: LedgerApp): Promise => { const buffer = u8aToBuffer(message); const { signature } = await this.wrapError(app.sign(account, change, addressIndex, buffer)); return { - signature: `0x${signature}` + signature: u8aToHex(bufferToU8a(signature)) }; }); }