Feat/ledger install app#808
Merged
Merged
Conversation
Add OS-level Ledger app management alongside the existing chain handlers: - DeviceApps + DeviceAppsManager: install, list installed/available, and read firmware/device info via DMK device actions, built per-call with signer-style onInteraction / onRegisterCanceller wiring. - installApp uses InstallOrUpdateAppsDeviceAction so DMK refreshes metadata, prechecks memory, and fails OOM before writing any bytes; install progress is surfaced as 'app-install-progress' events. - Custom duck-typed DeviceActions (GetOsVersion, catalog lookup) so unlock prompts flow through onInteraction like every other method. - New DeviceOutOfMemory error code for install OOM. - deviceActionToPromise gains a raw intermediateValue hook for progress. Scope: Ledger-only (hwk-ledger-adapter / hwk-adapter-core). Does not touch the OneKey SDK stack.
- progress now flows through ConnectorEventMap 'app-install-progress' instead of passing an onProgress function ref via connector.call params (would have been stripped by IHardwareBridge structured-clone / JSON serializers). Adapter forwards the event with sessionId → connectId mapping; both ConnectorEventMap and HardwareEventMap have typed entries (no more `as never`). - device-app dispatch cases (installApp / listInstalledApps / listAvailableApps / getFirmwareVersion / getDeviceInfo) wrap errors with ctx.wrapError and invalidate the session on failure, mirroring chain handlers — DMK errors now flow through mapLedgerError / isOutOfMemoryError instead of bypassing classification. - InstallProgress payload drops the raw DMK requiredUserInteraction string; raw signals go to debugLog for post-hoc diagnosis. The public 'ui-event' channel continues to surface the collapsed EConnectorInteraction so install UI keeps working. - DeviceApps.install throws AppNotFoundInCatalogError when DMK resolves Completed with missingApplications populated, so a no-op install doesn't silently look like success. - deviceActionToPromise consolidates four reject paths (watchdog timeout / external canceller / rxjs error / rxjs complete) through a shared completeInteraction() helper so an outstanding interaction prompt always gets a closing 'interaction-complete'. - Drop the dead InstallAppCallParams.unlockTimeout field (LedgerConnectorBase never forwarded it to apps.install and the public adapter API never exposed it).
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
CodeQL flagged the previous `/out of memory|not enough.*space| insufficient.*memory/i` pattern as polynomial-time on uncontrolled input — `.*` could backtrack catastrophically on adversarial strings like "not enough" repeated N times. Switch to plain Array.some + String.includes which runs in linear time and is impossible to ReDoS. Matched substrings are the same three phrases.
Apply prettier auto-fix to LedgerAdapter, LedgerConnectorBase, DeviceApps, DeviceAppsManager (line-wrapping + trailing-comma cleanup, imports collapsed to single line where they fit). Add scoped eslint-disable for max-classes-per-file and the no-useless-constructor / no-empty-function pair on TS parameter-property constructors, matching the existing convention in SignerEth/Btc/Sol.
Standard fix for the max-classes-per-file lint error instead of
suppressing the rule at file scope. AppNotFoundInCatalogError and the
two duck-typed DMK custom DeviceActions are independent concerns and
already had their own scope of concerns.
- device-apps/errors.ts — AppNotFoundInCatalogError
- device-apps/customActions.ts — GetOsVersionDeviceAction +
ListAvailableAppsDeviceAction
(still co-located: shared internal
OsVersionDeps / InternalApiLike /
AnyState types, two same-shape
DeviceAction implementations; matches
the slip39.ts precedent in the repo)
- device-apps/DeviceApps.ts — main class + public API types
The previous ReDoS fix (908beb3) lost matching coverage: the old regex `/not enough.*space|insufficient.*memory/i` matched intermediate tokens like "Not enough free space" / "Insufficient available memory" via `.*`, but the substring list only had the exact phrases. Switch to AND-checks ('not enough' && 'space', 'insufficient' && 'memory') so any message containing both anchor tokens — regardless of words in between — still hits, while keeping linear-time evaluation. Verified equivalent to the original regex on 10 representative cases including the tricky token-order edge cases.
The original regex was added as a "safety net" for messages that happen to carry the OOM phrasing but lack `_tag = OutOfMemoryDAError`. In practice DMK always sets that tag for `OutOfMemoryDAError`, so the message heuristic was speculative — and the two attempts at safely rewriting the regex either lost coverage (literal substrings) or over-classified (token AND-checks). Drop the heuristic entirely. `isOutOfMemoryError` now identifies only the canonical DMK tag. If we ever observe a real OOM that doesn't carry the tag, add a precise check then — don't speculate now. Eliminates the CodeQL ReDoS finding and the equivalence concern in one go.
wabicai
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.