@metamask/eth-ledger-bridge-keyring 12.0.2 → 12.1.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 +19 -1
- package/dist/errors.cjs +4 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/ledger-error-handler.cjs +2 -1
- package/dist/ledger-error-handler.cjs.map +1 -1
- package/dist/ledger-iframe-bridge.d.cts +1 -0
- package/dist/ledger-iframe-bridge.d.cts.map +1 -1
- package/dist/ledger-iframe-bridge.d.mts +1 -0
- package/dist/ledger-iframe-bridge.d.mts.map +1 -1
- package/dist/ledger-mobile-bridge.cjs +26 -7
- package/dist/ledger-mobile-bridge.cjs.map +1 -1
- package/dist/ledger-mobile-bridge.d.cts +3 -0
- package/dist/ledger-mobile-bridge.d.cts.map +1 -1
- package/dist/ledger-mobile-bridge.d.mts +3 -0
- package/dist/ledger-mobile-bridge.d.mts.map +1 -1
- package/dist/ledger-mobile-bridge.mjs +26 -7
- package/dist/ledger-mobile-bridge.mjs.map +1 -1
- package/dist/utils.cjs +2 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/v2/ledger-keyring.cjs +90 -0
- package/dist/v2/ledger-keyring.cjs.map +1 -1
- package/dist/v2/ledger-keyring.d.cts +65 -1
- package/dist/v2/ledger-keyring.d.cts.map +1 -1
- package/dist/v2/ledger-keyring.d.mts +65 -1
- package/dist/v2/ledger-keyring.d.mts.map +1 -1
- package/dist/v2/ledger-keyring.mjs +90 -0
- package/dist/v2/ledger-keyring.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [12.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Expose device-management pass-throughs on the V2 `LedgerKeyring` wrapper: `hdPath` (getter), `bridge` (getter), `getDeviceId`, `setDeviceId`, `setHdPath`, `getFirstPage`, `getNextPage`, `getPreviousPage`, `forgetDevice`, `isUnlocked`, `attemptMakeApp`, `getAppNameAndVersion`. `forgetDevice` additionally clears the V2 account registry to keep it in sync with the inner keyring. ([#551](https://github.com/MetaMask/accounts/pull/551))
|
|
15
|
+
|
|
16
|
+
## [12.0.3]
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Bump `@metamask/keyring-sdk` from `^2.0.2` to `^2.1.1` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546))
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Fall back to blind signing on mobile when `clearSignTransaction` fails, except when the user rejects on the device ([#522](https://github.com/MetaMask/accounts/pull/522))
|
|
25
|
+
|
|
10
26
|
## [12.0.2]
|
|
11
27
|
|
|
12
28
|
### Changed
|
|
@@ -424,7 +440,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
424
440
|
|
|
425
441
|
- Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
|
|
426
442
|
|
|
427
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0
|
|
443
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.1.0...HEAD
|
|
444
|
+
[12.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.3...@metamask/eth-ledger-bridge-keyring@12.1.0
|
|
445
|
+
[12.0.3]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.2...@metamask/eth-ledger-bridge-keyring@12.0.3
|
|
428
446
|
[12.0.2]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.1...@metamask/eth-ledger-bridge-keyring@12.0.2
|
|
429
447
|
[12.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.0...@metamask/eth-ledger-bridge-keyring@12.0.1
|
|
430
448
|
[12.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.4.0...@metamask/eth-ledger-bridge-keyring@12.0.0
|
package/dist/errors.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLedgerError =
|
|
4
|
-
exports.isKnownLedgerError = isKnownLedgerError;
|
|
5
|
-
exports.getLedgerErrorMapping = getLedgerErrorMapping;
|
|
3
|
+
exports.getLedgerErrorMapping = exports.isKnownLedgerError = exports.createLedgerError = void 0;
|
|
6
4
|
const hw_wallet_sdk_1 = require("@metamask/hw-wallet-sdk");
|
|
7
5
|
/**
|
|
8
6
|
* Factory function to create a HardwareWalletError from a Ledger error code.
|
|
@@ -35,6 +33,7 @@ function createLedgerError(ledgerErrorCode, context) {
|
|
|
35
33
|
userMessage: fallbackMessage,
|
|
36
34
|
});
|
|
37
35
|
}
|
|
36
|
+
exports.createLedgerError = createLedgerError;
|
|
38
37
|
/**
|
|
39
38
|
* Checks if a Ledger error code exists in the error mappings.
|
|
40
39
|
*
|
|
@@ -44,6 +43,7 @@ function createLedgerError(ledgerErrorCode, context) {
|
|
|
44
43
|
function isKnownLedgerError(ledgerErrorCode) {
|
|
45
44
|
return ledgerErrorCode in hw_wallet_sdk_1.LEDGER_ERROR_MAPPINGS;
|
|
46
45
|
}
|
|
46
|
+
exports.isKnownLedgerError = isKnownLedgerError;
|
|
47
47
|
/**
|
|
48
48
|
* Gets the error mapping details for a Ledger error code without creating an error instance.
|
|
49
49
|
*
|
|
@@ -53,4 +53,5 @@ function isKnownLedgerError(ledgerErrorCode) {
|
|
|
53
53
|
function getLedgerErrorMapping(ledgerErrorCode) {
|
|
54
54
|
return hw_wallet_sdk_1.LEDGER_ERROR_MAPPINGS[ledgerErrorCode];
|
|
55
55
|
}
|
|
56
|
+
exports.getLedgerErrorMapping = getLedgerErrorMapping;
|
|
56
57
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,2DAOiC;AAEjC;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,eAAuB,EACvB,OAAgB;IAEhB,MAAM,YAAY,GAAG,qBAAqB,CAAC,eAAe,CAAC,CAAC;IAE5D,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,OAAO;YACrB,CAAC,CAAC,GAAG,YAAY,CAAC,OAAO,KAAK,OAAO,GAAG;YACxC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC;QAEzB,OAAO,IAAI,mCAAmB,CAAC,OAAO,EAAE;YACtC,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,WAAW,EAAE,YAAY,CAAC,WAAW,IAAI,OAAO;SACjD,CAAC,CAAC;IACL,CAAC;IAED,mCAAmC;IACnC,MAAM,eAAe,GAAG,OAAO;QAC7B,CAAC,CAAC,yBAAyB,eAAe,KAAK,OAAO,GAAG;QACzD,CAAC,CAAC,yBAAyB,eAAe,EAAE,CAAC;IAE/C,OAAO,IAAI,mCAAmB,CAAC,eAAe,EAAE;QAC9C,IAAI,EAAE,yBAAS,CAAC,OAAO;QACvB,QAAQ,EAAE,wBAAQ,CAAC,GAAG;QACtB,QAAQ,EAAE,wBAAQ,CAAC,OAAO;QAC1B,WAAW,EAAE,eAAe;KAC7B,CAAC,CAAC;AACL,CAAC;AA9BD,8CA8BC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,eAAuB;IACxD,OAAO,eAAe,IAAI,qCAAqB,CAAC;AAClD,CAAC;AAFD,gDAEC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CACnC,eAAuB;IAEvB,OAAO,qCAAqB,CAAC,eAAe,CAAC,CAAC;AAChD,CAAC;AAJD,sDAIC","sourcesContent":["import {\n ErrorMapping,\n ErrorCode,\n Severity,\n Category,\n HardwareWalletError,\n LEDGER_ERROR_MAPPINGS,\n} from '@metamask/hw-wallet-sdk';\n\n/**\n * Factory function to create a HardwareWalletError from a Ledger error code.\n *\n * @param ledgerErrorCode - The Ledger error code (e.g., '0x6985', '0x5515')\n * @param context - Optional additional context to append to the error message\n * @returns A HardwareWalletError instance with mapped error details\n */\nexport function createLedgerError(\n ledgerErrorCode: string,\n context?: string,\n): HardwareWalletError {\n const errorMapping = getLedgerErrorMapping(ledgerErrorCode);\n\n if (errorMapping) {\n const message = context\n ? `${errorMapping.message} (${context})`\n : errorMapping.message;\n\n return new HardwareWalletError(message, {\n code: errorMapping.code,\n severity: errorMapping.severity,\n category: errorMapping.category,\n userMessage: errorMapping.userMessage ?? message,\n });\n }\n\n // Fallback for unknown error codes\n const fallbackMessage = context\n ? `Unknown Ledger error: ${ledgerErrorCode} (${context})`\n : `Unknown Ledger error: ${ledgerErrorCode}`;\n\n return new HardwareWalletError(fallbackMessage, {\n code: ErrorCode.Unknown,\n severity: Severity.Err,\n category: Category.Unknown,\n userMessage: fallbackMessage,\n });\n}\n\n/**\n * Checks if a Ledger error code exists in the error mappings.\n *\n * @param ledgerErrorCode - The Ledger error code to check\n * @returns True if the error code is mapped, false otherwise\n */\nexport function isKnownLedgerError(ledgerErrorCode: string): boolean {\n return ledgerErrorCode in LEDGER_ERROR_MAPPINGS;\n}\n\n/**\n * Gets the error mapping details for a Ledger error code without creating an error instance.\n *\n * @param ledgerErrorCode - The Ledger error code to look up\n * @returns The error mapping details or undefined if not found\n */\nexport function getLedgerErrorMapping(\n ledgerErrorCode: string,\n): ErrorMapping | undefined {\n return LEDGER_ERROR_MAPPINGS[ledgerErrorCode];\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleLedgerTransportError =
|
|
3
|
+
exports.handleLedgerTransportError = void 0;
|
|
4
4
|
const hw_transport_1 = require("@ledgerhq/hw-transport");
|
|
5
5
|
const hw_wallet_sdk_1 = require("@metamask/hw-wallet-sdk");
|
|
6
6
|
const errors_1 = require("./errors.cjs");
|
|
@@ -73,4 +73,5 @@ function handleLedgerTransportError(error, fallbackMessage) {
|
|
|
73
73
|
userMessage: fallbackMessage,
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
+
exports.handleLedgerTransportError = handleLedgerTransportError;
|
|
76
77
|
//# sourceMappingURL=ledger-error-handler.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-error-handler.cjs","sourceRoot":"","sources":["../src/ledger-error-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-error-handler.cjs","sourceRoot":"","sources":["../src/ledger-error-handler.ts"],"names":[],"mappings":";;;AAAA,yDAA8D;AAC9D,2DAKiC;AAEjC,yCAAiE;AAEjE,MAAM,mBAAmB,GAAG,UAAU,CAAC;AACvC,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC;IACzC,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;CACT,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,OAAO,CAAC,UAAU,CAAC,mBAAmB,CAAC;QAC5C,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,GAAG,mBAAmB,GAAG,OAAO,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AAC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AAmB,CAAC,eAAe,EAAE;QAC7C,IAAI,EAAE,yBAAa,CAAC,OAAO;QAC3B,QAAQ,EAAE,wBAAY,CAAC,GAAG;QAC1B,QAAQ,EAAE,wBAAY,CAAC,OAAO;QAC9B,WAAW,EAAE,eAAe;KAC7B,CAAC,CAAC;AACL,CAAC;AAjDD,gEAiDC","sourcesContent":["import { TransportStatusError } from '@ledgerhq/hw-transport';\nimport {\n ErrorCode as ErrorCodeEnum,\n Severity as SeverityEnum,\n Category as CategoryEnum,\n HardwareWalletError,\n} from '@metamask/hw-wallet-sdk';\n\nimport { createLedgerError, isKnownLedgerError } from './errors';\n\nconst LEDGER_ERROR_PREFIX = 'Ledger: ';\nconst LEDGER_PREFIX_STATUS_CODES = new Set([\n '0x6985',\n '0x6a80',\n '0x5515',\n '0x650f',\n]);\n\n/**\n * Prefixes error messages with the Ledger identifier when needed.\n *\n * @param message - The error message to prefix.\n * @returns The message with a Ledger prefix.\n */\nfunction withLedgerPrefix(message: string): string {\n return message.startsWith(LEDGER_ERROR_PREFIX)\n ? message\n : `${LEDGER_ERROR_PREFIX}${message}`;\n}\n\n/**\n * Central error handler for Ledger TransportStatusError instances.\n * Converts Ledger transport errors into properly typed HardwareWalletError instances\n * using the error mapping system.\n *\n * @param error - The error to handle\n * @param fallbackMessage - Default error message if no specific handling is found\n * @throws HardwareWalletError with appropriate error details from mappings\n */\nexport function handleLedgerTransportError(\n error: unknown,\n fallbackMessage: string,\n): never {\n if (error instanceof TransportStatusError) {\n const statusCodeHex = `0x${error.statusCode.toString(16)}`;\n\n // Try to create error from known status code\n if (isKnownLedgerError(statusCodeHex)) {\n const ledgerError = createLedgerError(statusCodeHex);\n if (LEDGER_PREFIX_STATUS_CODES.has(statusCodeHex)) {\n ledgerError.message = withLedgerPrefix(ledgerError.message);\n }\n throw ledgerError;\n }\n\n // Unknown status code - create generic error with details\n throw new HardwareWalletError(error.message, {\n code: ErrorCodeEnum.Unknown,\n severity: SeverityEnum.Err,\n category: CategoryEnum.Unknown,\n userMessage: error.message,\n cause: error,\n });\n }\n\n // Handle HardwareWalletError - pass through\n if (error instanceof HardwareWalletError) {\n throw error;\n }\n\n // For any other error type\n if (error instanceof Error) {\n throw new HardwareWalletError(error.message, {\n code: ErrorCodeEnum.Unknown,\n severity: SeverityEnum.Err,\n category: CategoryEnum.Unknown,\n userMessage: error.message,\n cause: error,\n });\n }\n\n // Unknown error type\n throw new HardwareWalletError(fallbackMessage, {\n code: ErrorCodeEnum.Unknown,\n severity: SeverityEnum.Err,\n category: CategoryEnum.Unknown,\n userMessage: fallbackMessage,\n });\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="web" />
|
|
1
2
|
import { AppConfigurationResponse, GetAppNameAndVersionResponse, GetPublicKeyParams, GetPublicKeyResponse, LedgerBridge, LedgerSignMessageParams, LedgerSignMessageResponse, LedgerSignTransactionParams, LedgerSignTransactionResponse, LedgerSignTypedDataParams, LedgerSignTypedDataResponse } from "./ledger-bridge.cjs";
|
|
2
3
|
export declare enum IFrameMessageAction {
|
|
3
4
|
LedgerIsIframeReady = "ledger-is-iframe-ready",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-iframe-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-iframe-bridge.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AAMzB,oBAAY,mBAAmB;IAC7B,mBAAmB,2BAA2B;IAC9C,sBAAsB,6BAA6B;IACnD,YAAY,kBAAkB;IAC9B,aAAa,oBAAoB;IACjC,qBAAqB,4BAA4B;IACjD,qBAAqB,4BAA4B;IACjD,yBAAyB,iCAAiC;IAC1D,mBAAmB,2BAA2B;IAC9C,0BAA0B,o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ACrB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,yBAAyB,CAAC;IAO/B,mBAAmB,CACvB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,2BAA2B,CAAC;IAOjC,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAO7D,mBAAmB,IAAI,OAAO,CAAC,wBAAwB,CAAC;CA6J/D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="web" />
|
|
1
2
|
import { AppConfigurationResponse, GetAppNameAndVersionResponse, GetPublicKeyParams, GetPublicKeyResponse, LedgerBridge, LedgerSignMessageParams, LedgerSignMessageResponse, LedgerSignTransactionParams, LedgerSignTransactionResponse, LedgerSignTypedDataParams, LedgerSignTypedDataResponse } from "./ledger-bridge.mjs";
|
|
2
3
|
export declare enum IFrameMessageAction {
|
|
3
4
|
LedgerIsIframeReady = "ledger-is-iframe-ready",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-iframe-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-iframe-bridge.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AAMzB,oBAAY,mBAAmB;IAC7B,mBAAmB,2BAA2B;IAC9C,sBAAsB,6BAA6B;IACnD,YAAY,kBAAkB;IAC9B,aAAa,oBAAoB;IACjC,qBAAqB,4BAA4B;IACjD,qBAAqB,4BAA4B;IACjD,yBAAyB,iCAAiC;IAC1D,mBAAmB,2BAA2B;IAC9C,0BAA0B,oCAAoC;IAC9D,yBAAyB,iCAAiC;CAC3D;AAED,KAAK,yBAAyB,CAC5B,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7C,aAAa,GAAG,KAAK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jC,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAO7D,mBAAmB,IAAI,OAAO,CAAC,wBAAwB,CAAC;CA6J/D"}
|
|
@@ -10,12 +10,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
|
|
13
|
+
var _LedgerMobileBridge_instances, _a, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp, _LedgerMobileBridge_isLedgerUserRejection;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.LedgerMobileBridge = void 0;
|
|
16
|
+
const hw_transport_1 = require("@ledgerhq/hw-transport");
|
|
16
17
|
const constants_1 = require("./constants.cjs");
|
|
17
18
|
const ledger_hw_app_1 = require("./ledger-hw-app.cjs");
|
|
18
19
|
const utils_1 = require("./utils.cjs");
|
|
20
|
+
/** Ledger APDU: CONDITIONS_OF_USE_NOT_SATISFIED (user rejected on device). */
|
|
21
|
+
const LEDGER_USER_REJECTION_STATUS = 0x6985;
|
|
19
22
|
/**
|
|
20
23
|
* LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.
|
|
21
24
|
*/
|
|
@@ -78,6 +81,9 @@ class LedgerMobileBridge {
|
|
|
78
81
|
* Method to sign a transaction
|
|
79
82
|
* Sending the hexadecimal transaction message to the device and returning the signed transaction.
|
|
80
83
|
*
|
|
84
|
+
* Tries clear-signing first. If resolution fails (e.g. no Ledger plugin for the chain or contract),
|
|
85
|
+
* falls back to blind signing via `signTransaction(..., null)` unless the user rejected on the device.
|
|
86
|
+
*
|
|
81
87
|
* @param params - An object contains tx, hdPath.
|
|
82
88
|
* @param params.tx - The raw ethereum transaction in hexadecimal to sign.
|
|
83
89
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
@@ -87,11 +93,21 @@ class LedgerMobileBridge {
|
|
|
87
93
|
const selector = (0, utils_1.getTransactionSelector)(tx);
|
|
88
94
|
const nft = Boolean(selector && constants_1.NFT_ONLY_SELECTORS.has(selector));
|
|
89
95
|
const erc20 = Boolean(selector && constants_1.ERC20_WRITE_SELECTORS.has(selector));
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
const ethApp = __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this);
|
|
97
|
+
try {
|
|
98
|
+
return await ethApp.clearSignTransaction(hdPath, tx, {
|
|
99
|
+
externalPlugins: true,
|
|
100
|
+
erc20,
|
|
101
|
+
nft,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (__classPrivateFieldGet(_a, _a, "m", _LedgerMobileBridge_isLedgerUserRejection).call(_a, error)) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
console.warn('Ledger clear-sign failed; falling back to blind signing.', error);
|
|
109
|
+
return ethApp.signTransaction(hdPath, tx, null);
|
|
110
|
+
}
|
|
95
111
|
}
|
|
96
112
|
/**
|
|
97
113
|
* Method to retrieve the ethereum address for a given BIP 32 path.
|
|
@@ -175,12 +191,15 @@ class LedgerMobileBridge {
|
|
|
175
191
|
}
|
|
176
192
|
}
|
|
177
193
|
exports.LedgerMobileBridge = LedgerMobileBridge;
|
|
178
|
-
_LedgerMobileBridge_transportMiddleware = new WeakMap(), _LedgerMobileBridge_opts = new WeakMap(), _LedgerMobileBridge_instances = new WeakSet(), _LedgerMobileBridge_getTransportMiddleWare = function _LedgerMobileBridge_getTransportMiddleWare() {
|
|
194
|
+
_a = LedgerMobileBridge, _LedgerMobileBridge_transportMiddleware = new WeakMap(), _LedgerMobileBridge_opts = new WeakMap(), _LedgerMobileBridge_instances = new WeakSet(), _LedgerMobileBridge_getTransportMiddleWare = function _LedgerMobileBridge_getTransportMiddleWare() {
|
|
179
195
|
if (__classPrivateFieldGet(this, _LedgerMobileBridge_transportMiddleware, "f")) {
|
|
180
196
|
return __classPrivateFieldGet(this, _LedgerMobileBridge_transportMiddleware, "f");
|
|
181
197
|
}
|
|
182
198
|
throw new Error('Instance `transportMiddleware` is not initialized.');
|
|
183
199
|
}, _LedgerMobileBridge_getEthApp = function _LedgerMobileBridge_getEthApp() {
|
|
184
200
|
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getTransportMiddleWare).call(this).getEthApp();
|
|
201
|
+
}, _LedgerMobileBridge_isLedgerUserRejection = function _LedgerMobileBridge_isLedgerUserRejection(error) {
|
|
202
|
+
return (error instanceof hw_transport_1.TransportStatusError &&
|
|
203
|
+
error.statusCode === LEDGER_USER_REJECTION_STATUS);
|
|
185
204
|
};
|
|
186
205
|
//# sourceMappingURL=ledger-mobile-bridge.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.cjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,+CAAwE;AAcxE,uDAAyD;AAGzD,uCAAiD;AAQjD;;GAEG;AACH,MAAa,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,KAA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AC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,EAAE,CAAC;IACjD,CAAC;CAsBF;AA/MD,gDA+MC;;IAdG,IAAI,uBAAA,IAAI,+CAAqB,EAAE,CAAC;QAC9B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;IACnC,CAAC;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 type Transport from '@ledgerhq/hw-transport';\n\nimport { ERC20_WRITE_SELECTORS, NFT_ONLY_SELECTORS } from './constants';\nimport {\n AppConfigurationResponse,\n GetAppNameAndVersionResponse,\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 { LedgerMobileBridgeOptions } from './type';\nimport { getTransactionSelector } from './utils';\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\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 readonly #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 * @returns A promise that will resolve once the bridge is initialized.\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 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.message - The EIP712 message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n message,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712Message(hdPath, message);\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 selector = getTransactionSelector(tx);\n const nft = Boolean(selector && NFT_ONLY_SELECTORS.has(selector));\n const erc20 = Boolean(selector && ERC20_WRITE_SELECTORS.has(selector));\n\n return this.#getEthApp().clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20,\n nft,\n });\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 current configuration of the Ethereum application on the Ledger device.\n *\n * @returns An object containing the application configuration including blind signing support, ERC20 provisioning status, Stark support, and version.\n */\n async getAppConfiguration(): Promise<AppConfigurationResponse> {\n return this.#getEthApp().getAppConfiguration();\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"]}
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.cjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAA8D;AAG9D,+CAAwE;AAcxE,uDAAyD;AAGzD,uCAAiD;AAEjD,8EAA8E;AAC9E,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAQ5C;;GAEG;AACH,MAAa,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC;YACH,MAAM,uBAAA,IAAI,iFAAwB,MAA5B,IAAI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AAK,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;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,EAAE,CAAC;IACjD,CAAC;CAoCF;AA9OD,gDA8OC;;IA5BG,IAAI,uBAAA,IAAI,+CAAqB,EAAE,CAAC;QAC9B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;IACnC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;IAQC,OAAO,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,SAAS,EAAE,CAAC;AACpD,CAAC,iGAS6B,KAAc;IAC1C,OAAO,CACL,KAAK,YAAY,mCAAoB;QACrC,KAAK,CAAC,UAAU,KAAK,4BAA4B,CAClD,CAAC;AACJ,CAAC","sourcesContent":["import { TransportStatusError } from '@ledgerhq/hw-transport';\nimport type Transport from '@ledgerhq/hw-transport';\n\nimport { ERC20_WRITE_SELECTORS, NFT_ONLY_SELECTORS } from './constants';\nimport {\n AppConfigurationResponse,\n GetAppNameAndVersionResponse,\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 { LedgerMobileBridgeOptions } from './type';\nimport { getTransactionSelector } from './utils';\n\n/** Ledger APDU: CONDITIONS_OF_USE_NOT_SATISFIED (user rejected on device). */\nconst LEDGER_USER_REJECTION_STATUS = 0x6985;\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\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 readonly #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 * @returns A promise that will resolve once the bridge is initialized.\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 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.message - The EIP712 message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n message,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712Message(hdPath, message);\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 * Tries clear-signing first. If resolution fails (e.g. no Ledger plugin for the chain or contract),\n * falls back to blind signing via `signTransaction(..., null)` unless the user rejected on the device.\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 selector = getTransactionSelector(tx);\n const nft = Boolean(selector && NFT_ONLY_SELECTORS.has(selector));\n const erc20 = Boolean(selector && ERC20_WRITE_SELECTORS.has(selector));\n\n const ethApp = this.#getEthApp();\n\n try {\n return await ethApp.clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20,\n nft,\n });\n } catch (error: unknown) {\n if (LedgerMobileBridge.#isLedgerUserRejection(error)) {\n throw error;\n }\n\n console.warn(\n 'Ledger clear-sign failed; falling back to blind signing.',\n error,\n );\n return ethApp.signTransaction(hdPath, tx, null);\n }\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 current configuration of the Ethereum application on the Ledger device.\n *\n * @returns An object containing the application configuration including blind signing support, ERC20 provisioning status, Stark support, and version.\n */\n async getAppConfiguration(): Promise<AppConfigurationResponse> {\n return this.#getEthApp().getAppConfiguration();\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 /**\n * Detects an explicit on-device rejection so we do not fall back to blind signing\n * and re-prompt the user.\n *\n * @param error - Error from Ledger transport or hw-app-eth.\n * @returns True when the user rejected the action on the device.\n */\n static #isLedgerUserRejection(error: unknown): boolean {\n return (\n error instanceof TransportStatusError &&\n error.statusCode === LEDGER_USER_REJECTION_STATUS\n );\n }\n}\n"]}
|
|
@@ -49,6 +49,9 @@ export declare class LedgerMobileBridge implements MobileBridge {
|
|
|
49
49
|
* Method to sign a transaction
|
|
50
50
|
* Sending the hexadecimal transaction message to the device and returning the signed transaction.
|
|
51
51
|
*
|
|
52
|
+
* Tries clear-signing first. If resolution fails (e.g. no Ledger plugin for the chain or contract),
|
|
53
|
+
* falls back to blind signing via `signTransaction(..., null)` unless the user rejected on the device.
|
|
54
|
+
*
|
|
52
55
|
* @param params - An object contains tx, hdPath.
|
|
53
56
|
* @param params.tx - The raw ethereum transaction in hexadecimal to sign.
|
|
54
57
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,+BAA+B;AAGpD,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AAEzB,OAAO,EAAE,mBAAmB,EAAE,0CAAsC;AACpE,OAAO,EAAE,yBAAyB,EAAE,mBAAe;AAOnD,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,yBAAyB,CAAC,GAAG;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IAAI,OAAO,CAAC,4BAA4B,CAAC;IAInE;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,wBAAwB,CAAC;CAsC/D"}
|
|
@@ -49,6 +49,9 @@ export declare class LedgerMobileBridge implements MobileBridge {
|
|
|
49
49
|
* Method to sign a transaction
|
|
50
50
|
* Sending the hexadecimal transaction message to the device and returning the signed transaction.
|
|
51
51
|
*
|
|
52
|
+
* Tries clear-signing first. If resolution fails (e.g. no Ledger plugin for the chain or contract),
|
|
53
|
+
* falls back to blind signing via `signTransaction(..., null)` unless the user rejected on the device.
|
|
54
|
+
*
|
|
52
55
|
* @param params - An object contains tx, hdPath.
|
|
53
56
|
* @param params.tx - The raw ethereum transaction in hexadecimal to sign.
|
|
54
57
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,+BAA+B;AAGpD,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,6BAA6B,EAC7B,yBAAyB,EACzB,2BAA2B,EAC5B,4BAAwB;AAEzB,OAAO,EAAE,mBAAmB,EAAE,0CAAsC;AACpE,OAAO,EAAE,yBAAyB,EAAE,mBAAe;AAOnD,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,yBAAyB,CAAC,GAAG;IACnE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,qBAAa,kBAAmB,YAAW,YAAY;;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FieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
|
|
12
|
+
var _LedgerMobileBridge_instances, _a, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp, _LedgerMobileBridge_isLedgerUserRejection;
|
|
13
|
+
import { TransportStatusError } from "@ledgerhq/hw-transport";
|
|
13
14
|
import { ERC20_WRITE_SELECTORS, NFT_ONLY_SELECTORS } from "./constants.mjs";
|
|
14
15
|
import { MetaMaskLedgerHwAppEth } from "./ledger-hw-app.mjs";
|
|
15
16
|
import { getTransactionSelector } from "./utils.mjs";
|
|
17
|
+
/** Ledger APDU: CONDITIONS_OF_USE_NOT_SATISFIED (user rejected on device). */
|
|
18
|
+
const LEDGER_USER_REJECTION_STATUS = 0x6985;
|
|
16
19
|
/**
|
|
17
20
|
* LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.
|
|
18
21
|
*/
|
|
@@ -75,6 +78,9 @@ export class LedgerMobileBridge {
|
|
|
75
78
|
* Method to sign a transaction
|
|
76
79
|
* Sending the hexadecimal transaction message to the device and returning the signed transaction.
|
|
77
80
|
*
|
|
81
|
+
* Tries clear-signing first. If resolution fails (e.g. no Ledger plugin for the chain or contract),
|
|
82
|
+
* falls back to blind signing via `signTransaction(..., null)` unless the user rejected on the device.
|
|
83
|
+
*
|
|
78
84
|
* @param params - An object contains tx, hdPath.
|
|
79
85
|
* @param params.tx - The raw ethereum transaction in hexadecimal to sign.
|
|
80
86
|
* @param params.hdPath - The BIP 32 path of the account.
|
|
@@ -84,11 +90,21 @@ export class LedgerMobileBridge {
|
|
|
84
90
|
const selector = getTransactionSelector(tx);
|
|
85
91
|
const nft = Boolean(selector && NFT_ONLY_SELECTORS.has(selector));
|
|
86
92
|
const erc20 = Boolean(selector && ERC20_WRITE_SELECTORS.has(selector));
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
const ethApp = __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this);
|
|
94
|
+
try {
|
|
95
|
+
return await ethApp.clearSignTransaction(hdPath, tx, {
|
|
96
|
+
externalPlugins: true,
|
|
97
|
+
erc20,
|
|
98
|
+
nft,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (__classPrivateFieldGet(_a, _a, "m", _LedgerMobileBridge_isLedgerUserRejection).call(_a, error)) {
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
console.warn('Ledger clear-sign failed; falling back to blind signing.', error);
|
|
106
|
+
return ethApp.signTransaction(hdPath, tx, null);
|
|
107
|
+
}
|
|
92
108
|
}
|
|
93
109
|
/**
|
|
94
110
|
* Method to retrieve the ethereum address for a given BIP 32 path.
|
|
@@ -171,12 +187,15 @@ export class LedgerMobileBridge {
|
|
|
171
187
|
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).getAppConfiguration();
|
|
172
188
|
}
|
|
173
189
|
}
|
|
174
|
-
_LedgerMobileBridge_transportMiddleware = new WeakMap(), _LedgerMobileBridge_opts = new WeakMap(), _LedgerMobileBridge_instances = new WeakSet(), _LedgerMobileBridge_getTransportMiddleWare = function _LedgerMobileBridge_getTransportMiddleWare() {
|
|
190
|
+
_a = LedgerMobileBridge, _LedgerMobileBridge_transportMiddleware = new WeakMap(), _LedgerMobileBridge_opts = new WeakMap(), _LedgerMobileBridge_instances = new WeakSet(), _LedgerMobileBridge_getTransportMiddleWare = function _LedgerMobileBridge_getTransportMiddleWare() {
|
|
175
191
|
if (__classPrivateFieldGet(this, _LedgerMobileBridge_transportMiddleware, "f")) {
|
|
176
192
|
return __classPrivateFieldGet(this, _LedgerMobileBridge_transportMiddleware, "f");
|
|
177
193
|
}
|
|
178
194
|
throw new Error('Instance `transportMiddleware` is not initialized.');
|
|
179
195
|
}, _LedgerMobileBridge_getEthApp = function _LedgerMobileBridge_getEthApp() {
|
|
180
196
|
return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getTransportMiddleWare).call(this).getEthApp();
|
|
197
|
+
}, _LedgerMobileBridge_isLedgerUserRejection = function _LedgerMobileBridge_isLedgerUserRejection(error) {
|
|
198
|
+
return (error instanceof TransportStatusError &&
|
|
199
|
+
error.statusCode === LEDGER_USER_REJECTION_STATUS);
|
|
181
200
|
};
|
|
182
201
|
//# sourceMappingURL=ledger-mobile-bridge.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-mobile-bridge.mjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAoB;AAcxE,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AAGzD,OAAO,EAAE,sBAAsB,EAAE,oBAAgB;AAQjD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED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I,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,EAAE,CAAC;IACjD,CAAC;CAsBF;;IAdG,IAAI,uBAAA,IAAI,+CAAqB,EAAE,CAAC;QAC9B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;IACnC,CAAC;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 type Transport from '@ledgerhq/hw-transport';\n\nimport { ERC20_WRITE_SELECTORS, NFT_ONLY_SELECTORS } from './constants';\nimport {\n AppConfigurationResponse,\n GetAppNameAndVersionResponse,\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 { LedgerMobileBridgeOptions } from './type';\nimport { getTransactionSelector } from './utils';\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\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 readonly #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 * @returns A promise that will resolve once the bridge is initialized.\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 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.message - The EIP712 message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n message,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712Message(hdPath, message);\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 selector = getTransactionSelector(tx);\n const nft = Boolean(selector && NFT_ONLY_SELECTORS.has(selector));\n const erc20 = Boolean(selector && ERC20_WRITE_SELECTORS.has(selector));\n\n return this.#getEthApp().clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20,\n nft,\n });\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 current configuration of the Ethereum application on the Ledger device.\n *\n * @returns An object containing the application configuration including blind signing support, ERC20 provisioning status, Stark support, and version.\n */\n async getAppConfiguration(): Promise<AppConfigurationResponse> {\n return this.#getEthApp().getAppConfiguration();\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"]}
|
|
1
|
+
{"version":3,"file":"ledger-mobile-bridge.mjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAG9D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAoB;AAcxE,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AAGzD,OAAO,EAAE,sBAAsB,EAAE,oBAAgB;AAEjD,8EAA8E;AAC9E,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAQ5C;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC;YACH,MAAM,uBAA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AC;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;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,EAAE,CAAC;IACjD,CAAC;CAoCF;;IA5BG,IAAI,uBAAA,IAAI,+CAAqB,EAAE,CAAC;QAC9B,OAAO,uBAAA,IAAI,+CAAqB,CAAC;IACnC,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;IAQC,OAAO,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,SAAS,EAAE,CAAC;AACpD,CAAC,iGAS6B,KAAc;IAC1C,OAAO,CACL,KAAK,YAAY,oBAAoB;QACrC,KAAK,CAAC,UAAU,KAAK,4BAA4B,CAClD,CAAC;AACJ,CAAC","sourcesContent":["import { TransportStatusError } from '@ledgerhq/hw-transport';\nimport type Transport from '@ledgerhq/hw-transport';\n\nimport { ERC20_WRITE_SELECTORS, NFT_ONLY_SELECTORS } from './constants';\nimport {\n AppConfigurationResponse,\n GetAppNameAndVersionResponse,\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 { LedgerMobileBridgeOptions } from './type';\nimport { getTransactionSelector } from './utils';\n\n/** Ledger APDU: CONDITIONS_OF_USE_NOT_SATISFIED (user rejected on device). */\nconst LEDGER_USER_REJECTION_STATUS = 0x6985;\n\n// MobileBridge Type will always use LedgerBridge with LedgerMobileBridgeOptions\nexport type MobileBridge = LedgerBridge<LedgerMobileBridgeOptions> & {\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 readonly #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 * @returns A promise that will resolve once the bridge is initialized.\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 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.message - The EIP712 message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignTypedData({\n hdPath,\n message,\n }: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse> {\n return this.#getEthApp().signEIP712Message(hdPath, message);\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 * Tries clear-signing first. If resolution fails (e.g. no Ledger plugin for the chain or contract),\n * falls back to blind signing via `signTransaction(..., null)` unless the user rejected on the device.\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 selector = getTransactionSelector(tx);\n const nft = Boolean(selector && NFT_ONLY_SELECTORS.has(selector));\n const erc20 = Boolean(selector && ERC20_WRITE_SELECTORS.has(selector));\n\n const ethApp = this.#getEthApp();\n\n try {\n return await ethApp.clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20,\n nft,\n });\n } catch (error: unknown) {\n if (LedgerMobileBridge.#isLedgerUserRejection(error)) {\n throw error;\n }\n\n console.warn(\n 'Ledger clear-sign failed; falling back to blind signing.',\n error,\n );\n return ethApp.signTransaction(hdPath, tx, null);\n }\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 current configuration of the Ethereum application on the Ledger device.\n *\n * @returns An object containing the application configuration including blind signing support, ERC20 provisioning status, Stark support, and version.\n */\n async getAppConfiguration(): Promise<AppConfigurationResponse> {\n return this.#getEthApp().getAppConfiguration();\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 /**\n * Detects an explicit on-device rejection so we do not fall back to blind signing\n * and re-prompt the user.\n *\n * @param error - Error from Ledger transport or hw-app-eth.\n * @returns True when the user rejected the action on the device.\n */\n static #isLedgerUserRejection(error: unknown): boolean {\n return (\n error instanceof TransportStatusError &&\n error.statusCode === LEDGER_USER_REJECTION_STATUS\n );\n }\n}\n"]}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTransactionSelector =
|
|
3
|
+
exports.getTransactionSelector = void 0;
|
|
4
4
|
const tx_1 = require("@ethereumjs/tx");
|
|
5
5
|
const util_1 = require("@ethereumjs/util");
|
|
6
6
|
const utils_1 = require("@metamask/utils");
|
|
@@ -26,4 +26,5 @@ function getTransactionSelector(rawTxHex) {
|
|
|
26
26
|
}
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
29
|
+
exports.getTransactionSelector = getTransactionSelector;
|
|
29
30
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AACpD,2CAA0D;AAC1D,2CAAwC;AAExC;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,QAAgB;IACrD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAA,aAAK,EAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,EAAE,GAAG,uBAAkB,CAAC,kBAAkB,CAAC,IAAA,iBAAU,EAAC,WAAW,CAAC,CAAC,CAAC;QAC1E,MAAM,OAAO,GAAG,IAAA,iBAAU,EAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,YAAY,GAAG,CAAC,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,mBAAmB;QAC5D,IAAI,OAAO,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAbD,wDAaC","sourcesContent":["import { TransactionFactory } from '@ethereumjs/tx';\nimport { bytesToHex, hexToBytes } from '@ethereumjs/util';\nimport { add0x } from '@metamask/utils';\n\n/**\n * Returns the 4-byte selector from raw serialized transaction hex or undefined if not present.\n * Supports legacy RLP and EIP-2718 typed transactions (via `@ethereumjs/tx`).\n *\n * @param rawTxHex - Raw serialized transaction hex (with or without `0x` prefix).\n * @returns The selector (`0x` + 8 hex digits, lowercased) or undefined if parsing fails or no calldata.\n */\nexport function getTransactionSelector(rawTxHex: string): string | undefined {\n try {\n const prefixedHex = add0x(rawTxHex);\n const tx = TransactionFactory.fromSerializedData(hexToBytes(prefixedHex));\n const dataHex = bytesToHex(tx.data);\n const selectorSize = 2 /* 0x */ + 4 * 2; /* 4 bytes (hex) */\n if (dataHex.length >= selectorSize) {\n return dataHex.slice(0, selectorSize).toLowerCase();\n }\n } catch {\n // ignore parse errors\n }\n return undefined;\n}\n"]}
|
|
@@ -137,6 +137,96 @@ class LedgerKeyring extends v2_2.EthKeyringWrapper {
|
|
|
137
137
|
this.registry.delete(accountId);
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* @returns The current derivation path used by the inner keyring.
|
|
142
|
+
*/
|
|
143
|
+
get hdPath() {
|
|
144
|
+
return this.inner.hdPath;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @returns The bridge instance used by the inner keyring to communicate
|
|
148
|
+
* with the device.
|
|
149
|
+
*/
|
|
150
|
+
get bridge() {
|
|
151
|
+
return this.inner.bridge;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @returns The device ID for the paired Ledger device.
|
|
155
|
+
*/
|
|
156
|
+
getDeviceId() {
|
|
157
|
+
return this.inner.getDeviceId();
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Set the device ID for the paired Ledger device.
|
|
161
|
+
*
|
|
162
|
+
* @param deviceId - The device ID to set.
|
|
163
|
+
*/
|
|
164
|
+
setDeviceId(deviceId) {
|
|
165
|
+
this.inner.setDeviceId(deviceId);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Set the derivation path on the inner keyring.
|
|
169
|
+
*
|
|
170
|
+
* @param hdPath - The derivation path to set.
|
|
171
|
+
*/
|
|
172
|
+
setHdPath(hdPath) {
|
|
173
|
+
this.inner.setHdPath(hdPath);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Fetch the first page of candidate addresses from the device.
|
|
177
|
+
*
|
|
178
|
+
* @returns The first page of accounts.
|
|
179
|
+
*/
|
|
180
|
+
async getFirstPage() {
|
|
181
|
+
return this.inner.getFirstPage();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Fetch the next page of candidate addresses from the device.
|
|
185
|
+
*
|
|
186
|
+
* @returns The next page of accounts.
|
|
187
|
+
*/
|
|
188
|
+
async getNextPage() {
|
|
189
|
+
return this.inner.getNextPage();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Fetch the previous page of candidate addresses from the device.
|
|
193
|
+
*
|
|
194
|
+
* @returns The previous page of accounts.
|
|
195
|
+
*/
|
|
196
|
+
async getPreviousPage() {
|
|
197
|
+
return this.inner.getPreviousPage();
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Clear the inner keyring's device-pairing state and accounts, and reset
|
|
201
|
+
* the V2 account registry to keep them in sync.
|
|
202
|
+
*/
|
|
203
|
+
async forgetDevice() {
|
|
204
|
+
await this.withLock(async () => {
|
|
205
|
+
this.inner.forgetDevice();
|
|
206
|
+
this.registry.clear();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @returns Whether the inner keyring has an unlocked HD key.
|
|
211
|
+
*/
|
|
212
|
+
isUnlocked() {
|
|
213
|
+
return this.inner.isUnlocked();
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Attempt to open the Ethereum app on the connected Ledger device.
|
|
217
|
+
*
|
|
218
|
+
* @returns Whether the app was opened.
|
|
219
|
+
*/
|
|
220
|
+
async attemptMakeApp() {
|
|
221
|
+
return this.inner.attemptMakeApp();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @returns The app name and version currently running on the connected
|
|
225
|
+
* Ledger device.
|
|
226
|
+
*/
|
|
227
|
+
async getAppNameAndVersion() {
|
|
228
|
+
return this.inner.getAppNameAndVersion();
|
|
229
|
+
}
|
|
140
230
|
}
|
|
141
231
|
exports.LedgerKeyring = LedgerKeyring;
|
|
142
232
|
_LedgerKeyring_instances = new WeakSet(), _LedgerKeyring_getChecksumHexAddress = function _LedgerKeyring_getChecksumHexAddress(address) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.cjs","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":";;;;;;;;;AACA,uDAK+B;AAE/B,iDAAuD;AAMvD,iDAA6D;AAE7D,2CAA4D;AAK5D;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,eAAe;CAC1B,CAAC;AAEF,MAAM,yBAAyB,GAAwB;IACrD,MAAM,EAAE,CAAC,sBAAQ,CAAC,GAAG,CAAC;IACtB,KAAK,EAAE;QACL,WAAW,EAAE,IAAI;QACjB,UAAU,E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F,IAAI,EAAE,4BAAc,CAAC,GAAG;QACxB,OAAO;QACP,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,sBAAsB,CAAC;QACpC,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,IAAI,EAAE,6CAA+B,CAAC,QAAQ;gBAC9C,EAAE,EAAE,IAAI,CAAC,aAAa;gBACtB,UAAU,EAAE,YAAY;gBACxB,cAAc,EAAE,OAAO,CAAC,MAAM;aAC/B;SACF;KACF,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringAccount, EntropySourceId } from '@metamask/keyring-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n KeyringCapabilities,\n Keyring,\n} from '@metamask/keyring-api/v2';\nimport { EthKeyringWrapper } from '@metamask/keyring-sdk/v2';\nimport type { AccountId, EthKeyring } from '@metamask/keyring-utils';\nimport { add0x, getChecksumAddress } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { LedgerKeyring as LegacyLedgerKeyring } from '../ledger-keyring';\n\n/**\n * Methods supported by Ledger keyring EOA accounts.\n * Ledger keyrings support a subset of signing methods (no encryption, app keys, or EIP-7702).\n */\nconst LEDGER_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV4,\n];\n\nconst ledgerKeyringCapabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n bip44: {\n deriveIndex: true,\n derivePath: true,\n },\n};\n\n/**\n * Ledger Live HD path constant.\n */\nconst LEDGER_LIVE_HD_PATH = `m/44'/60'/0'/0/0`;\n\n/**\n * BIP-44 standard HD path prefix constant for Ethereum.\n */\nconst BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;\n\n/**\n * Regex pattern for validating and parsing Ledger Live derivation paths.\n * Format: m/44'/60'/{index}'/0/0\n */\nconst LEDGER_LIVE_PATH_PATTERN = /^m\\/44'\\/60'\\/(\\d+)'\\/0\\/0$/u;\n\n/**\n * Regex pattern for validating and parsing non-Ledger-Live derivation paths.\n * Supports Legacy (m/44'/60'/0'/{index}), BIP44 (m/44'/60'/0'/0/{index}),\n * and custom paths that follow the m/44'/60'/... pattern.\n */\nconst INDEX_AT_END_PATH_PATTERN = /^(m\\/44'\\/60'(?:\\/\\d+'?)*)\\/(\\d+)$/u;\n\n/**\n * Concrete {@link Keyring} adapter for {@link LedgerKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * Ledger keyring via the unified V2 interface.\n *\n * All Ledger keyring accounts are BIP-44 derived from the device.\n */\nexport type LedgerKeyringOptions = {\n legacyKeyring: LegacyLedgerKeyring;\n entropySource: EntropySourceId;\n};\n\n// LegacyLedgerKeyring.signTransaction returns `TypedTransaction | OldEthJsTransaction` for\n// backwards compatibility with old ethereumjs-tx, but EthKeyring expects `TypedTxData`.\n// The runtime behavior is correct - we cast the type to satisfy the constraint.\ntype LedgerKeyringAsEthKeyring = LegacyLedgerKeyring & EthKeyring;\n\nexport class LedgerKeyring\n extends EthKeyringWrapper<\n LedgerKeyringAsEthKeyring,\n Bip44Account<KeyringAccount>\n >\n implements Keyring\n{\n readonly entropySource: EntropySourceId;\n\n constructor(options: LedgerKeyringOptions) {\n super({\n type: KeyringType.Ledger,\n inner: options.legacyKeyring as LedgerKeyringAsEthKeyring,\n capabilities: ledgerKeyringCapabilities,\n });\n this.entropySource = options.entropySource;\n }\n\n /**\n * Normalizes an address to a checksummed hex address.\n *\n * @param address - The address to normalize.\n * @returns The checksummed hex address.\n */\n #getChecksumHexAddress(address: string): Hex {\n return getChecksumAddress(add0x(address));\n }\n\n /**\n * Parses a derivation path to extract the base HD path and account index.\n *\n * Supports two path formats:\n * - Ledger Live: m/44'/60'/{index}'/0/0 → base: m/44'/60'/0'/0/0, index from position 3\n * - Index at end: m/44'/60'/.../{index} → base: m/44'/60'/..., index from last segment\n *\n * @param derivationPath - The full derivation path.\n * @returns The base HD path and account index.\n * @throws If the path format is invalid.\n */\n #parseDerivationPath(derivationPath: string): {\n basePath: string;\n index: number;\n } {\n // Try Ledger Live format first: m/44'/60'/{index}'/0/0\n const ledgerLiveMatch = derivationPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (ledgerLiveMatch?.[1]) {\n return {\n // This constant is used by `inner.setHdPath` to determine which derivation\n // mode we should use (Ledger Live derivation mode here).\n basePath: LEDGER_LIVE_HD_PATH,\n index: parseInt(ledgerLiveMatch[1], 10),\n };\n }\n\n // Try index-at-end format: m/44'/60'/.../{index}\n const indexAtEndMatch = derivationPath.match(INDEX_AT_END_PATH_PATTERN);\n if (indexAtEndMatch) {\n // If the condition is true, indexAtEndMatch[1] and indexAtEndMatch[2] are defined, so\n // we can safely cast them to string.\n // This is necessary to get 100% code coverage.\n return {\n // Here, we use a derivation path prefix for `inner.setHdPath`\n // (prefix + index derivation mode).\n basePath: indexAtEndMatch[1] as string,\n index: parseInt(indexAtEndMatch[2] as string, 10),\n };\n }\n\n throw new Error(\n `Invalid derivation path format: ${derivationPath}. ` +\n `Expected Ledger Live (m/44'/60'/{index}'/0/0) or index-at-end (m/44'/60'/.../{index}) format.`,\n );\n }\n\n /**\n * Gets the index for an address from the account details.\n *\n * @param address - The address to get the index for.\n * @returns The index for the address.\n * @throws If the address is not found in account details.\n */\n #getIndexForAddress(address: Hex): number {\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details) {\n throw new Error(\n `Address ${checksummedAddress} not found in account details`,\n );\n }\n\n // Extract index from hdPath\n const { hdPath } = details;\n if (!hdPath) {\n throw new Error(`No HD path found for address ${checksummedAddress}`);\n }\n\n // Ledger supports multiple derivation path formats:\n // - Ledger Live (bip44: true): m/44'/60'/{index}'/0/0 - index at position 3\n // - Other paths (bip44: false): {hdPath}/{index} - index at end\n // - BIP44: m/44'/60'/0'/0/{index}\n // - Legacy: m/44'/60'/0'/{index}\n // - Custom paths via setHdPath\n //\n // We use the `bip44` flag to determine which extraction pattern to use.\n if (details.bip44) {\n // Ledger Live format: m/44'/60'/{index}'/0/0\n const match = hdPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (match?.[1]) {\n return parseInt(match[1], 10);\n }\n } else {\n // Index-at-end format: m/44'/60'/.../{index}\n const match = hdPath.match(INDEX_AT_END_PATH_PATTERN);\n if (match?.[2]) {\n return parseInt(match[2], 10);\n }\n }\n\n throw new Error(`Could not extract index from HD path: ${hdPath}`);\n }\n\n /**\n * Creates a Bip44Account object for the given address.\n *\n * @param address - The account address.\n * @param addressIndex - The account index in the derivation path.\n * @returns The created Bip44Account.\n */\n #createKeyringAccount(\n address: Hex,\n addressIndex: number,\n ): Bip44Account<KeyringAccount> {\n const id = this.registry.register(address);\n\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details?.hdPath) {\n throw new Error(\n `No HD path found for address ${checksummedAddress}. Cannot create account.`,\n );\n }\n\n const account: Bip44Account<KeyringAccount> = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...LEDGER_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: this.entropySource,\n groupIndex: addressIndex,\n derivationPath: details.hdPath,\n },\n },\n };\n\n this.registry.set(account);\n return account;\n }\n\n async getAccounts(): Promise<Bip44Account<KeyringAccount>[]> {\n const addresses = await this.inner.getAccounts();\n\n if (addresses.length === 0) {\n return [];\n }\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n const addressIndex = this.#getIndexForAddress(address);\n return this.#createKeyringAccount(address, addressIndex);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withLock(async () => {\n if (\n options.type === 'bip44:derive-path' ||\n options.type === 'bip44:derive-index'\n ) {\n // Validate that the entropy source matches this keyring's entropy source\n if (options.entropySource !== this.entropySource) {\n throw new Error(\n `Entropy source mismatch: expected '${this.entropySource}', got '${options.entropySource}'`,\n );\n }\n } else {\n throw new Error(\n `Unsupported account creation type for LedgerKeyring: ${String(\n options.type,\n )}`,\n );\n }\n\n // Check if an account at this index already exists with the same derivation path\n const currentAccounts = await this.getAccounts();\n\n let targetIndex: number;\n let basePath: string;\n let derivationPath: string;\n\n if (options.type === 'bip44:derive-path') {\n // Parse the derivation path to extract base path and index\n const parsed = this.#parseDerivationPath(options.derivationPath);\n targetIndex = parsed.index;\n basePath = parsed.basePath;\n\n derivationPath = options.derivationPath;\n } else {\n // derive-index uses BIP-44 standard path by default\n targetIndex = options.groupIndex;\n basePath = BIP44_HD_PATH_PREFIX;\n derivationPath = `${basePath}/${targetIndex}`;\n }\n\n const existingAccount = currentAccounts.find((account) => {\n return (\n account.options.entropy.groupIndex === targetIndex &&\n account.options.entropy.derivationPath === derivationPath\n );\n });\n\n if (existingAccount) {\n return [existingAccount];\n }\n\n // Derive the account at the specified index\n this.inner.setHdPath(basePath);\n this.inner.setAccountToUnlock(targetIndex);\n const [newAddress] = await this.inner.addAccounts(1);\n\n if (!newAddress) {\n throw new Error('Failed to create new account');\n }\n\n const newAccount = this.#createKeyringAccount(newAddress, targetIndex);\n\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const { address } = await this.getAccount(accountId);\n const hexAddress = this.toHexAddress(address);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(hexAddress);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-keyring.cjs","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":";;;;;;;;;AACA,uDAK+B;AAE/B,iDAAuD;AAMvD,iDAA6D;AAE7D,2CAA4D;AAa5D;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,eAAe;CAC1B,CAAC;AAEF,MAAM,yBAAyB,GAAwB;IACrD,MAAM,EAAE,CAAC,sBAAQ,CAAC,GAAG,CAAC;IACtB,KAAK,EAAE;QACL,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,IAAI;KACjB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,MAAM,wBAAwB,GAAG,8BAA8B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,qCAAqC,CAAC;AAoBxE,MAAa,aACX,SAAQ,sBAGP;IAKD,YAAY,OAA6B;QACvC,KAAK,CAAC;YACJ,IAAI,EAAE,gBAAW,CAAC,MAAM;YACxB,KAAK,EAAE,OAAO,CAAC,aAA0C;YACzD,YAAY,EAAE,yBAAyB;SACxC,CAAC,CAAC;;QACH,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAC7C,CAAC;IAoJD,KAAK,CAAC,WAAW;QACf,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAEjD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,SAAS,CAAC,GAAG,CAAC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Q,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,EAAE,CAAC,CAAC;AACrE,CAAC,qFAUC,OAAY,EACZ,YAAoB;IAEpB,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE3C,MAAM,kBAAkB,GAAG,uBAAA,IAAI,sEAAuB,MAA3B,IAAI,EAAwB,OAAO,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAE9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,gCAAgC,kBAAkB,0BAA0B,CAC7E,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAiC;QAC5C,EAAE;QACF,IAAI,EAAE,4BAAc,CAAC,GAAG;QACxB,OAAO;QACP,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,sBAAsB,CAAC;QACpC,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,IAAI,EAAE,6CAA+B,CAAC,QAAQ;gBAC9C,EAAE,EAAE,IAAI,CAAC,aAAa;gBACtB,UAAU,EAAE,YAAY;gBACxB,cAAc,EAAE,OAAO,CAAC,MAAM;aAC/B;SACF;KACF,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringAccount, EntropySourceId } from '@metamask/keyring-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n KeyringCapabilities,\n Keyring,\n} from '@metamask/keyring-api/v2';\nimport { EthKeyringWrapper } from '@metamask/keyring-sdk/v2';\nimport type { AccountId, EthKeyring } from '@metamask/keyring-utils';\nimport { add0x, getChecksumAddress } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n GetAppNameAndVersionResponse,\n LedgerBridge,\n LedgerBridgeOptions,\n} from '../ledger-bridge';\nimport type {\n AccountPage,\n LedgerKeyring as LegacyLedgerKeyring,\n} from '../ledger-keyring';\n\n/**\n * Methods supported by Ledger keyring EOA accounts.\n * Ledger keyrings support a subset of signing methods (no encryption, app keys, or EIP-7702).\n */\nconst LEDGER_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV4,\n];\n\nconst ledgerKeyringCapabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n bip44: {\n deriveIndex: true,\n derivePath: true,\n },\n};\n\n/**\n * Ledger Live HD path constant.\n */\nconst LEDGER_LIVE_HD_PATH = `m/44'/60'/0'/0/0`;\n\n/**\n * BIP-44 standard HD path prefix constant for Ethereum.\n */\nconst BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;\n\n/**\n * Regex pattern for validating and parsing Ledger Live derivation paths.\n * Format: m/44'/60'/{index}'/0/0\n */\nconst LEDGER_LIVE_PATH_PATTERN = /^m\\/44'\\/60'\\/(\\d+)'\\/0\\/0$/u;\n\n/**\n * Regex pattern for validating and parsing non-Ledger-Live derivation paths.\n * Supports Legacy (m/44'/60'/0'/{index}), BIP44 (m/44'/60'/0'/0/{index}),\n * and custom paths that follow the m/44'/60'/... pattern.\n */\nconst INDEX_AT_END_PATH_PATTERN = /^(m\\/44'\\/60'(?:\\/\\d+'?)*)\\/(\\d+)$/u;\n\n/**\n * Concrete {@link Keyring} adapter for {@link LedgerKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * Ledger keyring via the unified V2 interface.\n *\n * All Ledger keyring accounts are BIP-44 derived from the device.\n */\nexport type LedgerKeyringOptions = {\n legacyKeyring: LegacyLedgerKeyring;\n entropySource: EntropySourceId;\n};\n\n// LegacyLedgerKeyring.signTransaction returns `TypedTransaction | OldEthJsTransaction` for\n// backwards compatibility with old ethereumjs-tx, but EthKeyring expects `TypedTxData`.\n// The runtime behavior is correct - we cast the type to satisfy the constraint.\ntype LedgerKeyringAsEthKeyring = LegacyLedgerKeyring & EthKeyring;\n\nexport class LedgerKeyring\n extends EthKeyringWrapper<\n LedgerKeyringAsEthKeyring,\n Bip44Account<KeyringAccount>\n >\n implements Keyring\n{\n readonly entropySource: EntropySourceId;\n\n constructor(options: LedgerKeyringOptions) {\n super({\n type: KeyringType.Ledger,\n inner: options.legacyKeyring as LedgerKeyringAsEthKeyring,\n capabilities: ledgerKeyringCapabilities,\n });\n this.entropySource = options.entropySource;\n }\n\n /**\n * Normalizes an address to a checksummed hex address.\n *\n * @param address - The address to normalize.\n * @returns The checksummed hex address.\n */\n #getChecksumHexAddress(address: string): Hex {\n return getChecksumAddress(add0x(address));\n }\n\n /**\n * Parses a derivation path to extract the base HD path and account index.\n *\n * Supports two path formats:\n * - Ledger Live: m/44'/60'/{index}'/0/0 → base: m/44'/60'/0'/0/0, index from position 3\n * - Index at end: m/44'/60'/.../{index} → base: m/44'/60'/..., index from last segment\n *\n * @param derivationPath - The full derivation path.\n * @returns The base HD path and account index.\n * @throws If the path format is invalid.\n */\n #parseDerivationPath(derivationPath: string): {\n basePath: string;\n index: number;\n } {\n // Try Ledger Live format first: m/44'/60'/{index}'/0/0\n const ledgerLiveMatch = derivationPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (ledgerLiveMatch?.[1]) {\n return {\n // This constant is used by `inner.setHdPath` to determine which derivation\n // mode we should use (Ledger Live derivation mode here).\n basePath: LEDGER_LIVE_HD_PATH,\n index: parseInt(ledgerLiveMatch[1], 10),\n };\n }\n\n // Try index-at-end format: m/44'/60'/.../{index}\n const indexAtEndMatch = derivationPath.match(INDEX_AT_END_PATH_PATTERN);\n if (indexAtEndMatch) {\n // If the condition is true, indexAtEndMatch[1] and indexAtEndMatch[2] are defined, so\n // we can safely cast them to string.\n // This is necessary to get 100% code coverage.\n return {\n // Here, we use a derivation path prefix for `inner.setHdPath`\n // (prefix + index derivation mode).\n basePath: indexAtEndMatch[1] as string,\n index: parseInt(indexAtEndMatch[2] as string, 10),\n };\n }\n\n throw new Error(\n `Invalid derivation path format: ${derivationPath}. ` +\n `Expected Ledger Live (m/44'/60'/{index}'/0/0) or index-at-end (m/44'/60'/.../{index}) format.`,\n );\n }\n\n /**\n * Gets the index for an address from the account details.\n *\n * @param address - The address to get the index for.\n * @returns The index for the address.\n * @throws If the address is not found in account details.\n */\n #getIndexForAddress(address: Hex): number {\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details) {\n throw new Error(\n `Address ${checksummedAddress} not found in account details`,\n );\n }\n\n // Extract index from hdPath\n const { hdPath } = details;\n if (!hdPath) {\n throw new Error(`No HD path found for address ${checksummedAddress}`);\n }\n\n // Ledger supports multiple derivation path formats:\n // - Ledger Live (bip44: true): m/44'/60'/{index}'/0/0 - index at position 3\n // - Other paths (bip44: false): {hdPath}/{index} - index at end\n // - BIP44: m/44'/60'/0'/0/{index}\n // - Legacy: m/44'/60'/0'/{index}\n // - Custom paths via setHdPath\n //\n // We use the `bip44` flag to determine which extraction pattern to use.\n if (details.bip44) {\n // Ledger Live format: m/44'/60'/{index}'/0/0\n const match = hdPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (match?.[1]) {\n return parseInt(match[1], 10);\n }\n } else {\n // Index-at-end format: m/44'/60'/.../{index}\n const match = hdPath.match(INDEX_AT_END_PATH_PATTERN);\n if (match?.[2]) {\n return parseInt(match[2], 10);\n }\n }\n\n throw new Error(`Could not extract index from HD path: ${hdPath}`);\n }\n\n /**\n * Creates a Bip44Account object for the given address.\n *\n * @param address - The account address.\n * @param addressIndex - The account index in the derivation path.\n * @returns The created Bip44Account.\n */\n #createKeyringAccount(\n address: Hex,\n addressIndex: number,\n ): Bip44Account<KeyringAccount> {\n const id = this.registry.register(address);\n\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details?.hdPath) {\n throw new Error(\n `No HD path found for address ${checksummedAddress}. Cannot create account.`,\n );\n }\n\n const account: Bip44Account<KeyringAccount> = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...LEDGER_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: this.entropySource,\n groupIndex: addressIndex,\n derivationPath: details.hdPath,\n },\n },\n };\n\n this.registry.set(account);\n return account;\n }\n\n async getAccounts(): Promise<Bip44Account<KeyringAccount>[]> {\n const addresses = await this.inner.getAccounts();\n\n if (addresses.length === 0) {\n return [];\n }\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n const addressIndex = this.#getIndexForAddress(address);\n return this.#createKeyringAccount(address, addressIndex);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withLock(async () => {\n if (\n options.type === 'bip44:derive-path' ||\n options.type === 'bip44:derive-index'\n ) {\n // Validate that the entropy source matches this keyring's entropy source\n if (options.entropySource !== this.entropySource) {\n throw new Error(\n `Entropy source mismatch: expected '${this.entropySource}', got '${options.entropySource}'`,\n );\n }\n } else {\n throw new Error(\n `Unsupported account creation type for LedgerKeyring: ${String(\n options.type,\n )}`,\n );\n }\n\n // Check if an account at this index already exists with the same derivation path\n const currentAccounts = await this.getAccounts();\n\n let targetIndex: number;\n let basePath: string;\n let derivationPath: string;\n\n if (options.type === 'bip44:derive-path') {\n // Parse the derivation path to extract base path and index\n const parsed = this.#parseDerivationPath(options.derivationPath);\n targetIndex = parsed.index;\n basePath = parsed.basePath;\n\n derivationPath = options.derivationPath;\n } else {\n // derive-index uses BIP-44 standard path by default\n targetIndex = options.groupIndex;\n basePath = BIP44_HD_PATH_PREFIX;\n derivationPath = `${basePath}/${targetIndex}`;\n }\n\n const existingAccount = currentAccounts.find((account) => {\n return (\n account.options.entropy.groupIndex === targetIndex &&\n account.options.entropy.derivationPath === derivationPath\n );\n });\n\n if (existingAccount) {\n return [existingAccount];\n }\n\n // Derive the account at the specified index\n this.inner.setHdPath(basePath);\n this.inner.setAccountToUnlock(targetIndex);\n const [newAddress] = await this.inner.addAccounts(1);\n\n if (!newAddress) {\n throw new Error('Failed to create new account');\n }\n\n const newAccount = this.#createKeyringAccount(newAddress, targetIndex);\n\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const { address } = await this.getAccount(accountId);\n const hexAddress = this.toHexAddress(address);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(hexAddress);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n\n /**\n * @returns The current derivation path used by the inner keyring.\n */\n get hdPath(): string {\n return this.inner.hdPath;\n }\n\n /**\n * @returns The bridge instance used by the inner keyring to communicate\n * with the device.\n */\n get bridge(): LedgerBridge<LedgerBridgeOptions> {\n return this.inner.bridge;\n }\n\n /**\n * @returns The device ID for the paired Ledger device.\n */\n getDeviceId(): string {\n return this.inner.getDeviceId();\n }\n\n /**\n * Set the device ID for the paired Ledger device.\n *\n * @param deviceId - The device ID to set.\n */\n setDeviceId(deviceId: string): void {\n this.inner.setDeviceId(deviceId);\n }\n\n /**\n * Set the derivation path on the inner keyring.\n *\n * @param hdPath - The derivation path to set.\n */\n setHdPath(hdPath: string): void {\n this.inner.setHdPath(hdPath);\n }\n\n /**\n * Fetch the first page of candidate addresses from the device.\n *\n * @returns The first page of accounts.\n */\n async getFirstPage(): Promise<AccountPage> {\n return this.inner.getFirstPage();\n }\n\n /**\n * Fetch the next page of candidate addresses from the device.\n *\n * @returns The next page of accounts.\n */\n async getNextPage(): Promise<AccountPage> {\n return this.inner.getNextPage();\n }\n\n /**\n * Fetch the previous page of candidate addresses from the device.\n *\n * @returns The previous page of accounts.\n */\n async getPreviousPage(): Promise<AccountPage> {\n return this.inner.getPreviousPage();\n }\n\n /**\n * Clear the inner keyring's device-pairing state and accounts, and reset\n * the V2 account registry to keep them in sync.\n */\n async forgetDevice(): Promise<void> {\n await this.withLock(async () => {\n this.inner.forgetDevice();\n this.registry.clear();\n });\n }\n\n /**\n * @returns Whether the inner keyring has an unlocked HD key.\n */\n isUnlocked(): boolean {\n return this.inner.isUnlocked();\n }\n\n /**\n * Attempt to open the Ethereum app on the connected Ledger device.\n *\n * @returns Whether the app was opened.\n */\n async attemptMakeApp(): Promise<boolean> {\n return this.inner.attemptMakeApp();\n }\n\n /**\n * @returns The app name and version currently running on the connected\n * Ledger device.\n */\n async getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse> {\n return this.inner.getAppNameAndVersion();\n }\n}\n"]}
|
|
@@ -3,7 +3,8 @@ import type { KeyringAccount, EntropySourceId } from "@metamask/keyring-api";
|
|
|
3
3
|
import type { CreateAccountOptions, Keyring } from "@metamask/keyring-api/v2";
|
|
4
4
|
import { EthKeyringWrapper } from "@metamask/keyring-sdk/v2";
|
|
5
5
|
import type { AccountId, EthKeyring } from "@metamask/keyring-utils";
|
|
6
|
-
import type {
|
|
6
|
+
import type { GetAppNameAndVersionResponse, LedgerBridge, LedgerBridgeOptions } from "../ledger-bridge.cjs";
|
|
7
|
+
import type { AccountPage, LedgerKeyring as LegacyLedgerKeyring } from "../ledger-keyring.cjs";
|
|
7
8
|
/**
|
|
8
9
|
* Concrete {@link Keyring} adapter for {@link LedgerKeyring}.
|
|
9
10
|
*
|
|
@@ -29,6 +30,69 @@ export declare class LedgerKeyring extends EthKeyringWrapper<LedgerKeyringAsEthK
|
|
|
29
30
|
* @param accountId - The account ID to delete.
|
|
30
31
|
*/
|
|
31
32
|
deleteAccount(accountId: AccountId): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* @returns The current derivation path used by the inner keyring.
|
|
35
|
+
*/
|
|
36
|
+
get hdPath(): string;
|
|
37
|
+
/**
|
|
38
|
+
* @returns The bridge instance used by the inner keyring to communicate
|
|
39
|
+
* with the device.
|
|
40
|
+
*/
|
|
41
|
+
get bridge(): LedgerBridge<LedgerBridgeOptions>;
|
|
42
|
+
/**
|
|
43
|
+
* @returns The device ID for the paired Ledger device.
|
|
44
|
+
*/
|
|
45
|
+
getDeviceId(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Set the device ID for the paired Ledger device.
|
|
48
|
+
*
|
|
49
|
+
* @param deviceId - The device ID to set.
|
|
50
|
+
*/
|
|
51
|
+
setDeviceId(deviceId: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Set the derivation path on the inner keyring.
|
|
54
|
+
*
|
|
55
|
+
* @param hdPath - The derivation path to set.
|
|
56
|
+
*/
|
|
57
|
+
setHdPath(hdPath: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch the first page of candidate addresses from the device.
|
|
60
|
+
*
|
|
61
|
+
* @returns The first page of accounts.
|
|
62
|
+
*/
|
|
63
|
+
getFirstPage(): Promise<AccountPage>;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch the next page of candidate addresses from the device.
|
|
66
|
+
*
|
|
67
|
+
* @returns The next page of accounts.
|
|
68
|
+
*/
|
|
69
|
+
getNextPage(): Promise<AccountPage>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch the previous page of candidate addresses from the device.
|
|
72
|
+
*
|
|
73
|
+
* @returns The previous page of accounts.
|
|
74
|
+
*/
|
|
75
|
+
getPreviousPage(): Promise<AccountPage>;
|
|
76
|
+
/**
|
|
77
|
+
* Clear the inner keyring's device-pairing state and accounts, and reset
|
|
78
|
+
* the V2 account registry to keep them in sync.
|
|
79
|
+
*/
|
|
80
|
+
forgetDevice(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* @returns Whether the inner keyring has an unlocked HD key.
|
|
83
|
+
*/
|
|
84
|
+
isUnlocked(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Attempt to open the Ethereum app on the connected Ledger device.
|
|
87
|
+
*
|
|
88
|
+
* @returns Whether the app was opened.
|
|
89
|
+
*/
|
|
90
|
+
attemptMakeApp(): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* @returns The app name and version currently running on the connected
|
|
93
|
+
* Ledger device.
|
|
94
|
+
*/
|
|
95
|
+
getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;
|
|
32
96
|
}
|
|
33
97
|
export {};
|
|
34
98
|
//# sourceMappingURL=ledger-keyring.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.d.cts","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAO1D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,EACR,iCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAE,iCAAiC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,gCAAgC;AAIrE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ledger-keyring.d.cts","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAO1D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,EACR,iCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAE,i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e,IAAI,OAAO,CAAC,WAAW,CAAC;IAI7C;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;CAGpE"}
|
|
@@ -3,7 +3,8 @@ import type { KeyringAccount, EntropySourceId } from "@metamask/keyring-api";
|
|
|
3
3
|
import type { CreateAccountOptions, Keyring } from "@metamask/keyring-api/v2";
|
|
4
4
|
import { EthKeyringWrapper } from "@metamask/keyring-sdk/v2";
|
|
5
5
|
import type { AccountId, EthKeyring } from "@metamask/keyring-utils";
|
|
6
|
-
import type {
|
|
6
|
+
import type { GetAppNameAndVersionResponse, LedgerBridge, LedgerBridgeOptions } from "../ledger-bridge.mjs";
|
|
7
|
+
import type { AccountPage, LedgerKeyring as LegacyLedgerKeyring } from "../ledger-keyring.mjs";
|
|
7
8
|
/**
|
|
8
9
|
* Concrete {@link Keyring} adapter for {@link LedgerKeyring}.
|
|
9
10
|
*
|
|
@@ -29,6 +30,69 @@ export declare class LedgerKeyring extends EthKeyringWrapper<LedgerKeyringAsEthK
|
|
|
29
30
|
* @param accountId - The account ID to delete.
|
|
30
31
|
*/
|
|
31
32
|
deleteAccount(accountId: AccountId): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* @returns The current derivation path used by the inner keyring.
|
|
35
|
+
*/
|
|
36
|
+
get hdPath(): string;
|
|
37
|
+
/**
|
|
38
|
+
* @returns The bridge instance used by the inner keyring to communicate
|
|
39
|
+
* with the device.
|
|
40
|
+
*/
|
|
41
|
+
get bridge(): LedgerBridge<LedgerBridgeOptions>;
|
|
42
|
+
/**
|
|
43
|
+
* @returns The device ID for the paired Ledger device.
|
|
44
|
+
*/
|
|
45
|
+
getDeviceId(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Set the device ID for the paired Ledger device.
|
|
48
|
+
*
|
|
49
|
+
* @param deviceId - The device ID to set.
|
|
50
|
+
*/
|
|
51
|
+
setDeviceId(deviceId: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Set the derivation path on the inner keyring.
|
|
54
|
+
*
|
|
55
|
+
* @param hdPath - The derivation path to set.
|
|
56
|
+
*/
|
|
57
|
+
setHdPath(hdPath: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch the first page of candidate addresses from the device.
|
|
60
|
+
*
|
|
61
|
+
* @returns The first page of accounts.
|
|
62
|
+
*/
|
|
63
|
+
getFirstPage(): Promise<AccountPage>;
|
|
64
|
+
/**
|
|
65
|
+
* Fetch the next page of candidate addresses from the device.
|
|
66
|
+
*
|
|
67
|
+
* @returns The next page of accounts.
|
|
68
|
+
*/
|
|
69
|
+
getNextPage(): Promise<AccountPage>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch the previous page of candidate addresses from the device.
|
|
72
|
+
*
|
|
73
|
+
* @returns The previous page of accounts.
|
|
74
|
+
*/
|
|
75
|
+
getPreviousPage(): Promise<AccountPage>;
|
|
76
|
+
/**
|
|
77
|
+
* Clear the inner keyring's device-pairing state and accounts, and reset
|
|
78
|
+
* the V2 account registry to keep them in sync.
|
|
79
|
+
*/
|
|
80
|
+
forgetDevice(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* @returns Whether the inner keyring has an unlocked HD key.
|
|
83
|
+
*/
|
|
84
|
+
isUnlocked(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Attempt to open the Ethereum app on the connected Ledger device.
|
|
87
|
+
*
|
|
88
|
+
* @returns Whether the app was opened.
|
|
89
|
+
*/
|
|
90
|
+
attemptMakeApp(): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* @returns The app name and version currently running on the connected
|
|
93
|
+
* Ledger device.
|
|
94
|
+
*/
|
|
95
|
+
getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;
|
|
32
96
|
}
|
|
33
97
|
export {};
|
|
34
98
|
//# sourceMappingURL=ledger-keyring.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.d.mts","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAO1D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,EACR,iCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAE,iCAAiC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,gCAAgC;AAIrE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ledger-keyring.d.mts","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAO1D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,EACR,iCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAE,iCAAiC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,gCAAgC;AAIrE,OAAO,KAAK,EACV,4BAA4B,EAC5B,YAAY,EACZ,mBAAmB,EACpB,6BAAyB;AAC1B,OAAO,KAAK,EACV,WAAW,EACX,aAAa,IAAI,mBAAmB,EACrC,8BAA0B;AA2C3B;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,mBAAmB,CAAC;IACnC,aAAa,EAAE,eAAe,CAAC;CAChC,CAAC;AAKF,KAAK,yBAAyB,GAAG,mBAAmB,GAAG,UAAU,CAAC;AAElE,qBAAa,aACX,SAAQ,iBAAiB,CACvB,yBAAyB,EACzB,YAAY,CAAC,cAAc,CAAC,CAE9B,YAAW,OAAO;;IAElB,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC;gBAE5B,OAAO,EAAE,oBAAoB;IA2JnC,WAAW,IAAI,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAsBtD,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;IAmE1C;;;;OAIG;IACG,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxD;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,YAAY,CAAC,mBAAmB,CAAC,CAE9C;IAED;;OAEG;IACH,WAAW,IAAI,MAAM;IAIrB;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAInC;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC;IAI1C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAIzC;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC,WAAW,CAAC;IAI7C;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;CAGpE"}
|
|
@@ -134,6 +134,96 @@ export class LedgerKeyring extends EthKeyringWrapper {
|
|
|
134
134
|
this.registry.delete(accountId);
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* @returns The current derivation path used by the inner keyring.
|
|
139
|
+
*/
|
|
140
|
+
get hdPath() {
|
|
141
|
+
return this.inner.hdPath;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @returns The bridge instance used by the inner keyring to communicate
|
|
145
|
+
* with the device.
|
|
146
|
+
*/
|
|
147
|
+
get bridge() {
|
|
148
|
+
return this.inner.bridge;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @returns The device ID for the paired Ledger device.
|
|
152
|
+
*/
|
|
153
|
+
getDeviceId() {
|
|
154
|
+
return this.inner.getDeviceId();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Set the device ID for the paired Ledger device.
|
|
158
|
+
*
|
|
159
|
+
* @param deviceId - The device ID to set.
|
|
160
|
+
*/
|
|
161
|
+
setDeviceId(deviceId) {
|
|
162
|
+
this.inner.setDeviceId(deviceId);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Set the derivation path on the inner keyring.
|
|
166
|
+
*
|
|
167
|
+
* @param hdPath - The derivation path to set.
|
|
168
|
+
*/
|
|
169
|
+
setHdPath(hdPath) {
|
|
170
|
+
this.inner.setHdPath(hdPath);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Fetch the first page of candidate addresses from the device.
|
|
174
|
+
*
|
|
175
|
+
* @returns The first page of accounts.
|
|
176
|
+
*/
|
|
177
|
+
async getFirstPage() {
|
|
178
|
+
return this.inner.getFirstPage();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Fetch the next page of candidate addresses from the device.
|
|
182
|
+
*
|
|
183
|
+
* @returns The next page of accounts.
|
|
184
|
+
*/
|
|
185
|
+
async getNextPage() {
|
|
186
|
+
return this.inner.getNextPage();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Fetch the previous page of candidate addresses from the device.
|
|
190
|
+
*
|
|
191
|
+
* @returns The previous page of accounts.
|
|
192
|
+
*/
|
|
193
|
+
async getPreviousPage() {
|
|
194
|
+
return this.inner.getPreviousPage();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Clear the inner keyring's device-pairing state and accounts, and reset
|
|
198
|
+
* the V2 account registry to keep them in sync.
|
|
199
|
+
*/
|
|
200
|
+
async forgetDevice() {
|
|
201
|
+
await this.withLock(async () => {
|
|
202
|
+
this.inner.forgetDevice();
|
|
203
|
+
this.registry.clear();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @returns Whether the inner keyring has an unlocked HD key.
|
|
208
|
+
*/
|
|
209
|
+
isUnlocked() {
|
|
210
|
+
return this.inner.isUnlocked();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Attempt to open the Ethereum app on the connected Ledger device.
|
|
214
|
+
*
|
|
215
|
+
* @returns Whether the app was opened.
|
|
216
|
+
*/
|
|
217
|
+
async attemptMakeApp() {
|
|
218
|
+
return this.inner.attemptMakeApp();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @returns The app name and version currently running on the connected
|
|
222
|
+
* Ledger device.
|
|
223
|
+
*/
|
|
224
|
+
async getAppNameAndVersion() {
|
|
225
|
+
return this.inner.getAppNameAndVersion();
|
|
226
|
+
}
|
|
137
227
|
}
|
|
138
228
|
_LedgerKeyring_instances = new WeakSet(), _LedgerKeyring_getChecksumHexAddress = function _LedgerKeyring_getChecksumHexAddress(address) {
|
|
139
229
|
return getChecksumAddress(add0x(address));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-keyring.mjs","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,+BAA+B,EAChC,8BAA8B;AAE/B,OAAO,EAAE,WAAW,EAAE,iCAAiC;AAMvD,OAAO,EAAE,iBAAiB,EAAE,iCAAiC;AAE7D,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAK5D;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,SAAS,CAAC,eAAe;IACzB,SAAS,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I,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,gCAAgC,kBAAkB,0BAA0B,CAC7E,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAiC;QAC5C,EAAE;QACF,IAAI,EAAE,cAAc,CAAC,GAAG;QACxB,OAAO;QACP,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,sBAAsB,CAAC;QACpC,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,IAAI,EAAE,+BAA+B,CAAC,QAAQ;gBAC9C,EAAE,EAAE,IAAI,CAAC,aAAa;gBACtB,UAAU,EAAE,YAAY;gBACxB,cAAc,EAAE,OAAO,CAAC,MAAM;aAC/B;SACF;KACF,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringAccount, EntropySourceId } from '@metamask/keyring-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n KeyringCapabilities,\n Keyring,\n} from '@metamask/keyring-api/v2';\nimport { EthKeyringWrapper } from '@metamask/keyring-sdk/v2';\nimport type { AccountId, EthKeyring } from '@metamask/keyring-utils';\nimport { add0x, getChecksumAddress } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { LedgerKeyring as LegacyLedgerKeyring } from '../ledger-keyring';\n\n/**\n * Methods supported by Ledger keyring EOA accounts.\n * Ledger keyrings support a subset of signing methods (no encryption, app keys, or EIP-7702).\n */\nconst LEDGER_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV4,\n];\n\nconst ledgerKeyringCapabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n bip44: {\n deriveIndex: true,\n derivePath: true,\n },\n};\n\n/**\n * Ledger Live HD path constant.\n */\nconst LEDGER_LIVE_HD_PATH = `m/44'/60'/0'/0/0`;\n\n/**\n * BIP-44 standard HD path prefix constant for Ethereum.\n */\nconst BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;\n\n/**\n * Regex pattern for validating and parsing Ledger Live derivation paths.\n * Format: m/44'/60'/{index}'/0/0\n */\nconst LEDGER_LIVE_PATH_PATTERN = /^m\\/44'\\/60'\\/(\\d+)'\\/0\\/0$/u;\n\n/**\n * Regex pattern for validating and parsing non-Ledger-Live derivation paths.\n * Supports Legacy (m/44'/60'/0'/{index}), BIP44 (m/44'/60'/0'/0/{index}),\n * and custom paths that follow the m/44'/60'/... pattern.\n */\nconst INDEX_AT_END_PATH_PATTERN = /^(m\\/44'\\/60'(?:\\/\\d+'?)*)\\/(\\d+)$/u;\n\n/**\n * Concrete {@link Keyring} adapter for {@link LedgerKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * Ledger keyring via the unified V2 interface.\n *\n * All Ledger keyring accounts are BIP-44 derived from the device.\n */\nexport type LedgerKeyringOptions = {\n legacyKeyring: LegacyLedgerKeyring;\n entropySource: EntropySourceId;\n};\n\n// LegacyLedgerKeyring.signTransaction returns `TypedTransaction | OldEthJsTransaction` for\n// backwards compatibility with old ethereumjs-tx, but EthKeyring expects `TypedTxData`.\n// The runtime behavior is correct - we cast the type to satisfy the constraint.\ntype LedgerKeyringAsEthKeyring = LegacyLedgerKeyring & EthKeyring;\n\nexport class LedgerKeyring\n extends EthKeyringWrapper<\n LedgerKeyringAsEthKeyring,\n Bip44Account<KeyringAccount>\n >\n implements Keyring\n{\n readonly entropySource: EntropySourceId;\n\n constructor(options: LedgerKeyringOptions) {\n super({\n type: KeyringType.Ledger,\n inner: options.legacyKeyring as LedgerKeyringAsEthKeyring,\n capabilities: ledgerKeyringCapabilities,\n });\n this.entropySource = options.entropySource;\n }\n\n /**\n * Normalizes an address to a checksummed hex address.\n *\n * @param address - The address to normalize.\n * @returns The checksummed hex address.\n */\n #getChecksumHexAddress(address: string): Hex {\n return getChecksumAddress(add0x(address));\n }\n\n /**\n * Parses a derivation path to extract the base HD path and account index.\n *\n * Supports two path formats:\n * - Ledger Live: m/44'/60'/{index}'/0/0 → base: m/44'/60'/0'/0/0, index from position 3\n * - Index at end: m/44'/60'/.../{index} → base: m/44'/60'/..., index from last segment\n *\n * @param derivationPath - The full derivation path.\n * @returns The base HD path and account index.\n * @throws If the path format is invalid.\n */\n #parseDerivationPath(derivationPath: string): {\n basePath: string;\n index: number;\n } {\n // Try Ledger Live format first: m/44'/60'/{index}'/0/0\n const ledgerLiveMatch = derivationPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (ledgerLiveMatch?.[1]) {\n return {\n // This constant is used by `inner.setHdPath` to determine which derivation\n // mode we should use (Ledger Live derivation mode here).\n basePath: LEDGER_LIVE_HD_PATH,\n index: parseInt(ledgerLiveMatch[1], 10),\n };\n }\n\n // Try index-at-end format: m/44'/60'/.../{index}\n const indexAtEndMatch = derivationPath.match(INDEX_AT_END_PATH_PATTERN);\n if (indexAtEndMatch) {\n // If the condition is true, indexAtEndMatch[1] and indexAtEndMatch[2] are defined, so\n // we can safely cast them to string.\n // This is necessary to get 100% code coverage.\n return {\n // Here, we use a derivation path prefix for `inner.setHdPath`\n // (prefix + index derivation mode).\n basePath: indexAtEndMatch[1] as string,\n index: parseInt(indexAtEndMatch[2] as string, 10),\n };\n }\n\n throw new Error(\n `Invalid derivation path format: ${derivationPath}. ` +\n `Expected Ledger Live (m/44'/60'/{index}'/0/0) or index-at-end (m/44'/60'/.../{index}) format.`,\n );\n }\n\n /**\n * Gets the index for an address from the account details.\n *\n * @param address - The address to get the index for.\n * @returns The index for the address.\n * @throws If the address is not found in account details.\n */\n #getIndexForAddress(address: Hex): number {\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details) {\n throw new Error(\n `Address ${checksummedAddress} not found in account details`,\n );\n }\n\n // Extract index from hdPath\n const { hdPath } = details;\n if (!hdPath) {\n throw new Error(`No HD path found for address ${checksummedAddress}`);\n }\n\n // Ledger supports multiple derivation path formats:\n // - Ledger Live (bip44: true): m/44'/60'/{index}'/0/0 - index at position 3\n // - Other paths (bip44: false): {hdPath}/{index} - index at end\n // - BIP44: m/44'/60'/0'/0/{index}\n // - Legacy: m/44'/60'/0'/{index}\n // - Custom paths via setHdPath\n //\n // We use the `bip44` flag to determine which extraction pattern to use.\n if (details.bip44) {\n // Ledger Live format: m/44'/60'/{index}'/0/0\n const match = hdPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (match?.[1]) {\n return parseInt(match[1], 10);\n }\n } else {\n // Index-at-end format: m/44'/60'/.../{index}\n const match = hdPath.match(INDEX_AT_END_PATH_PATTERN);\n if (match?.[2]) {\n return parseInt(match[2], 10);\n }\n }\n\n throw new Error(`Could not extract index from HD path: ${hdPath}`);\n }\n\n /**\n * Creates a Bip44Account object for the given address.\n *\n * @param address - The account address.\n * @param addressIndex - The account index in the derivation path.\n * @returns The created Bip44Account.\n */\n #createKeyringAccount(\n address: Hex,\n addressIndex: number,\n ): Bip44Account<KeyringAccount> {\n const id = this.registry.register(address);\n\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details?.hdPath) {\n throw new Error(\n `No HD path found for address ${checksummedAddress}. Cannot create account.`,\n );\n }\n\n const account: Bip44Account<KeyringAccount> = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...LEDGER_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: this.entropySource,\n groupIndex: addressIndex,\n derivationPath: details.hdPath,\n },\n },\n };\n\n this.registry.set(account);\n return account;\n }\n\n async getAccounts(): Promise<Bip44Account<KeyringAccount>[]> {\n const addresses = await this.inner.getAccounts();\n\n if (addresses.length === 0) {\n return [];\n }\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n const addressIndex = this.#getIndexForAddress(address);\n return this.#createKeyringAccount(address, addressIndex);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withLock(async () => {\n if (\n options.type === 'bip44:derive-path' ||\n options.type === 'bip44:derive-index'\n ) {\n // Validate that the entropy source matches this keyring's entropy source\n if (options.entropySource !== this.entropySource) {\n throw new Error(\n `Entropy source mismatch: expected '${this.entropySource}', got '${options.entropySource}'`,\n );\n }\n } else {\n throw new Error(\n `Unsupported account creation type for LedgerKeyring: ${String(\n options.type,\n )}`,\n );\n }\n\n // Check if an account at this index already exists with the same derivation path\n const currentAccounts = await this.getAccounts();\n\n let targetIndex: number;\n let basePath: string;\n let derivationPath: string;\n\n if (options.type === 'bip44:derive-path') {\n // Parse the derivation path to extract base path and index\n const parsed = this.#parseDerivationPath(options.derivationPath);\n targetIndex = parsed.index;\n basePath = parsed.basePath;\n\n derivationPath = options.derivationPath;\n } else {\n // derive-index uses BIP-44 standard path by default\n targetIndex = options.groupIndex;\n basePath = BIP44_HD_PATH_PREFIX;\n derivationPath = `${basePath}/${targetIndex}`;\n }\n\n const existingAccount = currentAccounts.find((account) => {\n return (\n account.options.entropy.groupIndex === targetIndex &&\n account.options.entropy.derivationPath === derivationPath\n );\n });\n\n if (existingAccount) {\n return [existingAccount];\n }\n\n // Derive the account at the specified index\n this.inner.setHdPath(basePath);\n this.inner.setAccountToUnlock(targetIndex);\n const [newAddress] = await this.inner.addAccounts(1);\n\n if (!newAddress) {\n throw new Error('Failed to create new account');\n }\n\n const newAccount = this.#createKeyringAccount(newAddress, targetIndex);\n\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const { address } = await this.getAccount(accountId);\n const hexAddress = this.toHexAddress(address);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(hexAddress);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-keyring.mjs","sourceRoot":"","sources":["../../src/v2/ledger-keyring.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,+BAA+B,EAChC,8BAA8B;AAE/B,OAAO,EAAE,WAAW,EAAE,iCAAiC;AAMvD,OAAO,EAAE,iBAAiB,EAAE,iCAAiC;AAE7D,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAa5D;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,YAAY;IACtB,SAAS,CAAC,eAAe;CAC1B,CAAC;AAEF,MAAM,yBAAyB,GAAwB;IACrD,MAAM,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;IACtB,KAAK,EAAE;QACL,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,IAAI;KACjB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,MAAM,wBAAwB,GAAG,8BAA8B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,qCAAqC,CAAC;AAoBxE,MAAM,OAAO,aACX,SAAQ,iBAGP;IAKD,YAAY,OAA6B;QACvC,KAAK,CAAC;YACJ,IAAI,EAAE,WAAW,CAAC,MAAM;YACxB,KAAK,EAAE,OAAO,CAAC,aAA0C;YACzD,YAAY,EAAE,yBAAyB;SACxC,C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AAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Bip44Account } from '@metamask/account-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringAccount, EntropySourceId } from '@metamask/keyring-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n KeyringCapabilities,\n Keyring,\n} from '@metamask/keyring-api/v2';\nimport { EthKeyringWrapper } from '@metamask/keyring-sdk/v2';\nimport type { AccountId, EthKeyring } from '@metamask/keyring-utils';\nimport { add0x, getChecksumAddress } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n GetAppNameAndVersionResponse,\n LedgerBridge,\n LedgerBridgeOptions,\n} from '../ledger-bridge';\nimport type {\n AccountPage,\n LedgerKeyring as LegacyLedgerKeyring,\n} from '../ledger-keyring';\n\n/**\n * Methods supported by Ledger keyring EOA accounts.\n * Ledger keyrings support a subset of signing methods (no encryption, app keys, or EIP-7702).\n */\nconst LEDGER_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV4,\n];\n\nconst ledgerKeyringCapabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n bip44: {\n deriveIndex: true,\n derivePath: true,\n },\n};\n\n/**\n * Ledger Live HD path constant.\n */\nconst LEDGER_LIVE_HD_PATH = `m/44'/60'/0'/0/0`;\n\n/**\n * BIP-44 standard HD path prefix constant for Ethereum.\n */\nconst BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;\n\n/**\n * Regex pattern for validating and parsing Ledger Live derivation paths.\n * Format: m/44'/60'/{index}'/0/0\n */\nconst LEDGER_LIVE_PATH_PATTERN = /^m\\/44'\\/60'\\/(\\d+)'\\/0\\/0$/u;\n\n/**\n * Regex pattern for validating and parsing non-Ledger-Live derivation paths.\n * Supports Legacy (m/44'/60'/0'/{index}), BIP44 (m/44'/60'/0'/0/{index}),\n * and custom paths that follow the m/44'/60'/... pattern.\n */\nconst INDEX_AT_END_PATH_PATTERN = /^(m\\/44'\\/60'(?:\\/\\d+'?)*)\\/(\\d+)$/u;\n\n/**\n * Concrete {@link Keyring} adapter for {@link LedgerKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * Ledger keyring via the unified V2 interface.\n *\n * All Ledger keyring accounts are BIP-44 derived from the device.\n */\nexport type LedgerKeyringOptions = {\n legacyKeyring: LegacyLedgerKeyring;\n entropySource: EntropySourceId;\n};\n\n// LegacyLedgerKeyring.signTransaction returns `TypedTransaction | OldEthJsTransaction` for\n// backwards compatibility with old ethereumjs-tx, but EthKeyring expects `TypedTxData`.\n// The runtime behavior is correct - we cast the type to satisfy the constraint.\ntype LedgerKeyringAsEthKeyring = LegacyLedgerKeyring & EthKeyring;\n\nexport class LedgerKeyring\n extends EthKeyringWrapper<\n LedgerKeyringAsEthKeyring,\n Bip44Account<KeyringAccount>\n >\n implements Keyring\n{\n readonly entropySource: EntropySourceId;\n\n constructor(options: LedgerKeyringOptions) {\n super({\n type: KeyringType.Ledger,\n inner: options.legacyKeyring as LedgerKeyringAsEthKeyring,\n capabilities: ledgerKeyringCapabilities,\n });\n this.entropySource = options.entropySource;\n }\n\n /**\n * Normalizes an address to a checksummed hex address.\n *\n * @param address - The address to normalize.\n * @returns The checksummed hex address.\n */\n #getChecksumHexAddress(address: string): Hex {\n return getChecksumAddress(add0x(address));\n }\n\n /**\n * Parses a derivation path to extract the base HD path and account index.\n *\n * Supports two path formats:\n * - Ledger Live: m/44'/60'/{index}'/0/0 → base: m/44'/60'/0'/0/0, index from position 3\n * - Index at end: m/44'/60'/.../{index} → base: m/44'/60'/..., index from last segment\n *\n * @param derivationPath - The full derivation path.\n * @returns The base HD path and account index.\n * @throws If the path format is invalid.\n */\n #parseDerivationPath(derivationPath: string): {\n basePath: string;\n index: number;\n } {\n // Try Ledger Live format first: m/44'/60'/{index}'/0/0\n const ledgerLiveMatch = derivationPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (ledgerLiveMatch?.[1]) {\n return {\n // This constant is used by `inner.setHdPath` to determine which derivation\n // mode we should use (Ledger Live derivation mode here).\n basePath: LEDGER_LIVE_HD_PATH,\n index: parseInt(ledgerLiveMatch[1], 10),\n };\n }\n\n // Try index-at-end format: m/44'/60'/.../{index}\n const indexAtEndMatch = derivationPath.match(INDEX_AT_END_PATH_PATTERN);\n if (indexAtEndMatch) {\n // If the condition is true, indexAtEndMatch[1] and indexAtEndMatch[2] are defined, so\n // we can safely cast them to string.\n // This is necessary to get 100% code coverage.\n return {\n // Here, we use a derivation path prefix for `inner.setHdPath`\n // (prefix + index derivation mode).\n basePath: indexAtEndMatch[1] as string,\n index: parseInt(indexAtEndMatch[2] as string, 10),\n };\n }\n\n throw new Error(\n `Invalid derivation path format: ${derivationPath}. ` +\n `Expected Ledger Live (m/44'/60'/{index}'/0/0) or index-at-end (m/44'/60'/.../{index}) format.`,\n );\n }\n\n /**\n * Gets the index for an address from the account details.\n *\n * @param address - The address to get the index for.\n * @returns The index for the address.\n * @throws If the address is not found in account details.\n */\n #getIndexForAddress(address: Hex): number {\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details) {\n throw new Error(\n `Address ${checksummedAddress} not found in account details`,\n );\n }\n\n // Extract index from hdPath\n const { hdPath } = details;\n if (!hdPath) {\n throw new Error(`No HD path found for address ${checksummedAddress}`);\n }\n\n // Ledger supports multiple derivation path formats:\n // - Ledger Live (bip44: true): m/44'/60'/{index}'/0/0 - index at position 3\n // - Other paths (bip44: false): {hdPath}/{index} - index at end\n // - BIP44: m/44'/60'/0'/0/{index}\n // - Legacy: m/44'/60'/0'/{index}\n // - Custom paths via setHdPath\n //\n // We use the `bip44` flag to determine which extraction pattern to use.\n if (details.bip44) {\n // Ledger Live format: m/44'/60'/{index}'/0/0\n const match = hdPath.match(LEDGER_LIVE_PATH_PATTERN);\n if (match?.[1]) {\n return parseInt(match[1], 10);\n }\n } else {\n // Index-at-end format: m/44'/60'/.../{index}\n const match = hdPath.match(INDEX_AT_END_PATH_PATTERN);\n if (match?.[2]) {\n return parseInt(match[2], 10);\n }\n }\n\n throw new Error(`Could not extract index from HD path: ${hdPath}`);\n }\n\n /**\n * Creates a Bip44Account object for the given address.\n *\n * @param address - The account address.\n * @param addressIndex - The account index in the derivation path.\n * @returns The created Bip44Account.\n */\n #createKeyringAccount(\n address: Hex,\n addressIndex: number,\n ): Bip44Account<KeyringAccount> {\n const id = this.registry.register(address);\n\n const checksummedAddress = this.#getChecksumHexAddress(address);\n const details = this.inner.accountDetails[checksummedAddress];\n\n if (!details?.hdPath) {\n throw new Error(\n `No HD path found for address ${checksummedAddress}. Cannot create account.`,\n );\n }\n\n const account: Bip44Account<KeyringAccount> = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...LEDGER_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: this.entropySource,\n groupIndex: addressIndex,\n derivationPath: details.hdPath,\n },\n },\n };\n\n this.registry.set(account);\n return account;\n }\n\n async getAccounts(): Promise<Bip44Account<KeyringAccount>[]> {\n const addresses = await this.inner.getAccounts();\n\n if (addresses.length === 0) {\n return [];\n }\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n const addressIndex = this.#getIndexForAddress(address);\n return this.#createKeyringAccount(address, addressIndex);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<Bip44Account<KeyringAccount>[]> {\n return this.withLock(async () => {\n if (\n options.type === 'bip44:derive-path' ||\n options.type === 'bip44:derive-index'\n ) {\n // Validate that the entropy source matches this keyring's entropy source\n if (options.entropySource !== this.entropySource) {\n throw new Error(\n `Entropy source mismatch: expected '${this.entropySource}', got '${options.entropySource}'`,\n );\n }\n } else {\n throw new Error(\n `Unsupported account creation type for LedgerKeyring: ${String(\n options.type,\n )}`,\n );\n }\n\n // Check if an account at this index already exists with the same derivation path\n const currentAccounts = await this.getAccounts();\n\n let targetIndex: number;\n let basePath: string;\n let derivationPath: string;\n\n if (options.type === 'bip44:derive-path') {\n // Parse the derivation path to extract base path and index\n const parsed = this.#parseDerivationPath(options.derivationPath);\n targetIndex = parsed.index;\n basePath = parsed.basePath;\n\n derivationPath = options.derivationPath;\n } else {\n // derive-index uses BIP-44 standard path by default\n targetIndex = options.groupIndex;\n basePath = BIP44_HD_PATH_PREFIX;\n derivationPath = `${basePath}/${targetIndex}`;\n }\n\n const existingAccount = currentAccounts.find((account) => {\n return (\n account.options.entropy.groupIndex === targetIndex &&\n account.options.entropy.derivationPath === derivationPath\n );\n });\n\n if (existingAccount) {\n return [existingAccount];\n }\n\n // Derive the account at the specified index\n this.inner.setHdPath(basePath);\n this.inner.setAccountToUnlock(targetIndex);\n const [newAddress] = await this.inner.addAccounts(1);\n\n if (!newAddress) {\n throw new Error('Failed to create new account');\n }\n\n const newAccount = this.#createKeyringAccount(newAddress, targetIndex);\n\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const { address } = await this.getAccount(accountId);\n const hexAddress = this.toHexAddress(address);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(hexAddress);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n\n /**\n * @returns The current derivation path used by the inner keyring.\n */\n get hdPath(): string {\n return this.inner.hdPath;\n }\n\n /**\n * @returns The bridge instance used by the inner keyring to communicate\n * with the device.\n */\n get bridge(): LedgerBridge<LedgerBridgeOptions> {\n return this.inner.bridge;\n }\n\n /**\n * @returns The device ID for the paired Ledger device.\n */\n getDeviceId(): string {\n return this.inner.getDeviceId();\n }\n\n /**\n * Set the device ID for the paired Ledger device.\n *\n * @param deviceId - The device ID to set.\n */\n setDeviceId(deviceId: string): void {\n this.inner.setDeviceId(deviceId);\n }\n\n /**\n * Set the derivation path on the inner keyring.\n *\n * @param hdPath - The derivation path to set.\n */\n setHdPath(hdPath: string): void {\n this.inner.setHdPath(hdPath);\n }\n\n /**\n * Fetch the first page of candidate addresses from the device.\n *\n * @returns The first page of accounts.\n */\n async getFirstPage(): Promise<AccountPage> {\n return this.inner.getFirstPage();\n }\n\n /**\n * Fetch the next page of candidate addresses from the device.\n *\n * @returns The next page of accounts.\n */\n async getNextPage(): Promise<AccountPage> {\n return this.inner.getNextPage();\n }\n\n /**\n * Fetch the previous page of candidate addresses from the device.\n *\n * @returns The previous page of accounts.\n */\n async getPreviousPage(): Promise<AccountPage> {\n return this.inner.getPreviousPage();\n }\n\n /**\n * Clear the inner keyring's device-pairing state and accounts, and reset\n * the V2 account registry to keep them in sync.\n */\n async forgetDevice(): Promise<void> {\n await this.withLock(async () => {\n this.inner.forgetDevice();\n this.registry.clear();\n });\n }\n\n /**\n * @returns Whether the inner keyring has an unlocked HD key.\n */\n isUnlocked(): boolean {\n return this.inner.isUnlocked();\n }\n\n /**\n * Attempt to open the Ethereum app on the connected Ledger device.\n *\n * @returns Whether the app was opened.\n */\n async attemptMakeApp(): Promise<boolean> {\n return this.inner.attemptMakeApp();\n }\n\n /**\n * @returns The app name and version currently running on the connected\n * Ledger device.\n */\n async getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse> {\n return this.inner.getAppNameAndVersion();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/eth-ledger-bridge-keyring",
|
|
3
|
-
"version": "12.0
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "A MetaMask compatible keyring, for ledger hardware wallets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ethereum",
|
|
@@ -72,23 +72,23 @@
|
|
|
72
72
|
"@ethereumjs/tx": "^5.4.0",
|
|
73
73
|
"@ethereumjs/util": "^9.1.0",
|
|
74
74
|
"@ledgerhq/hw-app-eth": "^6.42.0",
|
|
75
|
+
"@ledgerhq/hw-transport": "^6.31.3",
|
|
75
76
|
"@metamask/eth-sig-util": "^8.2.0",
|
|
76
77
|
"@metamask/hw-wallet-sdk": "^0.8.0",
|
|
77
78
|
"@metamask/keyring-api": "^23.1.0",
|
|
78
|
-
"@metamask/keyring-sdk": "^2.
|
|
79
|
+
"@metamask/keyring-sdk": "^2.1.1",
|
|
79
80
|
"hdkey": "^2.1.0"
|
|
80
81
|
},
|
|
81
82
|
"devDependencies": {
|
|
82
83
|
"@ethereumjs/common": "^4.4.0",
|
|
83
84
|
"@lavamoat/allow-scripts": "^3.2.1",
|
|
84
85
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
85
|
-
"@ledgerhq/hw-transport": "^6.31.3",
|
|
86
86
|
"@ledgerhq/types-cryptoassets": "^7.15.1",
|
|
87
87
|
"@ledgerhq/types-devices": "^6.25.3",
|
|
88
88
|
"@ledgerhq/types-live": "^6.52.0",
|
|
89
89
|
"@metamask/account-api": "^1.0.4",
|
|
90
90
|
"@metamask/auto-changelog": "^6.1.0",
|
|
91
|
-
"@metamask/keyring-utils": "^3.
|
|
91
|
+
"@metamask/keyring-utils": "^3.3.1",
|
|
92
92
|
"@metamask/utils": "^11.11.0",
|
|
93
93
|
"@ts-bridge/cli": "^0.6.3",
|
|
94
94
|
"@types/ethereumjs-tx": "^1.0.1",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"ts-jest": "^29.0.5",
|
|
106
106
|
"ts-node": "^10.9.2",
|
|
107
107
|
"typedoc": "^0.25.13",
|
|
108
|
-
"typescript": "~5.
|
|
108
|
+
"typescript": "~5.3.3"
|
|
109
109
|
},
|
|
110
110
|
"engines": {
|
|
111
111
|
"node": "^18.18 || >=20"
|