@ledgerhq/hw-app-eth 6.22.3 → 6.24.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.
@@ -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) => {
@@ -108,14 +108,14 @@ const ledgerService: LedgerEthTransactionService = {
108
108
  }
109
109
  return value[seg];
110
110
  }, args);
111
- provideForContract(address);
111
+ await provideForContract(address);
112
112
  }
113
113
  }
114
114
  } else {
115
115
  log("ethereum", "no infos for selector " + selector);
116
116
  }
117
117
  }
118
- provideForContract(decodedTx.to);
118
+ await provideForContract(decodedTx.to);
119
119
  }
120
120
 
121
121
  return resolution;
@@ -32,12 +32,21 @@ export const getNFTInfo = async (
32
32
  .catch(axiosErrorHandling);
33
33
  if (!response) return;
34
34
 
35
+ // APDU response specification: https://ledgerhq.atlassian.net/wiki/spaces/WALLETCO/pages/3269984297/NFT-1+NFT+Backend+design#NFT-Metadata-BLOB
35
36
  const payload = response["payload"];
36
- const collectionNameLength = Number(payload.slice(2, 3));
37
- const collectionName = payload.slice(3, 3 + collectionNameLength).toString();
37
+ // Collection name length position: 3rd byte -> caracter 4 to 6
38
+ const collectionNameLength = parseInt(payload.slice(4, 6), 16);
39
+ const collectionNameHex = payload.substr(6, collectionNameLength * 2);
40
+ const collectionName = collectionNameHex
41
+ .match(/.{2}/g) // split every 2 characters
42
+ ?.reduce(
43
+ (acc, curr) => (acc += String.fromCharCode(parseInt(curr, 16))),
44
+ ""
45
+ ); // convert hex to string
46
+
38
47
  return {
39
48
  contractAddress: contractAddress,
40
- collectionName: collectionName,
49
+ collectionName: collectionName || "",
41
50
  data: payload,
42
51
  };
43
52
  };
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
+ });