@metamask-previews/eth-ledger-bridge-keyring 4.1.1-672cc7b

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.
@@ -0,0 +1,106 @@
1
+ import type Transport from '@ledgerhq/hw-transport';
2
+ import { GetPublicKeyParams, GetPublicKeyResponse, LedgerBridge, LedgerSignMessageParams, LedgerSignMessageResponse, LedgerSignTransactionParams, LedgerSignTransactionResponse, LedgerSignTypedDataParams, LedgerSignTypedDataResponse } from './ledger-bridge';
3
+ import { TransportMiddleware } from './ledger-transport-middleware';
4
+ import { GetAppNameAndVersionResponse, LedgerMobileBridgeOptions } from './type';
5
+ export declare type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {
6
+ getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;
7
+ openEthApp(): Promise<void>;
8
+ closeApps(): Promise<void>;
9
+ };
10
+ /**
11
+ * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.
12
+ */
13
+ export declare class LedgerMobileBridge implements MobileBridge {
14
+ #private;
15
+ isDeviceConnected: boolean;
16
+ constructor(transportMiddleware: TransportMiddleware, opts?: LedgerMobileBridgeOptions);
17
+ /**
18
+ * Method to initializes the keyring.
19
+ * Mobile ledger doesnt not require init.
20
+ */
21
+ init(): Promise<void>;
22
+ /**
23
+ * Method to destroy the keyring.
24
+ * It will dispose the transportmiddleware and set isDeviceConnected to false.
25
+ */
26
+ destroy(): Promise<void>;
27
+ /**
28
+ * Method to sign a string Message.
29
+ * Sending the string message to the device and returning the signed message.
30
+ *
31
+ * @param params - An object contains hdPath and message.
32
+ * @param params.hdPath - The BIP 32 path of the account.
33
+ * @param params.message - The message to sign.
34
+ * @returns Retrieve v, r, s from the signed message.
35
+ */
36
+ deviceSignMessage({ hdPath, message, }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse>;
37
+ /**
38
+ * Method to sign a EIP712 Message.
39
+ * Sending the typed data message to the device and returning the signed message.
40
+ *
41
+ * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.
42
+ * @param params.hdPath - The BIP 32 path of the account.
43
+ * @param params.domainSeparatorHex - The domain separator.
44
+ * @param params.hashStructMessageHex - The hashed struct message.
45
+ * @returns Retrieve v, r, s from the signed message.
46
+ */
47
+ deviceSignTypedData({ hdPath, domainSeparatorHex, hashStructMessageHex, }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse>;
48
+ /**
49
+ * Method to sign a transaction
50
+ * Sending the hexadecimal transaction message to the device and returning the signed transaction.
51
+ *
52
+ * @param params - An object contains tx, hdPath.
53
+ * @param params.tx - The raw ethereum transaction in hexadecimal to sign.
54
+ * @param params.hdPath - The BIP 32 path of the account.
55
+ * @returns Retrieve v, r, s from the signed transaction.
56
+ */
57
+ deviceSignTransaction({ tx, hdPath, }: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse>;
58
+ /**
59
+ * Method to retrieve the ethereum address for a given BIP 32 path.
60
+ *
61
+ * @param params - An object contains hdPath.
62
+ * @param params.hdPath - The BIP 32 path of the account.
63
+ * @returns An object contains publicKey, address and chainCode.
64
+ */
65
+ getPublicKey({ hdPath, }: GetPublicKeyParams): Promise<GetPublicKeyResponse>;
66
+ /**
67
+ * Method to retrieve the current configuration.
68
+ *
69
+ * @returns Retrieve current configuration.
70
+ */
71
+ getOptions(): Promise<LedgerMobileBridgeOptions>;
72
+ /**
73
+ * Method to set the current configuration.
74
+ *
75
+ * @param opts - An configuration object.
76
+ */
77
+ setOptions(opts: LedgerMobileBridgeOptions): Promise<void>;
78
+ /**
79
+ * Method to set the transport object to communicate with the device.
80
+ *
81
+ * @param transport - The communication interface with the Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb).
82
+ * @returns Retrieve boolean.
83
+ */
84
+ updateTransportMethod(transport: Transport): Promise<boolean>;
85
+ /**
86
+ * Method to init eth app object on ledger device.
87
+ * This method is not supported on mobile.
88
+ */
89
+ attemptMakeApp(): Promise<boolean>;
90
+ /**
91
+ * Method to open ethereum application on ledger device.
92
+ *
93
+ */
94
+ openEthApp(): Promise<void>;
95
+ /**
96
+ * Method to close all running application on ledger device.
97
+ *
98
+ */
99
+ closeApps(): Promise<void>;
100
+ /**
101
+ * Method to retrieve the name and version of the running application in ledger device.
102
+ *
103
+ * @returns An object contains appName and version.
104
+ */
105
+ getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;
106
+ }
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.LedgerMobileBridge = void 0;
19
+ const ledger_1 = __importDefault(require("@ledgerhq/hw-app-eth/lib/services/ledger"));
20
+ /**
21
+ * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.
22
+ */
23
+ class LedgerMobileBridge {
24
+ constructor(transportMiddleware, opts = {}) {
25
+ _LedgerMobileBridge_instances.add(this);
26
+ _LedgerMobileBridge_transportMiddleware.set(this, void 0);
27
+ _LedgerMobileBridge_opts.set(this, void 0);
28
+ this.isDeviceConnected = false;
29
+ __classPrivateFieldSet(this, _LedgerMobileBridge_opts, opts, "f");
30
+ __classPrivateFieldSet(this, _LedgerMobileBridge_transportMiddleware, transportMiddleware, "f");
31
+ }
32
+ /**
33
+ * Method to initializes the keyring.
34
+ * Mobile ledger doesnt not require init.
35
+ */
36
+ async init() {
37
+ return Promise.resolve();
38
+ }
39
+ /**
40
+ * Method to destroy the keyring.
41
+ * It will dispose the transportmiddleware and set isDeviceConnected to false.
42
+ */
43
+ async destroy() {
44
+ try {
45
+ await __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getTransportMiddleWare).call(this).dispose();
46
+ }
47
+ catch (error) {
48
+ // eslint-disable-next-line no-console
49
+ console.error(error);
50
+ }
51
+ this.isDeviceConnected = false;
52
+ }
53
+ /**
54
+ * Method to sign a string Message.
55
+ * Sending the string message to the device and returning the signed message.
56
+ *
57
+ * @param params - An object contains hdPath and message.
58
+ * @param params.hdPath - The BIP 32 path of the account.
59
+ * @param params.message - The message to sign.
60
+ * @returns Retrieve v, r, s from the signed message.
61
+ */
62
+ async deviceSignMessage({ hdPath, message, }) {
63
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).signPersonalMessage(hdPath, message);
64
+ }
65
+ /**
66
+ * Method to sign a EIP712 Message.
67
+ * Sending the typed data message to the device and returning the signed message.
68
+ *
69
+ * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.
70
+ * @param params.hdPath - The BIP 32 path of the account.
71
+ * @param params.domainSeparatorHex - The domain separator.
72
+ * @param params.hashStructMessageHex - The hashed struct message.
73
+ * @returns Retrieve v, r, s from the signed message.
74
+ */
75
+ async deviceSignTypedData({ hdPath, domainSeparatorHex, hashStructMessageHex, }) {
76
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).signEIP712HashedMessage(hdPath, domainSeparatorHex, hashStructMessageHex);
77
+ }
78
+ /**
79
+ * Method to sign a transaction
80
+ * Sending the hexadecimal transaction message to the device and returning the signed transaction.
81
+ *
82
+ * @param params - An object contains tx, hdPath.
83
+ * @param params.tx - The raw ethereum transaction in hexadecimal to sign.
84
+ * @param params.hdPath - The BIP 32 path of the account.
85
+ * @returns Retrieve v, r, s from the signed transaction.
86
+ */
87
+ async deviceSignTransaction({ tx, hdPath, }) {
88
+ const resolution = await ledger_1.default.resolveTransaction(tx, {}, {});
89
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).signTransaction(hdPath, tx, resolution);
90
+ }
91
+ /**
92
+ * Method to retrieve the ethereum address for a given BIP 32 path.
93
+ *
94
+ * @param params - An object contains hdPath.
95
+ * @param params.hdPath - The BIP 32 path of the account.
96
+ * @returns An object contains publicKey, address and chainCode.
97
+ */
98
+ async getPublicKey({ hdPath, }) {
99
+ return await __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).getAddress(hdPath, false, true);
100
+ }
101
+ /**
102
+ * Method to retrieve the current configuration.
103
+ *
104
+ * @returns Retrieve current configuration.
105
+ */
106
+ async getOptions() {
107
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_opts, "f");
108
+ }
109
+ /**
110
+ * Method to set the current configuration.
111
+ *
112
+ * @param opts - An configuration object.
113
+ */
114
+ async setOptions(opts) {
115
+ __classPrivateFieldSet(this, _LedgerMobileBridge_opts, opts, "f");
116
+ }
117
+ /**
118
+ * Method to set the transport object to communicate with the device.
119
+ *
120
+ * @param transport - The communication interface with the Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb).
121
+ * @returns Retrieve boolean.
122
+ */
123
+ async updateTransportMethod(transport) {
124
+ if (!transport.deviceModel) {
125
+ throw new Error('Property `deviceModel` is not defined in `transport`.');
126
+ }
127
+ if (!transport.deviceModel.id) {
128
+ throw new Error('Property `deviceModel.id` is not defined in `transport`.');
129
+ }
130
+ __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getTransportMiddleWare).call(this).setTransport(transport);
131
+ this.isDeviceConnected = true;
132
+ return Promise.resolve(true);
133
+ }
134
+ /**
135
+ * Method to init eth app object on ledger device.
136
+ * This method is not supported on mobile.
137
+ */
138
+ async attemptMakeApp() {
139
+ throw new Error('Method not supported.');
140
+ }
141
+ /**
142
+ * Method to open ethereum application on ledger device.
143
+ *
144
+ */
145
+ async openEthApp() {
146
+ await __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).openEthApp();
147
+ }
148
+ /**
149
+ * Method to close all running application on ledger device.
150
+ *
151
+ */
152
+ async closeApps() {
153
+ await __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).closeApps();
154
+ }
155
+ /**
156
+ * Method to retrieve the name and version of the running application in ledger device.
157
+ *
158
+ * @returns An object contains appName and version.
159
+ */
160
+ async getAppNameAndVersion() {
161
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).getAppNameAndVersion();
162
+ }
163
+ }
164
+ exports.LedgerMobileBridge = LedgerMobileBridge;
165
+ _LedgerMobileBridge_transportMiddleware = new WeakMap(), _LedgerMobileBridge_opts = new WeakMap(), _LedgerMobileBridge_instances = new WeakSet(), _LedgerMobileBridge_getTransportMiddleWare = function _LedgerMobileBridge_getTransportMiddleWare() {
166
+ if (__classPrivateFieldGet(this, _LedgerMobileBridge_transportMiddleware, "f")) {
167
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_transportMiddleware, "f");
168
+ }
169
+ throw new Error('Instance `transportMiddleware` is not initialized.');
170
+ }, _LedgerMobileBridge_getEthApp = function _LedgerMobileBridge_getEthApp() {
171
+ return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getTransportMiddleWare).call(this).getEthApp();
172
+ };
173
+ //# sourceMappingURL=ledger-mobile-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger-mobile-bridge.js","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sFAAqE;AA4BrE;;GAEG;AACH,MAAa,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QARtC,0DAA2C;QAE3C,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,IAAI;YACF,MAAM,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,OAAO,EAAE,CAAC;SAChD;QAAC,OAAO,KAAK,EAAE;YACd,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACtB;QACD,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;IACjC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,iBAAiB,CAAC,EACtB,MAAM,EACN,OAAO,GACiB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,mBAAmB,CAAC,EACxB,MAAM,EACN,kBAAkB,EAClB,oBAAoB,GACM;QAC1B,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,uBAAuB,CAC9C,MAAM,EACN,kBAAkB,EAClB,oBAAoB,CACrB,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,qBAAqB,CAAC,EAC1B,EAAE,EACF,MAAM,GACsB;QAC5B,MAAM,UAAU,GAAG,MAAM,gBAAa,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACtE,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,EACjB,MAAM,GACa;QACnB,OAAO,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,uBAAA,IAAI,gCAAM,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU,CAAC,IAA+B;QAC9C,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,qBAAqB,CAAC,SAAoB;QAC9C,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC1E;QACD,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,EAAE;YAC7B,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;SACH;QACD,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;CAsBF;AApMD,gDAoMC;;IAdG,IAAI,uBAAA,IAAI,+CAAqB,EAAE;QAC7B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;KAClC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;IAQC,OAAO,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,SAAS,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import ledgerService from '@ledgerhq/hw-app-eth/lib/services/ledger';\nimport type Transport from '@ledgerhq/hw-transport';\n\nimport {\n GetPublicKeyParams,\n GetPublicKeyResponse,\n LedgerBridge,\n LedgerSignMessageParams,\n LedgerSignMessageResponse,\n LedgerSignTransactionParams,\n LedgerSignTransactionResponse,\n LedgerSignTypedDataParams,\n LedgerSignTypedDataResponse,\n} from './ledger-bridge';\nimport { MetaMaskLedgerHwAppEth } from './ledger-hw-app';\nimport { TransportMiddleware } from './ledger-transport-middleware';\nimport {\n GetAppNameAndVersionResponse,\n LedgerMobileBridgeOptions,\n} from './type';\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\n getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;\n openEthApp(): Promise<void>;\n closeApps(): Promise<void>;\n};\n\n/**\n * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.\n */\nexport class LedgerMobileBridge implements MobileBridge {\n #transportMiddleware?: TransportMiddleware;\n\n #opts: LedgerMobileBridgeOptions;\n\n isDeviceConnected = false;\n\n constructor(\n transportMiddleware: TransportMiddleware,\n opts: LedgerMobileBridgeOptions = {},\n ) {\n this.#opts = opts;\n this.#transportMiddleware = transportMiddleware;\n }\n\n /**\n * Method to initializes the keyring.\n * Mobile ledger doesnt not require init.\n */\n async init(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Method to destroy the keyring.\n * It will dispose the transportmiddleware and set isDeviceConnected to false.\n */\n async destroy(): Promise<void> {\n try {\n await this.#getTransportMiddleWare().dispose();\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.domainSeparatorHex - The domain separator.\n * @param params.hashStructMessageHex - The hashed struct message.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712HashedMessage(\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n );\n }\n\n /**\n * Method to sign a transaction\n * Sending the hexadecimal transaction message to the device and returning the signed transaction.\n *\n * @param params - An object contains tx, hdPath.\n * @param params.tx - The raw ethereum transaction in hexadecimal to sign.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns Retrieve v, r, s from the signed transaction.\n */\n async deviceSignTransaction({\n tx,\n hdPath,\n }: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse> {\n const resolution = await ledgerService.resolveTransaction(tx, {}, {});\n return this.#getEthApp().signTransaction(hdPath, tx, resolution);\n }\n\n /**\n * Method to retrieve the ethereum address for a given BIP 32 path.\n *\n * @param params - An object contains hdPath.\n * @param params.hdPath - The BIP 32 path of the account.\n * @returns An object contains publicKey, address and chainCode.\n */\n async getPublicKey({\n hdPath,\n }: GetPublicKeyParams): Promise<GetPublicKeyResponse> {\n return await this.#getEthApp().getAddress(hdPath, false, true);\n }\n\n /**\n * Method to retrieve the current configuration.\n *\n * @returns Retrieve current configuration.\n */\n async getOptions(): Promise<LedgerMobileBridgeOptions> {\n return this.#opts;\n }\n\n /**\n * Method to set the current configuration.\n *\n * @param opts - An configuration object.\n */\n async setOptions(opts: LedgerMobileBridgeOptions): Promise<void> {\n this.#opts = opts;\n }\n\n /**\n * Method to set the transport object to communicate with the device.\n *\n * @param transport - The communication interface with the Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb).\n * @returns Retrieve boolean.\n */\n async updateTransportMethod(transport: Transport): Promise<boolean> {\n if (!transport.deviceModel) {\n throw new Error('Property `deviceModel` is not defined in `transport`.');\n }\n if (!transport.deviceModel.id) {\n throw new Error(\n 'Property `deviceModel.id` is not defined in `transport`.',\n );\n }\n this.#getTransportMiddleWare().setTransport(transport);\n this.isDeviceConnected = true;\n return Promise.resolve(true);\n }\n\n /**\n * Method to init eth app object on ledger device.\n * This method is not supported on mobile.\n */\n async attemptMakeApp(): Promise<boolean> {\n throw new Error('Method not supported.');\n }\n\n /**\n * Method to open ethereum application on ledger device.\n *\n */\n async openEthApp(): Promise<void> {\n await this.#getEthApp().openEthApp();\n }\n\n /**\n * Method to close all running application on ledger device.\n *\n */\n async closeApps(): Promise<void> {\n await this.#getEthApp().closeApps();\n }\n\n /**\n * Method to retrieve the name and version of the running application in ledger device.\n *\n * @returns An object contains appName and version.\n */\n async getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse> {\n return this.#getEthApp().getAppNameAndVersion();\n }\n\n /**\n * Method to retrieve the transport middleWare object.\n *\n * @returns The TransportMiddleware object.\n */\n #getTransportMiddleWare(): TransportMiddleware {\n if (this.#transportMiddleware) {\n return this.#transportMiddleware;\n }\n throw new Error('Instance `transportMiddleware` is not initialized.');\n }\n\n /**\n * Method to retrieve the ledger Eth App object.\n *\n * @returns The ledger Eth App object.\n */\n #getEthApp(): MetaMaskLedgerHwAppEth {\n return this.#getTransportMiddleWare().getEthApp();\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import type Transport from '@ledgerhq/hw-transport';
2
+ import { MetaMaskLedgerHwAppEth } from './ledger-hw-app';
3
+ export interface TransportMiddleware {
4
+ setTransport(transport: Transport): void;
5
+ getTransport(): Transport;
6
+ getEthApp(): MetaMaskLedgerHwAppEth;
7
+ dispose(): Promise<void>;
8
+ }
9
+ /**
10
+ * LedgerTransportMiddleware is a middleware to communicate with the Ledger device via transport or LedgerHwAppEth
11
+ */
12
+ export declare class LedgerTransportMiddleware implements TransportMiddleware {
13
+ #private;
14
+ readonly mainAppName = "BOLOS";
15
+ readonly ethAppName = "Ethereum";
16
+ readonly transportEncoding = "ascii";
17
+ /**
18
+ * Method to close the transport connection.
19
+ */
20
+ dispose(): Promise<void>;
21
+ /**
22
+ * Method to set the transport object.
23
+ *
24
+ * @param transport - The transport object for communicating with a Ledger hardware wallet.
25
+ */
26
+ setTransport(transport: Transport): void;
27
+ /**
28
+ * Method to retrieve the transport object.
29
+ *
30
+ * @returns An generic interface for communicating with a Ledger hardware wallet.
31
+ */
32
+ getTransport(): Transport;
33
+ /**
34
+ * Method to get a new instance of the eth app object.
35
+ *
36
+ * @returns An generic interface for communicating with a Ledger hardware wallet to perform operation.
37
+ */
38
+ getEthApp(): MetaMaskLedgerHwAppEth;
39
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _LedgerTransportMiddleware_transport;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LedgerTransportMiddleware = void 0;
16
+ const ledger_hw_app_1 = require("./ledger-hw-app");
17
+ /**
18
+ * LedgerTransportMiddleware is a middleware to communicate with the Ledger device via transport or LedgerHwAppEth
19
+ */
20
+ class LedgerTransportMiddleware {
21
+ constructor() {
22
+ this.mainAppName = 'BOLOS';
23
+ this.ethAppName = 'Ethereum';
24
+ this.transportEncoding = 'ascii';
25
+ _LedgerTransportMiddleware_transport.set(this, void 0);
26
+ }
27
+ /**
28
+ * Method to close the transport connection.
29
+ */
30
+ async dispose() {
31
+ const transport = this.getTransport();
32
+ await transport.close();
33
+ }
34
+ /**
35
+ * Method to set the transport object.
36
+ *
37
+ * @param transport - The transport object for communicating with a Ledger hardware wallet.
38
+ */
39
+ setTransport(transport) {
40
+ __classPrivateFieldSet(this, _LedgerTransportMiddleware_transport, transport, "f");
41
+ }
42
+ /**
43
+ * Method to retrieve the transport object.
44
+ *
45
+ * @returns An generic interface for communicating with a Ledger hardware wallet.
46
+ */
47
+ getTransport() {
48
+ if (!__classPrivateFieldGet(this, _LedgerTransportMiddleware_transport, "f")) {
49
+ throw new Error('Instance `transport` is not initialized.');
50
+ }
51
+ return __classPrivateFieldGet(this, _LedgerTransportMiddleware_transport, "f");
52
+ }
53
+ /**
54
+ * Method to get a new instance of the eth app object.
55
+ *
56
+ * @returns An generic interface for communicating with a Ledger hardware wallet to perform operation.
57
+ */
58
+ getEthApp() {
59
+ return new ledger_hw_app_1.MetaMaskLedgerHwAppEth(this.getTransport());
60
+ }
61
+ }
62
+ exports.LedgerTransportMiddleware = LedgerTransportMiddleware;
63
+ _LedgerTransportMiddleware_transport = new WeakMap();
64
+ //# sourceMappingURL=ledger-transport-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger-transport-middleware.js","sourceRoot":"","sources":["../src/ledger-transport-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,mDAAyD;AAUzD;;GAEG;AACH,MAAa,yBAAyB;IAAtC;QACW,gBAAW,GAAG,OAAO,CAAC;QAEtB,eAAU,GAAG,UAAU,CAAC;QAExB,sBAAiB,GAAG,OAAO,CAAC;QAErC,uDAAuB;IAuCzB,CAAC;IArCC;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAoB;QAC/B,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,IAAI,CAAC,uBAAA,IAAI,4CAAW,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC7D;QACD,OAAO,uBAAA,IAAI,4CAAW,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,sCAAsB,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACzD,CAAC;CACF;AA9CD,8DA8CC","sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\n\nimport { MetaMaskLedgerHwAppEth } from './ledger-hw-app';\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TransportMiddleware {\n setTransport(transport: Transport): void;\n getTransport(): Transport;\n getEthApp(): MetaMaskLedgerHwAppEth;\n dispose(): Promise<void>;\n}\n\n/**\n * LedgerTransportMiddleware is a middleware to communicate with the Ledger device via transport or LedgerHwAppEth\n */\nexport class LedgerTransportMiddleware implements TransportMiddleware {\n readonly mainAppName = 'BOLOS';\n\n readonly ethAppName = 'Ethereum';\n\n readonly transportEncoding = 'ascii';\n\n #transport?: Transport;\n\n /**\n * Method to close the transport connection.\n */\n async dispose(): Promise<void> {\n const transport = this.getTransport();\n await transport.close();\n }\n\n /**\n * Method to set the transport object.\n *\n * @param transport - The transport object for communicating with a Ledger hardware wallet.\n */\n setTransport(transport: Transport): void {\n this.#transport = transport;\n }\n\n /**\n * Method to retrieve the transport object.\n *\n * @returns An generic interface for communicating with a Ledger hardware wallet.\n */\n getTransport(): Transport {\n if (!this.#transport) {\n throw new Error('Instance `transport` is not initialized.');\n }\n return this.#transport;\n }\n\n /**\n * Method to get a new instance of the eth app object.\n *\n * @returns An generic interface for communicating with a Ledger hardware wallet to perform operation.\n */\n getEthApp(): MetaMaskLedgerHwAppEth {\n return new MetaMaskLedgerHwAppEth(this.getTransport());\n }\n}\n"]}
package/dist/type.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare type GetAppNameAndVersionResponse = {
2
+ appName: string;
3
+ version: string;
4
+ };
5
+ export declare type LedgerMobileBridgeOptions = Record<string, never>;
package/dist/type.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"","sourcesContent":["export type GetAppNameAndVersionResponse = {\n appName: string;\n version: string;\n};\n\nexport type LedgerMobileBridgeOptions = Record<string, never>;\n"]}
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@metamask-previews/eth-ledger-bridge-keyring",
3
+ "version": "4.1.1-672cc7b",
4
+ "description": "A MetaMask compatible keyring, for ledger hardware wallets",
5
+ "keywords": [
6
+ "ethereum",
7
+ "keyring",
8
+ "ledger",
9
+ "metamask"
10
+ ],
11
+ "homepage": "https://github.com/MetaMask/eth-ledger-bridge-keyring#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/MetaMask/eth-ledger-bridge-keyring/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/MetaMask/eth-ledger-bridge-keyring.git"
18
+ },
19
+ "license": "ISC",
20
+ "author": "Bruno Barbieri",
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "files": [
24
+ "dist/"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc --build tsconfig.build.json",
28
+ "build:clean": "rimraf dist && yarn build",
29
+ "build:docs": "typedoc",
30
+ "build:force": "tsc --build tsconfig.build.json --force",
31
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/eth-ledger-bridge-keyring",
32
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-ledger-bridge-keyring",
33
+ "publish:preview": "yarn npm publish --tag preview",
34
+ "test": "jest && jest-it-up",
35
+ "test:clean": "jest --clearCache",
36
+ "test:verbose": "jest --verbose",
37
+ "test:watch": "jest --watch"
38
+ },
39
+ "dependencies": {
40
+ "@ethereumjs/rlp": "^4.0.0",
41
+ "@ethereumjs/tx": "^4.2.0",
42
+ "@ethereumjs/util": "^8.0.0",
43
+ "@ledgerhq/hw-app-eth": "6.26.1",
44
+ "@metamask/eth-sig-util": "^7.0.1",
45
+ "deepmerge": "^4.2.2",
46
+ "hdkey": "^2.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "@ethereumjs/common": "^3.2.0",
50
+ "@lavamoat/allow-scripts": "^2.5.1",
51
+ "@ledgerhq/hw-transport": "^6.24.1",
52
+ "@ledgerhq/types-cryptoassets": "^7.6.0",
53
+ "@ledgerhq/types-devices": "^6.22.4",
54
+ "@metamask/auto-changelog": "^3.1.0",
55
+ "@metamask/utils": "^8.2.0",
56
+ "@types/ethereumjs-tx": "^1.0.1",
57
+ "@types/hdkey": "^2.0.1",
58
+ "@types/jest": "^28.1.6",
59
+ "@types/node": "^16.18.59",
60
+ "@types/web": "^0.0.69",
61
+ "depcheck": "^1.4.3",
62
+ "ethereumjs-tx": "^1.3.4",
63
+ "jest": "^28.1.3",
64
+ "jest-it-up": "^2.2.0",
65
+ "rimraf": "^4.1.2",
66
+ "ts-jest": "^28.0.7",
67
+ "ts-node": "^10.7.0",
68
+ "typedoc": "^0.23.15",
69
+ "typescript": "~4.8.4"
70
+ },
71
+ "engines": {
72
+ "node": "^18.18 || >=20"
73
+ },
74
+ "publishConfig": {
75
+ "access": "public",
76
+ "registry": "https://registry.npmjs.org/"
77
+ },
78
+ "lavamoat": {
79
+ "allowScripts": {
80
+ "@lavamoat/preinstall-always-fail": false,
81
+ "@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
82
+ "ethereumjs-tx>ethereumjs-util>keccak": false,
83
+ "ethereumjs-tx>ethereumjs-util>secp256k1": false,
84
+ "hdkey>secp256k1": false,
85
+ "ethereumjs-tx>ethereumjs-util>ethereum-cryptography>keccak": false
86
+ }
87
+ }
88
+ }