@ledgerhq/device-core 0.3.3 → 0.3.4-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/CHANGELOG.md +7 -0
- package/lib/commands/entities/ReinstallConfigEntity.d.ts +7 -0
- package/lib/commands/entities/ReinstallConfigEntity.d.ts.map +1 -0
- package/lib/commands/entities/ReinstallConfigEntity.js +10 -0
- package/lib/commands/entities/ReinstallConfigEntity.js.map +1 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.d.ts +19 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.d.ts.map +1 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.js +79 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.js.map +1 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.test.d.ts +2 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.test.d.ts.map +1 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.test.js +48 -0
- package/lib/commands/use-cases/consent/reinstallConfigurationConsent.test.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib-es/commands/entities/ReinstallConfigEntity.d.ts +7 -0
- package/lib-es/commands/entities/ReinstallConfigEntity.d.ts.map +1 -0
- package/lib-es/commands/entities/ReinstallConfigEntity.js +9 -0
- package/lib-es/commands/entities/ReinstallConfigEntity.js.map +1 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.d.ts +19 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.d.ts.map +1 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.js +74 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.js.map +1 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.test.d.ts +2 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.test.d.ts.map +1 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.test.js +46 -0
- package/lib-es/commands/use-cases/consent/reinstallConfigurationConsent.test.js.map +1 -0
- package/lib-es/index.d.ts +2 -0
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +2 -0
- package/lib-es/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/entities/ReinstallConfigEntity.ts +15 -0
- package/src/commands/use-cases/consent/reinstallConfigurationConsent.test.ts +56 -0
- package/src/commands/use-cases/consent/reinstallConfigurationConsent.ts +75 -0
- package/src/index.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @ledgerhq/device-core
|
|
2
2
|
|
|
3
|
+
## 0.3.4-nightly.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`672875f`](https://github.com/LedgerHQ/ledger-live/commit/672875feb9876edacf06aaea6c7bb47f4bb7d993)]:
|
|
8
|
+
- @ledgerhq/types-live@6.51.1-nightly.0
|
|
9
|
+
|
|
3
10
|
## 0.3.3
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReinstallConfigEntity.d.ts","sourceRoot":"","sources":["../../../src/commands/entities/ReinstallConfigEntity.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAEhC,qBAAqB,EAAE,IAAI,GAAG,IAAI;IAClC,yBAAyB,EAAE,IAAI,GAAG,IAAI;IACtC,gBAAgB,EAAE,MAAM;IACxB,mBAAmB,EAAE,MAAM;CAC5B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// TODO: model used when getting the config from the device before a software update
|
|
4
|
+
// export type ReinstallConfig = {
|
|
5
|
+
// languageId?: LanguageId,
|
|
6
|
+
// CustomLockScreen?: CustomLockScreen,
|
|
7
|
+
// reinstallApps: AppName[],
|
|
8
|
+
// reinstallStorage: AppName[],
|
|
9
|
+
// };
|
|
10
|
+
//# sourceMappingURL=ReinstallConfigEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReinstallConfigEntity.js","sourceRoot":"","sources":["../../../src/commands/entities/ReinstallConfigEntity.ts"],"names":[],"mappings":";;AAQA,oFAAoF;AACpF,kCAAkC;AAClC,6BAA6B;AAC7B,yCAAyC;AACzC,8BAA8B;AAC9B,iCAAiC;AACjC,KAAK"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import type { ReinstallConfigArgs } from "../../entities/ReinstallConfigEntity";
|
|
4
|
+
/**
|
|
5
|
+
* Requests consent from the user to allow reinstalling all the previous
|
|
6
|
+
* settings after an OS update.
|
|
7
|
+
*
|
|
8
|
+
* @param transport - The transport object used to communicate with the device.
|
|
9
|
+
* @returns A promise that resolves when the consent is granted.
|
|
10
|
+
*/
|
|
11
|
+
export declare function reinstallConfigurationConsent(transport: Transport, args: ReinstallConfigArgs): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Parses the response data buffer, check the status code and return the data.
|
|
14
|
+
*
|
|
15
|
+
* @param data - The response data buffer w/ status code.
|
|
16
|
+
* @returns The response data as a buffer w/o status code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseResponse(data: Buffer): void;
|
|
19
|
+
//# sourceMappingURL=reinstallConfigurationConsent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.d.ts","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.ts"],"names":[],"mappings":";AAAA,OAAO,SAAgD,MAAM,wBAAwB,CAAC;AAItF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAuBhF;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAiBhD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.parseResponse = exports.reinstallConfigurationConsent = void 0;
|
|
13
|
+
const hw_transport_1 = require("@ledgerhq/hw-transport");
|
|
14
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
15
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
16
|
+
/**
|
|
17
|
+
* Name in documentation: REINSTALL_CONFIG
|
|
18
|
+
* cla: 0xe0
|
|
19
|
+
* ins: 0x6f
|
|
20
|
+
* p1: 0x00
|
|
21
|
+
* p2: 0x00
|
|
22
|
+
* data: CHUNK_LEN + CHUNK to configure at runtime
|
|
23
|
+
*/
|
|
24
|
+
const REINSTALL_CONFIG = [0xe0, 0x6f, 0x00, 0x00];
|
|
25
|
+
/**
|
|
26
|
+
* 0x9000: Success.
|
|
27
|
+
* 0xYYYY: already in REINSTALL mode
|
|
28
|
+
* 0xZZZZ: if other error (TBD)
|
|
29
|
+
*/
|
|
30
|
+
const RESPONSE_STATUS_SET = [
|
|
31
|
+
hw_transport_1.StatusCodes.OK,
|
|
32
|
+
hw_transport_1.StatusCodes.USER_REFUSED_ON_DEVICE,
|
|
33
|
+
hw_transport_1.StatusCodes.PIN_NOT_SET,
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Requests consent from the user to allow reinstalling all the previous
|
|
37
|
+
* settings after an OS update.
|
|
38
|
+
*
|
|
39
|
+
* @param transport - The transport object used to communicate with the device.
|
|
40
|
+
* @returns A promise that resolves when the consent is granted.
|
|
41
|
+
*/
|
|
42
|
+
function reinstallConfigurationConsent(transport, args) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const tracer = new logs_1.LocalTracer("hw", {
|
|
45
|
+
transport: transport.getTraceContext(),
|
|
46
|
+
function: "reinstallConfigurationConsent",
|
|
47
|
+
});
|
|
48
|
+
tracer.trace("Start");
|
|
49
|
+
const apdu = [...REINSTALL_CONFIG, Buffer.from(args)];
|
|
50
|
+
const response = yield transport.send(...apdu, RESPONSE_STATUS_SET);
|
|
51
|
+
return parseResponse(response);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.reinstallConfigurationConsent = reinstallConfigurationConsent;
|
|
55
|
+
/**
|
|
56
|
+
* Parses the response data buffer, check the status code and return the data.
|
|
57
|
+
*
|
|
58
|
+
* @param data - The response data buffer w/ status code.
|
|
59
|
+
* @returns The response data as a buffer w/o status code.
|
|
60
|
+
*/
|
|
61
|
+
function parseResponse(data) {
|
|
62
|
+
const tracer = new logs_1.LocalTracer("hw", {
|
|
63
|
+
function: "parseResponse@reinstallConfigurationConsent",
|
|
64
|
+
});
|
|
65
|
+
const status = data.readUInt16BE(data.length - 2);
|
|
66
|
+
tracer.trace("Result status from 0xe06f0000", { status });
|
|
67
|
+
switch (status) {
|
|
68
|
+
case hw_transport_1.StatusCodes.OK:
|
|
69
|
+
return;
|
|
70
|
+
case hw_transport_1.StatusCodes.USER_REFUSED_ON_DEVICE:
|
|
71
|
+
throw new errors_1.UserRefusedOnDevice("User refused on device");
|
|
72
|
+
case hw_transport_1.StatusCodes.PIN_NOT_SET:
|
|
73
|
+
throw new errors_1.PinNotSet("PIN not set");
|
|
74
|
+
default:
|
|
75
|
+
throw new hw_transport_1.TransportStatusError(status);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.parseResponse = parseResponse;
|
|
79
|
+
//# sourceMappingURL=reinstallConfigurationConsent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.js","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAsF;AACtF,yCAA6C;AAC7C,6CAAkE;AAIlE;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAC;AAE3D;;;;GAIG;AACH,MAAM,mBAAmB,GAAa;IACpC,0BAAW,CAAC,EAAE;IACd,0BAAW,CAAC,sBAAsB;IAClC,0BAAW,CAAC,WAAW;CACxB,CAAC;AAEF;;;;;;GAMG;AACH,SAAsB,6BAA6B,CACjD,SAAoB,EACpB,IAAyB;;QAEzB,MAAM,MAAM,GAAG,IAAI,kBAAW,CAAC,IAAI,EAAE;YACnC,SAAS,EAAE,SAAS,CAAC,eAAe,EAAE;YACtC,QAAQ,EAAE,+BAA+B;SAC1C,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEtB,MAAM,IAAI,GAAmB,CAAC,GAAG,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEtE,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,mBAAmB,CAAC,CAAC;QAEpE,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;CAAA;AAfD,sEAeC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,MAAM,GAAG,IAAI,kBAAW,CAAC,IAAI,EAAE;QACnC,QAAQ,EAAE,6CAA6C;KACxD,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE1D,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,0BAAW,CAAC,EAAE;YACjB,OAAO;QACT,KAAK,0BAAW,CAAC,sBAAsB;YACrC,MAAM,IAAI,4BAAmB,CAAC,wBAAwB,CAAC,CAAC;QAC1D,KAAK,0BAAW,CAAC,WAAW;YAC1B,MAAM,IAAI,kBAAS,CAAC,aAAa,CAAC,CAAC;QACrC;YACE,MAAM,IAAI,mCAAoB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAjBD,sCAiBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const hw_transport_1 = require("@ledgerhq/hw-transport");
|
|
13
|
+
const reinstallConfigurationConsent_1 = require("./reinstallConfigurationConsent");
|
|
14
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
15
|
+
describe("reinstallConfigurationConsent", () => {
|
|
16
|
+
let transport;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
transport = {
|
|
19
|
+
send: jest.fn().mockResolvedValue(Buffer.from([])),
|
|
20
|
+
getTraceContext: jest.fn().mockResolvedValue(undefined),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
jest.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
describe("success cases", () => {
|
|
27
|
+
it("should call the send function with correct parameters", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x90, 0x00]));
|
|
29
|
+
yield (0, reinstallConfigurationConsent_1.reinstallConfigurationConsent)(transport, [0x00, 0x00, 0x00, 0x00]);
|
|
30
|
+
expect(transport.send).toHaveBeenCalledWith(0xe0, 0x6f, 0x00, 0x00, Buffer.from([0x00, 0x00, 0x00, 0x00]), [hw_transport_1.StatusCodes.OK, hw_transport_1.StatusCodes.USER_REFUSED_ON_DEVICE, hw_transport_1.StatusCodes.PIN_NOT_SET]);
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
describe("error cases", () => {
|
|
34
|
+
it("should throw UserRefusedOnDevice if the user refused on device", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x55, 0x01]));
|
|
36
|
+
yield expect((0, reinstallConfigurationConsent_1.reinstallConfigurationConsent)(transport, [0x00, 0x00, 0x00, 0x00])).rejects.toThrow(new errors_1.UserRefusedOnDevice("User refused on device"));
|
|
37
|
+
}));
|
|
38
|
+
it("should throw PINNotSet if the PIN is not set", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x55, 0x02]));
|
|
40
|
+
yield expect((0, reinstallConfigurationConsent_1.reinstallConfigurationConsent)(transport, [0x00, 0x00, 0x00, 0x00])).rejects.toThrow(new errors_1.PinNotSet("PIN not set"));
|
|
41
|
+
}));
|
|
42
|
+
it("should throw TransportStatusError if the response status is invalid", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x6f, 0x00]));
|
|
44
|
+
yield expect((0, reinstallConfigurationConsent_1.reinstallConfigurationConsent)(transport, [0x00, 0x00, 0x00, 0x00])).rejects.toThrow(new hw_transport_1.TransportStatusError(0x6f00));
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=reinstallConfigurationConsent.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.test.js","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yDAAsF;AACtF,mFAAgF;AAChF,6CAAkE;AAElE,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,IAAI,SAAoB,CAAC;IAEzB,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG;YACV,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClD,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;SAChC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG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EH,EAAE,CAAC,8CAA8C,EAAE,GAAS,EAAE;YAC5D,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,MAAM,CACV,IAAA,6DAA6B,EAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CACnE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,kBAAS,CAAC,aAAa,CAAC,CAAC,CAAC;QAClD,CAAC,CAAA,CAAC,CAAC;QAEH,EAAE,CAAC,qEAAqE,EAAE,GAAS,EAAE;YACnF,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,MAAM,CACV,IAAA,6DAA6B,EAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CACnE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,mCAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;QACtD,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { DeviceInfoEntity } from "./managerApi/entities/DeviceInfoEntity";
|
|
2
2
|
export type { FinalFirmware, OsuFirmware, FirmwareUpdateContextEntity, } from "./managerApi/entities/FirmwareUpdateContextEntity";
|
|
3
|
+
export type { ReinstallConfigArgs } from "./commands/entities/ReinstallConfigEntity";
|
|
3
4
|
export type { ManagerApiRepository } from "./managerApi/repositories/ManagerApiRepository";
|
|
4
5
|
export { HttpManagerApiRepository } from "./managerApi/repositories/HttpManagerApiRepository";
|
|
5
6
|
export { StubManagerApiRepository } from "./managerApi/repositories/StubManagerApiRepository";
|
|
@@ -29,4 +30,5 @@ export { supportedDeviceModelIds } from "./capabilities/isCustomLockScreenSuppor
|
|
|
29
30
|
export * from "./customLockScreen/screenSpecs";
|
|
30
31
|
export { shouldForceFirmwareUpdate } from "./firmwareUpdate/shouldForceFirmwareUpdate";
|
|
31
32
|
export * from "./errors";
|
|
33
|
+
export { reinstallConfigurationConsent } from "./commands/use-cases/consent/reinstallConfigurationConsent";
|
|
32
34
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,YAAY,EACV,aAAa,EACb,WAAW,EACX,2BAA2B,GAC5B,MAAM,mDAAmD,CAAC;AAC3D,YAAY,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,mDAAmD,CAAC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AAEzF,YAAY,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,uBA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AAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AAErF,cAAc,gCAAgC,CAAC;AAE/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.shouldForceFirmwareUpdate = exports.supportedDeviceModelIds = exports.isSyncOnboardingSupported = exports.isEditDeviceNameSupported = exports.isCustomLockScreenSupported = exports.restoreAppStorageInit = exports.restoreAppStorageCommit = exports.restoreAppStorage = exports.getAppStorageInfo = exports.backupAppStorage = exports.isAppStorageInfo = exports.getVersion = exports.isBootloaderVersionSupported = exports.isHardwareVersionSupported = exports.getDeviceName = exports.parseGetVersionResponse = exports.GET_VERSION_APDU = exports.getAppsCatalogForDevice = exports.aDeviceInfoBuilder = exports.fetchMcus = exports.getProviderIdUseCase = exports.PROVIDERS = exports.isDeviceLocalizationSupported = exports.getLatestFirmwareForDevice = exports.StubManagerApiRepository = exports.HttpManagerApiRepository = void 0;
|
|
17
|
+
exports.reinstallConfigurationConsent = exports.shouldForceFirmwareUpdate = exports.supportedDeviceModelIds = exports.isSyncOnboardingSupported = exports.isEditDeviceNameSupported = exports.isCustomLockScreenSupported = exports.restoreAppStorageInit = exports.restoreAppStorageCommit = exports.restoreAppStorage = exports.getAppStorageInfo = exports.backupAppStorage = exports.isAppStorageInfo = exports.getVersion = exports.isBootloaderVersionSupported = exports.isHardwareVersionSupported = exports.getDeviceName = exports.parseGetVersionResponse = exports.GET_VERSION_APDU = exports.getAppsCatalogForDevice = exports.aDeviceInfoBuilder = exports.fetchMcus = exports.getProviderIdUseCase = exports.PROVIDERS = exports.isDeviceLocalizationSupported = exports.getLatestFirmwareForDevice = exports.StubManagerApiRepository = exports.HttpManagerApiRepository = void 0;
|
|
18
18
|
var HttpManagerApiRepository_1 = require("./managerApi/repositories/HttpManagerApiRepository");
|
|
19
19
|
Object.defineProperty(exports, "HttpManagerApiRepository", { enumerable: true, get: function () { return HttpManagerApiRepository_1.HttpManagerApiRepository; } });
|
|
20
20
|
var StubManagerApiRepository_1 = require("./managerApi/repositories/StubManagerApiRepository");
|
|
@@ -72,4 +72,7 @@ var shouldForceFirmwareUpdate_1 = require("./firmwareUpdate/shouldForceFirmwareU
|
|
|
72
72
|
Object.defineProperty(exports, "shouldForceFirmwareUpdate", { enumerable: true, get: function () { return shouldForceFirmwareUpdate_1.shouldForceFirmwareUpdate; } });
|
|
73
73
|
// errors
|
|
74
74
|
__exportStar(require("./errors"), exports);
|
|
75
|
+
// src/commands/consent/
|
|
76
|
+
var reinstallConfigurationConsent_1 = require("./commands/use-cases/consent/reinstallConfigurationConsent");
|
|
77
|
+
Object.defineProperty(exports, "reinstallConfigurationConsent", { enumerable: true, get: function () { return reinstallConfigurationConsent_1.reinstallConfigurationConsent; } });
|
|
75
78
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AASA,+FAA8F;AAArF,oIAAA,wBAAwB,OAAA;AACjC,+FAA8F;AAArF,oIAAA,wBAAwB,OAAA;AACjC,gGAA+F;AAAtF,wIAAA,0BAA0B,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.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAEhC,qBAAqB,EAAE,IAAI,GAAG,IAAI;IAClC,yBAAyB,EAAE,IAAI,GAAG,IAAI;IACtC,gBAAgB,EAAE,MAAM;IACxB,mBAAmB,EAAE,MAAM;CAC5B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
// TODO: model used when getting the config from the device before a software update
|
|
3
|
+
// export type ReinstallConfig = {
|
|
4
|
+
// languageId?: LanguageId,
|
|
5
|
+
// CustomLockScreen?: CustomLockScreen,
|
|
6
|
+
// reinstallApps: AppName[],
|
|
7
|
+
// reinstallStorage: AppName[],
|
|
8
|
+
// };
|
|
9
|
+
//# sourceMappingURL=ReinstallConfigEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReinstallConfigEntity.js","sourceRoot":"","sources":["../../../src/commands/entities/ReinstallConfigEntity.ts"],"names":[],"mappings":";AAQA,oFAAoF;AACpF,kCAAkC;AAClC,6BAA6B;AAC7B,yCAAyC;AACzC,8BAA8B;AAC9B,iCAAiC;AACjC,KAAK"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import type { ReinstallConfigArgs } from "../../entities/ReinstallConfigEntity";
|
|
4
|
+
/**
|
|
5
|
+
* Requests consent from the user to allow reinstalling all the previous
|
|
6
|
+
* settings after an OS update.
|
|
7
|
+
*
|
|
8
|
+
* @param transport - The transport object used to communicate with the device.
|
|
9
|
+
* @returns A promise that resolves when the consent is granted.
|
|
10
|
+
*/
|
|
11
|
+
export declare function reinstallConfigurationConsent(transport: Transport, args: ReinstallConfigArgs): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Parses the response data buffer, check the status code and return the data.
|
|
14
|
+
*
|
|
15
|
+
* @param data - The response data buffer w/ status code.
|
|
16
|
+
* @returns The response data as a buffer w/o status code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseResponse(data: Buffer): void;
|
|
19
|
+
//# sourceMappingURL=reinstallConfigurationConsent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.d.ts","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.ts"],"names":[],"mappings":";AAAA,OAAO,SAAgD,MAAM,wBAAwB,CAAC;AAItF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAuBhF;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAiBhD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { StatusCodes, TransportStatusError } from "@ledgerhq/hw-transport";
|
|
11
|
+
import { LocalTracer } from "@ledgerhq/logs";
|
|
12
|
+
import { UserRefusedOnDevice, PinNotSet } from "@ledgerhq/errors";
|
|
13
|
+
/**
|
|
14
|
+
* Name in documentation: REINSTALL_CONFIG
|
|
15
|
+
* cla: 0xe0
|
|
16
|
+
* ins: 0x6f
|
|
17
|
+
* p1: 0x00
|
|
18
|
+
* p2: 0x00
|
|
19
|
+
* data: CHUNK_LEN + CHUNK to configure at runtime
|
|
20
|
+
*/
|
|
21
|
+
const REINSTALL_CONFIG = [0xe0, 0x6f, 0x00, 0x00];
|
|
22
|
+
/**
|
|
23
|
+
* 0x9000: Success.
|
|
24
|
+
* 0xYYYY: already in REINSTALL mode
|
|
25
|
+
* 0xZZZZ: if other error (TBD)
|
|
26
|
+
*/
|
|
27
|
+
const RESPONSE_STATUS_SET = [
|
|
28
|
+
StatusCodes.OK,
|
|
29
|
+
StatusCodes.USER_REFUSED_ON_DEVICE,
|
|
30
|
+
StatusCodes.PIN_NOT_SET,
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Requests consent from the user to allow reinstalling all the previous
|
|
34
|
+
* settings after an OS update.
|
|
35
|
+
*
|
|
36
|
+
* @param transport - The transport object used to communicate with the device.
|
|
37
|
+
* @returns A promise that resolves when the consent is granted.
|
|
38
|
+
*/
|
|
39
|
+
export function reinstallConfigurationConsent(transport, args) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const tracer = new LocalTracer("hw", {
|
|
42
|
+
transport: transport.getTraceContext(),
|
|
43
|
+
function: "reinstallConfigurationConsent",
|
|
44
|
+
});
|
|
45
|
+
tracer.trace("Start");
|
|
46
|
+
const apdu = [...REINSTALL_CONFIG, Buffer.from(args)];
|
|
47
|
+
const response = yield transport.send(...apdu, RESPONSE_STATUS_SET);
|
|
48
|
+
return parseResponse(response);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parses the response data buffer, check the status code and return the data.
|
|
53
|
+
*
|
|
54
|
+
* @param data - The response data buffer w/ status code.
|
|
55
|
+
* @returns The response data as a buffer w/o status code.
|
|
56
|
+
*/
|
|
57
|
+
export function parseResponse(data) {
|
|
58
|
+
const tracer = new LocalTracer("hw", {
|
|
59
|
+
function: "parseResponse@reinstallConfigurationConsent",
|
|
60
|
+
});
|
|
61
|
+
const status = data.readUInt16BE(data.length - 2);
|
|
62
|
+
tracer.trace("Result status from 0xe06f0000", { status });
|
|
63
|
+
switch (status) {
|
|
64
|
+
case StatusCodes.OK:
|
|
65
|
+
return;
|
|
66
|
+
case StatusCodes.USER_REFUSED_ON_DEVICE:
|
|
67
|
+
throw new UserRefusedOnDevice("User refused on device");
|
|
68
|
+
case StatusCodes.PIN_NOT_SET:
|
|
69
|
+
throw new PinNotSet("PIN not set");
|
|
70
|
+
default:
|
|
71
|
+
throw new TransportStatusError(status);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=reinstallConfigurationConsent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.js","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlE;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAC;AAE3D;;;;GAIG;AACH,MAAM,mBAAmB,GAAa;IACpC,WAAW,CAAC,EAAE;IACd,WAAW,CAAC,sBAAsB;IAClC,WAAW,CAAC,WAAW;CACxB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAgB,6BAA6B,CACjD,SAAoB,EACpB,IAAyB;;QAEzB,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE;YACnC,SAAS,EAAE,SAAS,CAAC,eAAe,EAAE;YACtC,QAAQ,EAAE,+BAA+B;SAC1C,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEtB,MAAM,IAAI,GAAmB,CAAC,GAAG,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEtE,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,mBAAmB,CAAC,CAAC;QAEpE,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE;QACnC,QAAQ,EAAE,6CAA6C;KACxD,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE1D,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,WAAW,CAAC,EAAE;YACjB,OAAO;QACT,KAAK,WAAW,CAAC,sBAAsB;YACrC,MAAM,IAAI,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;QAC1D,KAAK,WAAW,CAAC,WAAW;YAC1B,MAAM,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC;QACrC;YACE,MAAM,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { StatusCodes, TransportStatusError } from "@ledgerhq/hw-transport";
|
|
11
|
+
import { reinstallConfigurationConsent } from "./reinstallConfigurationConsent";
|
|
12
|
+
import { PinNotSet, UserRefusedOnDevice } from "@ledgerhq/errors";
|
|
13
|
+
describe("reinstallConfigurationConsent", () => {
|
|
14
|
+
let transport;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
transport = {
|
|
17
|
+
send: jest.fn().mockResolvedValue(Buffer.from([])),
|
|
18
|
+
getTraceContext: jest.fn().mockResolvedValue(undefined),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
describe("success cases", () => {
|
|
25
|
+
it("should call the send function with correct parameters", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x90, 0x00]));
|
|
27
|
+
yield reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00]);
|
|
28
|
+
expect(transport.send).toHaveBeenCalledWith(0xe0, 0x6f, 0x00, 0x00, Buffer.from([0x00, 0x00, 0x00, 0x00]), [StatusCodes.OK, StatusCodes.USER_REFUSED_ON_DEVICE, StatusCodes.PIN_NOT_SET]);
|
|
29
|
+
}));
|
|
30
|
+
});
|
|
31
|
+
describe("error cases", () => {
|
|
32
|
+
it("should throw UserRefusedOnDevice if the user refused on device", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x55, 0x01]));
|
|
34
|
+
yield expect(reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00])).rejects.toThrow(new UserRefusedOnDevice("User refused on device"));
|
|
35
|
+
}));
|
|
36
|
+
it("should throw PINNotSet if the PIN is not set", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x55, 0x02]));
|
|
38
|
+
yield expect(reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00])).rejects.toThrow(new PinNotSet("PIN not set"));
|
|
39
|
+
}));
|
|
40
|
+
it("should throw TransportStatusError if the response status is invalid", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x6f, 0x00]));
|
|
42
|
+
yield expect(reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00])).rejects.toThrow(new TransportStatusError(0x6f00));
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=reinstallConfigurationConsent.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reinstallConfigurationConsent.test.js","sourceRoot":"","sources":["../../../../src/commands/use-cases/consent/reinstallConfigurationConsent.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAElE,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,IAAI,SAAoB,CAAC;IAEzB,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG;YACV,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,EA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,IAAI,CAAC,CAAC,CACnE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,mBAAmB,CAAC,wBAAwB,CAAC,CAAC,CAAC;QACvE,CAAC,CAAA,CAAC,CAAC;QAEH,EAAE,CAAC,8CAA8C,EAAE,GAAS,EAAE;YAC5D,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,MAAM,CACV,6BAA6B,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CACnE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;QAClD,CAAC,CAAA,CAAC,CAAC;QAEH,EAAE,CAAC,qEAAqE,EAAE,GAAS,EAAE;YACnF,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACxE,MAAM,MAAM,CACV,6BAA6B,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CACnE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;QACtD,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { DeviceInfoEntity } from "./managerApi/entities/DeviceInfoEntity";
|
|
2
2
|
export type { FinalFirmware, OsuFirmware, FirmwareUpdateContextEntity, } from "./managerApi/entities/FirmwareUpdateContextEntity";
|
|
3
|
+
export type { ReinstallConfigArgs } from "./commands/entities/ReinstallConfigEntity";
|
|
3
4
|
export type { ManagerApiRepository } from "./managerApi/repositories/ManagerApiRepository";
|
|
4
5
|
export { HttpManagerApiRepository } from "./managerApi/repositories/HttpManagerApiRepository";
|
|
5
6
|
export { StubManagerApiRepository } from "./managerApi/repositories/StubManagerApiRepository";
|
|
@@ -29,4 +30,5 @@ export { supportedDeviceModelIds } from "./capabilities/isCustomLockScreenSuppor
|
|
|
29
30
|
export * from "./customLockScreen/screenSpecs";
|
|
30
31
|
export { shouldForceFirmwareUpdate } from "./firmwareUpdate/shouldForceFirmwareUpdate";
|
|
31
32
|
export * from "./errors";
|
|
33
|
+
export { reinstallConfigurationConsent } from "./commands/use-cases/consent/reinstallConfigurationConsent";
|
|
32
34
|
//# sourceMappingURL=index.d.ts.map
|
package/lib-es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,YAAY,EACV,aAAa,EACb,WAAW,EACX,2BAA2B,GAC5B,MAAM,mDAAmD,CAAC;AAC3D,YAAY,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,mDAAmD,CAAC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AA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E,qBAAqB,EAAE,MAAM,uDAAuD,CAAC;AAE9F,OAAO,EACL,KAAK,yBAAyB,EAC9B,2BAA2B,GAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AAErF,cAAc,gCAAgC,CAAC;AAE/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,6BAA6B,EAAE,MAAM,4DAA4D,CAAC"}
|
package/lib-es/index.js
CHANGED
|
@@ -29,4 +29,6 @@ export * from "./customLockScreen/screenSpecs";
|
|
|
29
29
|
export { shouldForceFirmwareUpdate } from "./firmwareUpdate/shouldForceFirmwareUpdate";
|
|
30
30
|
// errors
|
|
31
31
|
export * from "./errors";
|
|
32
|
+
// src/commands/consent/
|
|
33
|
+
export { reinstallConfigurationConsent } from "./commands/use-cases/consent/reinstallConfigurationConsent";
|
|
32
34
|
//# sourceMappingURL=index.js.map
|
package/lib-es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oDAAoD,CAAC;AAC9F,OAAO,EAAE,0BAA0B,EAAE,MAAM,mDAAmD,CAAC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,k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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/device-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4-nightly.0",
|
|
4
4
|
"description": "Ledger Live device core module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@ledgerhq/hw-transport": "^6.31.3",
|
|
26
26
|
"@ledgerhq/logs": "^6.12.0",
|
|
27
27
|
"@ledgerhq/devices": "^8.4.3",
|
|
28
|
-
"@ledgerhq/types-live": "^6.51.0"
|
|
28
|
+
"@ledgerhq/types-live": "^6.51.1-nightly.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@testing-library/react": "14",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ReinstallConfigArgs = [
|
|
2
|
+
// 0x00 = false, 0x01 = true
|
|
3
|
+
ReinstallLanguagePack: 0x00 | 0x01, // 1 byte
|
|
4
|
+
ReinstallCustomLockScreen: 0x00 | 0x01, // 1 byte
|
|
5
|
+
ReinstallAppsNum: number, // 1 byte UINT8
|
|
6
|
+
ReinstallAppDataNum: number, // 1 byte UINT8
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
// TODO: model used when getting the config from the device before a software update
|
|
10
|
+
// export type ReinstallConfig = {
|
|
11
|
+
// languageId?: LanguageId,
|
|
12
|
+
// CustomLockScreen?: CustomLockScreen,
|
|
13
|
+
// reinstallApps: AppName[],
|
|
14
|
+
// reinstallStorage: AppName[],
|
|
15
|
+
// };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Transport, { StatusCodes, TransportStatusError } from "@ledgerhq/hw-transport";
|
|
2
|
+
import { reinstallConfigurationConsent } from "./reinstallConfigurationConsent";
|
|
3
|
+
import { PinNotSet, UserRefusedOnDevice } from "@ledgerhq/errors";
|
|
4
|
+
|
|
5
|
+
describe("reinstallConfigurationConsent", () => {
|
|
6
|
+
let transport: Transport;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
transport = {
|
|
10
|
+
send: jest.fn().mockResolvedValue(Buffer.from([])),
|
|
11
|
+
getTraceContext: jest.fn().mockResolvedValue(undefined),
|
|
12
|
+
} as unknown as Transport;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("success cases", () => {
|
|
20
|
+
it("should call the send function with correct parameters", async () => {
|
|
21
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x90, 0x00]));
|
|
22
|
+
await reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00]);
|
|
23
|
+
expect(transport.send).toHaveBeenCalledWith(
|
|
24
|
+
0xe0,
|
|
25
|
+
0x6f,
|
|
26
|
+
0x00,
|
|
27
|
+
0x00,
|
|
28
|
+
Buffer.from([0x00, 0x00, 0x00, 0x00]),
|
|
29
|
+
[StatusCodes.OK, StatusCodes.USER_REFUSED_ON_DEVICE, StatusCodes.PIN_NOT_SET],
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("error cases", () => {
|
|
35
|
+
it("should throw UserRefusedOnDevice if the user refused on device", async () => {
|
|
36
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x55, 0x01]));
|
|
37
|
+
await expect(
|
|
38
|
+
reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00]),
|
|
39
|
+
).rejects.toThrow(new UserRefusedOnDevice("User refused on device"));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should throw PINNotSet if the PIN is not set", async () => {
|
|
43
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x55, 0x02]));
|
|
44
|
+
await expect(
|
|
45
|
+
reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00]),
|
|
46
|
+
).rejects.toThrow(new PinNotSet("PIN not set"));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should throw TransportStatusError if the response status is invalid", async () => {
|
|
50
|
+
transport.send = jest.fn().mockResolvedValue(Buffer.from([0x6f, 0x00]));
|
|
51
|
+
await expect(
|
|
52
|
+
reinstallConfigurationConsent(transport, [0x00, 0x00, 0x00, 0x00]),
|
|
53
|
+
).rejects.toThrow(new TransportStatusError(0x6f00));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import Transport, { StatusCodes, TransportStatusError } from "@ledgerhq/hw-transport";
|
|
2
|
+
import { LocalTracer } from "@ledgerhq/logs";
|
|
3
|
+
import { UserRefusedOnDevice, PinNotSet } from "@ledgerhq/errors";
|
|
4
|
+
import type { APDU } from "../../entities/APDU";
|
|
5
|
+
import type { ReinstallConfigArgs } from "../../entities/ReinstallConfigEntity";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Name in documentation: REINSTALL_CONFIG
|
|
9
|
+
* cla: 0xe0
|
|
10
|
+
* ins: 0x6f
|
|
11
|
+
* p1: 0x00
|
|
12
|
+
* p2: 0x00
|
|
13
|
+
* data: CHUNK_LEN + CHUNK to configure at runtime
|
|
14
|
+
*/
|
|
15
|
+
const REINSTALL_CONFIG = [0xe0, 0x6f, 0x00, 0x00] as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 0x9000: Success.
|
|
19
|
+
* 0xYYYY: already in REINSTALL mode
|
|
20
|
+
* 0xZZZZ: if other error (TBD)
|
|
21
|
+
*/
|
|
22
|
+
const RESPONSE_STATUS_SET: number[] = [
|
|
23
|
+
StatusCodes.OK,
|
|
24
|
+
StatusCodes.USER_REFUSED_ON_DEVICE,
|
|
25
|
+
StatusCodes.PIN_NOT_SET,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Requests consent from the user to allow reinstalling all the previous
|
|
30
|
+
* settings after an OS update.
|
|
31
|
+
*
|
|
32
|
+
* @param transport - The transport object used to communicate with the device.
|
|
33
|
+
* @returns A promise that resolves when the consent is granted.
|
|
34
|
+
*/
|
|
35
|
+
export async function reinstallConfigurationConsent(
|
|
36
|
+
transport: Transport,
|
|
37
|
+
args: ReinstallConfigArgs,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const tracer = new LocalTracer("hw", {
|
|
40
|
+
transport: transport.getTraceContext(),
|
|
41
|
+
function: "reinstallConfigurationConsent",
|
|
42
|
+
});
|
|
43
|
+
tracer.trace("Start");
|
|
44
|
+
|
|
45
|
+
const apdu: Readonly<APDU> = [...REINSTALL_CONFIG, Buffer.from(args)];
|
|
46
|
+
|
|
47
|
+
const response = await transport.send(...apdu, RESPONSE_STATUS_SET);
|
|
48
|
+
|
|
49
|
+
return parseResponse(response);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parses the response data buffer, check the status code and return the data.
|
|
54
|
+
*
|
|
55
|
+
* @param data - The response data buffer w/ status code.
|
|
56
|
+
* @returns The response data as a buffer w/o status code.
|
|
57
|
+
*/
|
|
58
|
+
export function parseResponse(data: Buffer): void {
|
|
59
|
+
const tracer = new LocalTracer("hw", {
|
|
60
|
+
function: "parseResponse@reinstallConfigurationConsent",
|
|
61
|
+
});
|
|
62
|
+
const status = data.readUInt16BE(data.length - 2);
|
|
63
|
+
tracer.trace("Result status from 0xe06f0000", { status });
|
|
64
|
+
|
|
65
|
+
switch (status) {
|
|
66
|
+
case StatusCodes.OK:
|
|
67
|
+
return;
|
|
68
|
+
case StatusCodes.USER_REFUSED_ON_DEVICE:
|
|
69
|
+
throw new UserRefusedOnDevice("User refused on device");
|
|
70
|
+
case StatusCodes.PIN_NOT_SET:
|
|
71
|
+
throw new PinNotSet("PIN not set");
|
|
72
|
+
default:
|
|
73
|
+
throw new TransportStatusError(status);
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type {
|
|
|
5
5
|
OsuFirmware,
|
|
6
6
|
FirmwareUpdateContextEntity,
|
|
7
7
|
} from "./managerApi/entities/FirmwareUpdateContextEntity";
|
|
8
|
+
export type { ReinstallConfigArgs } from "./commands/entities/ReinstallConfigEntity";
|
|
8
9
|
export type { ManagerApiRepository } from "./managerApi/repositories/ManagerApiRepository";
|
|
9
10
|
export { HttpManagerApiRepository } from "./managerApi/repositories/HttpManagerApiRepository";
|
|
10
11
|
export { StubManagerApiRepository } from "./managerApi/repositories/StubManagerApiRepository";
|
|
@@ -42,3 +43,5 @@ export * from "./customLockScreen/screenSpecs";
|
|
|
42
43
|
export { shouldForceFirmwareUpdate } from "./firmwareUpdate/shouldForceFirmwareUpdate";
|
|
43
44
|
// errors
|
|
44
45
|
export * from "./errors";
|
|
46
|
+
// src/commands/consent/
|
|
47
|
+
export { reinstallConfigurationConsent } from "./commands/use-cases/consent/reinstallConfigurationConsent";
|