diff --git a/blue_modules/encryption.ts b/blue_modules/encryption.ts index 31f029181..746926a76 100644 --- a/blue_modules/encryption.ts +++ b/blue_modules/encryption.ts @@ -1,17 +1,17 @@ -// @ts-ignore: Ignore import errors -import CryptoJS from 'crypto-js'; +import AES from 'crypto-js/aes'; +import Utf8 from 'crypto-js/enc-utf8'; export function encrypt(data: string, password: string): string { if (data.length < 10) throw new Error('data length cant be < 10'); - const ciphertext = CryptoJS.AES.encrypt(data, password); + const ciphertext = AES.encrypt(data, password); return ciphertext.toString(); } export function decrypt(data: string, password: string): string | false { - const bytes = CryptoJS.AES.decrypt(data, password); + const bytes = AES.decrypt(data, password); let str: string | false = false; try { - str = bytes.toString(CryptoJS.enc.Utf8); + str = bytes.toString(Utf8); } catch (e) {} // For some reason, sometimes decrypt would succeed with an incorrect password and return random characters. diff --git a/blue_modules/notifications.js b/blue_modules/notifications.js index e7ab920b9..61f80d005 100644 --- a/blue_modules/notifications.js +++ b/blue_modules/notifications.js @@ -7,14 +7,14 @@ import loc from '../loc'; import { requestNotifications } from 'react-native-permissions'; import PushNotification from 'react-native-push-notification'; import ActionSheet from '../screen/ActionSheet'; +import { groundControlUri } from './constants'; -const constants = require('./constants'); const PUSH_TOKEN = 'PUSH_TOKEN'; const GROUNDCONTROL_BASE_URI = 'GROUNDCONTROL_BASE_URI'; const NOTIFICATIONS_STORAGE = 'NOTIFICATIONS_STORAGE'; const NOTIFICATIONS_NO_AND_DONT_ASK_FLAG = 'NOTIFICATIONS_NO_AND_DONT_ASK_FLAG'; let alreadyConfigured = false; -let baseURI = constants.groundControlUri; +let baseURI = groundControlUri; function Notifications(props) { async function _setPushToken(token) { @@ -254,11 +254,11 @@ function Notifications(props) { }; Notifications.getDefaultUri = function () { - return constants.groundControlUri; + return groundControlUri; }; Notifications.saveUri = async function (uri) { - baseURI = uri || constants.groundControlUri; // settign the url to use currently. if not set - use default + baseURI = uri || groundControlUri; // settign the url to use currently. if not set - use default return AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, uri); }; diff --git a/class/deeplink-schema-match.ts b/class/deeplink-schema-match.ts index a8247a4d9..89b7f8608 100644 --- a/class/deeplink-schema-match.ts +++ b/class/deeplink-schema-match.ts @@ -9,9 +9,7 @@ import { LightningCustodianWallet, WatchOnlyWallet } from './'; import Azteco from './azteco'; import Lnurl from './lnurl'; import type { TWallet } from './wallets/types'; - -const BlueApp = require('../BlueApp'); -const AppStorage = BlueApp.AppStorage; +import { AppStorage } from '../BlueApp'; type TCompletionHandlerParams = [string, object]; type TContext = { diff --git a/class/hd-segwit-bech32-transaction.js b/class/hd-segwit-bech32-transaction.js index 0788b7488..61f2452fe 100644 --- a/class/hd-segwit-bech32-transaction.js +++ b/class/hd-segwit-bech32-transaction.js @@ -1,8 +1,9 @@ +import * as bitcoin from 'bitcoinjs-lib'; +import BigNumber from 'bignumber.js'; + import { HDSegwitBech32Wallet } from './wallets/hd-segwit-bech32-wallet'; import { SegwitBech32Wallet } from './wallets/segwit-bech32-wallet'; import * as BlueElectrum from '../blue_modules/BlueElectrum'; -const bitcoin = require('bitcoinjs-lib'); -const BigNumber = require('bignumber.js'); /** * Represents transaction of a BIP84 wallet. diff --git a/class/lnurl.js b/class/lnurl.js index a6ea7e8cb..50d964d92 100644 --- a/class/lnurl.js +++ b/class/lnurl.js @@ -3,8 +3,8 @@ import bolt11 from 'bolt11'; import { parse } from 'url'; // eslint-disable-line n/no-deprecated-api import { createHmac } from 'crypto'; import secp256k1 from 'secp256k1'; -const CryptoJS = require('crypto-js'); -const createHash = require('create-hash'); +import CryptoJS from 'crypto-js'; +import createHash from 'create-hash'; const ONION_REGEX = /^(http:\/\/[^/:@]+\.onion(?::\d{1,5})?)(\/.*)?$/; // regex for onion URL diff --git a/class/synced-async-storage.ts b/class/synced-async-storage.ts index 23720ba4b..cc11d1c25 100644 --- a/class/synced-async-storage.ts +++ b/class/synced-async-storage.ts @@ -1,9 +1,9 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; -const SHA256 = require('crypto-js/sha256'); -const ENCHEX = require('crypto-js/enc-hex'); -const ENCUTF8 = require('crypto-js/enc-utf8'); -const AES = require('crypto-js/aes'); +import SHA256 from 'crypto-js/sha256'; +import ENCHEX from 'crypto-js/enc-hex'; +import ENCUTF8 from 'crypto-js/enc-utf8'; +import AES from 'crypto-js/aes'; export default class SyncedAsyncStorage { defaultBaseUrl = 'https://bytes-store.herokuapp.com'; diff --git a/package-lock.json b/package-lock.json index 67127fb69..284baccbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -119,6 +119,7 @@ "@types/bip38": "^3.1.2", "@types/bs58check": "^2.1.0", "@types/create-hash": "^1.2.2", + "@types/crypto-js": "^4.2.2", "@types/jest": "^29.4.0", "@types/react": "^18.2.16", "@types/react-native": "^0.72.0", @@ -6359,6 +6360,12 @@ "@types/node": "*" } }, + "node_modules/@types/crypto-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", + "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", + "dev": true + }, "node_modules/@types/graceful-fs": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", @@ -27164,6 +27171,12 @@ "@types/node": "*" } }, + "@types/crypto-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", + "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", + "dev": true + }, "@types/graceful-fs": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", diff --git a/package.json b/package.json index c34b47068..8eeb9579e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@types/bip38": "^3.1.2", "@types/bs58check": "^2.1.0", "@types/create-hash": "^1.2.2", + "@types/crypto-js": "^4.2.2", "@types/jest": "^29.4.0", "@types/react": "^18.2.16", "@types/react-native": "^0.72.0", diff --git a/screen/selftest.js b/screen/selftest.js index f38486647..76f7dc510 100644 --- a/screen/selftest.js +++ b/screen/selftest.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { ScrollView, View, StyleSheet, Linking } from 'react-native'; import wif from 'wif'; +import * as bip39 from 'bip39'; import bip38 from 'bip38'; import BIP32Factory from 'bip32'; import * as bitcoin from 'bitcoinjs-lib'; @@ -172,8 +173,6 @@ export default class Selftest extends Component { } // - - const bip39 = require('bip39'); const mnemonic = 'honey risk juice trip orient galaxy win situate shoot anchor bounce remind horse traffic exotic since escape mimic ramp skin judge owner topple erode'; const seed = bip39.mnemonicToSeedSync(mnemonic); diff --git a/screen/send/ScanQRCode.js b/screen/send/ScanQRCode.js index 1986eb94d..4c2963e15 100644 --- a/screen/send/ScanQRCode.js +++ b/screen/send/ScanQRCode.js @@ -16,9 +16,9 @@ import Button from '../../components/Button'; import { useTheme } from '../../components/themes'; import { isCameraAuthorizationStatusGranted } from '../../helpers/scan-qr'; import loc from '../../loc'; +import Base43 from '../../blue_modules/base43'; const LocalQRCode = require('@remobile/react-native-qrcode-local-image'); -const Base43 = require('../../blue_modules/base43'); let decoder = false; diff --git a/screen/send/confirm.js b/screen/send/confirm.js index d217a272a..00090e88f 100644 --- a/screen/send/confirm.js +++ b/screen/send/confirm.js @@ -3,6 +3,9 @@ import { ActivityIndicator, FlatList, TouchableOpacity, StyleSheet, Switch, View import { Text } from 'react-native-elements'; import { PayjoinClient } from 'payjoin-client'; import PropTypes from 'prop-types'; +import BigNumber from 'bignumber.js'; +import * as bitcoin from 'bitcoinjs-lib'; + import PayjoinTransaction from '../../class/payjoin-transaction'; import { BlueText, BlueCard } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; @@ -19,8 +22,6 @@ import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/h import SafeArea from '../../components/SafeArea'; import { satoshiToBTC, satoshiToLocalCurrency } from '../../blue_modules/currency'; import * as BlueElectrum from '../../blue_modules/BlueElectrum'; -const Bignumber = require('bignumber.js'); -const bitcoin = require('bitcoinjs-lib'); const Confirm = () => { const { wallets, fetchAndSaveWalletTransactions, isElectrumDisabled } = useContext(BlueStorageContext); @@ -31,7 +32,7 @@ const Confirm = () => { const [isPayjoinEnabled, setIsPayjoinEnabled] = useState(false); const wallet = wallets.find(w => w.getID() === walletID); const payjoinUrl = wallet.allowPayJoin() ? params.payjoinUrl : false; - const feeSatoshi = new Bignumber(fee).multipliedBy(100000000).toNumber(); + const feeSatoshi = new BigNumber(fee).multipliedBy(100000000).toNumber(); const { navigate, setOptions } = useNavigation(); const { colors } = useTheme(); const stylesHook = StyleSheet.create({ diff --git a/screen/send/create.js b/screen/send/create.js index 2bf07f29b..dd7165cbf 100644 --- a/screen/send/create.js +++ b/screen/send/create.js @@ -6,6 +6,8 @@ import { Icon } from 'react-native-elements'; import Share from 'react-native-share'; import RNFS from 'react-native-fs'; import BigNumber from 'bignumber.js'; +import * as bitcoin from 'bitcoinjs-lib'; + import { BlueText } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; import { BitcoinUnit } from '../../models/bitcoinUnits'; @@ -18,7 +20,6 @@ import { PERMISSIONS, RESULTS, request } from 'react-native-permissions'; import { useTheme } from '../../components/themes'; import { satoshiToBTC } from '../../blue_modules/currency'; import usePrivacy from '../../hooks/usePrivacy'; -const bitcoin = require('bitcoinjs-lib'); const SendCreate = () => { const { fee, recipients, memo = '', satoshiPerByte, psbt, showAnimatedQr, tx } = useRoute().params; diff --git a/screen/send/psbtMultisig.js b/screen/send/psbtMultisig.js index c9a4a5a13..854ee94e2 100644 --- a/screen/send/psbtMultisig.js +++ b/screen/send/psbtMultisig.js @@ -2,6 +2,8 @@ import React, { useContext, useEffect, useState } from 'react'; import { FlatList, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { Icon } from 'react-native-elements'; import { useNavigation, useRoute } from '@react-navigation/native'; +import * as bitcoin from 'bitcoinjs-lib'; +import BigNumber from 'bignumber.js'; import { BlueCard, BlueText } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; @@ -13,8 +15,6 @@ import { useTheme } from '../../components/themes'; import Button from '../../components/Button'; import SafeArea from '../../components/SafeArea'; import { satoshiToBTC, satoshiToLocalCurrency } from '../../blue_modules/currency'; -const bitcoin = require('bitcoinjs-lib'); -const BigNumber = require('bignumber.js'); const shortenAddress = addr => { return addr.substr(0, Math.floor(addr.length / 2) - 1) + '\n' + addr.substr(Math.floor(addr.length / 2) - 1, addr.length); diff --git a/screen/settings/lightningSettings.tsx b/screen/settings/lightningSettings.tsx index 78f81500b..646683903 100644 --- a/screen/settings/lightningSettings.tsx +++ b/screen/settings/lightningSettings.tsx @@ -12,9 +12,7 @@ import DeeplinkSchemaMatch from '../../class/deeplink-schema-match'; import presentAlert from '../../components/Alert'; import { requestCameraAuthorization } from '../../helpers/scan-qr'; import { Button } from '../../components/Button'; - -const BlueApp = require('../../BlueApp'); -const AppStorage = BlueApp.AppStorage; +import { AppStorage } from '../../BlueApp'; const styles = StyleSheet.create({ uri: { diff --git a/screen/transactions/details.js b/screen/transactions/details.js index acda91235..97b1e2b0c 100644 --- a/screen/transactions/details.js +++ b/screen/transactions/details.js @@ -2,6 +2,7 @@ import React, { useContext, useEffect, useLayoutEffect, useState } from 'react'; import { View, ScrollView, TouchableOpacity, Text, TextInput, Linking, StyleSheet, Keyboard } from 'react-native'; import { useNavigation, useRoute } from '@react-navigation/native'; import Clipboard from '@react-native-clipboard/clipboard'; +import dayjs from 'dayjs'; import { BlueCard, BlueLoading, BlueSpacing20, BlueText } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; import HandOffComponent from '../../components/HandOffComponent'; @@ -13,7 +14,6 @@ import { useTheme } from '../../components/themes'; import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback'; import CopyToClipboardButton from '../../components/CopyToClipboardButton'; import { BitcoinUnit } from '../../models/bitcoinUnits'; -const dayjs = require('dayjs'); function onlyUnique(value, index, self) { return self.indexOf(value) === index; diff --git a/scripts/maccatalystpatches/lightning-ldk-wallet.ts b/scripts/maccatalystpatches/lightning-ldk-wallet.ts index c9cd14942..82d223c2f 100644 --- a/scripts/maccatalystpatches/lightning-ldk-wallet.ts +++ b/scripts/maccatalystpatches/lightning-ldk-wallet.ts @@ -6,7 +6,7 @@ import { HDSegwitBech32Wallet } from './hd-segwit-bech32-wallet'; import bolt11 from 'bolt11'; import { SegwitBech32Wallet } from './segwit-bech32-wallet'; import presentAlert from '../../components/Alert'; -const bitcoin = require('bitcoinjs-lib'); +import * as bitcoin from 'bitcoinjs-lib'; export class LightningLdkWallet extends LightningCustodianWallet { static type = 'lightningLdk'; diff --git a/tests/e2e/bluewallet.spec.js b/tests/e2e/bluewallet.spec.js index 04212eb71..2c475605c 100644 --- a/tests/e2e/bluewallet.spec.js +++ b/tests/e2e/bluewallet.spec.js @@ -9,8 +9,8 @@ import { helperCreateWallet, helperSwitchAdvancedMode, } from './helperz'; -const bitcoin = require('bitcoinjs-lib'); -const assert = require('assert'); +import * as bitcoin from 'bitcoinjs-lib'; +import assert from 'assert'; /** * this testsuite is for test cases that require no wallets to be present diff --git a/tests/e2e/bluewallet2.spec.js b/tests/e2e/bluewallet2.spec.js index 5cc4018c6..8ac164836 100644 --- a/tests/e2e/bluewallet2.spec.js +++ b/tests/e2e/bluewallet2.spec.js @@ -1,7 +1,7 @@ import { extractTextFromElementById, hashIt, helperImportWallet, sleep, sup, yo } from './helperz'; -const bitcoin = require('bitcoinjs-lib'); -const assert = require('assert'); +import * as bitcoin from 'bitcoinjs-lib'; +import assert from 'assert'; /** * in this suite each test requires that there is one specific wallet present, thus, we import it diff --git a/tests/e2e/helperz.js b/tests/e2e/helperz.js index b8304c443..bf63a8b27 100644 --- a/tests/e2e/helperz.js +++ b/tests/e2e/helperz.js @@ -1,4 +1,4 @@ -const createHash = require('create-hash'); +import createHash from 'create-hash'; export function yo(id, timeout = 33000) { return waitFor(element(by.id(id))) diff --git a/tests/integration/bip47.test.ts b/tests/integration/bip47.test.ts index c1d186bdc..58d547e37 100644 --- a/tests/integration/bip47.test.ts +++ b/tests/integration/bip47.test.ts @@ -6,8 +6,8 @@ import * as BlueElectrum from '../../blue_modules/BlueElectrum'; import BIP47Factory from '@spsina/bip47'; import assert from 'assert'; -const bitcoin = require('bitcoinjs-lib'); -const ecc = require('tiny-secp256k1'); +import * as bitcoin from 'bitcoinjs-lib'; +import ecc from 'tiny-secp256k1'; const ECPair = ECPairFactory(ecc); jest.setTimeout(90 * 1000); diff --git a/tests/integration/lightning-ldk-wallet.test.js b/tests/integration/lightning-ldk-wallet.test.js index 27a74e91c..a3d9cb2e5 100644 --- a/tests/integration/lightning-ldk-wallet.test.js +++ b/tests/integration/lightning-ldk-wallet.test.js @@ -1,6 +1,6 @@ import { LightningLdkWallet } from '../../class'; import SyncedAsyncStorage from '../../class/synced-async-storage'; -const assert = require('assert'); +import assert from 'assert'; describe('', () => { // eslint-disable-next-line jest/no-disabled-tests diff --git a/tests/unit/bip47.test.ts b/tests/unit/bip47.test.ts index 3b3e00813..5ba3497f6 100644 --- a/tests/unit/bip47.test.ts +++ b/tests/unit/bip47.test.ts @@ -4,7 +4,7 @@ import assert from 'assert'; import { HDSegwitBech32Wallet, WatchOnlyWallet } from '../../class'; import { ECPairFactory } from 'ecpair'; -const bitcoin = require('bitcoinjs-lib'); +import * as bitcoin from 'bitcoinjs-lib'; const ECPair = ECPairFactory(ecc); diff --git a/tests/unit/hd-aezeed.test.js b/tests/unit/hd-aezeed.test.js index e24baed38..fa288e4cf 100644 --- a/tests/unit/hd-aezeed.test.js +++ b/tests/unit/hd-aezeed.test.js @@ -1,5 +1,5 @@ +import assert from 'assert'; import { HDAezeedWallet, WatchOnlyWallet } from '../../class'; -const assert = require('assert'); describe('HDAezeedWallet', () => { it('can import mnemonics and generate addresses and WIFs', async function () { diff --git a/tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.ts b/tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.ts index b3b3e2d64..522047418 100644 --- a/tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.ts +++ b/tests/unit/hd-legacy-electrum-seed-p2pkh-wallet.test.ts @@ -1,5 +1,5 @@ +import assert from 'assert'; import { HDLegacyElectrumSeedP2PKHWallet } from '../../class'; -const assert = require('assert'); describe('HDLegacyElectrumSeedP2PKHWallet', () => { it('wont accept BIP39 seed', () => { diff --git a/tests/unit/legacy-wallet.test.js b/tests/unit/legacy-wallet.test.js index 3e251b6a0..630045f0d 100644 --- a/tests/unit/legacy-wallet.test.js +++ b/tests/unit/legacy-wallet.test.js @@ -1,9 +1,9 @@ +import * as bitcoin from 'bitcoinjs-lib'; +import assert from 'assert'; import { LegacyWallet } from '../../class'; import { ECPairFactory } from 'ecpair'; import ecc from '../../blue_modules/noble_ecc'; const ECPair = ECPairFactory(ecc); -const bitcoin = require('bitcoinjs-lib'); -const assert = require('assert'); describe('Legacy wallet', () => { it('can validate addresses', () => { diff --git a/tests/unit/lnurl.test.js b/tests/unit/lnurl.test.js index 3c5bb99b4..ea574c01b 100644 --- a/tests/unit/lnurl.test.js +++ b/tests/unit/lnurl.test.js @@ -1,5 +1,5 @@ +import assert from 'assert'; import Lnurl from '../../class/lnurl'; -const assert = require('assert'); describe('LNURL', function () { it('can findlnurl', () => { diff --git a/tests/unit/segwit-bech32-wallet.test.js b/tests/unit/segwit-bech32-wallet.test.js index 895bcb9d0..6dc71f38f 100644 --- a/tests/unit/segwit-bech32-wallet.test.js +++ b/tests/unit/segwit-bech32-wallet.test.js @@ -1,6 +1,6 @@ +import * as bitcoin from 'bitcoinjs-lib'; +import assert from 'assert'; import { SegwitBech32Wallet } from '../../class'; -const bitcoin = require('bitcoinjs-lib'); -const assert = require('assert'); describe('Segwit P2SH wallet', () => { it('can create transaction', async () => { diff --git a/tests/unit/segwit-p2sh-wallet.test.js b/tests/unit/segwit-p2sh-wallet.test.js index 8355cb47c..8483331e9 100644 --- a/tests/unit/segwit-p2sh-wallet.test.js +++ b/tests/unit/segwit-p2sh-wallet.test.js @@ -1,6 +1,6 @@ +import * as bitcoin from 'bitcoinjs-lib'; +import assert from 'assert'; import { SegwitP2SHWallet } from '../../class'; -const bitcoin = require('bitcoinjs-lib'); -const assert = require('assert'); describe('Segwit P2SH wallet', () => { it('can create transaction', async () => { diff --git a/tests/unit/storage.test.js b/tests/unit/storage.test.js index 1b6d792d6..b91e812f8 100644 --- a/tests/unit/storage.test.js +++ b/tests/unit/storage.test.js @@ -1,8 +1,7 @@ +import assert from 'assert'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { SegwitP2SHWallet } from '../../class'; -const BlueApp = require('../../BlueApp'); -const AppStorage = BlueApp.AppStorage; -const assert = require('assert'); +import { AppStorage } from '../../BlueApp'; jest.mock('../../blue_modules/BlueElectrum', () => { return { diff --git a/tests/unit/watch-only-wallet.test.js b/tests/unit/watch-only-wallet.test.js index afa4e305f..6f571c3c6 100644 --- a/tests/unit/watch-only-wallet.test.js +++ b/tests/unit/watch-only-wallet.test.js @@ -1,7 +1,7 @@ import { WatchOnlyWallet } from '../../class'; import { decodeUR, encodeUR, setUseURv1, clearUseURv1, extractSingleWorkload, BlueURDecoder } from '../../blue_modules/ur'; import { Psbt } from 'bitcoinjs-lib'; -const assert = require('assert'); +import assert from 'assert'; describe('Watch only wallet', () => { it('can validate address', async () => {