@ledgerhq/live-common 34.38.1 → 34.39.0-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/hw/getLatestFirmwareForDevice.js +4 -0
- package/lib/__tests__/hw/getLatestFirmwareForDevice.js.map +1 -1
- package/lib/__tests__/test-helpers/deviceInfos.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/deviceInfos.js +5 -0
- package/lib/__tests__/test-helpers/deviceInfos.js.map +1 -1
- package/lib/apps/mock.d.ts +2 -32
- package/lib/apps/mock.d.ts.map +1 -1
- package/lib/apps/mock.js +3 -0
- package/lib/apps/mock.js.map +1 -1
- package/lib/apps/polyfill.d.ts +4 -1
- package/lib/apps/polyfill.d.ts.map +1 -1
- package/lib/deposit/deposit.test.js +418 -74
- package/lib/deposit/deposit.test.js.map +1 -1
- package/lib/deposit/helper.d.ts +1 -0
- package/lib/deposit/helper.d.ts.map +1 -1
- package/lib/deposit/helper.js +19 -6
- package/lib/deposit/helper.js.map +1 -1
- package/lib/deviceSDK/tasks/getDeviceInfo.d.ts.map +1 -1
- package/lib/deviceSDK/tasks/getDeviceInfo.js +3 -1
- package/lib/deviceSDK/tasks/getDeviceInfo.js.map +1 -1
- package/lib/e2e/enum/Provider.d.ts +1 -1
- package/lib/e2e/enum/Provider.d.ts.map +1 -1
- package/lib/e2e/enum/Provider.js +1 -1
- package/lib/e2e/enum/Provider.js.map +1 -1
- package/lib/e2e/index.d.ts +2 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/e2e/swap.d.ts.map +1 -1
- package/lib/e2e/swap.js +10 -7
- package/lib/e2e/swap.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +24 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/hw/connectManager.d.ts.map +1 -1
- package/lib/hw/connectManager.js +9 -0
- package/lib/hw/connectManager.js.map +1 -1
- package/lib/hw/customLockScreenLoad.d.ts.map +1 -1
- package/lib/hw/customLockScreenLoad.js +22 -18
- package/lib/hw/customLockScreenLoad.js.map +1 -1
- package/lib/hw/customLockScreenLoad.test.d.ts +2 -0
- package/lib/hw/customLockScreenLoad.test.d.ts.map +1 -0
- package/lib/hw/customLockScreenLoad.test.js +63 -0
- package/lib/hw/customLockScreenLoad.test.js.map +1 -0
- package/lib/hw/extractOnboardingState.d.ts +15 -2
- package/lib/hw/extractOnboardingState.d.ts.map +1 -1
- package/lib/hw/extractOnboardingState.js +67 -19
- package/lib/hw/extractOnboardingState.js.map +1 -1
- package/lib/hw/extractOnboardingState.test.js +96 -1
- package/lib/hw/extractOnboardingState.test.js.map +1 -1
- package/lib/hw/getDeviceInfo.d.ts.map +1 -1
- package/lib/hw/getDeviceInfo.js +3 -1
- package/lib/hw/getDeviceInfo.js.map +1 -1
- package/lib/hw/getGenuineCheckFromDeviceId.test.js +1 -0
- package/lib/hw/getGenuineCheckFromDeviceId.test.js.map +1 -1
- package/lib/hw/getOnboardingStatePolling.js +1 -1
- package/lib/hw/getOnboardingStatePolling.js.map +1 -1
- package/lib/hw/getOnboardingStatePolling.test.js +2 -0
- package/lib/hw/getOnboardingStatePolling.test.js.map +1 -1
- package/lib/hw/isFirmwareUpdateVersionSupported.test.js +2 -1
- package/lib/hw/isFirmwareUpdateVersionSupported.test.js.map +1 -1
- package/lib/mock/fixtures/aDeviceInfo.d.ts.map +1 -1
- package/lib/mock/fixtures/aDeviceInfo.js +1 -0
- package/lib/mock/fixtures/aDeviceInfo.js.map +1 -1
- package/lib/onboarding/hooks/useOnboardingStatePolling.test.js +2 -0
- package/lib/onboarding/hooks/useOnboardingStatePolling.test.js.map +1 -1
- package/lib-es/__tests__/hw/getLatestFirmwareForDevice.js +4 -0
- package/lib-es/__tests__/hw/getLatestFirmwareForDevice.js.map +1 -1
- package/lib-es/__tests__/test-helpers/deviceInfos.d.ts.map +1 -1
- package/lib-es/__tests__/test-helpers/deviceInfos.js +5 -0
- package/lib-es/__tests__/test-helpers/deviceInfos.js.map +1 -1
- package/lib-es/apps/mock.d.ts +2 -32
- package/lib-es/apps/mock.d.ts.map +1 -1
- package/lib-es/apps/mock.js +3 -0
- package/lib-es/apps/mock.js.map +1 -1
- package/lib-es/apps/polyfill.d.ts +4 -1
- package/lib-es/apps/polyfill.d.ts.map +1 -1
- package/lib-es/deposit/deposit.test.js +419 -75
- package/lib-es/deposit/deposit.test.js.map +1 -1
- package/lib-es/deposit/helper.d.ts +1 -0
- package/lib-es/deposit/helper.d.ts.map +1 -1
- package/lib-es/deposit/helper.js +18 -6
- package/lib-es/deposit/helper.js.map +1 -1
- package/lib-es/deviceSDK/tasks/getDeviceInfo.d.ts.map +1 -1
- package/lib-es/deviceSDK/tasks/getDeviceInfo.js +3 -1
- package/lib-es/deviceSDK/tasks/getDeviceInfo.js.map +1 -1
- package/lib-es/e2e/enum/Provider.d.ts +1 -1
- package/lib-es/e2e/enum/Provider.d.ts.map +1 -1
- package/lib-es/e2e/enum/Provider.js +1 -1
- package/lib-es/e2e/enum/Provider.js.map +1 -1
- package/lib-es/e2e/index.d.ts +2 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/e2e/swap.d.ts.map +1 -1
- package/lib-es/e2e/swap.js +10 -7
- package/lib-es/e2e/swap.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +24 -0
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/hw/connectManager.d.ts.map +1 -1
- package/lib-es/hw/connectManager.js +9 -0
- package/lib-es/hw/connectManager.js.map +1 -1
- package/lib-es/hw/customLockScreenLoad.d.ts.map +1 -1
- package/lib-es/hw/customLockScreenLoad.js +22 -18
- package/lib-es/hw/customLockScreenLoad.js.map +1 -1
- package/lib-es/hw/customLockScreenLoad.test.d.ts +2 -0
- package/lib-es/hw/customLockScreenLoad.test.d.ts.map +1 -0
- package/lib-es/hw/customLockScreenLoad.test.js +58 -0
- package/lib-es/hw/customLockScreenLoad.test.js.map +1 -0
- package/lib-es/hw/extractOnboardingState.d.ts +15 -2
- package/lib-es/hw/extractOnboardingState.d.ts.map +1 -1
- package/lib-es/hw/extractOnboardingState.js +66 -18
- package/lib-es/hw/extractOnboardingState.js.map +1 -1
- package/lib-es/hw/extractOnboardingState.test.js +97 -2
- package/lib-es/hw/extractOnboardingState.test.js.map +1 -1
- package/lib-es/hw/getDeviceInfo.d.ts.map +1 -1
- package/lib-es/hw/getDeviceInfo.js +3 -1
- package/lib-es/hw/getDeviceInfo.js.map +1 -1
- package/lib-es/hw/getGenuineCheckFromDeviceId.test.js +1 -0
- package/lib-es/hw/getGenuineCheckFromDeviceId.test.js.map +1 -1
- package/lib-es/hw/getOnboardingStatePolling.js +1 -1
- package/lib-es/hw/getOnboardingStatePolling.js.map +1 -1
- package/lib-es/hw/getOnboardingStatePolling.test.js +2 -0
- package/lib-es/hw/getOnboardingStatePolling.test.js.map +1 -1
- package/lib-es/hw/isFirmwareUpdateVersionSupported.test.js +2 -1
- package/lib-es/hw/isFirmwareUpdateVersionSupported.test.js.map +1 -1
- package/lib-es/mock/fixtures/aDeviceInfo.d.ts.map +1 -1
- package/lib-es/mock/fixtures/aDeviceInfo.js +1 -0
- package/lib-es/mock/fixtures/aDeviceInfo.js.map +1 -1
- package/lib-es/onboarding/hooks/useOnboardingStatePolling.test.js +2 -0
- package/lib-es/onboarding/hooks/useOnboardingStatePolling.test.js.map +1 -1
- package/package.json +43 -43
- package/src/__tests__/hw/getLatestFirmwareForDevice.ts +8 -3
- package/src/__tests__/test-helpers/deviceInfos.ts +5 -0
- package/src/apps/mock.ts +5 -2
- package/src/deposit/deposit.test.ts +611 -136
- package/src/deposit/helper.ts +27 -9
- package/src/deviceSDK/tasks/getDeviceInfo.ts +3 -0
- package/src/e2e/enum/Provider.ts +1 -1
- package/src/e2e/swap.ts +12 -7
- package/src/featureFlags/defaultFeatures.ts +24 -0
- package/src/hw/connectManager.ts +18 -0
- package/src/hw/customLockScreenLoad.test.ts +86 -0
- package/src/hw/customLockScreenLoad.ts +31 -17
- package/src/hw/extractOnboardingState.test.ts +122 -2
- package/src/hw/extractOnboardingState.ts +81 -18
- package/src/hw/getDeviceInfo.ts +4 -1
- package/src/hw/getGenuineCheckFromDeviceId.test.ts +2 -1
- package/src/hw/getOnboardingStatePolling.test.ts +2 -0
- package/src/hw/getOnboardingStatePolling.ts +1 -1
- package/src/hw/isFirmwareUpdateVersionSupported.test.ts +3 -1
- package/src/mock/fixtures/aDeviceInfo.ts +1 -0
- package/src/onboarding/hooks/useOnboardingStatePolling.test.ts +2 -0
@@ -1,6 +1,8 @@
|
|
1
1
|
import { DeviceExtractOnboardingStateError } from "@ledgerhq/errors";
|
2
2
|
import { SeedPhraseType } from "@ledgerhq/types-live";
|
3
3
|
|
4
|
+
const CHARON_STEP_BIT_MASK = 0x1000;
|
5
|
+
|
4
6
|
const onboardingFlagsBytesLength = 4;
|
5
7
|
|
6
8
|
const onboardedMask = 0x04;
|
@@ -38,25 +40,34 @@ export enum OnboardingStep {
|
|
38
40
|
RecoverRestore = "RECOVER_RESTORE", // path "restore with Recover"
|
39
41
|
SafetyWarning = "SAFETY WARNING",
|
40
42
|
Ready = "READY",
|
43
|
+
BackupCharon = "BACKUP_CHARON",
|
44
|
+
RestoreCharon = "RESTORE_CHARON",
|
41
45
|
}
|
42
46
|
|
43
47
|
const fromBitsToOnboardingStep = new Map<number, OnboardingStep>([
|
44
|
-
[
|
45
|
-
[
|
46
|
-
[
|
47
|
-
[
|
48
|
-
[
|
49
|
-
[
|
50
|
-
[
|
51
|
-
[
|
52
|
-
[
|
53
|
-
[
|
54
|
-
[
|
55
|
-
[
|
56
|
-
[
|
57
|
-
[
|
58
|
-
[
|
59
|
-
[
|
48
|
+
[0x0, OnboardingStep.WelcomeScreen1],
|
49
|
+
[0x1, OnboardingStep.WelcomeScreen2],
|
50
|
+
[0x2, OnboardingStep.WelcomeScreen3],
|
51
|
+
[0x3, OnboardingStep.WelcomeScreen4],
|
52
|
+
[0x4, OnboardingStep.WelcomeScreenReminder],
|
53
|
+
[0x5, OnboardingStep.SetupChoice],
|
54
|
+
[0x6, OnboardingStep.Pin],
|
55
|
+
[0x7, OnboardingStep.NewDevice],
|
56
|
+
[0x8, OnboardingStep.NewDeviceConfirming],
|
57
|
+
[0x9, OnboardingStep.RestoreSeed],
|
58
|
+
[0xa, OnboardingStep.SafetyWarning],
|
59
|
+
[0xb, OnboardingStep.Ready],
|
60
|
+
[0xc, OnboardingStep.ChooseName],
|
61
|
+
[0xd, OnboardingStep.RecoverRestore],
|
62
|
+
[0xe, OnboardingStep.SetupChoiceRestore],
|
63
|
+
[0xf, OnboardingStep.OnboardingEarlyCheck],
|
64
|
+
[0x10, OnboardingStep.RestoreCharon],
|
65
|
+
[CHARON_STEP_BIT_MASK + 0x0, OnboardingStep.Ready], // default state, after boot, if no backup was pending, this is also the state right after the device is seeded (if it was seeded with Charon)
|
66
|
+
[CHARON_STEP_BIT_MASK + 0x1, OnboardingStep.Ready], // backup fully refused
|
67
|
+
[CHARON_STEP_BIT_MASK + 0x2, OnboardingStep.BackupCharon], // backup not started or fully refused, this is the state right after the device is seeded (unless it was seeded with Charon)
|
68
|
+
[CHARON_STEP_BIT_MASK + 0x3, OnboardingStep.BackupCharon], // backup process started but not finished
|
69
|
+
[CHARON_STEP_BIT_MASK + 0x4, OnboardingStep.BackupCharon], // backup done on RK and naming not finished
|
70
|
+
[CHARON_STEP_BIT_MASK + 0x5, OnboardingStep.Ready], // backup done on RK and backup-process exited
|
60
71
|
]);
|
61
72
|
|
62
73
|
export type OnboardingState = {
|
@@ -69,14 +80,36 @@ export type OnboardingState = {
|
|
69
80
|
|
70
81
|
currentOnboardingStep: OnboardingStep;
|
71
82
|
currentSeedWordIndex: number;
|
83
|
+
charonSupported: boolean;
|
84
|
+
charonStatus: CharonStatus | null;
|
72
85
|
};
|
73
86
|
|
87
|
+
export enum CharonStatus {
|
88
|
+
Rejected = 1,
|
89
|
+
Choice,
|
90
|
+
Running,
|
91
|
+
Naming,
|
92
|
+
Ready,
|
93
|
+
}
|
94
|
+
|
95
|
+
export const fromBitsToCharonStatusMap = new Map<number, CharonStatus>([
|
96
|
+
[0x1, CharonStatus.Rejected],
|
97
|
+
[0x2, CharonStatus.Choice],
|
98
|
+
[0x3, CharonStatus.Running],
|
99
|
+
[0x4, CharonStatus.Naming],
|
100
|
+
[0x5, CharonStatus.Ready],
|
101
|
+
]);
|
102
|
+
|
74
103
|
/**
|
75
104
|
* Extracts the onboarding state of the device
|
76
105
|
* @param flagsBytes Buffer of bytes of length onboardingFlagsBytesLength representing the device state flags
|
106
|
+
* @param charonStatusFlags Buffer of bytes of length charonStatusFlagsLength representing the charon status flags
|
77
107
|
* @returns An OnboardingState
|
78
108
|
*/
|
79
|
-
export const extractOnboardingState = (
|
109
|
+
export const extractOnboardingState = (
|
110
|
+
flagsBytes: Buffer,
|
111
|
+
charonState?: Buffer,
|
112
|
+
): OnboardingState => {
|
80
113
|
if (!flagsBytes || flagsBytes.length < onboardingFlagsBytesLength) {
|
81
114
|
throw new DeviceExtractOnboardingStateError("Incorrect onboarding flags bytes");
|
82
115
|
}
|
@@ -94,7 +127,7 @@ export const extractOnboardingState = (flagsBytes: Buffer): OnboardingState => {
|
|
94
127
|
}
|
95
128
|
|
96
129
|
const currentOnboardingStepBits = flagsBytes[3];
|
97
|
-
|
130
|
+
let currentOnboardingStep = fromBitsToOnboardingStep.get(currentOnboardingStepBits);
|
98
131
|
|
99
132
|
if (!currentOnboardingStep) {
|
100
133
|
throw new DeviceExtractOnboardingStateError(
|
@@ -104,11 +137,41 @@ export const extractOnboardingState = (flagsBytes: Buffer): OnboardingState => {
|
|
104
137
|
|
105
138
|
const currentSeedWordIndex = flagsBytes[2] & currentSeedWordIndexMask;
|
106
139
|
|
140
|
+
/*
|
141
|
+
* Once the device is seeded, there are some additional states for backing up with Charon (for devices that support it)
|
142
|
+
* There are 2 scenarios:
|
143
|
+
* - After the seeding of the device, the user goes through the safety warnings screens (step SafetyWarning), and then, compatible devices will display the backup screens.
|
144
|
+
* Then, the value of "currentOnboardingStep" is "Ready", and the additional information about the status of the backup is in the "charonState" buffer.
|
145
|
+
* - If the device is rebooted while the backup screens are displayed on the device, it will still display the backup screens when it is turned back on.
|
146
|
+
* Then, the value of "currentOnboardingStep" is "WelcomeScreen1", and the additional information about the status of the backup is in the "charonState" buffer.
|
147
|
+
*/
|
148
|
+
if (
|
149
|
+
isOnboarded &&
|
150
|
+
[OnboardingStep.Ready, OnboardingStep.WelcomeScreen1].includes(currentOnboardingStep) &&
|
151
|
+
charonState !== undefined
|
152
|
+
) {
|
153
|
+
currentOnboardingStep = fromBitsToOnboardingStep.get(charonState[0] + CHARON_STEP_BIT_MASK);
|
154
|
+
|
155
|
+
if (!currentOnboardingStep) {
|
156
|
+
throw new DeviceExtractOnboardingStateError(
|
157
|
+
"Incorrect onboarding bits for the current charon step",
|
158
|
+
);
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
const charonSupported = charonState !== undefined && charonState.length > 0;
|
163
|
+
const charonStatus =
|
164
|
+
charonSupported && fromBitsToCharonStatusMap.has(charonState[0])
|
165
|
+
? fromBitsToCharonStatusMap.get(charonState[0])!
|
166
|
+
: null;
|
167
|
+
|
107
168
|
return {
|
108
169
|
isOnboarded,
|
109
170
|
isInRecoveryMode,
|
110
171
|
seedPhraseType,
|
111
172
|
currentOnboardingStep,
|
112
173
|
currentSeedWordIndex,
|
174
|
+
charonSupported,
|
175
|
+
charonStatus,
|
113
176
|
};
|
114
177
|
};
|
package/src/hw/getDeviceInfo.ts
CHANGED
@@ -61,10 +61,11 @@ export default async function (transport: Transport): Promise<DeviceInfo> {
|
|
61
61
|
mcuBlVersion,
|
62
62
|
mcuVersion,
|
63
63
|
mcuTargetId,
|
64
|
-
flags,
|
65
64
|
bootloaderVersion,
|
66
65
|
hardwareVersion,
|
67
66
|
languageId,
|
67
|
+
charonState,
|
68
|
+
flags,
|
68
69
|
} = res;
|
69
70
|
const isOSU = rawVersion.includes("-osu");
|
70
71
|
const version = rawVersion.replace("-osu", "");
|
@@ -114,5 +115,7 @@ export default async function (transport: Transport): Promise<DeviceInfo> {
|
|
114
115
|
bootloaderVersion,
|
115
116
|
hardwareVersion,
|
116
117
|
languageId,
|
118
|
+
charonState,
|
119
|
+
seFlags: flags,
|
117
120
|
};
|
118
121
|
}
|
@@ -41,7 +41,7 @@ jest.mock("./genuineCheck");
|
|
41
41
|
const mockedGetDeviceInfo = jest.mocked(getDeviceInfo);
|
42
42
|
const mockedGenuineCheck = jest.mocked(genuineCheck);
|
43
43
|
|
44
|
-
const aDeviceInfo = {
|
44
|
+
const aDeviceInfo: DeviceInfo = {
|
45
45
|
mcuVersion: "A_MCU_VERSION",
|
46
46
|
version: "A_VERSION",
|
47
47
|
majMin: "A_MAJ_MIN",
|
@@ -51,6 +51,7 @@ const aDeviceInfo = {
|
|
51
51
|
providerName: undefined,
|
52
52
|
managerAllowed: false,
|
53
53
|
pinValidated: true,
|
54
|
+
seFlags: Buffer.alloc(0),
|
54
55
|
};
|
55
56
|
|
56
57
|
describe("getGenuineCheckFromDeviceId", () => {
|
@@ -83,7 +83,7 @@ export const getOnboardingStatePolling = ({
|
|
83
83
|
}
|
84
84
|
|
85
85
|
try {
|
86
|
-
onboardingState = extractOnboardingState(firmwareInfo.flags);
|
86
|
+
onboardingState = extractOnboardingState(firmwareInfo.flags, firmwareInfo.charonState);
|
87
87
|
} catch (error: unknown) {
|
88
88
|
if (error instanceof DeviceExtractOnboardingStateError) {
|
89
89
|
return {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { DeviceModelId } from "@ledgerhq/devices";
|
2
|
+
import { DeviceInfo } from "@ledgerhq/types-live";
|
2
3
|
import isFirmwareUpdateVersionSupported from "./isFirmwareUpdateVersionSupported";
|
3
4
|
import { setEnv } from "@ledgerhq/live-env";
|
4
5
|
|
@@ -17,7 +18,7 @@ const badDataset: { [key in DeviceModelId]?: string[] } = {
|
|
17
18
|
};
|
18
19
|
|
19
20
|
describe("Firmware update version availability checks", () => {
|
20
|
-
const getDeviceInfo = version => ({
|
21
|
+
const getDeviceInfo = (version): DeviceInfo => ({
|
21
22
|
version,
|
22
23
|
mcuVersion: "0.0",
|
23
24
|
majMin: "0.0",
|
@@ -27,6 +28,7 @@ describe("Firmware update version availability checks", () => {
|
|
27
28
|
isBootloader: false,
|
28
29
|
managerAllowed: false,
|
29
30
|
pinValidated: false,
|
31
|
+
seFlags: Buffer.alloc(0),
|
30
32
|
});
|
31
33
|
|
32
34
|
describe("Fails with bad values", () => {
|
@@ -36,6 +36,8 @@ describe("useOnboardingStatePolling", () => {
|
|
36
36
|
seedPhraseType: SeedPhraseType.TwentyFour,
|
37
37
|
currentSeedWordIndex: 0,
|
38
38
|
currentOnboardingStep: OnboardingStep.NewDevice,
|
39
|
+
charonSupported: false,
|
40
|
+
charonStatus: null,
|
39
41
|
};
|
40
42
|
|
41
43
|
aSecondOnboardingState = {
|