@metamask/eth-ledger-bridge-keyring 12.0.2 → 12.0.3
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 +12 -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/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [12.0.3]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- 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))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- 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))
|
|
19
|
+
|
|
10
20
|
## [12.0.2]
|
|
11
21
|
|
|
12
22
|
### Changed
|
|
@@ -424,7 +434,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
424
434
|
|
|
425
435
|
- Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
|
|
426
436
|
|
|
427
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.
|
|
437
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.3...HEAD
|
|
438
|
+
[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
439
|
[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
440
|
[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
441
|
[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-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,KAAK,CAAC,OAAO;YAC1B,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,4CAA4C;IAC5C,IAAI,KAAK,YAAY,mCAAmB,EAAE,CAAC;QACzC,MAAM,KAAK,CAAC;IACd,CAAC;IAED,2BAA2B;IAC3B,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,IAAI,mCAAmB,CAAC,KAAK,CAAC,OAAO,EAAE;YAC3C,IAAI,EAAE,yBAAa,CAAC,OAAO;YAC3B,QAAQ,EAAE,wBAAY,CAAC,GAAG;YAC1B,QAAQ,EAAE,wBAAY,CAAC,OAAO;YAC9B,WAAW,EAAE,KAAK,CAAC,OAAO;YAC1B,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IAED,qBAAqB;IACrB,MAAM,IAAI,mCAAmB,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",
|
|
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gBAAgB,SAAK;gBAQnB,IAAI,GAAE,yBAEL;IAQG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAMxB,UAAU,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAIhD,UAAU,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAkBlC,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB9D,YAAY,CAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,oBAAoB,CAAC;IAI1B,qBAAqB,CACzB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,6BAA6B,CAAC;IAOnC,iBAAiB,CACrB,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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AU,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAIhD,UAAU,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAkBlC,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB9D,YAAY,CAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,oBAAoB,CAAC;IAI1B,qBAAqB,CACzB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,6BAA6B,CAAC;IAOnC,iBAAiB,CACrB,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"}
|
|
@@ -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,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,CAA0B,CAAC,OAAO,EAAE,CAAC;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;IACjC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,iBAAiB,CAAC,EACtB,MAAM,EACN,OAAO,GACiB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,mBAAmB,CAAC,EACxB,MAAM,EACN,OAAO,GACmB;QAC1B,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,iBAAiB,CAAC,MAAM,EAAE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ACD,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;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;A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AI,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;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;;IAKrD,iBAAiB,UAAS;gBAGxB,mBAAmB,EAAE,mBAAmB,EACxC,IAAI,GAAE,yBAA8B;IAMtC;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B;;;;;;;;OAQG;IACG,iBAAiB,CAAC,EACtB,MAAM,EACN,OAAO,GACR,EAAE,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAI/D;;;;;;;;OAQG;IACG,mBAAmB,CAAC,EACxB,MAAM,EACN,OAAO,GACR,EAAE,yBAAyB,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAInE;;;;;;;;;;;OAWG;IACG,qBAAqB,CAAC,EAC1B,EAAE,EACF,MAAM,GACP,EAAE,2BAA2B,GAAG,OAAO,CAAC,6BAA6B,CAAC;IA0BvE;;;;;;OAMG;IACG,YAAY,CAAC,EACjB,MAAM,GACP,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAIrD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAItD;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE;;;;;OAKG;IACG,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAcnE;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;OAIG;IACG,oBAAoB,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":"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D;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE;;;;;OAKG;IACG,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAcnE;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;OAIG;IACG,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAInE;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,wBAAwB,CAAC;CAsC/D"}
|
|
@@ -9,10 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || 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-b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AC;QACvD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;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,EAA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A5B,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"]}
|
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.0.3",
|
|
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"
|