Skip to content

Commit 3432867

Browse files
authored
Merge branch 'main' into feat/trezor-keyring-v2
2 parents bb65ac5 + 6c3b576 commit 3432867

22 files changed

Lines changed: 1318 additions & 188 deletions

AGENTS.md

Lines changed: 1014 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/accounts-monorepo",
3-
"version": "81.0.0",
3+
"version": "82.0.0",
44
"private": true,
55
"description": "Monorepo for MetaMask accounts related packages",
66
"repository": {

packages/hw-wallet-sdk/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.0]
11+
1012
### Added
1113

1214
- Add hardware related error mappings and custom hardware error ([#421](https://github.com/MetaMask/accounts/pull/421))
15+
- Add BLE and mobile error mappings with new error codes for Bluetooth permissions, connection states, and mobile support ([#433](https://github.com/MetaMask/accounts/pull/433))
1316

14-
[Unreleased]: https://github.com/MetaMask/accounts/
17+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/hw-wallet-sdk@0.1.0...HEAD
18+
[0.1.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/hw-wallet-sdk@0.1.0

packages/hw-wallet-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/hw-wallet-sdk",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"description": "MetaMask Hardware Device SDK",
55
"keywords": [
66
"metamask",

packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { LEDGER_ERROR_MAPPINGS } from './hardware-error-mappings';
1+
import {
2+
LEDGER_ERROR_MAPPINGS,
3+
BLE_ERROR_MAPPINGS,
4+
MOBILE_ERROR_MAPPINGS,
5+
} from './hardware-error-mappings';
26
import { ErrorCode, Severity, Category } from './hardware-errors-enums';
37

48
describe('HARDWARE_ERROR_MAPPINGS', () => {
@@ -102,4 +106,110 @@ describe('HARDWARE_ERROR_MAPPINGS', () => {
102106
});
103107
});
104108
});
109+
110+
describe('BLE mappings', () => {
111+
const errorMappings = BLE_ERROR_MAPPINGS;
112+
113+
it('has errorMappings object', () => {
114+
expect(errorMappings).toBeDefined();
115+
expect(typeof errorMappings).toBe('object');
116+
});
117+
118+
describe('permission errors', () => {
119+
it('maps BLUETOOTH_PERMISSION_DENIED correctly', () => {
120+
const mapping = errorMappings.BLUETOOTH_PERMISSION_DENIED;
121+
expect(mapping.code).toBe(ErrorCode.PermissionBluetoothDenied);
122+
expect(mapping.severity).toBe(Severity.Err);
123+
expect(mapping.category).toBe(Category.Configuration);
124+
});
125+
126+
it('maps LOCATION_PERMISSION_DENIED correctly', () => {
127+
const mapping = errorMappings.LOCATION_PERMISSION_DENIED;
128+
expect(mapping.code).toBe(ErrorCode.PermissionLocationDenied);
129+
expect(mapping.severity).toBe(Severity.Err);
130+
expect(mapping.category).toBe(Category.Configuration);
131+
expect(mapping.userMessage).toContain('Location');
132+
});
133+
134+
it('maps NEARBY_DEVICES_PERMISSION_DENIED correctly', () => {
135+
const mapping = errorMappings.NEARBY_DEVICES_PERMISSION_DENIED;
136+
expect(mapping.code).toBe(ErrorCode.PermissionNearbyDevicesDenied);
137+
expect(mapping.severity).toBe(Severity.Err);
138+
expect(mapping.category).toBe(Category.Configuration);
139+
});
140+
});
141+
142+
describe('bluetooth state errors', () => {
143+
it('maps BLUETOOTH_DISABLED correctly', () => {
144+
const mapping = errorMappings.BLUETOOTH_DISABLED;
145+
expect(mapping.code).toBe(ErrorCode.BluetoothDisabled);
146+
expect(mapping.severity).toBe(Severity.Warning);
147+
expect(mapping.category).toBe(Category.Connection);
148+
});
149+
150+
it('maps BLUETOOTH_SCAN_FAILED correctly', () => {
151+
const mapping = errorMappings.BLUETOOTH_SCAN_FAILED;
152+
expect(mapping.code).toBe(ErrorCode.BluetoothScanFailed);
153+
expect(mapping.severity).toBe(Severity.Err);
154+
expect(mapping.category).toBe(Category.Connection);
155+
});
156+
157+
it('maps BLUETOOTH_CONNECTION_FAILED correctly', () => {
158+
const mapping = errorMappings.BLUETOOTH_CONNECTION_FAILED;
159+
expect(mapping.code).toBe(ErrorCode.BluetoothConnectionFailed);
160+
expect(mapping.severity).toBe(Severity.Err);
161+
expect(mapping.category).toBe(Category.Connection);
162+
});
163+
});
164+
165+
it('has valid structure for all mappings', () => {
166+
Object.entries(errorMappings).forEach(([_, mapping]) => {
167+
expect(mapping).toHaveProperty('code');
168+
expect(mapping).toHaveProperty('message');
169+
expect(mapping).toHaveProperty('severity');
170+
expect(mapping).toHaveProperty('category');
171+
172+
const numericErrorCodes = Object.values(ErrorCode).filter(
173+
(value): value is number => typeof value === 'number',
174+
);
175+
expect(numericErrorCodes).toContain(mapping.code);
176+
expect(Object.values(Severity)).toContain(mapping.severity);
177+
expect(Object.values(Category)).toContain(mapping.category);
178+
expect(typeof mapping.message).toBe('string');
179+
});
180+
});
181+
});
182+
183+
describe('Mobile mappings', () => {
184+
const errorMappings = MOBILE_ERROR_MAPPINGS;
185+
186+
it('has errorMappings object', () => {
187+
expect(errorMappings).toBeDefined();
188+
expect(typeof errorMappings).toBe('object');
189+
});
190+
191+
it('maps NOT_SUPPORTED correctly', () => {
192+
const mapping = errorMappings.NOT_SUPPORTED;
193+
expect(mapping.code).toBe(ErrorCode.MobileNotSupported);
194+
expect(mapping.severity).toBe(Severity.Err);
195+
expect(mapping.category).toBe(Category.DeviceState);
196+
});
197+
198+
it('has valid structure for all mappings', () => {
199+
Object.entries(errorMappings).forEach(([_, mapping]) => {
200+
expect(mapping).toHaveProperty('code');
201+
expect(mapping).toHaveProperty('message');
202+
expect(mapping).toHaveProperty('severity');
203+
expect(mapping).toHaveProperty('category');
204+
205+
const numericErrorCodes = Object.values(ErrorCode).filter(
206+
(value): value is number => typeof value === 'number',
207+
);
208+
expect(numericErrorCodes).toContain(mapping.code);
209+
expect(Object.values(Severity)).toContain(mapping.severity);
210+
expect(Object.values(Category)).toContain(mapping.category);
211+
expect(typeof mapping.message).toBe('string');
212+
});
213+
});
214+
});
105215
});

packages/hw-wallet-sdk/src/hardware-error-mappings.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,63 @@ export const LEDGER_ERROR_MAPPINGS = {
114114
userMessage: 'Ethereum app is out of date. Please update it to continue.',
115115
},
116116
};
117+
118+
export const BLE_ERROR_MAPPINGS = {
119+
BLUETOOTH_PERMISSION_DENIED: {
120+
code: ErrorCode.PermissionBluetoothDenied,
121+
message: 'Bluetooth permission denied',
122+
severity: Severity.Err,
123+
category: Category.Configuration,
124+
userMessage:
125+
'Bluetooth permission is required to connect to your hardware wallet. Please enable it in your device settings.',
126+
},
127+
LOCATION_PERMISSION_DENIED: {
128+
code: ErrorCode.PermissionLocationDenied,
129+
message: 'Location permission denied',
130+
severity: Severity.Err,
131+
category: Category.Configuration,
132+
userMessage:
133+
'Location permission is required for Bluetooth scanning on Android. Please enable it in your device settings.',
134+
},
135+
NEARBY_DEVICES_PERMISSION_DENIED: {
136+
code: ErrorCode.PermissionNearbyDevicesDenied,
137+
message: 'Nearby devices permission denied',
138+
severity: Severity.Err,
139+
category: Category.Configuration,
140+
userMessage:
141+
'Nearby devices permission is required to scan for your hardware wallet. Please enable it in your device settings.',
142+
},
143+
BLUETOOTH_DISABLED: {
144+
code: ErrorCode.BluetoothDisabled,
145+
message: 'Bluetooth is turned off',
146+
severity: Severity.Warning,
147+
category: Category.Connection,
148+
userMessage:
149+
'Bluetooth is turned off. Please enable Bluetooth to connect to your hardware wallet.',
150+
},
151+
BLUETOOTH_SCAN_FAILED: {
152+
code: ErrorCode.BluetoothScanFailed,
153+
message: 'Bluetooth scanning failed',
154+
severity: Severity.Err,
155+
category: Category.Connection,
156+
userMessage: 'Unable to scan for Bluetooth devices. Please try again.',
157+
},
158+
BLUETOOTH_CONNECTION_FAILED: {
159+
code: ErrorCode.BluetoothConnectionFailed,
160+
message: 'Bluetooth connection failed',
161+
severity: Severity.Err,
162+
category: Category.Connection,
163+
userMessage:
164+
'Failed to connect via Bluetooth. Please make sure your device is nearby and try again.',
165+
},
166+
};
167+
168+
export const MOBILE_ERROR_MAPPINGS = {
169+
NOT_SUPPORTED: {
170+
code: ErrorCode.MobileNotSupported,
171+
message: 'Operation not supported on mobile',
172+
severity: Severity.Err,
173+
category: Category.DeviceState,
174+
userMessage: 'This operation is not supported on mobile devices.',
175+
},
176+
};

packages/hw-wallet-sdk/src/hardware-errors-enums.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ export enum ErrorCode {
4848
DeviceStateEthAppClosed = 6003,
4949
DeviceStateEthAppOutOfDate = 6004,
5050

51+
// Mobile/BLE Permission Errors
52+
PermissionBluetoothDenied = 7000,
53+
PermissionLocationDenied = 7001,
54+
PermissionNearbyDevicesDenied = 7002,
55+
BluetoothDisabled = 7100,
56+
BluetoothScanFailed = 7101,
57+
BluetoothConnectionFailed = 7102,
58+
MobileNotSupported = 7300,
59+
5160
// Transaction
5261
TxInsufficientFunds = 10000,
5362

@@ -72,4 +81,5 @@ export enum Category {
7281
UserAction = 'UserAction',
7382
DeviceState = 'DeviceState',
7483
Unknown = 'Unknown',
84+
Configuration = 'Configuration',
7585
}

packages/keyring-internal-api/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **BREAKING:** Rename `KeyringRequestV1` type to `KeyringRequestWithoutOrigin` ([#423](https://github.com/MetaMask/accounts/pull/423))
13+
- **BREAKING:** Rename `toKeyringRequestV1` method to `toKeyringRequestWithoutOrigin` ([#423](https://github.com/MetaMask/accounts/pull/423))
14+
15+
### Removed
16+
17+
- **BREAKING:** Remove `KeyringVersion` support ([#423](https://github.com/MetaMask/accounts/pull/423))
18+
1019
## [9.1.1]
1120

1221
### Changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './v1';
1+
export * from './keyring-request';

packages/keyring-internal-api/src/compatibility/v1.test.ts renamed to packages/keyring-internal-api/src/compatibility/keyring-request.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { EthMethod, EthScope } from '@metamask/keyring-api';
22

3-
import { toKeyringRequestV1 } from './v1';
3+
import { toKeyringRequestWithoutOrigin } from './keyring-request';
44

55
describe('v1', () => {
6-
describe('toKeyringRequestV1', () => {
6+
describe('toKeyringRequestWithoutOrigin', () => {
77
const request = {
88
id: 'mock-request-id',
99
scope: EthScope.Mainnet,
@@ -17,7 +17,7 @@ describe('v1', () => {
1717
const { origin, ...requestV1 } = request;
1818

1919
it('converts a keyring request to a keyring request v1', () => {
20-
expect(toKeyringRequestV1(request)).toStrictEqual(requestV1);
20+
expect(toKeyringRequestWithoutOrigin(request)).toStrictEqual(requestV1);
2121
});
2222
});
2323
});

0 commit comments

Comments
 (0)