generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add new hardware errors #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d7e6756
feat: add new hardware errors
montelaidev 8023f97
fix: casing
montelaidev b86b627
refactor: remove unneeded
montelaidev 5777cba
fix: refactor to pascal case and remove unused
montelaidev 53206ed
fix: align key
montelaidev 7d906ee
fix: test
montelaidev cae2667
refactor: remove codes and refactor error values to numbers
montelaidev c4cd240
fix: add code
montelaidev 8cf427b
fix: test
montelaidev 928e0de
fix: use Error for value
montelaidev 9a617f4
fix: unknown error code
montelaidev a829975
feat: add erro prefix helper
montelaidev 6e59f1f
fix; update subcategory
montelaidev 131e513
fix: lint and test
montelaidev b3f1404
fix: fallback
montelaidev de46ef7
Apply suggestions from code review
montelaidev a555c4b
fix: remove retryStrategy and userActionable
montelaidev 4c01d43
fix: remove trezor
montelaidev f5b2230
fix: lint
montelaidev 85fe698
fix: remove unused
montelaidev ce66cea
fix test
montelaidev 954c66a
fix: refactor mapping and update enum key
montelaidev 6fc8735
Merge remote-tracking branch 'origin/main' into feat/hardware-errors-…
montelaidev 414fef0
refactor: move to new package
montelaidev b865d0a
fix: lint
montelaidev 8d064af
fix: enum name and change customCode to code
montelaidev 4ff27b1
fix: remove dep
montelaidev 95c731c
fix: changelog
montelaidev 9b4fd1b
Apply suggestions from code review
montelaidev b91f07e
fix: tests
montelaidev cd66ace
fix: test
montelaidev 887c781
fix: changelog
montelaidev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
117 changes: 117 additions & 0 deletions
117
packages/hw-device-sdk/src/hardware-error-mappings.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { LEDGER_ERROR_MAPPINGS } from './hardware-error-mappings'; | ||
| import { ErrorCode, Severity, Category } from './hardware-errors-enums'; | ||
|
|
||
| describe('HARDWARE_ERROR_MAPPINGS', () => { | ||
| describe('Ledger mappings', () => { | ||
| const errorMappings = LEDGER_ERROR_MAPPINGS; | ||
|
|
||
| it('have errorMappings object', () => { | ||
| expect(errorMappings).toBeDefined(); | ||
| expect(typeof errorMappings).toBe('object'); | ||
| }); | ||
|
|
||
| describe('success codes', () => { | ||
| it('map 0x9000 to success', () => { | ||
| const mapping = errorMappings['0x9000']; | ||
| expect(mapping).toBeDefined(); | ||
| expect(mapping.customCode).toBe(ErrorCode.Success); | ||
| expect(mapping.severity).toBe(Severity.Info); | ||
| expect(mapping.category).toBe(Category.Success); | ||
| }); | ||
| }); | ||
|
|
||
| describe('authentication errors', () => { | ||
| it('map 0x6300 to authentication failed', () => { | ||
| const mapping = errorMappings['0x6300']; | ||
| expect(mapping.customCode).toBe(ErrorCode.AuthenticationFailed); | ||
| expect(mapping.severity).toBe(Severity.Err); | ||
| expect(mapping.category).toBe(Category.Authentication); | ||
| expect(mapping.userMessage).toBeDefined(); | ||
| }); | ||
|
|
||
| it('map 0x63c0 to PIN attempts remaining', () => { | ||
| const mapping = errorMappings['0x63c0']; | ||
| expect(mapping.customCode).toBe( | ||
| ErrorCode.AuthenticationPinAttemptsRemaining, | ||
| ); | ||
| expect(mapping.severity).toBe(Severity.Warning); | ||
| }); | ||
|
|
||
| it('map 0x5515 to device locked', () => { | ||
| const mapping = errorMappings['0x5515']; | ||
| expect(mapping.customCode).toBe(ErrorCode.AuthenticationDeviceLocked); | ||
| expect(mapping.severity).toBe(Severity.Err); | ||
| expect(mapping.userMessage).toContain('unlock'); | ||
| }); | ||
|
|
||
| it('map 0x9840 to device blocked', () => { | ||
| const mapping = errorMappings['0x9840']; | ||
| expect(mapping.customCode).toBe(ErrorCode.AuthenticationDeviceBlocked); | ||
| expect(mapping.severity).toBe(Severity.Critical); | ||
| }); | ||
| }); | ||
|
|
||
| describe('user action errors', () => { | ||
| it('map 0x6985 to user rejected', () => { | ||
| const mapping = errorMappings['0x6985']; | ||
| expect(mapping.customCode).toBe(ErrorCode.UserRejected); | ||
| expect(mapping.severity).toBe(Severity.Warning); | ||
| expect(mapping.category).toBe(Category.UserAction); | ||
| }); | ||
|
|
||
| it('map 0x5501 to user refused', () => { | ||
| const mapping = errorMappings['0x5501']; | ||
| expect(mapping.customCode).toBe(ErrorCode.UserRejected); | ||
| expect(mapping.severity).toBe(Severity.Warning); | ||
| }); | ||
| }); | ||
| describe('connection errors', () => { | ||
| it('map 0x650f to connection issue', () => { | ||
| const mapping = errorMappings['0x650f']; | ||
| expect(mapping.customCode).toBe(ErrorCode.ConnClosed); | ||
| expect(mapping.category).toBe(Category.Connection); | ||
| }); | ||
| }); | ||
|
|
||
| it('have valid structure for all mappings', () => { | ||
| Object.entries(errorMappings).forEach(([_, mapping]) => { | ||
| expect(mapping).toHaveProperty('customCode'); | ||
| expect(mapping).toHaveProperty('message'); | ||
| expect(mapping).toHaveProperty('severity'); | ||
| expect(mapping).toHaveProperty('category'); | ||
|
|
||
| const numericErrorCodes = Object.values(ErrorCode).filter( | ||
| (value): value is number => typeof value === 'number', | ||
| ); | ||
| expect(numericErrorCodes).toContain(mapping.customCode); | ||
| expect(Object.values(Severity)).toContain(mapping.severity); | ||
| expect(Object.values(Category)).toContain(mapping.category); | ||
| expect(typeof mapping.message).toBe('string'); | ||
| }); | ||
| }); | ||
|
|
||
| it('have valid userMessage when present', () => { | ||
| const mappingsWithUserMessage = Object.values(errorMappings).filter( | ||
| (mapping): mapping is typeof mapping & { userMessage: string } => | ||
| 'userMessage' in mapping && | ||
| typeof mapping.userMessage === 'string' && | ||
| mapping.userMessage.length > 0, | ||
| ); | ||
| expect(mappingsWithUserMessage.length).toBeGreaterThan(0); | ||
| mappingsWithUserMessage.forEach((mapping) => { | ||
| expect(typeof mapping.userMessage).toBe('string'); | ||
| expect(mapping.userMessage.length).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('consistency checks', () => { | ||
| it('have unique error codes', () => { | ||
| const ledgerCodes = Object.values(LEDGER_ERROR_MAPPINGS); | ||
| const ledgerCustomCodes = ledgerCodes.map( | ||
| (mapping) => mapping.customCode, | ||
| ); | ||
| expect(ledgerCustomCodes.length).toBeGreaterThan(0); | ||
| }); | ||
montelaidev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
montelaidev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { ErrorCode, Severity, Category } from './hardware-errors-enums'; | ||
|
|
||
| export const LEDGER_ERROR_MAPPINGS = { | ||
| '0x9000': { | ||
| customCode: ErrorCode.Success, | ||
montelaidev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| message: 'Operation successful', | ||
| severity: Severity.Info, | ||
| category: Category.Success, | ||
| }, | ||
| '0x6300': { | ||
| customCode: ErrorCode.AuthenticationFailed, | ||
| message: 'Authentication failed', | ||
| severity: Severity.Err, | ||
| category: Category.Authentication, | ||
| userMessage: 'Authentication failed. Please verify your credentials.', | ||
| }, | ||
| '0x63c0': { | ||
| customCode: ErrorCode.AuthenticationPinAttemptsRemaining, | ||
| message: 'PIN attempts remaining', | ||
| severity: Severity.Warning, | ||
| category: Category.Authentication, | ||
| userMessage: 'Incorrect PIN. Please try again.', | ||
| }, | ||
| '0x6982': { | ||
| customCode: ErrorCode.AuthenticationSecurityCondition, | ||
| message: 'Security conditions not satisfied', | ||
| severity: Severity.Err, | ||
| category: Category.Authentication, | ||
|
|
||
| userMessage: | ||
| 'Device is locked or access rights are insufficient. Please unlock your device.', | ||
| }, | ||
| '0x6985': { | ||
| customCode: ErrorCode.UserRejected, | ||
| message: 'User rejected action on device', | ||
| severity: Severity.Warning, | ||
| category: Category.UserAction, | ||
|
|
||
| userMessage: | ||
| 'Transaction was rejected. Please approve on your device to continue.', | ||
| }, | ||
| '0x9804': { | ||
| customCode: ErrorCode.AuthenticationSecurityCondition, | ||
| message: 'App update required', | ||
| severity: Severity.Err, | ||
| category: Category.Authentication, | ||
|
|
||
| userMessage: 'Please update your Ledger app to continue.', | ||
| }, | ||
| '0x9808': { | ||
| customCode: ErrorCode.AuthenticationFailed, | ||
| message: 'Contradiction in secret code status', | ||
| severity: Severity.Err, | ||
| category: Category.Authentication, | ||
| }, | ||
| '0x9840': { | ||
| customCode: ErrorCode.AuthenticationDeviceBlocked, | ||
| message: 'Code blocked', | ||
| severity: Severity.Critical, | ||
| category: Category.Authentication, | ||
|
|
||
| userMessage: | ||
| 'Your device is blocked due to too many failed attempts. Please follow device recovery procedures.', | ||
| }, | ||
| '0x650f': { | ||
| customCode: ErrorCode.ConnClosed, | ||
| message: 'App closed or connection issue', | ||
| severity: Severity.Err, | ||
| category: Category.Connection, | ||
| userMessage: | ||
| 'Connection lost or app closed. Please open the corresponding app on your Ledger device.', | ||
| }, | ||
| '0x5515': { | ||
| customCode: ErrorCode.AuthenticationDeviceLocked, | ||
| message: 'Device is locked', | ||
| severity: Severity.Err, | ||
| category: Category.Authentication, | ||
| userMessage: 'Please unlock your Ledger device to continue.', | ||
| }, | ||
| '0x5501': { | ||
| customCode: ErrorCode.UserRejected, | ||
| message: 'User refused on device', | ||
| severity: Severity.Warning, | ||
| category: Category.UserAction, | ||
| userMessage: | ||
| 'Operation was rejected. Please approve on your device to continue.', | ||
| }, | ||
| '0x6a80': { | ||
| customCode: ErrorCode.DeviceStateBlindSignNotSupported, | ||
| message: 'Blind signing not supported', | ||
| severity: Severity.Err, | ||
| category: Category.DeviceState, | ||
| userMessage: 'Blind signing is not supported on this device.', | ||
| }, | ||
| '0x6d00': { | ||
| customCode: ErrorCode.DeviceStateOnlyV4Supported, | ||
| message: 'Ledger Only V4 supported', | ||
| severity: Severity.Err, | ||
| category: Category.DeviceState, | ||
| userMessage: 'Only V4 is supported on this device.', | ||
| }, | ||
| '0x6e00': { | ||
| customCode: ErrorCode.DeviceStateEthAppClosed, | ||
| message: 'Ethereum app closed', | ||
| severity: Severity.Err, | ||
| category: Category.DeviceState, | ||
| userMessage: 'Ethereum app is closed. Please open it to continue.', | ||
| }, | ||
| '0x6501': { | ||
| customCode: ErrorCode.DeviceStateEthAppOutOfDate, | ||
| message: 'Ethereum app out of date', | ||
| severity: Severity.Err, | ||
| category: Category.DeviceState, | ||
| userMessage: 'Ethereum app is out of date. Please update it to continue.', | ||
| }, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.