@ledgerhq/hw-app-eth 6.22.4 → 6.24.1

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 (64) hide show
  1. package/README.md +43 -2
  2. package/lib/Eth.d.ts +23 -0
  3. package/lib/Eth.d.ts.map +1 -1
  4. package/lib/Eth.js +53 -4
  5. package/lib/Eth.js.map +1 -1
  6. package/lib/services/ledger/index.js +2 -2
  7. package/lib/services/ledger/index.js.map +1 -1
  8. package/lib/utils.d.ts.map +1 -1
  9. package/lib/utils.js +4 -6
  10. package/lib/utils.js.map +1 -1
  11. package/lib-es/Eth.d.ts +23 -0
  12. package/lib-es/Eth.d.ts.map +1 -1
  13. package/lib-es/Eth.js +53 -4
  14. package/lib-es/Eth.js.map +1 -1
  15. package/lib-es/contracts.d.ts +2 -5
  16. package/lib-es/contracts.d.ts.map +1 -1
  17. package/lib-es/contracts.js +19 -26
  18. package/lib-es/contracts.js.map +1 -1
  19. package/lib-es/erc20.d.ts +0 -0
  20. package/lib-es/erc20.d.ts.map +0 -0
  21. package/lib-es/erc20.js +0 -0
  22. package/lib-es/erc20.js.map +0 -0
  23. package/lib-es/loadConfig.d.ts +7 -0
  24. package/lib-es/loadConfig.d.ts.map +1 -0
  25. package/lib-es/loadConfig.js +20 -0
  26. package/lib-es/loadConfig.js.map +1 -0
  27. package/lib-es/nfts.d.ts +11 -0
  28. package/lib-es/nfts.d.ts.map +1 -0
  29. package/lib-es/nfts.js +94 -0
  30. package/lib-es/nfts.js.map +1 -0
  31. package/lib-es/services/ledger/contracts.d.ts +0 -0
  32. package/lib-es/services/ledger/contracts.d.ts.map +0 -0
  33. package/lib-es/services/ledger/contracts.js +0 -0
  34. package/lib-es/services/ledger/contracts.js.map +0 -0
  35. package/lib-es/services/ledger/erc20.d.ts +0 -0
  36. package/lib-es/services/ledger/erc20.d.ts.map +0 -0
  37. package/lib-es/services/ledger/erc20.js +0 -0
  38. package/lib-es/services/ledger/erc20.js.map +0 -0
  39. package/lib-es/services/ledger/index.d.ts +0 -0
  40. package/lib-es/services/ledger/index.d.ts.map +0 -0
  41. package/lib-es/services/ledger/index.js +2 -2
  42. package/lib-es/services/ledger/index.js.map +1 -1
  43. package/lib-es/services/ledger/loadConfig.d.ts +0 -0
  44. package/lib-es/services/ledger/loadConfig.d.ts.map +0 -0
  45. package/lib-es/services/ledger/loadConfig.js +0 -0
  46. package/lib-es/services/ledger/loadConfig.js.map +0 -0
  47. package/lib-es/services/ledger/nfts.d.ts +0 -0
  48. package/lib-es/services/ledger/nfts.d.ts.map +0 -0
  49. package/lib-es/services/ledger/nfts.js +0 -0
  50. package/lib-es/services/ledger/nfts.js.map +0 -0
  51. package/lib-es/services/types.d.ts +0 -0
  52. package/lib-es/services/types.d.ts.map +0 -0
  53. package/lib-es/services/types.js +0 -0
  54. package/lib-es/services/types.js.map +0 -0
  55. package/lib-es/utils.d.ts +0 -0
  56. package/lib-es/utils.d.ts.map +1 -1
  57. package/lib-es/utils.js +4 -6
  58. package/lib-es/utils.js.map +1 -1
  59. package/package.json +7 -6
  60. package/src/Eth.ts +66 -4
  61. package/src/services/ledger/index.ts +2 -2
  62. package/src/utils.ts +4 -9
  63. package/tests/Eth.test.ts +28 -0
  64. package/.turbo/turbo-build.log +0 -2
package/src/Eth.ts CHANGED
@@ -120,6 +120,8 @@ export default class Eth {
120
120
  "eth2SetWithdrawalIndex",
121
121
  "setExternalPlugin",
122
122
  "setPlugin",
123
+ "getEIP1024PublicEncryptionKey",
124
+ "getEIP1024SharedSecret",
123
125
  ],
124
126
  scrambleKey
125
127
  );
@@ -1133,6 +1135,70 @@ export default class Eth {
1133
1135
  );
1134
1136
  }
1135
1137
 
1138
+ /**
1139
+ * get a public encryption key on Curve25519 according to EIP 1024
1140
+ * @param path a path in BIP 32 format
1141
+ * @option boolDisplay optionally enable or not the display
1142
+ * @return an object with a publicKey
1143
+ * @example
1144
+ * eth.getEIP1024PublicEncryptionKey("44'/60'/0'/0/0").then(o => o.publicKey)
1145
+ */
1146
+ getEIP1024PublicEncryptionKey(
1147
+ path: string,
1148
+ boolDisplay?: boolean
1149
+ ): Promise<{
1150
+ publicKey: string;
1151
+ }> {
1152
+ const paths = splitPath(path);
1153
+ const buffer = Buffer.alloc(1 + paths.length * 4);
1154
+ buffer[0] = paths.length;
1155
+ paths.forEach((element, index) => {
1156
+ buffer.writeUInt32BE(element, 1 + 4 * index);
1157
+ });
1158
+ return this.transport
1159
+ .send(0xe0, 0x18, boolDisplay ? 0x01 : 0x00, 0x00, buffer)
1160
+ .then((response) => {
1161
+ return {
1162
+ publicKey: response.slice(0, -2).toString("hex"),
1163
+ };
1164
+ });
1165
+ }
1166
+
1167
+ /**
1168
+ * get a shared secret on Curve25519 according to EIP 1024
1169
+ * @param path a path in BIP 32 format
1170
+ * @param remotePublicKeyHex remote Curve25519 public key
1171
+ * @option boolDisplay optionally enable or not the display
1172
+ * @return an object with a shared secret
1173
+ * @example
1174
+ * eth.getEIP1024SharedSecret("44'/60'/0'/0/0", "87020e80af6e07a6e4697f091eacadb9e7e6629cb7e5a8a371689a3ed53b3d64").then(o => o.sharedSecret)
1175
+ */
1176
+ getEIP1024SharedSecret(
1177
+ path: string,
1178
+ remotePublicKeyHex: string,
1179
+ boolDisplay?: boolean
1180
+ ): Promise<{
1181
+ sharedSecret: string;
1182
+ }> {
1183
+ const paths = splitPath(path);
1184
+ const remotePublicKey = hexBuffer(remotePublicKeyHex);
1185
+ const buffer = Buffer.alloc(1 + paths.length * 4 + 32);
1186
+ let offset = 0;
1187
+ buffer[0] = paths.length;
1188
+ paths.forEach((element, index) => {
1189
+ buffer.writeUInt32BE(element, 1 + 4 * index);
1190
+ });
1191
+ offset = 1 + 4 * paths.length;
1192
+ remotePublicKey.copy(buffer, offset);
1193
+ return this.transport
1194
+ .send(0xe0, 0x18, boolDisplay ? 0x01 : 0x00, 0x01, buffer)
1195
+ .then((response) => {
1196
+ return {
1197
+ sharedSecret: response.slice(0, -2).toString("hex"),
1198
+ };
1199
+ });
1200
+ }
1201
+
1136
1202
  provideERC20TokenInformation({ data }: { data: Buffer }): Promise<boolean> {
1137
1203
  console.warn(
1138
1204
  "hw-app-eth: eth.provideERC20TokenInformation is deprecated. signTransaction solves this for you when providing it in `resolution`."
@@ -1185,10 +1251,6 @@ function provideNFTInformation(
1185
1251
  return transport.send(0xe0, 0x14, 0x00, 0x00, data).then(
1186
1252
  () => true,
1187
1253
  (e) => {
1188
- if (e && e.statusCode === 0x6a80) {
1189
- // some issue with providing the data
1190
- return false;
1191
- }
1192
1254
  if (e && e.statusCode === 0x6d00) {
1193
1255
  // older version of ETH app => error because we don't allow blind sign when NFT is explicitly requested to be resolved.
1194
1256
  throw new EthAppNftNotSupported();
@@ -1,6 +1,6 @@
1
1
  // This implements the resolution of a Transaction using Ledger's own API
2
2
  import { log } from "@ledgerhq/logs";
3
- import { ethers } from "ethers";
3
+ import { Interface } from "@ethersproject/abi";
4
4
 
5
5
  import {
6
6
  LedgerEthTransactionResolution,
@@ -99,7 +99,7 @@ const ledgerService: LedgerEthTransactionService = {
99
99
  setExternalPlugin(payload, signature);
100
100
  }
101
101
  if (erc20OfInterest && erc20OfInterest.length && abi) {
102
- const contract = new ethers.utils.Interface(abi);
102
+ const contract = new Interface(abi);
103
103
  const args = contract.parseTransaction(decodedTx).args;
104
104
  for (const path of erc20OfInterest) {
105
105
  const address = path.split(".").reduce((value, seg) => {
package/src/utils.ts CHANGED
@@ -1,15 +1,13 @@
1
- import { ethers } from "ethers";
1
+ import { encode, decode } from "@ethersproject/rlp";
2
2
  import { BigNumber } from "bignumber.js";
3
3
 
4
4
  export function decodeTxInfo(rawTx: Buffer) {
5
5
  const VALID_TYPES = [1, 2];
6
6
  const txType = VALID_TYPES.includes(rawTx[0]) ? rawTx[0] : null;
7
7
  const rlpData = txType === null ? rawTx : rawTx.slice(1);
8
- const rlpTx = ethers.utils.RLP.decode(rlpData).map((hex) =>
9
- Buffer.from(hex.slice(2), "hex")
10
- );
8
+ const rlpTx = decode(rlpData).map((hex) => Buffer.from(hex.slice(2), "hex"));
11
9
  let chainIdTruncated = 0;
12
- const rlpDecoded = ethers.utils.RLP.decode(rlpData);
10
+ const rlpDecoded = decode(rlpData);
13
11
 
14
12
  let decodedTx;
15
13
  if (txType === 2) {
@@ -52,10 +50,7 @@ export function decodeTxInfo(rawTx: Buffer) {
52
50
 
53
51
  let vrsOffset = 0;
54
52
  if (txType === null && rlpTx.length > 6) {
55
- const rlpVrs = Buffer.from(
56
- ethers.utils.RLP.encode(rlpTx.slice(-3)).slice(2),
57
- "hex"
58
- );
53
+ const rlpVrs = Buffer.from(encode(rlpTx.slice(-3)).slice(2), "hex");
59
54
 
60
55
  vrsOffset = rawTx.length - (rlpVrs.length - 1);
61
56
 
package/tests/Eth.test.ts CHANGED
@@ -889,3 +889,31 @@ test("eth2SetWithdrawalIndex", async () => {
889
889
  const result = await eth.eth2SetWithdrawalIndex(1);
890
890
  expect(result).toEqual(true);
891
891
  });
892
+ test("getEIP1024PublicEncryptionKey", async () => {
893
+ const transport = await openTransportReplayer(
894
+ RecordStore.fromString(`
895
+ => e018000015058000002c8000003c800000000000000000000000
896
+ <= 2f720080750797da95a41b052cf5694be1be81c0a662d449cd15f946f376e76d9000
897
+ `)
898
+ );
899
+ const eth = new Eth(transport);
900
+ const result = await eth.getEIP1024PublicEncryptionKey("44'/60'/0'/0/0", false);
901
+ expect(result).toEqual({
902
+ publicKey:
903
+ "2f720080750797da95a41b052cf5694be1be81c0a662d449cd15f946f376e76d",
904
+ });
905
+ });
906
+ test("getEIP1024SharedSecret", async () => {
907
+ const transport = await openTransportReplayer(
908
+ RecordStore.fromString(`
909
+ => e018000135058000002c8000003c8000000000000000000000009ee8bf81321bc2a9e74de286621e13c013b5e4187b1c2fe42b686000672c6f33
910
+ <= 241dc9af8ecae08df6cf899a73a750b43117b50a7f1470405b5ff10adcf49f769000
911
+ `)
912
+ );
913
+ const eth = new Eth(transport);
914
+ const result = await eth.getEIP1024SharedSecret("44'/60'/0'/0/0", "9ee8bf81321bc2a9e74de286621e13c013b5e4187b1c2fe42b686000672c6f33", false);
915
+ expect(result).toEqual({
916
+ sharedSecret:
917
+ "241dc9af8ecae08df6cf899a73a750b43117b50a7f1470405b5ff10adcf49f76",
918
+ });
919
+ });
@@ -1,2 +0,0 @@
1
- @ledgerhq/hw-app-eth:build: cache hit, replaying output 715ee6b450935ba7
2
- @ledgerhq/hw-app-eth:build: $ NODE_ENV=production tsc && tsc -m ES6 --outDir lib-es