Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'LedgerHQ:master' into eip1024
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Bacca authored Jan 31, 2022
2 parents 6fb4c45 + c1e3c0e commit 2db304c
Show file tree
Hide file tree
Showing 32 changed files with 2,468 additions and 1,327 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**[We are hiring, join us! 👨‍💻👩‍💻](https://jobs.lever.co/ledger/?department=Engineering)**


<img src="https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png" height="80" /> <img src="https://user-images.githubusercontent.com/211411/52533081-e679d380-2d2e-11e9-9c5e-571e4ad0107b.png" height="80" />
<img src="https://user-images.githubusercontent.com/3273751/151214602-f5153588-1911-4456-ae65-604d56821b36.png" height="80" /> <img src="https://user-images.githubusercontent.com/211411/52533081-e679d380-2d2e-11e9-9c5e-571e4ad0107b.png" height="80" />

[![Ledger Devs Slack](https://img.shields.io/badge/Slack-LedgerDevs-yellow.svg?style=flat)](https://ledger-dev.slack.com/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
"packages/*"
],
"version": "6.22.3",
"version": "6.23.1",
"npmClient": "yarn",
"useWorkspaces": true
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"publish": "yarn && lerna run clean && lerna run build && lerna publish --registry=https://registry.npmjs.org/"
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"browserify": "^17.0.0",
Expand All @@ -29,8 +29,8 @@
"eslint": "7",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.27.1",
"jest": "^27.4.5",
"eslint-plugin-react": "^7.28.0",
"jest": "^27.4.7",
"lerna": "3.22.1",
"prettier": "^2.2.1",
"ts-jest": "^27.1.2",
Expand Down
21 changes: 21 additions & 0 deletions packages/cryptoassets/data/bep20.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/cryptoassets/data/erc20-signatures.js

Large diffs are not rendered by default.

555 changes: 295 additions & 260 deletions packages/cryptoassets/data/erc20.js

Large diffs are not rendered by default.

531 changes: 282 additions & 249 deletions packages/cryptoassets/data/exchange/erc20.js

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions packages/cryptoassets/data/polygon-erc20.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/cryptoassets/data/trc20.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = [
["TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT","USDJ","JUST Stablecoin","TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",18],
["TVj7RNVHy6thbM7BWdSe9G6gXwKhjhdNZS","KLV","Klever","TVj7RNVHy6thbM7BWdSe9G6gXwKhjhdNZS",6],
["TBwoSTyywvLrgjSgaatxrBhxt3DGpVuENh","SEED","SEED","TBwoSTyywvLrgjSgaatxrBhxt3DGpVuENh",6],
["TZJmk51TP3YEETw7phRP581A7H3VzLDFsa","TEUR","EUR AlteWay Token","TZJmk51TP3YEETw7phRP581A7H3VzLDFsa",4]
["TZJmk51TP3YEETw7phRP581A7H3VzLDFsa","TEUR","EUR AlteWay Token","TZJmk51TP3YEETw7phRP581A7H3VzLDFsa",4],
["TAFjULxiVgT4qWk6UZwjqwZXTSaGaqnVp4","BTT","BitTorrent","TAFjULxiVgT4qWk6UZwjqwZXTSaGaqnVp4",18]
];
2 changes: 1 addition & 1 deletion packages/cryptoassets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/cryptoassets",
"version": "6.22.3",
"version": "6.23.1",
"description": "Ledger crypto-assets list",
"keywords": [
"Ledger"
Expand Down
8 changes: 4 additions & 4 deletions packages/cryptoassets/src/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1865,8 +1865,8 @@ const cryptocurrenciesById: Record<string, CryptoCurrency> = {
],
explorerViews: [
{
tx: "https://explorer.peercoin.net/tx/$hash",
address: "https://explorer.peercoin.net/address/$address",
tx: "https://blockbook.peercoin.net/tx/$hash",
address: "https://blockbook.peercoin.net/address/$address",
},
],
},
Expand Down Expand Up @@ -2892,12 +2892,12 @@ const cryptocurrenciesById: Record<string, CryptoCurrency> = {
units: [
{
name: "CRO",
code: "cro",
code: "CRO",
magnitude: 8,
},
{
name: "baseCRO",
code: "basecro",
code: "baseCRO",
magnitude: 0,
},
],
Expand Down
6 changes: 3 additions & 3 deletions packages/hw-app-algorand/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Ledger Hardware Wallet Algorand JavaScript bindings.

### Algorand

Cosmos API
Algorand API

#### Parameters

Expand All @@ -37,7 +37,7 @@ const algo = new Algorand(transport)

#### getAddress

get Algorajt address for a given BIP 32 path.
get Algorant address for a given BIP 32 path.

##### Parameters

Expand All @@ -47,7 +47,7 @@ get Algorajt address for a given BIP 32 path.
##### Examples

```javascript
cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
```

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), address: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** an object with a publicKey, address and (optionally) chainCode
6 changes: 3 additions & 3 deletions packages/hw-app-algorand/src/Algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CLA = 0x80;
const INS_GET_PUBLIC_KEY = 0x03;
const INS_SIGN_MSGPACK = 0x08;
/**
* Cosmos API
* Algorand API
*
* @example
* import Algorand from "@ledgerhq/hw-app-algorand";
Expand All @@ -48,12 +48,12 @@ export default class Algorand {
}

/**
* get Algorajt address for a given BIP 32 path.
* get Algorant address for a given BIP 32 path.
* @param path a path in BIP 32 format
* @option boolDisplay optionally enable or not the display
* @return an object with a publicKey, address and (optionally) chainCode
* @example
* cosmos.getAddress("44'/60'/0'/0/0").then(o => o.address)
* cosmos.getAddress("44'/283'/0'/0/0").then(o => o.address)
*/
getAddress(
path: string,
Expand Down
8 changes: 4 additions & 4 deletions packages/hw-app-btc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ Ledger Hardware Wallet BTC JavaScript bindings. Also supports many altcoins.
* [serializeTransactionOutputs](#serializetransactionoutputs)
* [Parameters](#parameters-7)
* [Examples](#examples-6)
* [getWalletPublicKey](#getwalletpublickey-1)
* [impl](#impl)
* [BtcNew](#btcnew)
* [Parameters](#parameters-8)
* [getWalletXpub](#getwalletxpub-1)
* [Parameters](#parameters-9)
* [getWalletPublicKey](#getwalletpublickey-2)
* [getWalletPublicKey](#getwalletpublickey-1)
* [Parameters](#parameters-10)
* [createPaymentTransactionNew](#createpaymenttransactionnew-1)
* [Parameters](#parameters-11)
* [BtcOld](#btcold)
* [Parameters](#parameters-12)
* [Examples](#examples-7)
* [getWalletPublicKey](#getwalletpublickey-3)
* [getWalletPublicKey](#getwalletpublickey-2)
* [Parameters](#parameters-13)
* [Examples](#examples-8)
* [signMessageNew](#signmessagenew-1)
Expand Down Expand Up @@ -279,7 +279,7 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');

Returns **[Buffer](https://nodejs.org/api/buffer.html)**

### getWalletPublicKey
### impl

Definition: A "normal path" is a prefix of a standard path where all
the hardened steps of the standard path are included. For example, the
Expand Down
9 changes: 5 additions & 4 deletions packages/hw-app-eth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/hw-app-eth",
"version": "6.22.3",
"version": "6.23.1",
"description": "Ledger Hardware Wallet Ethereum Application API",
"keywords": [
"Ledger",
Expand All @@ -27,13 +27,14 @@
"types": "lib/Eth.d.ts",
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/cryptoassets": "^6.22.3",
"@ethersproject/abi": "^5.5.0",
"@ethersproject/rlp": "^5.5.0",
"@ledgerhq/cryptoassets": "^6.23.1",
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.20.0",
"@ledgerhq/logs": "^6.10.0",
"axios": "^0.24.0",
"bignumber.js": "^9.0.2",
"ethers": "^5.5.2"
"bignumber.js": "^9.0.2"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
8 changes: 4 additions & 4 deletions packages/hw-app-eth/src/services/ledger/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This implements the resolution of a Transaction using Ledger's own API
import { log } from "@ledgerhq/logs";
import { ethers } from "ethers";
import { Interface } from "@ethersproject/abi";

import {
LedgerEthTransactionResolution,
Expand Down Expand Up @@ -99,7 +99,7 @@ const ledgerService: LedgerEthTransactionService = {
setExternalPlugin(payload, signature);
}
if (erc20OfInterest && erc20OfInterest.length && abi) {
const contract = new ethers.utils.Interface(abi);
const contract = new Interface(abi);
const args = contract.parseTransaction(decodedTx).args;
for (const path of erc20OfInterest) {
const address = path.split(".").reduce((value, seg) => {
Expand All @@ -108,14 +108,14 @@ const ledgerService: LedgerEthTransactionService = {
}
return value[seg];
}, args);
provideForContract(address);
await provideForContract(address);
}
}
} else {
log("ethereum", "no infos for selector " + selector);
}
}
provideForContract(decodedTx.to);
await provideForContract(decodedTx.to);
}

return resolution;
Expand Down
15 changes: 12 additions & 3 deletions packages/hw-app-eth/src/services/ledger/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ export const getNFTInfo = async (
.catch(axiosErrorHandling);
if (!response) return;

// APDU response specification: https://ledgerhq.atlassian.net/wiki/spaces/WALLETCO/pages/3269984297/NFT-1+NFT+Backend+design#NFT-Metadata-BLOB
const payload = response["payload"];
const collectionNameLength = Number(payload.slice(2, 3));
const collectionName = payload.slice(3, 3 + collectionNameLength).toString();
// Collection name length position: 3rd byte -> caracter 4 to 6
const collectionNameLength = parseInt(payload.slice(4, 6), 16);
const collectionNameHex = payload.substr(6, collectionNameLength * 2);
const collectionName = collectionNameHex
.match(/.{2}/g) // split every 2 characters
?.reduce(
(acc, curr) => (acc += String.fromCharCode(parseInt(curr, 16))),
""
); // convert hex to string

return {
contractAddress: contractAddress,
collectionName: collectionName,
collectionName: collectionName || "",
data: payload,
};
};
Expand Down
13 changes: 4 additions & 9 deletions packages/hw-app-eth/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { ethers } from "ethers";
import { encode, decode } from "@ethersproject/rlp";
import { BigNumber } from "bignumber.js";

export function decodeTxInfo(rawTx: Buffer) {
const VALID_TYPES = [1, 2];
const txType = VALID_TYPES.includes(rawTx[0]) ? rawTx[0] : null;
const rlpData = txType === null ? rawTx : rawTx.slice(1);
const rlpTx = ethers.utils.RLP.decode(rlpData).map((hex) =>
Buffer.from(hex.slice(2), "hex")
);
const rlpTx = decode(rlpData).map((hex) => Buffer.from(hex.slice(2), "hex"));
let chainIdTruncated = 0;
const rlpDecoded = ethers.utils.RLP.decode(rlpData);
const rlpDecoded = decode(rlpData);

let decodedTx;
if (txType === 2) {
Expand Down Expand Up @@ -52,10 +50,7 @@ export function decodeTxInfo(rawTx: Buffer) {

let vrsOffset = 0;
if (txType === null && rlpTx.length > 6) {
const rlpVrs = Buffer.from(
ethers.utils.RLP.encode(rlpTx.slice(-3)).slice(2),
"hex"
);
const rlpVrs = Buffer.from(encode(rlpTx.slice(-3)).slice(2), "hex");

vrsOffset = rawTx.length - (rlpVrs.length - 1);

Expand Down
Loading

0 comments on commit 2db304c

Please sign in to comment.