@metamask/eth-ledger-bridge-keyring 11.3.1 → 12.0.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/README.md +8 -0
  3. package/dist/constants.cjs +26 -0
  4. package/dist/constants.cjs.map +1 -0
  5. package/dist/constants.d.cts +13 -0
  6. package/dist/constants.d.cts.map +1 -0
  7. package/dist/constants.d.mts +13 -0
  8. package/dist/constants.d.mts.map +1 -0
  9. package/dist/constants.mjs +23 -0
  10. package/dist/constants.mjs.map +1 -0
  11. package/dist/index.cjs +2 -1
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +2 -1
  14. package/dist/index.d.cts.map +1 -1
  15. package/dist/index.d.mts +2 -1
  16. package/dist/index.d.mts.map +1 -1
  17. package/dist/index.mjs +2 -1
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/ledger-mobile-bridge.cjs +7 -2
  20. package/dist/ledger-mobile-bridge.cjs.map +1 -1
  21. package/dist/ledger-mobile-bridge.d.cts.map +1 -1
  22. package/dist/ledger-mobile-bridge.d.mts.map +1 -1
  23. package/dist/ledger-mobile-bridge.mjs +7 -2
  24. package/dist/ledger-mobile-bridge.mjs.map +1 -1
  25. package/dist/utils.cjs +29 -0
  26. package/dist/utils.cjs.map +1 -0
  27. package/dist/utils.d.cts +9 -0
  28. package/dist/utils.d.cts.map +1 -0
  29. package/dist/utils.d.mts +9 -0
  30. package/dist/utils.d.mts.map +1 -0
  31. package/dist/utils.mjs +26 -0
  32. package/dist/utils.mjs.map +1 -0
  33. package/dist/v2/index.cjs +18 -0
  34. package/dist/v2/index.cjs.map +1 -0
  35. package/dist/v2/index.d.cts +2 -0
  36. package/dist/v2/index.d.cts.map +1 -0
  37. package/dist/v2/index.d.mts +2 -0
  38. package/dist/v2/index.d.mts.map +1 -0
  39. package/dist/v2/index.mjs +2 -0
  40. package/dist/v2/index.mjs.map +1 -0
  41. package/dist/{ledger-keyring-v2.cjs → v2/ledger-keyring.cjs} +21 -20
  42. package/dist/v2/ledger-keyring.cjs.map +1 -0
  43. package/dist/{ledger-keyring-v2.d.mts → v2/ledger-keyring.d.cts} +11 -10
  44. package/dist/v2/ledger-keyring.d.cts.map +1 -0
  45. package/dist/{ledger-keyring-v2.d.cts → v2/ledger-keyring.d.mts} +11 -10
  46. package/dist/v2/ledger-keyring.d.mts.map +1 -0
  47. package/dist/{ledger-keyring-v2.mjs → v2/ledger-keyring.mjs} +19 -18
  48. package/dist/v2/ledger-keyring.mjs.map +1 -0
  49. package/package.json +31 -14
  50. package/dist/ledger-keyring-v2.cjs.map +0 -1
  51. package/dist/ledger-keyring-v2.d.cts.map +0 -1
  52. package/dist/ledger-keyring-v2.d.mts.map +0 -1
  53. package/dist/ledger-keyring-v2.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [12.0.0]
11
+
12
+ ### Added
13
+
14
+ - Add `./v2` subpath export for keyring v2 implementation ([#513](https://github.com/MetaMask/accounts/pull/513))
15
+ - `LedgerKeyring` and `LedgerKeyringOptions` are now available from `@metamask/eth-ledger-bridge-keyring/v2`.
16
+
17
+ ### Changed
18
+
19
+ - **BREAKING:** Move and rename `LedgerKeyringV2` and `LedgerKeyringV2Options` to the new `./v2` subpath export ([#513](https://github.com/MetaMask/accounts/pull/513))
20
+ - `LedgerKeyringV2` is now `LedgerKeyring` from `@metamask/eth-ledger-bridge-keyring/v2`.
21
+ - `LedgerKeyringV2Options` is now `LedgerKeyringOptions` from `@metamask/eth-ledger-bridge-keyring/v2`.
22
+ - Bump `@metamask/utils` from `^11.10.0` to `^11.11.0` ([#483](https://github.com/MetaMask/accounts/pull/483))
23
+ - Bump `@metamask/account-api` from `^1.0.1` to `^1.0.2` ([#515](https://github.com/MetaMask/accounts/pull/515))
24
+ - Bump `@metamask/keyring-api` from `^22.0.0` to `^23.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
25
+ - Bump `@metamask/keyring-sdk` from `^1.2.0` to `^2.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
26
+
27
+ ### Fixed
28
+
29
+ - Add dynamic NFT and ERC-20 check ([#506](https://github.com/MetaMask/accounts/pull/506))
30
+
31
+ ## [11.4.0]
32
+
33
+ ### Added
34
+
35
+ - Add `getTransactionSelector` to read the 4-byte calldata selector from serialized transaction hex (legacy and typed txs) ([#506](https://github.com/MetaMask/accounts/pull/506))
36
+ - Ledger mobile bridge passes `nft: true` to `clearSignTransaction` when that selector is NFT-only (ERC-721 / ERC-1155).
37
+ - Add `ERC20_WRITE_SELECTORS` for the three EIP-20 write functions (`transfer`, `transferFrom`, `approve`) ([#506](https://github.com/MetaMask/accounts/pull/506))
38
+
10
39
  ## [11.3.1]
11
40
 
12
41
  ### Changed
@@ -376,7 +405,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
376
405
 
377
406
  - Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
378
407
 
379
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.3.1...HEAD
408
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@12.0.0...HEAD
409
+ [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
410
+ [11.4.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.3.1...@metamask/eth-ledger-bridge-keyring@11.4.0
380
411
  [11.3.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-ledger-bridge-keyring@11.3.0...@metamask/eth-ledger-bridge-keyring@11.3.1
381
412
  [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
382
413
  [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
package/README.md CHANGED
@@ -19,6 +19,14 @@ The iframe is allowed to interact with the Ledger device (since U2F requires SSL
19
19
 
20
20
  The iframe code it's hosted in the same repo under the branch [gh-pages](https://github.com/MetaMask/eth-ledger-bridge-keyring/tree/gh-pages) and it's being served via github pages. In the future we might move it under the metamask.io domain.
21
21
 
22
+ ## Installation
23
+
24
+ `yarn add @metamask/eth-ledger-bridge-keyring`
25
+
26
+ or
27
+
28
+ `npm install @metamask/eth-ledger-bridge-keyring`
29
+
22
30
  ## Usage
23
31
 
24
32
  In addition to all the known methods from the [Keyring class protocol](https://github.com/MetaMask/eth-simple-keyring#the-keyring-class-protocol),
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC20_WRITE_SELECTORS = exports.NFT_ONLY_SELECTORS = void 0;
4
+ /**
5
+ * Selectors that are used only by NFT standards (ERC721/ERC1155), not by ERC20.
6
+ * When the tx uses one of these, we enable Ledger NFT clear signing.
7
+ * approve(0x095ea7b3) is shared by ERC20 and ERC721 so we do NOT include it here.
8
+ */
9
+ exports.NFT_ONLY_SELECTORS = new Set([
10
+ '0xa22cb465', // setApprovalForAll (ERC721 + ERC1155)
11
+ '0x42842e0e', // safeTransferFrom (ERC721)
12
+ '0xb88d4fde', // safeTransferFrom(address,address,uint256,bytes) (ERC721)
13
+ '0xf242432a', // safeTransferFrom (ERC1155)
14
+ '0x2eb2c2d6', // safeBatchTransferFrom (ERC1155)
15
+ ]);
16
+ /**
17
+ * Four-byte selectors for the three state-changing functions defined in EIP-20.
18
+ *
19
+ * @see https://eips.ethereum.org/EIPS/eip-20
20
+ */
21
+ exports.ERC20_WRITE_SELECTORS = new Set([
22
+ '0xa9059cbb', // transfer(address,uint256)
23
+ '0x23b872dd', // transferFrom(address,address,uint256)
24
+ '0x095ea7b3', // approve(address,uint256)
25
+ ]);
26
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACxC,YAAY,EAAE,uCAAuC;IACrD,YAAY,EAAE,4BAA4B;IAC1C,YAAY,EAAE,2DAA2D;IACzE,YAAY,EAAE,6BAA6B;IAC3C,YAAY,EAAE,kCAAkC;CACjD,CAAC,CAAC;AAEH;;;;GAIG;AACU,QAAA,qBAAqB,GAAG,IAAI,GAAG,CAAC;IAC3C,YAAY,EAAE,4BAA4B;IAC1C,YAAY,EAAE,wCAAwC;IACtD,YAAY,EAAE,2BAA2B;CAC1C,CAAC,CAAC","sourcesContent":["/**\n * Selectors that are used only by NFT standards (ERC721/ERC1155), not by ERC20.\n * When the tx uses one of these, we enable Ledger NFT clear signing.\n * approve(0x095ea7b3) is shared by ERC20 and ERC721 so we do NOT include it here.\n */\nexport const NFT_ONLY_SELECTORS = new Set([\n '0xa22cb465', // setApprovalForAll (ERC721 + ERC1155)\n '0x42842e0e', // safeTransferFrom (ERC721)\n '0xb88d4fde', // safeTransferFrom(address,address,uint256,bytes) (ERC721)\n '0xf242432a', // safeTransferFrom (ERC1155)\n '0x2eb2c2d6', // safeBatchTransferFrom (ERC1155)\n]);\n\n/**\n * Four-byte selectors for the three state-changing functions defined in EIP-20.\n *\n * @see https://eips.ethereum.org/EIPS/eip-20\n */\nexport const ERC20_WRITE_SELECTORS = new Set([\n '0xa9059cbb', // transfer(address,uint256)\n '0x23b872dd', // transferFrom(address,address,uint256)\n '0x095ea7b3', // approve(address,uint256)\n]);\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Selectors that are used only by NFT standards (ERC721/ERC1155), not by ERC20.
3
+ * When the tx uses one of these, we enable Ledger NFT clear signing.
4
+ * approve(0x095ea7b3) is shared by ERC20 and ERC721 so we do NOT include it here.
5
+ */
6
+ export declare const NFT_ONLY_SELECTORS: Set<string>;
7
+ /**
8
+ * Four-byte selectors for the three state-changing functions defined in EIP-20.
9
+ *
10
+ * @see https://eips.ethereum.org/EIPS/eip-20
11
+ */
12
+ export declare const ERC20_WRITE_SELECTORS: Set<string>;
13
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,aAM7B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,aAIhC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Selectors that are used only by NFT standards (ERC721/ERC1155), not by ERC20.
3
+ * When the tx uses one of these, we enable Ledger NFT clear signing.
4
+ * approve(0x095ea7b3) is shared by ERC20 and ERC721 so we do NOT include it here.
5
+ */
6
+ export declare const NFT_ONLY_SELECTORS: Set<string>;
7
+ /**
8
+ * Four-byte selectors for the three state-changing functions defined in EIP-20.
9
+ *
10
+ * @see https://eips.ethereum.org/EIPS/eip-20
11
+ */
12
+ export declare const ERC20_WRITE_SELECTORS: Set<string>;
13
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,aAM7B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,aAIhC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Selectors that are used only by NFT standards (ERC721/ERC1155), not by ERC20.
3
+ * When the tx uses one of these, we enable Ledger NFT clear signing.
4
+ * approve(0x095ea7b3) is shared by ERC20 and ERC721 so we do NOT include it here.
5
+ */
6
+ export const NFT_ONLY_SELECTORS = new Set([
7
+ '0xa22cb465', // setApprovalForAll (ERC721 + ERC1155)
8
+ '0x42842e0e', // safeTransferFrom (ERC721)
9
+ '0xb88d4fde', // safeTransferFrom(address,address,uint256,bytes) (ERC721)
10
+ '0xf242432a', // safeTransferFrom (ERC1155)
11
+ '0x2eb2c2d6', // safeBatchTransferFrom (ERC1155)
12
+ ]);
13
+ /**
14
+ * Four-byte selectors for the three state-changing functions defined in EIP-20.
15
+ *
16
+ * @see https://eips.ethereum.org/EIPS/eip-20
17
+ */
18
+ export const ERC20_WRITE_SELECTORS = new Set([
19
+ '0xa9059cbb', // transfer(address,uint256)
20
+ '0x23b872dd', // transferFrom(address,address,uint256)
21
+ '0x095ea7b3', // approve(address,uint256)
22
+ ]);
23
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACxC,YAAY,EAAE,uCAAuC;IACrD,YAAY,EAAE,4BAA4B;IAC1C,YAAY,EAAE,2DAA2D;IACzE,YAAY,EAAE,6BAA6B;IAC3C,YAAY,EAAE,kCAAkC;CACjD,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IAC3C,YAAY,EAAE,4BAA4B;IAC1C,YAAY,EAAE,wCAAwC;IACtD,YAAY,EAAE,2BAA2B;CAC1C,CAAC,CAAC","sourcesContent":["/**\n * Selectors that are used only by NFT standards (ERC721/ERC1155), not by ERC20.\n * When the tx uses one of these, we enable Ledger NFT clear signing.\n * approve(0x095ea7b3) is shared by ERC20 and ERC721 so we do NOT include it here.\n */\nexport const NFT_ONLY_SELECTORS = new Set([\n '0xa22cb465', // setApprovalForAll (ERC721 + ERC1155)\n '0x42842e0e', // safeTransferFrom (ERC721)\n '0xb88d4fde', // safeTransferFrom(address,address,uint256,bytes) (ERC721)\n '0xf242432a', // safeTransferFrom (ERC1155)\n '0x2eb2c2d6', // safeBatchTransferFrom (ERC1155)\n]);\n\n/**\n * Four-byte selectors for the three state-changing functions defined in EIP-20.\n *\n * @see https://eips.ethereum.org/EIPS/eip-20\n */\nexport const ERC20_WRITE_SELECTORS = new Set([\n '0xa9059cbb', // transfer(address,uint256)\n '0x23b872dd', // transferFrom(address,address,uint256)\n '0x095ea7b3', // approve(address,uint256)\n]);\n"]}
package/dist/index.cjs CHANGED
@@ -15,11 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./ledger-keyring.cjs"), exports);
18
- __exportStar(require("./ledger-keyring-v2.cjs"), exports);
19
18
  __exportStar(require("./ledger-iframe-bridge.cjs"), exports);
20
19
  __exportStar(require("./ledger-mobile-bridge.cjs"), exports);
21
20
  __exportStar(require("./ledger-transport-middleware.cjs"), exports);
22
21
  __exportStar(require("./ledger-hw-app.cjs"), exports);
23
22
  __exportStar(require("./errors.cjs"), exports);
24
23
  __exportStar(require("./ledger-error-handler.cjs"), exports);
24
+ __exportStar(require("./constants.cjs"), exports);
25
+ __exportStar(require("./utils.cjs"), exports);
25
26
  //# sourceMappingURL=index.cjs.map
@@ -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;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"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAiC;AACjC,6DAAuC;AACvC,6DAAuC;AAEvC,oEAA8C;AAE9C,sDAAgC;AAChC,+CAAyB;AACzB,6DAAuC;AACvC,kDAA4B;AAC5B,8CAAwB","sourcesContent":["export * from './ledger-keyring';\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';\nexport * from './constants';\nexport * from './utils';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./ledger-keyring.cjs";
2
- export * from "./ledger-keyring-v2.cjs";
3
2
  export * from "./ledger-iframe-bridge.cjs";
4
3
  export * from "./ledger-mobile-bridge.cjs";
5
4
  export type * from "./ledger-bridge.cjs";
@@ -8,4 +7,6 @@ export type * from "./type.cjs";
8
7
  export * from "./ledger-hw-app.cjs";
9
8
  export * from "./errors.cjs";
10
9
  export * from "./ledger-error-handler.cjs";
10
+ export * from "./constants.cjs";
11
+ export * from "./utils.cjs";
11
12
  //# sourceMappingURL=index.d.cts.map
@@ -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;AAChC,6BAAyB;AACzB,2CAAuC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,kDAA8C;AAC9C,gCAA4B;AAC5B,oCAAgC;AAChC,6BAAyB;AACzB,2CAAuC;AACvC,gCAA4B;AAC5B,4BAAwB"}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./ledger-keyring.mjs";
2
- export * from "./ledger-keyring-v2.mjs";
3
2
  export * from "./ledger-iframe-bridge.mjs";
4
3
  export * from "./ledger-mobile-bridge.mjs";
5
4
  export type * from "./ledger-bridge.mjs";
@@ -8,4 +7,6 @@ export type * from "./type.mjs";
8
7
  export * from "./ledger-hw-app.mjs";
9
8
  export * from "./errors.mjs";
10
9
  export * from "./ledger-error-handler.mjs";
10
+ export * from "./constants.mjs";
11
+ export * from "./utils.mjs";
11
12
  //# sourceMappingURL=index.d.mts.map
@@ -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;AAChC,6BAAyB;AACzB,2CAAuC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,kDAA8C;AAC9C,gCAA4B;AAC5B,oCAAgC;AAChC,6BAAyB;AACzB,2CAAuC;AACvC,gCAA4B;AAC5B,4BAAwB"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  export * from "./ledger-keyring.mjs";
2
- export * from "./ledger-keyring-v2.mjs";
3
2
  export * from "./ledger-iframe-bridge.mjs";
4
3
  export * from "./ledger-mobile-bridge.mjs";
5
4
  export * from "./ledger-transport-middleware.mjs";
6
5
  export * from "./ledger-hw-app.mjs";
7
6
  export * from "./errors.mjs";
8
7
  export * from "./ledger-error-handler.mjs";
8
+ export * from "./constants.mjs";
9
+ export * from "./utils.mjs";
9
10
  //# sourceMappingURL=index.mjs.map
@@ -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;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
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qCAAiC;AACjC,2CAAuC;AACvC,2CAAuC;AAEvC,kDAA8C;AAE9C,oCAAgC;AAChC,6BAAyB;AACzB,2CAAuC;AACvC,gCAA4B;AAC5B,4BAAwB","sourcesContent":["export * from './ledger-keyring';\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';\nexport * from './constants';\nexport * from './utils';\n"]}
@@ -13,7 +13,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.LedgerMobileBridge = void 0;
16
+ const constants_1 = require("./constants.cjs");
16
17
  const ledger_hw_app_1 = require("./ledger-hw-app.cjs");
18
+ const utils_1 = require("./utils.cjs");
17
19
  /**
18
20
  * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.
19
21
  */
@@ -83,10 +85,13 @@ class LedgerMobileBridge {
83
85
  * @returns Retrieve v, r, s from the signed transaction.
84
86
  */
85
87
  async deviceSignTransaction({ tx, hdPath, }) {
88
+ const selector = (0, utils_1.getTransactionSelector)(tx);
89
+ const nft = Boolean(selector && constants_1.NFT_ONLY_SELECTORS.has(selector));
90
+ const erc20 = Boolean(selector && constants_1.ERC20_WRITE_SELECTORS.has(selector));
86
91
  return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).clearSignTransaction(hdPath, tx, {
87
92
  externalPlugins: true,
88
- erc20: true,
89
- nft: true,
93
+ erc20,
94
+ nft,
90
95
  });
91
96
  }
92
97
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ledger-mobile-bridge.cjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAeA,uDAAyD;AAUzD;;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,sCAAsC;YACtC,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,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,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QACJ,CAAC;QACD,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,UAAU,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,oBAAoB;QACxB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,oBAAoB,EAAE,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB;QACvB,OAAO,uBAAA,IAAI,oEAAW,MAAf,IAAI,CAAa,CAAC,mBAAmB,EAAE,CAAC;IACjD,CAAC;CAsBF;AA5MD,gDA4MC;;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 {\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';\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 // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.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 return this.#getEthApp().clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20: true,\n nft: true,\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":";;;;;;;;;;;;;;;AAEA,+CAAwE;AAcxE,uDAAyD;AAGzD,uCAAiD;AAQjD;;GAEG;AACH,MAAa,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAA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,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;AAhND,gDAgNC;;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 // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.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 +1 @@
1
- {"version":3,"file":"ledger-mobile-bridge.d.cts","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,+BAA+B;AAEpD,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;AAGnD,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,yBAAyB,CAAC,GAA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AAoB,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;CAwB/D"}
@@ -10,7 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _LedgerMobileBridge_instances, _LedgerMobileBridge_transportMiddleware, _LedgerMobileBridge_opts, _LedgerMobileBridge_getTransportMiddleWare, _LedgerMobileBridge_getEthApp;
13
+ import { ERC20_WRITE_SELECTORS, NFT_ONLY_SELECTORS } from "./constants.mjs";
13
14
  import { MetaMaskLedgerHwAppEth } from "./ledger-hw-app.mjs";
15
+ import { getTransactionSelector } from "./utils.mjs";
14
16
  /**
15
17
  * LedgerMobileBridge is a bridge between the LedgerKeyring and the LedgerTransportMiddleware.
16
18
  */
@@ -80,10 +82,13 @@ export class LedgerMobileBridge {
80
82
  * @returns Retrieve v, r, s from the signed transaction.
81
83
  */
82
84
  async deviceSignTransaction({ tx, hdPath, }) {
85
+ const selector = getTransactionSelector(tx);
86
+ const nft = Boolean(selector && NFT_ONLY_SELECTORS.has(selector));
87
+ const erc20 = Boolean(selector && ERC20_WRITE_SELECTORS.has(selector));
83
88
  return __classPrivateFieldGet(this, _LedgerMobileBridge_instances, "m", _LedgerMobileBridge_getEthApp).call(this).clearSignTransaction(hdPath, tx, {
84
89
  externalPlugins: true,
85
- erc20: true,
86
- nft: true,
90
+ erc20,
91
+ nft,
87
92
  });
88
93
  }
89
94
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ledger-mobile-bridge.mjs","sourceRoot":"","sources":["../src/ledger-mobile-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;AAeA,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AAUzD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC;YACH,MAAM,uBAAA,IAAI,iFAAwB,MAA5B,IAAI,CAA0B,CAAC,OAAO,EAAE,CAAC;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,sCAAsC;YACtC,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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,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 {\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';\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 // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.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 return this.#getEthApp().clearSignTransaction(hdPath, tx, {\n externalPlugins: true,\n erc20: true,\n nft: true,\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":";;;;;;;;;;;;AAEA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAoB;AAcxE,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AAGzD,OAAO,EAAE,sBAAsB,EAAE,oBAAgB;AAQjD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAO7B,YACE,mBAAwC,EACxC,OAAkC,EAAE;;QAR7B,0DAA2C;QAEpD,2CAAiC;QAEjC,sBAAiB,GAAG,KAAK,CAAC;QAMxB,uBAAA,IAAI,4BAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,2C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;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 // eslint-disable-next-line no-console\n console.error(error);\n }\n this.isDeviceConnected = false;\n }\n\n /**\n * Method to sign a string Message.\n * Sending the string message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath and message.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.message - The message to sign.\n * @returns Retrieve v, r, s from the signed message.\n */\n async deviceSignMessage({\n hdPath,\n message,\n }: LedgerSignMessageParams): Promise<LedgerSignMessageResponse> {\n return this.#getEthApp().signPersonalMessage(hdPath, message);\n }\n\n /**\n * Method to sign a EIP712 Message.\n * Sending the typed data message to the device and returning the signed message.\n *\n * @param params - An object contains hdPath, domainSeparatorHex and hashStructMessageHex.\n * @param params.hdPath - The BIP 32 path of the account.\n * @param params.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"]}
package/dist/utils.cjs ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransactionSelector = getTransactionSelector;
4
+ const tx_1 = require("@ethereumjs/tx");
5
+ const util_1 = require("@ethereumjs/util");
6
+ const utils_1 = require("@metamask/utils");
7
+ /**
8
+ * Returns the 4-byte selector from raw serialized transaction hex or undefined if not present.
9
+ * Supports legacy RLP and EIP-2718 typed transactions (via `@ethereumjs/tx`).
10
+ *
11
+ * @param rawTxHex - Raw serialized transaction hex (with or without `0x` prefix).
12
+ * @returns The selector (`0x` + 8 hex digits, lowercased) or undefined if parsing fails or no calldata.
13
+ */
14
+ function getTransactionSelector(rawTxHex) {
15
+ try {
16
+ const prefixedHex = (0, utils_1.add0x)(rawTxHex);
17
+ const tx = tx_1.TransactionFactory.fromSerializedData((0, util_1.hexToBytes)(prefixedHex));
18
+ const dataHex = (0, util_1.bytesToHex)(tx.data);
19
+ const selectorSize = 2 /* 0x */ + 4 * 2; /* 4 bytes (hex) */
20
+ if (dataHex.length >= selectorSize) {
21
+ return dataHex.slice(0, selectorSize).toLowerCase();
22
+ }
23
+ }
24
+ catch {
25
+ // ignore parse errors
26
+ }
27
+ return undefined;
28
+ }
29
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAWA,wDAaC;AAxBD,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","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"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns the 4-byte selector from raw serialized transaction hex or undefined if not present.
3
+ * Supports legacy RLP and EIP-2718 typed transactions (via `@ethereumjs/tx`).
4
+ *
5
+ * @param rawTxHex - Raw serialized transaction hex (with or without `0x` prefix).
6
+ * @returns The selector (`0x` + 8 hex digits, lowercased) or undefined if parsing fails or no calldata.
7
+ */
8
+ export declare function getTransactionSelector(rawTxHex: string): string | undefined;
9
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAa3E"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns the 4-byte selector from raw serialized transaction hex or undefined if not present.
3
+ * Supports legacy RLP and EIP-2718 typed transactions (via `@ethereumjs/tx`).
4
+ *
5
+ * @param rawTxHex - Raw serialized transaction hex (with or without `0x` prefix).
6
+ * @returns The selector (`0x` + 8 hex digits, lowercased) or undefined if parsing fails or no calldata.
7
+ */
8
+ export declare function getTransactionSelector(rawTxHex: string): string | undefined;
9
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAa3E"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,26 @@
1
+ import { TransactionFactory } from "@ethereumjs/tx";
2
+ import { bytesToHex, hexToBytes } from "@ethereumjs/util";
3
+ import { add0x } from "@metamask/utils";
4
+ /**
5
+ * Returns the 4-byte selector from raw serialized transaction hex or undefined if not present.
6
+ * Supports legacy RLP and EIP-2718 typed transactions (via `@ethereumjs/tx`).
7
+ *
8
+ * @param rawTxHex - Raw serialized transaction hex (with or without `0x` prefix).
9
+ * @returns The selector (`0x` + 8 hex digits, lowercased) or undefined if parsing fails or no calldata.
10
+ */
11
+ export function getTransactionSelector(rawTxHex) {
12
+ try {
13
+ const prefixedHex = add0x(rawTxHex);
14
+ const tx = TransactionFactory.fromSerializedData(hexToBytes(prefixedHex));
15
+ const dataHex = bytesToHex(tx.data);
16
+ const selectorSize = 2 /* 0x */ + 4 * 2; /* 4 bytes (hex) */
17
+ if (dataHex.length >= selectorSize) {
18
+ return dataHex.slice(0, selectorSize).toLowerCase();
19
+ }
20
+ }
21
+ catch {
22
+ // ignore parse errors
23
+ }
24
+ return undefined;
25
+ }
26
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB;AACpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,yBAAyB;AAC1D,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,EAAE,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;QAC1E,MAAM,OAAO,GAAG,UAAU,CAAC,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","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"]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ledger-keyring.cjs"), exports);
18
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAiC","sourcesContent":["export * from './ledger-keyring';\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./ledger-keyring.cjs";
2
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,qCAAiC"}
@@ -0,0 +1,2 @@
1
+ export * from "./ledger-keyring.mjs";
2
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,qCAAiC"}
@@ -0,0 +1,2 @@
1
+ export * from "./ledger-keyring.mjs";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,qCAAiC","sourcesContent":["export * from './ledger-keyring';\n"]}