@metamask/eth-ledger-bridge-keyring 11.2.0 → 11.3.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 +14 -2
- package/dist/errors.cjs +56 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +24 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +24 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +51 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/ledger-bridge.cjs.map +1 -1
- package/dist/ledger-bridge.d.cts +23 -0
- package/dist/ledger-bridge.d.cts.map +1 -1
- package/dist/ledger-bridge.d.mts +23 -0
- package/dist/ledger-bridge.d.mts.map +1 -1
- package/dist/ledger-bridge.mjs.map +1 -1
- package/dist/ledger-error-handler.cjs +60 -26
- package/dist/ledger-error-handler.cjs.map +1 -1
- package/dist/ledger-error-handler.d.cts +3 -2
- package/dist/ledger-error-handler.d.cts.map +1 -1
- package/dist/ledger-error-handler.d.mts +3 -2
- package/dist/ledger-error-handler.d.mts.map +1 -1
- package/dist/ledger-error-handler.mjs +60 -26
- package/dist/ledger-error-handler.mjs.map +1 -1
- package/dist/ledger-hw-app.cjs.map +1 -1
- package/dist/ledger-hw-app.d.cts +1 -1
- package/dist/ledger-hw-app.d.cts.map +1 -1
- package/dist/ledger-hw-app.d.mts +1 -1
- package/dist/ledger-hw-app.d.mts.map +1 -1
- package/dist/ledger-hw-app.mjs.map +1 -1
- package/dist/ledger-iframe-bridge.cjs +8 -0
- package/dist/ledger-iframe-bridge.cjs.map +1 -1
- package/dist/ledger-iframe-bridge.d.cts +13 -3
- package/dist/ledger-iframe-bridge.d.cts.map +1 -1
- package/dist/ledger-iframe-bridge.d.mts +13 -3
- package/dist/ledger-iframe-bridge.d.mts.map +1 -1
- package/dist/ledger-iframe-bridge.mjs +8 -0
- package/dist/ledger-iframe-bridge.mjs.map +1 -1
- package/dist/ledger-keyring.cjs +16 -0
- package/dist/ledger-keyring.cjs.map +1 -1
- package/dist/ledger-keyring.d.cts +3 -1
- package/dist/ledger-keyring.d.cts.map +1 -1
- package/dist/ledger-keyring.d.mts +3 -1
- package/dist/ledger-keyring.d.mts.map +1 -1
- package/dist/ledger-keyring.mjs +16 -0
- package/dist/ledger-keyring.mjs.map +1 -1
- package/dist/ledger-mobile-bridge.cjs +8 -0
- package/dist/ledger-mobile-bridge.cjs.map +1 -1
- package/dist/ledger-mobile-bridge.d.cts +8 -3
- package/dist/ledger-mobile-bridge.d.cts.map +1 -1
- package/dist/ledger-mobile-bridge.d.mts +8 -3
- package/dist/ledger-mobile-bridge.d.mts.map +1 -1
- package/dist/ledger-mobile-bridge.mjs +8 -0
- package/dist/ledger-mobile-bridge.mjs.map +1 -1
- package/dist/type.cjs +5 -0
- package/dist/type.cjs.map +1 -1
- package/dist/type.d.cts +5 -4
- package/dist/type.d.cts.map +1 -1
- package/dist/type.d.mts +5 -4
- package/dist/type.d.mts.map +1 -1
- package/dist/type.mjs +5 -0
- package/dist/type.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [11.3.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Integrate `@metamask/hw-wallet-sdk` for standardized hardware wallet error handling ([#446](https://github.com/MetaMask/accounts/pull/446))
|
|
15
|
+
- Replace custom error handling with `HardwareWalletError` from the SDK.
|
|
16
|
+
- Use `LEDGER_ERROR_MAPPINGS` from the SDK for consistent error code mapping.
|
|
17
|
+
- Re-export `HardwareWalletError`, `ErrorCode`, `Severity`, `Category`, and error mappings for consumer convenience.
|
|
18
|
+
- Deprecate `LedgerStatusError` in favor of `HardwareWalletError`.
|
|
19
|
+
- Prefix Ledger transport error messages for compatibility.
|
|
20
|
+
|
|
10
21
|
## [11.2.0]
|
|
11
22
|
|
|
12
23
|
### Added
|
|
@@ -15,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
15
26
|
- Wraps legacy `LedgerKeyring` to expose accounts via the unified `KeyringV2` API and the `KeyringAccount` type.
|
|
16
27
|
- Extends `EthKeyringWrapper` for common Ethereum logic.
|
|
17
28
|
|
|
18
|
-
###
|
|
29
|
+
### Changed
|
|
19
30
|
|
|
20
31
|
- Normalize signature `v` value from Ledger devices for proper recovery ([#449](https://github.com/MetaMask/accounts/pull/449))
|
|
21
32
|
|
|
@@ -354,7 +365,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
354
365
|
|
|
355
366
|
- Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
|
|
356
367
|
|
|
357
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.
|
|
368
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.3.0...HEAD
|
|
369
|
+
[11.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.2.0...@metamask/eth-ledger-bridge-keyring@11.3.0
|
|
358
370
|
[11.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.1.2...@metamask/eth-ledger-bridge-keyring@11.2.0
|
|
359
371
|
[11.1.2]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.1.1...@metamask/eth-ledger-bridge-keyring@11.1.2
|
|
360
372
|
[11.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.1.0...@metamask/eth-ledger-bridge-keyring@11.1.1
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLedgerError = createLedgerError;
|
|
4
|
+
exports.isKnownLedgerError = isKnownLedgerError;
|
|
5
|
+
exports.getLedgerErrorMapping = getLedgerErrorMapping;
|
|
6
|
+
const hw_wallet_sdk_1 = require("@metamask/hw-wallet-sdk");
|
|
7
|
+
/**
|
|
8
|
+
* Factory function to create a HardwareWalletError from a Ledger error code.
|
|
9
|
+
*
|
|
10
|
+
* @param ledgerErrorCode - The Ledger error code (e.g., '0x6985', '0x5515')
|
|
11
|
+
* @param context - Optional additional context to append to the error message
|
|
12
|
+
* @returns A HardwareWalletError instance with mapped error details
|
|
13
|
+
*/
|
|
14
|
+
function createLedgerError(ledgerErrorCode, context) {
|
|
15
|
+
const errorMapping = getLedgerErrorMapping(ledgerErrorCode);
|
|
16
|
+
if (errorMapping) {
|
|
17
|
+
const message = context
|
|
18
|
+
? `${errorMapping.message} (${context})`
|
|
19
|
+
: errorMapping.message;
|
|
20
|
+
return new hw_wallet_sdk_1.HardwareWalletError(message, {
|
|
21
|
+
code: errorMapping.code,
|
|
22
|
+
severity: errorMapping.severity,
|
|
23
|
+
category: errorMapping.category,
|
|
24
|
+
userMessage: errorMapping.userMessage ?? message,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// Fallback for unknown error codes
|
|
28
|
+
const fallbackMessage = context
|
|
29
|
+
? `Unknown Ledger error: ${ledgerErrorCode} (${context})`
|
|
30
|
+
: `Unknown Ledger error: ${ledgerErrorCode}`;
|
|
31
|
+
return new hw_wallet_sdk_1.HardwareWalletError(fallbackMessage, {
|
|
32
|
+
code: hw_wallet_sdk_1.ErrorCode.Unknown,
|
|
33
|
+
severity: hw_wallet_sdk_1.Severity.Err,
|
|
34
|
+
category: hw_wallet_sdk_1.Category.Unknown,
|
|
35
|
+
userMessage: fallbackMessage,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a Ledger error code exists in the error mappings.
|
|
40
|
+
*
|
|
41
|
+
* @param ledgerErrorCode - The Ledger error code to check
|
|
42
|
+
* @returns True if the error code is mapped, false otherwise
|
|
43
|
+
*/
|
|
44
|
+
function isKnownLedgerError(ledgerErrorCode) {
|
|
45
|
+
return ledgerErrorCode in hw_wallet_sdk_1.LEDGER_ERROR_MAPPINGS;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets the error mapping details for a Ledger error code without creating an error instance.
|
|
49
|
+
*
|
|
50
|
+
* @param ledgerErrorCode - The Ledger error code to look up
|
|
51
|
+
* @returns The error mapping details or undefined if not found
|
|
52
|
+
*/
|
|
53
|
+
function getLedgerErrorMapping(ledgerErrorCode) {
|
|
54
|
+
return hw_wallet_sdk_1.LEDGER_ERROR_MAPPINGS[ledgerErrorCode];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;AAgBA,8CA8BC;AAQD,gDAEC;AAQD,sDAIC;AApED,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;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,eAAuB;IACxD,OAAO,eAAe,IAAI,qCAAqB,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CACnC,eAAuB;IAEvB,OAAO,qCAAqB,CAAC,eAAe,CAAC,CAAC;AAChD,CAAC","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"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ErrorMapping, HardwareWalletError } from "@metamask/hw-wallet-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create a HardwareWalletError from a Ledger error code.
|
|
4
|
+
*
|
|
5
|
+
* @param ledgerErrorCode - The Ledger error code (e.g., '0x6985', '0x5515')
|
|
6
|
+
* @param context - Optional additional context to append to the error message
|
|
7
|
+
* @returns A HardwareWalletError instance with mapped error details
|
|
8
|
+
*/
|
|
9
|
+
export declare function createLedgerError(ledgerErrorCode: string, context?: string): HardwareWalletError;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a Ledger error code exists in the error mappings.
|
|
12
|
+
*
|
|
13
|
+
* @param ledgerErrorCode - The Ledger error code to check
|
|
14
|
+
* @returns True if the error code is mapped, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare function isKnownLedgerError(ledgerErrorCode: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the error mapping details for a Ledger error code without creating an error instance.
|
|
19
|
+
*
|
|
20
|
+
* @param ledgerErrorCode - The Ledger error code to look up
|
|
21
|
+
* @returns The error mapping details or undefined if not found
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLedgerErrorMapping(ledgerErrorCode: string): ErrorMapping | undefined;
|
|
24
|
+
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAIZ,mBAAmB,EAEpB,gCAAgC;AAEjC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,mBAAmB,CA2BrB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,GACtB,YAAY,GAAG,SAAS,CAE1B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ErrorMapping, HardwareWalletError } from "@metamask/hw-wallet-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create a HardwareWalletError from a Ledger error code.
|
|
4
|
+
*
|
|
5
|
+
* @param ledgerErrorCode - The Ledger error code (e.g., '0x6985', '0x5515')
|
|
6
|
+
* @param context - Optional additional context to append to the error message
|
|
7
|
+
* @returns A HardwareWalletError instance with mapped error details
|
|
8
|
+
*/
|
|
9
|
+
export declare function createLedgerError(ledgerErrorCode: string, context?: string): HardwareWalletError;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a Ledger error code exists in the error mappings.
|
|
12
|
+
*
|
|
13
|
+
* @param ledgerErrorCode - The Ledger error code to check
|
|
14
|
+
* @returns True if the error code is mapped, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare function isKnownLedgerError(ledgerErrorCode: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the error mapping details for a Ledger error code without creating an error instance.
|
|
19
|
+
*
|
|
20
|
+
* @param ledgerErrorCode - The Ledger error code to look up
|
|
21
|
+
* @returns The error mapping details or undefined if not found
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLedgerErrorMapping(ledgerErrorCode: string): ErrorMapping | undefined;
|
|
24
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAIZ,mBAAmB,EAEpB,gCAAgC;AAEjC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,mBAAmB,CA2BrB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,MAAM,GACtB,YAAY,GAAG,SAAS,CAE1B"}
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ErrorCode, Severity, Category, HardwareWalletError, LEDGER_ERROR_MAPPINGS } from "@metamask/hw-wallet-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create a HardwareWalletError from a Ledger error code.
|
|
4
|
+
*
|
|
5
|
+
* @param ledgerErrorCode - The Ledger error code (e.g., '0x6985', '0x5515')
|
|
6
|
+
* @param context - Optional additional context to append to the error message
|
|
7
|
+
* @returns A HardwareWalletError instance with mapped error details
|
|
8
|
+
*/
|
|
9
|
+
export function createLedgerError(ledgerErrorCode, context) {
|
|
10
|
+
const errorMapping = getLedgerErrorMapping(ledgerErrorCode);
|
|
11
|
+
if (errorMapping) {
|
|
12
|
+
const message = context
|
|
13
|
+
? `${errorMapping.message} (${context})`
|
|
14
|
+
: errorMapping.message;
|
|
15
|
+
return new HardwareWalletError(message, {
|
|
16
|
+
code: errorMapping.code,
|
|
17
|
+
severity: errorMapping.severity,
|
|
18
|
+
category: errorMapping.category,
|
|
19
|
+
userMessage: errorMapping.userMessage ?? message,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// Fallback for unknown error codes
|
|
23
|
+
const fallbackMessage = context
|
|
24
|
+
? `Unknown Ledger error: ${ledgerErrorCode} (${context})`
|
|
25
|
+
: `Unknown Ledger error: ${ledgerErrorCode}`;
|
|
26
|
+
return new HardwareWalletError(fallbackMessage, {
|
|
27
|
+
code: ErrorCode.Unknown,
|
|
28
|
+
severity: Severity.Err,
|
|
29
|
+
category: Category.Unknown,
|
|
30
|
+
userMessage: fallbackMessage,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a Ledger error code exists in the error mappings.
|
|
35
|
+
*
|
|
36
|
+
* @param ledgerErrorCode - The Ledger error code to check
|
|
37
|
+
* @returns True if the error code is mapped, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export function isKnownLedgerError(ledgerErrorCode) {
|
|
40
|
+
return ledgerErrorCode in LEDGER_ERROR_MAPPINGS;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets the error mapping details for a Ledger error code without creating an error instance.
|
|
44
|
+
*
|
|
45
|
+
* @param ledgerErrorCode - The Ledger error code to look up
|
|
46
|
+
* @returns The error mapping details or undefined if not found
|
|
47
|
+
*/
|
|
48
|
+
export function getLedgerErrorMapping(ledgerErrorCode) {
|
|
49
|
+
return LEDGER_ERROR_MAPPINGS[ledgerErrorCode];
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,mBAA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ask/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"]}
|
package/dist/index.cjs
CHANGED
|
@@ -20,4 +20,6 @@ __exportStar(require("./ledger-iframe-bridge.cjs"), exports);
|
|
|
20
20
|
__exportStar(require("./ledger-mobile-bridge.cjs"), exports);
|
|
21
21
|
__exportStar(require("./ledger-transport-middleware.cjs"), exports);
|
|
22
22
|
__exportStar(require("./ledger-hw-app.cjs"), exports);
|
|
23
|
+
__exportStar(require("./errors.cjs"), exports);
|
|
24
|
+
__exportStar(require("./ledger-error-handler.cjs"), exports);
|
|
23
25
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAiC;AACjC,0DAAoC;AACpC,6DAAuC;AACvC,6DAAuC;AAEvC,oEAA8C;AAE9C,sDAAgC","sourcesContent":["export * from './ledger-keyring';\nexport * from './ledger-keyring-v2';\nexport * from './ledger-iframe-bridge';\nexport * from './ledger-mobile-bridge';\nexport type * from './ledger-bridge';\nexport * from './ledger-transport-middleware';\nexport type * from './type';\nexport * from './ledger-hw-app';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAiC;AACjC,0DAAoC;AACpC,6DAAuC;AACvC,6DAAuC;AAEvC,oEAA8C;AAE9C,sDAAgC;AAChC,+CAAyB;AACzB,6DAAuC","sourcesContent":["export * from './ledger-keyring';\nexport * from './ledger-keyring-v2';\nexport * from './ledger-iframe-bridge';\nexport * from './ledger-mobile-bridge';\nexport type * from './ledger-bridge';\nexport * from './ledger-transport-middleware';\nexport type * from './type';\nexport * from './ledger-hw-app';\nexport * from './errors';\nexport * from './ledger-error-handler';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,4 +6,6 @@ export type * from "./ledger-bridge.cjs";
|
|
|
6
6
|
export * from "./ledger-transport-middleware.cjs";
|
|
7
7
|
export type * from "./type.cjs";
|
|
8
8
|
export * from "./ledger-hw-app.cjs";
|
|
9
|
+
export * from "./errors.cjs";
|
|
10
|
+
export * from "./ledger-error-handler.cjs";
|
|
9
11
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,wCAAoC;AACpC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,kDAA8C;AAC9C,gCAA4B;AAC5B,oCAAgC"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,wCAAoC;AACpC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,kDAA8C;AAC9C,gCAA4B;AAC5B,oCAAgC;AAChC,6BAAyB;AACzB,2CAAuC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -6,4 +6,6 @@ export type * from "./ledger-bridge.mjs";
|
|
|
6
6
|
export * from "./ledger-transport-middleware.mjs";
|
|
7
7
|
export type * from "./type.mjs";
|
|
8
8
|
export * from "./ledger-hw-app.mjs";
|
|
9
|
+
export * from "./errors.mjs";
|
|
10
|
+
export * from "./ledger-error-handler.mjs";
|
|
9
11
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,wCAAoC;AACpC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,kDAA8C;AAC9C,gCAA4B;AAC5B,oCAAgC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,wCAAoC;AACpC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,kDAA8C;AAC9C,gCAA4B;AAC5B,oCAAgC;AAChC,6BAAyB;AACzB,2CAAuC"}
|
package/dist/index.mjs
CHANGED
|
@@ -4,4 +4,6 @@ export * from "./ledger-iframe-bridge.mjs";
|
|
|
4
4
|
export * from "./ledger-mobile-bridge.mjs";
|
|
5
5
|
export * from "./ledger-transport-middleware.mjs";
|
|
6
6
|
export * from "./ledger-hw-app.mjs";
|
|
7
|
+
export * from "./errors.mjs";
|
|
8
|
+
export * from "./ledger-error-handler.mjs";
|
|
7
9
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,wCAAoC;AACpC,2CAAuC;AACvC,2CAAuC;AAEvC,kDAA8C;AAE9C,oCAAgC","sourcesContent":["export * from './ledger-keyring';\nexport * from './ledger-keyring-v2';\nexport * from './ledger-iframe-bridge';\nexport * from './ledger-mobile-bridge';\nexport type * from './ledger-bridge';\nexport * from './ledger-transport-middleware';\nexport type * from './type';\nexport * from './ledger-hw-app';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,wCAAoC;AACpC,2CAAuC;AACvC,2CAAuC;AAEvC,kDAA8C;AAE9C,oCAAgC;AAChC,6BAAyB;AACzB,2CAAuC","sourcesContent":["export * from './ledger-keyring';\nexport * from './ledger-keyring-v2';\nexport * from './ledger-iframe-bridge';\nexport * from './ledger-mobile-bridge';\nexport type * from './ledger-bridge';\nexport * from './ledger-transport-middleware';\nexport type * from './type';\nexport * from './ledger-hw-app';\nexport * from './errors';\nexport * from './ledger-error-handler';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.cjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\nimport type { EIP712Message } from '@ledgerhq/types-live';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n message: EIP712Message;\n};\nexport type LedgerSignTypedDataResponse = Awaited<\n ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>\n>;\n\nexport type LedgerBridgeOptions = Record<string, unknown>;\n\nexport type LedgerBridge<T extends LedgerBridgeOptions> = {\n isDeviceConnected: boolean;\n\n init(): Promise<void>;\n\n destroy(): Promise<void>;\n\n /**\n * Method to get the current configuration of the ledger bridge keyring.\n */\n getOptions(): Promise<T>;\n\n /**\n * Method to set the current configuration of the ledger bridge keyring.\n *\n * @param opts - An object contains configuration of the bridge.\n */\n setOptions(opts: T): Promise<void>;\n\n attemptMakeApp(): Promise<boolean>;\n\n updateTransportMethod(transportType: string | Transport): Promise<boolean>;\n\n getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;\n\n deviceSignTransaction(\n params: LedgerSignTransactionParams,\n ): Promise<LedgerSignTransactionResponse>;\n\n deviceSignMessage(\n params: LedgerSignMessageParams,\n ): Promise<LedgerSignMessageResponse>;\n\n deviceSignTypedData(\n params: LedgerSignTypedDataParams,\n ): Promise<LedgerSignTypedDataResponse>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-bridge.cjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\nimport type { EIP712Message } from '@ledgerhq/types-live';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n message: EIP712Message;\n};\nexport type LedgerSignTypedDataResponse = Awaited<\n ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>\n>;\n\nexport type GetAppNameAndVersionResponse = {\n appName: string;\n version: string;\n};\n\nexport type AppConfigurationResponse = {\n arbitraryDataEnabled: number; // this is the blind signing support\n erc20ProvisioningNecessary: number;\n starkEnabled: number;\n starkv2Supported: number;\n version: string;\n};\n\nexport type LedgerBridgeOptions = Record<string, unknown>;\n\nexport type LedgerBridge<T extends LedgerBridgeOptions> = {\n isDeviceConnected: boolean;\n\n init(): Promise<void>;\n\n destroy(): Promise<void>;\n\n /**\n * Method to get the current configuration of the ledger bridge keyring.\n */\n getOptions(): Promise<T>;\n\n /**\n * Method to set the current configuration of the ledger bridge keyring.\n *\n * @param opts - An object contains configuration of the bridge.\n */\n setOptions(opts: T): Promise<void>;\n\n attemptMakeApp(): Promise<boolean>;\n\n updateTransportMethod(transportType: string | Transport): Promise<boolean>;\n\n getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;\n\n deviceSignTransaction(\n params: LedgerSignTransactionParams,\n ): Promise<LedgerSignTransactionResponse>;\n\n deviceSignMessage(\n params: LedgerSignMessageParams,\n ): Promise<LedgerSignMessageResponse>;\n\n deviceSignTypedData(\n params: LedgerSignTypedDataParams,\n ): Promise<LedgerSignTypedDataResponse>;\n\n /**\n * Method to retrieve the name and version of the running application on the Ledger device.\n *\n * @returns An object containing appName and version.\n */\n getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;\n\n /**\n * Method to retrieve the configuration of the running application on the Ledger device.\n *\n * @returns An object containing the configuration of the running application.\n */\n getAppConfiguration(): Promise<AppConfigurationResponse>;\n};\n"]}
|
package/dist/ledger-bridge.d.cts
CHANGED
|
@@ -20,6 +20,17 @@ export type LedgerSignTypedDataParams = {
|
|
|
20
20
|
message: EIP712Message;
|
|
21
21
|
};
|
|
22
22
|
export type LedgerSignTypedDataResponse = Awaited<ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>>;
|
|
23
|
+
export type GetAppNameAndVersionResponse = {
|
|
24
|
+
appName: string;
|
|
25
|
+
version: string;
|
|
26
|
+
};
|
|
27
|
+
export type AppConfigurationResponse = {
|
|
28
|
+
arbitraryDataEnabled: number;
|
|
29
|
+
erc20ProvisioningNecessary: number;
|
|
30
|
+
starkEnabled: number;
|
|
31
|
+
starkv2Supported: number;
|
|
32
|
+
version: string;
|
|
33
|
+
};
|
|
23
34
|
export type LedgerBridgeOptions = Record<string, unknown>;
|
|
24
35
|
export type LedgerBridge<T extends LedgerBridgeOptions> = {
|
|
25
36
|
isDeviceConnected: boolean;
|
|
@@ -41,5 +52,17 @@ export type LedgerBridge<T extends LedgerBridgeOptions> = {
|
|
|
41
52
|
deviceSignTransaction(params: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse>;
|
|
42
53
|
deviceSignMessage(params: LedgerSignMessageParams): Promise<LedgerSignMessageResponse>;
|
|
43
54
|
deviceSignTypedData(params: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse>;
|
|
55
|
+
/**
|
|
56
|
+
* Method to retrieve the name and version of the running application on the Ledger device.
|
|
57
|
+
*
|
|
58
|
+
* @returns An object containing appName and version.
|
|
59
|
+
*/
|
|
60
|
+
getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Method to retrieve the configuration of the running application on the Ledger device.
|
|
63
|
+
*
|
|
64
|
+
* @returns An object containing the configuration of the running application.
|
|
65
|
+
*/
|
|
66
|
+
getAppConfiguration(): Promise<AppConfigurationResponse>;
|
|
44
67
|
};
|
|
45
68
|
//# sourceMappingURL=ledger-bridge.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,6BAA6B;AACvD,OAAO,KAAK,SAAS,+BAA+B;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,6BAA6B;AAE1D,MAAM,MAAM,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AACpD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACxC,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CACzC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AACzE,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAC9C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1E,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,UAAU,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC,CAClD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG,OAAO,CAC/C,UAAU,CAAC,cAAc,CAAC,yBAAyB,CAAC,CAAC,CACtD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAAI;IACxD,iBAAiB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C,OAAO,CAAC,CAAC;IAEnC,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE,qBAAqB,CACnB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAE1C,iBAAiB,CACf,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC,mBAAmB,CACjB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAExC;;;;OAIG;IACH,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAE9D;;;;OAIG;IACH,mBAAmB,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC1D,CAAC"}
|
package/dist/ledger-bridge.d.mts
CHANGED
|
@@ -20,6 +20,17 @@ export type LedgerSignTypedDataParams = {
|
|
|
20
20
|
message: EIP712Message;
|
|
21
21
|
};
|
|
22
22
|
export type LedgerSignTypedDataResponse = Awaited<ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>>;
|
|
23
|
+
export type GetAppNameAndVersionResponse = {
|
|
24
|
+
appName: string;
|
|
25
|
+
version: string;
|
|
26
|
+
};
|
|
27
|
+
export type AppConfigurationResponse = {
|
|
28
|
+
arbitraryDataEnabled: number;
|
|
29
|
+
erc20ProvisioningNecessary: number;
|
|
30
|
+
starkEnabled: number;
|
|
31
|
+
starkv2Supported: number;
|
|
32
|
+
version: string;
|
|
33
|
+
};
|
|
23
34
|
export type LedgerBridgeOptions = Record<string, unknown>;
|
|
24
35
|
export type LedgerBridge<T extends LedgerBridgeOptions> = {
|
|
25
36
|
isDeviceConnected: boolean;
|
|
@@ -41,5 +52,17 @@ export type LedgerBridge<T extends LedgerBridgeOptions> = {
|
|
|
41
52
|
deviceSignTransaction(params: LedgerSignTransactionParams): Promise<LedgerSignTransactionResponse>;
|
|
42
53
|
deviceSignMessage(params: LedgerSignMessageParams): Promise<LedgerSignMessageResponse>;
|
|
43
54
|
deviceSignTypedData(params: LedgerSignTypedDataParams): Promise<LedgerSignTypedDataResponse>;
|
|
55
|
+
/**
|
|
56
|
+
* Method to retrieve the name and version of the running application on the Ledger device.
|
|
57
|
+
*
|
|
58
|
+
* @returns An object containing appName and version.
|
|
59
|
+
*/
|
|
60
|
+
getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* Method to retrieve the configuration of the running application on the Ledger device.
|
|
63
|
+
*
|
|
64
|
+
* @returns An object containing the configuration of the running application.
|
|
65
|
+
*/
|
|
66
|
+
getAppConfiguration(): Promise<AppConfigurationResponse>;
|
|
44
67
|
};
|
|
45
68
|
//# sourceMappingURL=ledger-bridge.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.d.mts","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,6BAA6B;AACvD,OAAO,KAAK,SAAS,+BAA+B;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,6BAA6B;AAE1D,MAAM,MAAM,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AACpD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACxC,UAAU,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CACzC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AACzE,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAC9C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IA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AM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAAI;IACxD,iBAAiB,EAAE,OAAO,CAAC;IAE3B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzB;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnC,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE,qBAAqB,CACnB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAE1C,iBAAiB,CACf,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC,mBAAmB,CACjB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAExC;;;;OAIG;IACH,oBAAoB,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAE9D;;;;OAIG;IACH,mBAAmB,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-bridge.mjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\nimport type { EIP712Message } from '@ledgerhq/types-live';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n message: EIP712Message;\n};\nexport type LedgerSignTypedDataResponse = Awaited<\n ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>\n>;\n\nexport type LedgerBridgeOptions = Record<string, unknown>;\n\nexport type LedgerBridge<T extends LedgerBridgeOptions> = {\n isDeviceConnected: boolean;\n\n init(): Promise<void>;\n\n destroy(): Promise<void>;\n\n /**\n * Method to get the current configuration of the ledger bridge keyring.\n */\n getOptions(): Promise<T>;\n\n /**\n * Method to set the current configuration of the ledger bridge keyring.\n *\n * @param opts - An object contains configuration of the bridge.\n */\n setOptions(opts: T): Promise<void>;\n\n attemptMakeApp(): Promise<boolean>;\n\n updateTransportMethod(transportType: string | Transport): Promise<boolean>;\n\n getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;\n\n deviceSignTransaction(\n params: LedgerSignTransactionParams,\n ): Promise<LedgerSignTransactionResponse>;\n\n deviceSignMessage(\n params: LedgerSignMessageParams,\n ): Promise<LedgerSignMessageResponse>;\n\n deviceSignTypedData(\n params: LedgerSignTypedDataParams,\n ): Promise<LedgerSignTypedDataResponse>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ledger-bridge.mjs","sourceRoot":"","sources":["../src/ledger-bridge.ts"],"names":[],"mappings":"","sourcesContent":["import type LedgerHwAppEth from '@ledgerhq/hw-app-eth';\nimport type Transport from '@ledgerhq/hw-transport';\nimport type { EIP712Message } from '@ledgerhq/types-live';\n\nexport type GetPublicKeyParams = { hdPath: string };\nexport type GetPublicKeyResponse = Awaited<\n ReturnType<LedgerHwAppEth['getAddress']>\n>;\n\nexport type LedgerSignTransactionParams = { hdPath: string; tx: string };\nexport type LedgerSignTransactionResponse = Awaited<\n ReturnType<LedgerHwAppEth['signTransaction']>\n>;\n\nexport type LedgerSignMessageParams = { hdPath: string; message: string };\nexport type LedgerSignMessageResponse = Awaited<\n ReturnType<LedgerHwAppEth['signPersonalMessage']>\n>;\n\nexport type LedgerSignTypedDataParams = {\n hdPath: string;\n message: EIP712Message;\n};\nexport type LedgerSignTypedDataResponse = Awaited<\n ReturnType<LedgerHwAppEth['signEIP712HashedMessage']>\n>;\n\nexport type GetAppNameAndVersionResponse = {\n appName: string;\n version: string;\n};\n\nexport type AppConfigurationResponse = {\n arbitraryDataEnabled: number; // this is the blind signing support\n erc20ProvisioningNecessary: number;\n starkEnabled: number;\n starkv2Supported: number;\n version: string;\n};\n\nexport type LedgerBridgeOptions = Record<string, unknown>;\n\nexport type LedgerBridge<T extends LedgerBridgeOptions> = {\n isDeviceConnected: boolean;\n\n init(): Promise<void>;\n\n destroy(): Promise<void>;\n\n /**\n * Method to get the current configuration of the ledger bridge keyring.\n */\n getOptions(): Promise<T>;\n\n /**\n * Method to set the current configuration of the ledger bridge keyring.\n *\n * @param opts - An object contains configuration of the bridge.\n */\n setOptions(opts: T): Promise<void>;\n\n attemptMakeApp(): Promise<boolean>;\n\n updateTransportMethod(transportType: string | Transport): Promise<boolean>;\n\n getPublicKey(params: GetPublicKeyParams): Promise<GetPublicKeyResponse>;\n\n deviceSignTransaction(\n params: LedgerSignTransactionParams,\n ): Promise<LedgerSignTransactionResponse>;\n\n deviceSignMessage(\n params: LedgerSignMessageParams,\n ): Promise<LedgerSignMessageResponse>;\n\n deviceSignTypedData(\n params: LedgerSignTypedDataParams,\n ): Promise<LedgerSignTypedDataResponse>;\n\n /**\n * Method to retrieve the name and version of the running application on the Ledger device.\n *\n * @returns An object containing appName and version.\n */\n getAppNameAndVersion(): Promise<GetAppNameAndVersionResponse>;\n\n /**\n * Method to retrieve the configuration of the running application on the Ledger device.\n *\n * @returns An object containing the configuration of the running application.\n */\n getAppConfiguration(): Promise<AppConfigurationResponse>;\n};\n"]}
|
|
@@ -2,41 +2,75 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleLedgerTransportError = handleLedgerTransportError;
|
|
4
4
|
const hw_transport_1 = require("@ledgerhq/hw-transport");
|
|
5
|
-
const
|
|
5
|
+
const hw_wallet_sdk_1 = require("@metamask/hw-wallet-sdk");
|
|
6
|
+
const errors_1 = require("./errors.cjs");
|
|
7
|
+
const LEDGER_ERROR_PREFIX = 'Ledger: ';
|
|
8
|
+
const LEDGER_PREFIX_STATUS_CODES = new Set([
|
|
9
|
+
'0x6985',
|
|
10
|
+
'0x6a80',
|
|
11
|
+
'0x5515',
|
|
12
|
+
'0x650f',
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* Prefixes error messages with the Ledger identifier when needed.
|
|
16
|
+
*
|
|
17
|
+
* @param message - The error message to prefix.
|
|
18
|
+
* @returns The message with a Ledger prefix.
|
|
19
|
+
*/
|
|
20
|
+
function withLedgerPrefix(message) {
|
|
21
|
+
return message.startsWith(LEDGER_ERROR_PREFIX)
|
|
22
|
+
? message
|
|
23
|
+
: `${LEDGER_ERROR_PREFIX}${message}`;
|
|
24
|
+
}
|
|
6
25
|
/**
|
|
7
26
|
* Central error handler for Ledger TransportStatusError instances.
|
|
8
|
-
* Converts
|
|
27
|
+
* Converts Ledger transport errors into properly typed HardwareWalletError instances
|
|
28
|
+
* using the error mapping system.
|
|
9
29
|
*
|
|
10
30
|
* @param error - The error to handle
|
|
11
31
|
* @param fallbackMessage - Default error message if no specific handling is found
|
|
12
|
-
* @throws
|
|
32
|
+
* @throws HardwareWalletError with appropriate error details from mappings
|
|
13
33
|
*/
|
|
14
34
|
function handleLedgerTransportError(error, fallbackMessage) {
|
|
15
35
|
if (error instanceof hw_transport_1.TransportStatusError) {
|
|
16
|
-
const
|
|
17
|
-
|
|
36
|
+
const statusCodeHex = `0x${error.statusCode.toString(16)}`;
|
|
37
|
+
// Try to create error from known status code
|
|
38
|
+
if ((0, errors_1.isKnownLedgerError)(statusCodeHex)) {
|
|
39
|
+
const ledgerError = (0, errors_1.createLedgerError)(statusCodeHex);
|
|
40
|
+
if (LEDGER_PREFIX_STATUS_CODES.has(statusCodeHex)) {
|
|
41
|
+
ledgerError.message = withLedgerPrefix(ledgerError.message);
|
|
42
|
+
}
|
|
43
|
+
throw ledgerError;
|
|
44
|
+
}
|
|
45
|
+
// Unknown status code - create generic error with details
|
|
46
|
+
throw new hw_wallet_sdk_1.HardwareWalletError(error.message, {
|
|
47
|
+
code: hw_wallet_sdk_1.ErrorCode.Unknown,
|
|
48
|
+
severity: hw_wallet_sdk_1.Severity.Err,
|
|
49
|
+
category: hw_wallet_sdk_1.Category.Unknown,
|
|
50
|
+
userMessage: error.message,
|
|
51
|
+
cause: error,
|
|
52
|
+
});
|
|
18
53
|
}
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case 0x6a80:
|
|
33
|
-
return 'Ledger: Blind signing must be enabled';
|
|
34
|
-
case 0x5515:
|
|
35
|
-
return 'Ledger: Device is locked. Unlock it to continue';
|
|
36
|
-
case 0x650f:
|
|
37
|
-
return 'Ledger: Ethereum app closed. Open it to unlock';
|
|
38
|
-
default:
|
|
39
|
-
return transportError.message;
|
|
54
|
+
// Handle HardwareWalletError - pass through
|
|
55
|
+
if (error instanceof hw_wallet_sdk_1.HardwareWalletError) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
// For any other error type
|
|
59
|
+
if (error instanceof Error) {
|
|
60
|
+
throw new hw_wallet_sdk_1.HardwareWalletError(error.message, {
|
|
61
|
+
code: hw_wallet_sdk_1.ErrorCode.Unknown,
|
|
62
|
+
severity: hw_wallet_sdk_1.Severity.Err,
|
|
63
|
+
category: hw_wallet_sdk_1.Category.Unknown,
|
|
64
|
+
userMessage: error.message,
|
|
65
|
+
cause: error,
|
|
66
|
+
});
|
|
40
67
|
}
|
|
68
|
+
// Unknown error type
|
|
69
|
+
throw new hw_wallet_sdk_1.HardwareWalletError(fallbackMessage, {
|
|
70
|
+
code: hw_wallet_sdk_1.ErrorCode.Unknown,
|
|
71
|
+
severity: hw_wallet_sdk_1.Severity.Err,
|
|
72
|
+
category: hw_wallet_sdk_1.Category.Unknown,
|
|
73
|
+
userMessage: fallbackMessage,
|
|
74
|
+
});
|
|
41
75
|
}
|
|
42
76
|
//# 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":";;AAuCA,gEAiDC;AAxFD,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;AACH,SAAgB,0BAA0B,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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","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,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Central error handler for Ledger TransportStatusError instances.
|
|
3
|
-
* Converts
|
|
3
|
+
* Converts Ledger transport errors into properly typed HardwareWalletError instances
|
|
4
|
+
* using the error mapping system.
|
|
4
5
|
*
|
|
5
6
|
* @param error - The error to handle
|
|
6
7
|
* @param fallbackMessage - Default error message if no specific handling is found
|
|
7
|
-
* @throws
|
|
8
|
+
* @throws HardwareWalletError with appropriate error details from mappings
|
|
8
9
|
*/
|
|
9
10
|
export declare function handleLedgerTransportError(error: unknown, fallbackMessage: string): never;
|
|
10
11
|
//# sourceMappingURL=ledger-error-handler.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-error-handler.d.cts","sourceRoot":"","sources":["../src/ledger-error-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-error-handler.d.cts","sourceRoot":"","sources":["../src/ledger-error-handler.ts"],"names":[],"mappings":"AA8BA;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,MAAM,GACtB,KAAK,CA8CP"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Central error handler for Ledger TransportStatusError instances.
|
|
3
|
-
* Converts
|
|
3
|
+
* Converts Ledger transport errors into properly typed HardwareWalletError instances
|
|
4
|
+
* using the error mapping system.
|
|
4
5
|
*
|
|
5
6
|
* @param error - The error to handle
|
|
6
7
|
* @param fallbackMessage - Default error message if no specific handling is found
|
|
7
|
-
* @throws
|
|
8
|
+
* @throws HardwareWalletError with appropriate error details from mappings
|
|
8
9
|
*/
|
|
9
10
|
export declare function handleLedgerTransportError(error: unknown, fallbackMessage: string): never;
|
|
10
11
|
//# sourceMappingURL=ledger-error-handler.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger-error-handler.d.mts","sourceRoot":"","sources":["../src/ledger-error-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ledger-error-handler.d.mts","sourceRoot":"","sources":["../src/ledger-error-handler.ts"],"names":[],"mappings":"AA8BA;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,MAAM,GACtB,KAAK,CA8CP"}
|