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

refactor: use buffer/ package to be compatible with browsers #736

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/devices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/logs": "^6.10.0",
"buffer": "^6.0.3",
"rxjs": "6",
"semver": "^7.3.5"
},
Expand Down
1 change: 1 addition & 0 deletions packages/devices/src/ble/receiveAPDU.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { TransportError, DisconnectedDevice } from "@ledgerhq/errors";
import { Observable } from "rxjs";
import { log } from "@ledgerhq/logs";
Expand Down
1 change: 1 addition & 0 deletions packages/devices/src/ble/sendAPDU.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { Observable } from "rxjs";
import { log } from "@ledgerhq/logs";
const TagId = 0x05;
Expand Down
1 change: 1 addition & 0 deletions packages/devices/src/hid-framing.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { TransportError } from "@ledgerhq/errors";
export type ResponseAcc =
| {
Expand Down
1 change: 1 addition & 0 deletions packages/devices/src/scrambling.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
export function wrapApdu(apdu: Buffer, key: Buffer) {
if (apdu.length === 0) return apdu;
const result = Buffer.alloc(apdu.length);
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-algorand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.11.2",
"bip32-path": "^0.4.2",
"buffer": "^6.0.3",
"hi-base32": "^0.5.1",
"js-sha512": "^0.8.0",
"tweetnacl": "^1.0.3"
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-algorand/src/Algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import BIPPath from "bip32-path";
import { UserRefusedOnDevice } from "@ledgerhq/errors";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"bip32-path": "^0.4.2",
"bitcoinjs-lib": "^5.2.0",
"bs58": "^4.0.1",
"buffer": "^6.0.3",
"invariant": "^2.2.4",
"ripemd160": "2",
"semver": "^7.3.5",
Expand Down
11 changes: 6 additions & 5 deletions packages/hw-app-btc/src/Btc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import { pathStringToArray } from "./bip32";
import BtcNew, { canSupportApp } from "./BtcNew";
Expand Down Expand Up @@ -129,11 +130,11 @@ export default class Btc {
!isPathNormal(path)
) {
console.warn(`WARNING: Using deprecated device protocol to get the public key because

* a non-standard path is requested, and
* verify flag is false
The new protocol only allows export of non-standard paths if the

The new protocol only allows export of non-standard paths if the
verify flag is true. Standard paths are (currently):

M/44'/(1|0)'/X'
Expand All @@ -142,9 +143,9 @@ export default class Btc {
M/86'/(1|0)'/X'
M/48'/(1|0)'/X'/Y'

followed by "", "(0|1)", or "(0|1)/b", where a and b are
followed by "", "(0|1)", or "(0|1)/b", where a and b are
non-hardened. For example, the following paths are standard

M/48'/1'/99'/7'
M/86'/1'/99'/0
M/48'/0'/99'/7'/1/17
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/BtcNew.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { crypto } from "bitcoinjs-lib";
import semver from "semver";
import { pointCompress } from "tiny-secp256k1";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/BtcOld.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import bs58 from "bs58";
import RIPEMD160 from "ripemd160";
import sha from "sha.js";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/bip32.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import bippath from "bip32-path";
import bs58check from "bs58check";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/buffertools.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import varuint from "varuint-bitcoin";

export function unsafeTo64bitLE(n: number): Buffer {
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/compressPublicKey.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
export function compressPublicKey(publicKey: Buffer): Buffer {
const prefix = (publicKey[64] & 1) !== 0 ? 0x03 : 0x02;
const prefixBuffer = Buffer.alloc(1);
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/createTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { log } from "@ledgerhq/logs";
import type Transport from "@ledgerhq/hw-transport";
import { hashPublicKey } from "./hashPublicKey";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/getTrustedInput.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import invariant from "invariant";
import type Transport from "@ledgerhq/hw-transport";
import type { Transaction } from "./types";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/getTrustedInputBIP143.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import Transport from "@ledgerhq/hw-transport";
import shajs from "sha.js";
import type { Transaction } from "./types";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/accounttype.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { crypto } from "bitcoinjs-lib";
import { pointAddScalar } from "tiny-secp256k1";
import { BufferWriter } from "../buffertools";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/appClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import Transport from "@ledgerhq/hw-transport";
import { pathElementsToBuffer } from "../bip32";
import { PsbtV2 } from "./psbtv2";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/clientCommands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { crypto } from "bitcoinjs-lib";
import { BufferReader } from "../buffertools";
import { createVarint } from "../varint";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/merkelizedPsbt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { MerkleMap } from "./merkleMap";
import { PsbtV2 } from "./psbtv2";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/merkle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { crypto } from "bitcoinjs-lib";

/**
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/merkleMap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { createVarint } from "../varint";
import { hashLeaf, Merkle } from "./merkle";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/policy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { crypto } from "bitcoinjs-lib";
import { pathArrayToString } from "../bip32";
import { BufferWriter } from "../buffertools";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/psbtExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { BufferWriter } from "../buffertools";
import { PsbtV2 } from "./psbtv2";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/psbtFinalizer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { BufferWriter } from "../buffertools";
import { psbtIn, PsbtV2 } from "./psbtv2";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/newops/psbtv2.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import {
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/serializeTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type { Transaction } from "./types";
import { createVarint } from "./varint";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/signMessage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import bippath from "bip32-path";
import { MAX_SCRIPT_BLOCK } from "./constants";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/signP2SHTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import { getTrustedInput } from "./getTrustedInput";
import { startUntrustedHashTransactionInput } from "./startUntrustedHashTransactionInput";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/signTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import { bip32asBuffer } from "./bip32";
export function signTransaction(
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/splitTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import { log } from "@ledgerhq/logs";
import type { Transaction, TransactionInput, TransactionOutput } from "./types";
import { getVarint } from "./varint";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import type { Transaction } from "./types";
import { createVarint } from "./varint";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-btc/src/varint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
export function getVarint(data: Buffer, offset: number): [number, number] {
if (data[offset] < 0xfd) {
return [data[offset], 1];
Expand Down
3 changes: 2 additions & 1 deletion packages/hw-app-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"dependencies": {
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.11.2",
"bip32-path": "^0.4.2"
"bip32-path": "^0.4.2",
"buffer": "^6.0.3"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-cosmos/src/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import BIPPath from "bip32-path";
import { UserRefusedOnDevice } from "@ledgerhq/errors";
Expand Down
3 changes: 2 additions & 1 deletion packages/hw-app-elrond/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"dependencies": {
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.11.2",
"bip32-path": "^0.4.2"
"bip32-path": "^0.4.2",
"buffer": "^6.0.3"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-elrond/src/Elrond.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@flow

import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import BIPPath from "bip32-path";

Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@ledgerhq/logs": "^6.10.0",
"axios": "^0.24.0",
"bignumber.js": "^9.0.1",
"buffer": "^6.0.3",
"ethers": "^5.5.1"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-eth/src/Eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
********************************************************************************/
// FIXME drop:
import { splitPath, foreach } from "./utils";
import { Buffer } from "buffer/";
import { log } from "@ledgerhq/logs";
import { EthAppPleaseEnableContractData } from "@ledgerhq/errors";
import type Transport from "@ledgerhq/hw-transport";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-eth/src/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import blob from "@ledgerhq/cryptoassets/data/erc20-signatures";

/**
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-eth/src/nfts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import axios from "axios";
import { getLoadConfig } from "./loadConfig";
import type { LoadConfig } from "./loadConfig";
Expand Down
3 changes: 2 additions & 1 deletion packages/hw-app-polkadot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"dependencies": {
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.11.2",
"bip32-path": "^0.4.2"
"bip32-path": "^0.4.2",
"buffer": "^6.0.3"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-polkadot/src/Polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
********************************************************************************/
import type Transport from "@ledgerhq/hw-transport";
import { Buffer } from "buffer/";
import BIPPath from "bip32-path";
import {
UserRefusedOnDevice,
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-str/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@ledgerhq/hw-transport": "^6.11.2",
"base32.js": "^0.1.0",
"buffer": "^6.0.3",
"sha.js": "^2.3.6",
"tweetnacl": "^1.0.3"
},
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-str/src/Str.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import {
splitPath,
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-str/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
import { Buffer } from "buffer/";
import base32 from "base32.js";
import nacl from "tweetnacl";
import { sha256 } from "sha.js";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-tezos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@ledgerhq/hw-transport": "^6.11.2",
"blake2b": "^2.1.3",
"bs58check": "^2.1.2",
"buffer": "^6.0.3",
"invariant": "^2.2.4"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-tezos/src/Tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
import { Buffer } from "buffer/";
import invariant from "invariant";
import bs58check from "bs58check";
import blake2b from "blake2b";
Expand Down
3 changes: 2 additions & 1 deletion packages/hw-app-trx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/errors": "^6.10.0",
"@ledgerhq/hw-transport": "^6.11.2"
"@ledgerhq/hw-transport": "^6.11.2",
"buffer": "^6.0.3"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-trx/src/Trx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { splitPath, foreach, decodeVarint } from "./utils";
//import { StatusCodes, TransportStatusError } from "@ledgerhq/errors";
import type Transport from "@ledgerhq/hw-transport";
import { Buffer } from "buffer/";

const remapTransactionRelatedErrors = (e) => {
if (e && e.statusCode === 0x6a80) {
Expand Down
3 changes: 2 additions & 1 deletion packages/hw-app-xrp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/hw-transport": "^6.11.2",
"bip32-path": "0.4.2"
"bip32-path": "0.4.2",
"buffer": "^6.0.3"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/hw-app-xrp/src/Xrp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import type Transport from "@ledgerhq/hw-transport";
import BIPPath from "bip32-path";
/**
Expand Down
1 change: 1 addition & 0 deletions packages/hw-transport-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@ledgerhq/hw-transport": "^6.11.2",
"@ledgerhq/logs": "^6.10.0",
"axios": "^0.24.0",
"buffer": "^6.0.3",
"ws": "7"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/hw-transport-http/src/HttpTransport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import Transport from "@ledgerhq/hw-transport";
import { TransportError } from "@ledgerhq/errors";
import axios from "axios";
Expand Down
1 change: 1 addition & 0 deletions packages/hw-transport-http/src/WebSocketTransport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
import Transport from "@ledgerhq/hw-transport";
import { TransportError } from "@ledgerhq/errors";
import { log } from "@ledgerhq/logs";
Expand Down
3 changes: 2 additions & 1 deletion packages/hw-transport-mocker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"license": "Apache-2.0",
"dependencies": {
"@ledgerhq/hw-transport": "^6.11.2",
"@ledgerhq/logs": "^6.10.0"
"@ledgerhq/logs": "^6.10.0",
"buffer": "^6.0.3"
},
"scripts": {
"clean": "bash ../../script/clean.sh",
Expand Down
1 change: 1 addition & 0 deletions packages/hw-transport-mocker/src/RecordStore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from "buffer/";
/**
* thrown by the RecordStore.fromString parser.
*/
Expand Down
Loading