fix: replace require with import

This commit is contained in:
Ivan Vershigora 2024-04-09 18:14:14 +02:00
parent 2a95f59201
commit 49f0b1a753
No known key found for this signature in database
GPG key ID: DCCF7FB5ED2CEBD7
30 changed files with 67 additions and 56 deletions

View file

@ -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.

View file

@ -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);
};

View file

@ -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 = {

View file

@ -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.

View file

@ -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

View file

@ -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';

13
package-lock.json generated
View file

@ -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",

View file

@ -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",

View file

@ -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);

View file

@ -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;

View file

@ -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({

View file

@ -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;

View file

@ -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);

View file

@ -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: {

View file

@ -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;

View file

@ -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';

View file

@ -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

View file

@ -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

View file

@ -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)))

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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 () {

View file

@ -1,5 +1,5 @@
import assert from 'assert';
import { HDLegacyElectrumSeedP2PKHWallet } from '../../class';
const assert = require('assert');
describe('HDLegacyElectrumSeedP2PKHWallet', () => {
it('wont accept BIP39 seed', () => {

View file

@ -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', () => {

View file

@ -1,5 +1,5 @@
import assert from 'assert';
import Lnurl from '../../class/lnurl';
const assert = require('assert');
describe('LNURL', function () {
it('can findlnurl', () => {

View file

@ -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 () => {

View file

@ -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 () => {

View file

@ -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 {

View file

@ -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 () => {