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 master
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandruPislariu authored Mar 15, 2022
2 parents 05bb4a3 + ae71cce commit 45d862b
Show file tree
Hide file tree
Showing 21 changed files with 633 additions and 491 deletions.
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.25.1",
"version": "6.26.1",
"npmClient": "yarn",
"useWorkspaces": true
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
"create-hash": "^1.1.3",
"documentation": "^13.2.5",
"eslint": "7",
"eslint-config-prettier": "^8.3.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.28.0",
"jest": "^27.4.7",
"eslint-plugin-react": "^7.29.3",
"jest": "^27.5.1",
"lerna": "3.22.1",
"prettier": "^2.2.1",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"uglify-js": "^3.14.5"
"ts-jest": "^27.1.3",
"ts-node": "^10.6.0",
"typescript": "^4.6.2",
"uglify-js": "^3.15.2"
},
"dependencies": {
"js-levenshtein": "^1.1.6"
Expand Down
11 changes: 11 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.

29 changes: 23 additions & 6 deletions packages/cryptoassets/data/erc20.js

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions packages/cryptoassets/data/exchange/erc20.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/cryptoassets/data/polygon-erc20.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.25.0",
"version": "6.26.1",
"description": "Ledger crypto-assets list",
"keywords": [
"Ledger"
Expand Down
1 change: 0 additions & 1 deletion packages/cryptoassets/src/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* DEPRECATED => these will eventually be moved into an internal crypto-assets repo
*
* ~~ fields ~~
*
Expand Down
6 changes: 3 additions & 3 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.25.0",
"version": "6.26.1",
"description": "Ledger Hardware Wallet Ethereum Application API",
"keywords": [
"Ledger",
Expand Down Expand Up @@ -29,11 +29,11 @@
"dependencies": {
"@ethersproject/abi": "^5.5.0",
"@ethersproject/rlp": "^5.5.0",
"@ledgerhq/cryptoassets": "^6.25.0",
"@ledgerhq/cryptoassets": "^6.26.1",
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.24.1",
"@ledgerhq/logs": "^6.10.0",
"axios": "^0.24.0",
"axios": "^0.26.0",
"bignumber.js": "^9.0.2"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/hw-app-helium/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/hw-app-helium",
"version": "6.24.1",
"version": "6.26.0",
"description": "Ledger Hardware Wallet Helium Application API",
"keywords": [
"Ledger",
Expand All @@ -27,7 +27,7 @@
"types": "lib/Helium.d.ts",
"license": "Apache-2.0",
"dependencies": {
"@helium/crypto": "^3.45.0",
"@helium/address": "^4.0.0",
"@helium/proto": "^1.5.0",
"@helium/transactions": "^3.62.0",
"@ledgerhq/errors": "^6.10.0",
Expand All @@ -38,7 +38,7 @@
},
"devDependencies": {
"@ledgerhq/hw-transport-node-speculos": "^6.24.1",
"axios": "^0.23.0"
"axios": "^0.26.0"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
4 changes: 2 additions & 2 deletions packages/hw-app-helium/src/Helium.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Transport from "@ledgerhq/hw-transport";
import { StatusCodes } from "@ledgerhq/errors";
import { Address } from "@helium/crypto";
import Address from "@helium/address";
import {
PaymentV2,
SecurityExchangeV1,
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class Helium {
pathBuffer
);

const address = Address.fromBin(addressBuffer.slice(1));
const address = Address.fromBin(addressBuffer.slice(1, 34));

return {
index: addressBuffer.slice(0, 1)[0],
Expand Down
2 changes: 1 addition & 1 deletion packages/hw-app-helium/src/serialization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from "@helium/crypto";
import Address from "@helium/address";
import {
PaymentV2,
StakeValidatorV1,
Expand Down
2 changes: 1 addition & 1 deletion packages/hw-app-helium/tests/Helium.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TransferValidatorStakeV1,
UnstakeValidatorV1,
} from "@helium/transactions";
import { Address } from "@helium/crypto";
import Address from "@helium/address";
import {
openTransportReplayer,
RecordStore,
Expand Down
4 changes: 2 additions & 2 deletions packages/hw-app-solana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/hw-app-solana",
"version": "6.24.1",
"version": "6.26.0",
"description": "Ledger Hardware Wallet Solana Application API",
"keywords": [
"Ledger",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"devDependencies": {
"@ledgerhq/hw-transport-node-speculos": "^6.24.1",
"axios": "^0.24.0"
"axios": "^0.26.0"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
6 changes: 3 additions & 3 deletions packages/hw-transport-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/hw-transport-http",
"version": "6.24.1",
"version": "6.26.0",
"description": "Ledger Hardware Wallet communication layer over http",
"keywords": [
"Ledger",
Expand Down Expand Up @@ -30,8 +30,8 @@
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.24.1",
"@ledgerhq/logs": "^6.10.0",
"axios": "^0.24.0",
"ws": "7"
"axios": "^0.26.0",
"ws": "8.5.0"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
21 changes: 20 additions & 1 deletion packages/hw-transport-node-hid-singleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ Allows to communicate with Ledger Hardware Wallets.

* [TransportNodeHidSingleton](#transportnodehidsingleton)
* [Examples](#examples)
* [exchange](#exchange)
* [Parameters](#parameters)
* [isSupported](#issupported)
* [list](#list)
* [listen](#listen)
* [Parameters](#parameters)
* [Parameters](#parameters-1)
* [autoDisconnect](#autodisconnect)
* [disconnect](#disconnect)
* [open](#open)

Expand All @@ -38,6 +41,16 @@ import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
TransportNodeHid.create().then(transport => ...)
```

#### exchange

Exchange with the device using APDU protocol.

##### Parameters

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

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** a promise of apdu response

#### isSupported

#### list
Expand All @@ -50,6 +63,12 @@ TransportNodeHid.create().then(transport => ...)

Returns **Subscription**

#### autoDisconnect

convenience wrapper for auto-disconnect logic

Returns **void**

#### disconnect

globally disconnect the transport singleton
Expand Down
2 changes: 1 addition & 1 deletion packages/hw-transport-node-hid-singleton/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/hw-transport-node-hid-singleton",
"version": "6.24.1",
"version": "6.26.0",
"description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid and usb-detection",
"keywords": [
"Ledger",
Expand Down
56 changes: 54 additions & 2 deletions packages/hw-transport-node-hid-singleton/src/TransportNodeHid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ import { identifyUSBProductId } from "@ledgerhq/devices";
import { CantOpenDevice } from "@ledgerhq/errors";
import { listenDevices } from "./listenDevices";
let transportInstance;

const DISCONNECT_TIMEOUT = 5000;
let disconnectTimeout;
const clearDisconnectTimeout = () => {
if (disconnectTimeout) {
clearTimeout(disconnectTimeout);
}
};

const setDisconnectTimeout = () => {
clearDisconnectTimeout();
disconnectTimeout = setTimeout(
() => TransportNodeHidSingleton.autoDisconnect(),
DISCONNECT_TIMEOUT
);
};

/**
* node-hid Transport implementation
* @example
Expand All @@ -21,6 +38,7 @@ let transportInstance;
*/

export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
preventAutoDisconnect = false;
/**
*
*/
Expand Down Expand Up @@ -88,6 +106,20 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
};
};

/**
* convenience wrapper for auto-disconnect logic
*/
static async autoDisconnect(): void {
if (transportInstance && !transportInstance.preventAutoDisconnect) {
log("hid-verbose", "triggering auto disconnect");
TransportNodeHidSingleton.disconnect();
} else if (transportInstance) {
// If we have disabled the auto-disconnect, try again in DISCONNECT_TIMEOUT
clearDisconnectTimeout();
setDisconnectTimeout();
}
}

/**
* globally disconnect the transport singleton
*/
Expand All @@ -97,12 +129,14 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
transportInstance.emit("disconnect");
transportInstance = null;
}
clearDisconnectTimeout();
}

/**
* if path="" is not provided, the library will take the first device
*/
static open(): Promise<TransportNodeHidSingleton> {
clearDisconnectTimeout();
return Promise.resolve().then(() => {
if (transportInstance) {
log("hid-verbose", "reusing opened transport instance");
Expand Down Expand Up @@ -138,8 +172,26 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
});
}

close() {
// intentionally, a close will not effectively close the hid connection
setAllowAutoDisconnect(allow: boolean): void {
this.preventAutoDisconnect = !allow;
}

/**
* Exchange with the device using APDU protocol.
* @param apdu
* @returns a promise of apdu response
*/
async exchange(apdu: Buffer): Promise<Buffer> {
clearDisconnectTimeout();
const result = await super.exchange(apdu);
setDisconnectTimeout();
return result;
}

close(): Promise<void> {
// intentionally, a close will not effectively close the hid connection but
// will allow an auto-disconnection after some inactivity
this.preventAutoDisconnect = false;
return Promise.resolve();
}
}
4 changes: 2 additions & 2 deletions packages/hw-transport-node-speculos-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/hw-transport-node-speculos-http",
"version": "6.24.1",
"version": "6.26.0",
"description": "Ledger Hardware Wallet communication layer with speculos Nano simulator using the http api",
"keywords": [
"Ledger",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.24.1",
"@ledgerhq/logs": "^6.10.0",
"axios": "^0.24.0"
"axios": "^0.26.0"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
Loading

0 comments on commit 45d862b

Please sign in to comment.