diff --git a/.yarn/patches/@rabby-wallet-eth-hd-keyring-npm-4.3.1-a1d8bbe289.patch b/.yarn/patches/@rabby-wallet-eth-hd-keyring-npm-4.3.1-a1d8bbe289.patch new file mode 100644 index 000000000..bed9abb15 --- /dev/null +++ b/.yarn/patches/@rabby-wallet-eth-hd-keyring-npm-4.3.1-a1d8bbe289.patch @@ -0,0 +1,41 @@ +diff --git a/dist/index.js b/dist/index.js +index fd317674caba8bba044ea5fd24c8a67fad859ad8..0a66313a7062e9e478d202c0b0669ce023d5b4f0 100644 +--- a/dist/index.js ++++ b/dist/index.js +@@ -2371,8 +2371,7 @@ __export(eth_hd_keyring_exports, { + module.exports = __toCommonJS(eth_hd_keyring_exports); + var import_hdkey = require("ethereum-cryptography/hdkey"); + var import_eth_simple_keyring = __toESM(require("@rabby-wallet/eth-simple-keyring")); +-var bip39 = __toESM(require("@scure/bip39")); +-var import_english = require("@scure/bip39/wordlists/english"); ++var bip39 = __toESM(require("react-native-quick-bip39")); + var sigUtil = __toESM(require("eth-sig-util")); + var import_util = require("@ethereumjs/util"); + var import_slip39 = __toESM(require_slip392()); +@@ -2469,7 +2468,7 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default { + } + addAccounts(numberOfAccounts = 1) { + if (!this.hdWallet) { +- this.initFromMnemonic(bip39.generateMnemonic(import_english.wordlist)); ++ this.initFromMnemonic(bip39.generateMnemonic(bip39.wordlists.english)); + } + let count = numberOfAccounts; + let currentIdx = 0; +@@ -2612,7 +2611,7 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default { + return (0, import_util.bytesToHex)((0, import_util.publicToAddress)(publicKey, true)).toLowerCase(); + } + generateMnemonic() { +- return bip39.generateMnemonic(import_english.wordlist); ++ return bip39.generateMnemonic(bip39.wordlists.english); + } + setHdPath(hdPath = HD_PATH_BASE["BIP44" /* BIP44 */]) { + this.hdPath = hdPath; +@@ -2690,7 +2689,7 @@ var _HdKeyring = class _HdKeyring extends import_eth_simple_keyring.default { + if (this.checkMnemonicIsSlip39(mnemonic)) { + return true; + } +- return bip39.validateMnemonic(mnemonic, import_english.wordlist); ++ return bip39.validateMnemonic(mnemonic, bip39.wordlists.english); + } + }; + _HdKeyring.type = type; diff --git a/.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch b/.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch deleted file mode 100644 index 24c642a16..000000000 --- a/.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch +++ /dev/null @@ -1,30 +0,0 @@ -diff --git a/index.js b/index.js -index f79318c817c35ea977ac4e51dbfb06ce25055832..1f70440fd27ea6f5dae12cb7cd9a05055af09f94 100644 ---- a/index.js -+++ b/index.js -@@ -8,6 +8,8 @@ const sha256_1 = require("@noble/hashes/sha256"); - const sha512_1 = require("@noble/hashes/sha512"); - const utils_1 = require("@noble/hashes/utils"); - const base_1 = require("@scure/base"); -+const AES = require("react-native-aes-crypto"); -+ - // Japanese wordlist - const isJapanese = (wordlist) => wordlist[0] === '\u3042\u3044\u3053\u304f\u3057\u3093'; - // Normalization replaces equivalent sequences of characters -@@ -138,6 +140,14 @@ exports.mnemonicToSeed = mnemonicToSeed; - * // new Uint8Array([...64 bytes]) - */ - function mnemonicToSeedSync(mnemonic, passphrase = '') { -- return (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 }); -+ const str = AES.default.pbkdf2Sync( -+ normalize(mnemonic).nfkd, -+ salt(passphrase), -+ 2048, -+ 64, -+ 'sha256', -+ ); -+ -+ return Uint8Array.from(str); - } - exports.mnemonicToSeedSync = mnemonicToSeedSync; -\ No newline at end of file diff --git a/apps/mobile/ios/Podfile.lock b/apps/mobile/ios/Podfile.lock index 8dfeb07de..250ee02b2 100644 --- a/apps/mobile/ios/Podfile.lock +++ b/apps/mobile/ios/Podfile.lock @@ -132,6 +132,7 @@ PODS: - nanopb/encode (= 2.30909.1) - nanopb/decode (2.30909.1) - nanopb/encode (2.30909.1) + - OpenSSL-Universal (3.3.2000) - PromisesObjC (2.3.1) - RCT-Folly (2021.07.22.00): - boost @@ -464,6 +465,11 @@ PODS: - react-native-pager-view (6.2.3): - RCT-Folly (= 2021.07.22.00) - React-Core + - react-native-quick-crypto (0.7.10): + - OpenSSL-Universal + - RCT-Folly (= 2021.07.22.00) + - React + - React-Core - react-native-randombytes (3.6.1): - React-Core - react-native-safe-area-context (4.8.2): @@ -703,6 +709,7 @@ DEPENDENCIES: - react-native-mmkv (from `../node_modules/react-native-mmkv`) - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" - react-native-pager-view (from `../node_modules/react-native-pager-view`) + - react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`) - react-native-randombytes (from `../node_modules/react-native-randombytes`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - react-native-splash-screen (from `../node_modules/react-native-splash-screen`) @@ -771,6 +778,7 @@ SPEC REPOS: - MMKVCore - MultiplatformBleAdapter - nanopb + - OpenSSL-Universal - PromisesObjC - SDWebImage - SDWebImageWebPCoder @@ -849,6 +857,8 @@ EXTERNAL SOURCES: :path: "../node_modules/@react-native-community/netinfo" react-native-pager-view: :path: "../node_modules/react-native-pager-view" + react-native-quick-crypto: + :path: "../node_modules/react-native-quick-crypto" react-native-randombytes: :path: "../node_modules/react-native-randombytes" react-native-safe-area-context: @@ -970,6 +980,7 @@ SPEC CHECKSUMS: MMKVCore: 9e2e5fd529b64a9fe15f1a7afb3d73b2e27b4db9 MultiplatformBleAdapter: b1fddd0d499b96b607e00f0faa8e60648343dc1d nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5 + OpenSSL-Universal: b60a3702c9fea8b3145549d421fdb018e53ab7b4 PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4 RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 RCTRequired: 83bca1c184feb4d2e51c72c8369b83d641443f95 @@ -998,6 +1009,7 @@ SPEC CHECKSUMS: react-native-mmkv: 436ee510dcc43b58a49d7be0451f285e06a9fd1d react-native-netinfo: 8a7fd3f7130ef4ad2fb4276d5c9f8d3f28d2df3d react-native-pager-view: cf96a223846458cc7e932017636b5c6d8cc2c549 + react-native-quick-crypto: 64b9662703b8613b41d909fdc85ff79552d21fde react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846 react-native-safe-area-context: 0ee144a6170530ccc37a0fd9388e28d06f516a89 react-native-splash-screen: 4312f786b13a81b5169ef346d76d33bc0c6dc457 diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 96a8b9488..08783dcdb 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -87,7 +87,6 @@ "@rematch/core": "^2.2.0", "@rneui/base": "^4.0.0-rc.8", "@rneui/themed": "^4.0.0-rc.8", - "@scure/bip39": "^1.3.0", "@sentry/react-native": "5.31.0", "@types/highlight-words-core": "1.2.3", "@types/lodash.debounce": "^4.0.9", @@ -152,6 +151,8 @@ "react-native-pager-view": "^6.2.3", "react-native-permissions": "^4.1.2", "react-native-qrcode-svg": "^6.2.0", + "react-native-quick-bip39": "0.0.9", + "react-native-quick-crypto": "0.7.10", "react-native-randombytes": "^3.6.1", "react-native-reanimated": "^3.6.1", "react-native-root-toast": "^3.5.1", diff --git a/apps/mobile/src/core/utils/mnemonic.ts b/apps/mobile/src/core/utils/mnemonic.ts index 346eed204..e860b6b94 100644 --- a/apps/mobile/src/core/utils/mnemonic.ts +++ b/apps/mobile/src/core/utils/mnemonic.ts @@ -1,4 +1,4 @@ -import * as bip39 from '@scure/bip39'; +import * as bip39 from 'react-native-quick-bip39'; import { HDKey } from 'ethereum-cryptography/hdkey'; import * as sigUtil from 'eth-sig-util'; import { bytesToHex, publicToAddress, privateToPublic } from '@ethereumjs/util'; diff --git a/apps/mobile/src/screens/Address/ImportSeedPhraseScreen.tsx b/apps/mobile/src/screens/Address/ImportSeedPhraseScreen.tsx index b076bcf49..3d0dff091 100644 --- a/apps/mobile/src/screens/Address/ImportSeedPhraseScreen.tsx +++ b/apps/mobile/src/screens/Address/ImportSeedPhraseScreen.tsx @@ -15,8 +15,7 @@ import { useScanner } from '../Scanner/ScannerScreen'; import { requestKeyring } from '@/core/apis/keyring'; import { toast } from '@/components/Toast'; import { useFocusEffect } from '@react-navigation/native'; -import { wordlist } from '@scure/bip39/wordlists/english'; -import * as bip39 from '@scure/bip39'; +import * as bip39 from 'react-native-quick-bip39'; const getStyles = (colors: AppColorsVariants) => StyleSheet.create({ @@ -112,13 +111,13 @@ export const ImportSeedPhraseScreen = () => { }); } else { try { - bip39.mnemonicToEntropy(mnemonics?.trim(), wordlist); + bip39.mnemonicToEntropy(mnemonics?.trim(), bip39.wordlists.english); } catch (e) { if ((e as any).message.includes('Unknown letter:')) { let errorWords: string[] = []; mnemonics.split(/\s+/).forEach(word => { let v = word?.trim(); - if (v && !wordlist.includes(v)) { + if (v && !bip39.wordlists.english.includes(v)) { errorWords.push(v); } }); diff --git a/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx b/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx index 4d1aa76a6..7bf86758c 100644 --- a/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx +++ b/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx @@ -11,8 +11,7 @@ import { useScanner } from '../Scanner/ScannerScreen'; import { requestKeyring } from '@/core/apis/keyring'; import { toast } from '@/components2024/Toast'; import { useFocusEffect } from '@react-navigation/native'; -import { wordlist } from '@scure/bip39/wordlists/english'; -import * as bip39 from '@scure/bip39'; +import * as bip39 from 'react-native-quick-bip39'; import PasteButton from '@/components2024/PasteButton'; import { NextInput } from '@/components2024/Form/Input'; import { createGetStyles2024, makeDebugBorder } from '@/utils/styles'; @@ -192,13 +191,13 @@ export const ImportSeedPhraseScreen2024 = () => { }); } else { try { - bip39.mnemonicToEntropy(mnemonics?.trim(), wordlist); + bip39.mnemonicToEntropy(mnemonics?.trim(), bip39.wordlists.english); } catch (e) { if ((e as any).message.includes('Unknown letter:')) { let errorWords: string[] = []; mnemonics.split(/\s+/).forEach(word => { let v = word?.trim(); - if (v && !wordlist.includes(v)) { + if (v && !bip39.wordlists.english.includes(v)) { errorWords.push(v); } }); diff --git a/package.json b/package.json index c3dbf753c..17fa2975f 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,31 @@ "yarn workspace dev-console-cra lint:commit:fix" ] }, + "resolutions": { + "@debank/common@0.3.58": "patch:@debank/common@npm%3A0.3.58#./.yarn/patches/@debank-common-npm-0.3.58-0aa25cb07b.patch", + "@debank/common@^0.3.54": "patch:@debank/common@npm%3A0.3.58#./.yarn/patches/@debank-common-npm-0.3.58-0aa25cb07b.patch", + "@keystonehq/bc-ur-registry@^0.5.0-alpha.4": "patch:@keystonehq/bc-ur-registry@npm%3A0.6.4#./.yarn/patches/@keystonehq-bc-ur-registry-npm-0.6.4-7922ce4e4c.patch", + "@keystonehq/bc-ur-registry@^0.6.0": "patch:@keystonehq/bc-ur-registry@npm%3A0.6.4#./.yarn/patches/@keystonehq-bc-ur-registry-npm-0.6.4-7922ce4e4c.patch", + "@ledgerhq/hw-app-eth@^6.40.0": "patch:@ledgerhq/hw-app-eth@npm%3A6.40.2#./.yarn/patches/@ledgerhq-hw-app-eth-npm-6.40.2-ffdc4add8c.patch", + "@ledgerhq/hw-transport@^6.31.4": "patch:@ledgerhq/hw-transport@npm%3A6.31.4#./.yarn/patches/@ledgerhq-hw-transport-npm-6.31.4-b439e9a1f8.patch", + "@metamask/eth-sig-util@5.1.0": "patch:@metamask/eth-sig-util@npm%3A5.1.0#./.yarn/patches/@metamask-eth-sig-util-npm-5.1.0-fb33750b27.patch", + "@metamask/eth-sig-util@^4.0.0": "patch:@metamask/eth-sig-util@npm%3A5.1.0#./.yarn/patches/@metamask-eth-sig-util-npm-5.1.0-fb33750b27.patch", + "@metamask/eth-sig-util@^5.0.0": "patch:@metamask/eth-sig-util@npm%3A5.1.0#./.yarn/patches/@metamask-eth-sig-util-npm-5.1.0-fb33750b27.patch", + "@onekeyfe/hd-transport-react-native@^1.0.10": "patch:@onekeyfe/hd-transport-react-native@npm%3A1.0.10#./.yarn/patches/@onekeyfe-hd-transport-react-native-npm-1.0.10-09c8057879.patch", + "@rabby-wallet/rabby-api@0.7.25": "patch:@rabby-wallet/rabby-api@npm%3A0.8.5#./.yarn/patches/@rabby-wallet-rabby-api-npm-0.8.5-b09d6e3f2f.patch", + "@rabby-wallet/rabby-api@0.8.5": "patch:@rabby-wallet/rabby-api@npm%3A0.8.5#./.yarn/patches/@rabby-wallet-rabby-api-npm-0.8.5-b09d6e3f2f.patch", + "@react-native-menu/menu@1.1.3": "patch:@react-native-menu/menu@npm%3A1.1.3#./.yarn/patches/@react-native-menu-menu-npm-1.1.3-6b0ecb2e6c.patch", + "eth-rpc-errors@^4.0.2": "patch:eth-rpc-errors@npm%3A4.0.3#./.yarn/patches/eth-rpc-errors-npm-4.0.3-d154190eb6.patch", + "eth-rpc-errors@^4.0.3": "patch:eth-rpc-errors@npm%3A4.0.3#./.yarn/patches/eth-rpc-errors-npm-4.0.3-d154190eb6.patch", + "nativewind@^2.0.11": "patch:nativewind@npm%3A2.0.11#./.yarn/patches/nativewind-npm-2.0.11-dc2ccf9fb5.patch", + "react-native-fs@^2.20.0": "patch:react-native-fs@npm%3A2.20.0#./.yarn/patches/react-native-fs-npm-2.20.0-a38fe24051.patch", + "react-native-keychain@8.0.0": "patch:react-native-keychain@npm%3A8.0.0#./.yarn/patches/react-native-keychain-npm-8.0.0-22c1f5c020.patch", + "react-native-mmkv@^2.12.2": "patch:react-native-mmkv@npm%3A2.12.2#./.yarn/patches/react-native-mmkv-npm-2.12.2-9efa7abf70.patch", + "react-native-webview@13.10.5": "patch:react-native-webview@npm%3A13.10.5#./.yarn/patches/react-native-webview-npm-13.10.5-714eb41569.patch", + "react-use@17.4.2": "patch:react-use@npm%3A17.4.2#./.yarn/patches/react-use-npm-17.4.2-d0e8220eaa.patch", + "zeego@1.10.0": "patch:zeego@npm%3A1.10.0#./.yarn/patches/zeego-npm-1.10.0-1958a3ea63.patch", + "@rabby-wallet/eth-hd-keyring@4.3.1": "patch:@rabby-wallet/eth-hd-keyring@npm%3A4.3.1#./.yarn/patches/@rabby-wallet-eth-hd-keyring-npm-4.3.1-a1d8bbe289.patch" + }, "dependencies": { "@babel/runtime": "^7.20.0", "@debank/common": "^0.3.54", @@ -110,34 +135,5 @@ "ethereumjs-util>ethereum-cryptography>secp256k1": true, "simple-git-hooks": false } - }, - "resolutions": { - "@debank/common@^0.3.54": "patch:@debank/common@npm%3A0.3.58#./.yarn/patches/@debank-common-npm-0.3.58-0aa25cb07b.patch", - "@debank/common@0.3.58": "patch:@debank/common@npm%3A0.3.58#./.yarn/patches/@debank-common-npm-0.3.58-0aa25cb07b.patch", - "@metamask/eth-sig-util@5.1.0": "patch:@metamask/eth-sig-util@npm%3A5.1.0#./.yarn/patches/@metamask-eth-sig-util-npm-5.1.0-fb33750b27.patch", - "@metamask/eth-sig-util@^4.0.0": "patch:@metamask/eth-sig-util@npm%3A5.1.0#./.yarn/patches/@metamask-eth-sig-util-npm-5.1.0-fb33750b27.patch", - "@metamask/eth-sig-util@^5.0.0": "patch:@metamask/eth-sig-util@npm%3A5.1.0#./.yarn/patches/@metamask-eth-sig-util-npm-5.1.0-fb33750b27.patch", - "@onekeyfe/hd-transport-react-native@^1.0.10": "patch:@onekeyfe/hd-transport-react-native@npm%3A1.0.10#./.yarn/patches/@onekeyfe-hd-transport-react-native-npm-1.0.10-09c8057879.patch", - "@rabby-wallet/rabby-api@0.7.25": "patch:@rabby-wallet/rabby-api@npm%3A0.8.5#./.yarn/patches/@rabby-wallet-rabby-api-npm-0.8.5-b09d6e3f2f.patch", - "@rabby-wallet/rabby-api@0.8.5": "patch:@rabby-wallet/rabby-api@npm%3A0.8.5#./.yarn/patches/@rabby-wallet-rabby-api-npm-0.8.5-b09d6e3f2f.patch", - "@react-native-menu/menu@1.1.3": "patch:@react-native-menu/menu@npm%3A1.1.3#./.yarn/patches/@react-native-menu-menu-npm-1.1.3-6b0ecb2e6c.patch", - "eth-rpc-errors@^4.0.3": "patch:eth-rpc-errors@npm%3A4.0.3#./.yarn/patches/eth-rpc-errors-npm-4.0.3-d154190eb6.patch", - "eth-rpc-errors@^4.0.2": "patch:eth-rpc-errors@npm%3A4.0.3#./.yarn/patches/eth-rpc-errors-npm-4.0.3-d154190eb6.patch", - "nativewind@^2.0.11": "patch:nativewind@npm%3A2.0.11#./.yarn/patches/nativewind-npm-2.0.11-dc2ccf9fb5.patch", - "react-native-fs@^2.20.0": "patch:react-native-fs@npm%3A2.20.0#./.yarn/patches/react-native-fs-npm-2.20.0-a38fe24051.patch", - "react-native-keychain@8.0.0": "patch:react-native-keychain@npm%3A8.0.0#./.yarn/patches/react-native-keychain-npm-8.0.0-22c1f5c020.patch", - "react-native-mmkv@^2.12.2": "patch:react-native-mmkv@npm%3A2.12.2#./.yarn/patches/react-native-mmkv-npm-2.12.2-9efa7abf70.patch", - "react-native-webview@13.10.5": "patch:react-native-webview@npm%3A13.10.5#./.yarn/patches/react-native-webview-npm-13.10.5-714eb41569.patch", - "react-use@17.4.2": "patch:react-use@npm%3A17.4.2#./.yarn/patches/react-use-npm-17.4.2-d0e8220eaa.patch", - "zeego@1.10.0": "patch:zeego@npm%3A1.10.0#./.yarn/patches/zeego-npm-1.10.0-1958a3ea63.patch", - "@keystonehq/bc-ur-registry@^0.6.0": "patch:@keystonehq/bc-ur-registry@npm%3A0.6.4#./.yarn/patches/@keystonehq-bc-ur-registry-npm-0.6.4-7922ce4e4c.patch", - "@keystonehq/bc-ur-registry@^0.5.0-alpha.4": "patch:@keystonehq/bc-ur-registry@npm%3A0.6.4#./.yarn/patches/@keystonehq-bc-ur-registry-npm-0.6.4-7922ce4e4c.patch", - "@ledgerhq/hw-app-eth@^6.40.0": "patch:@ledgerhq/hw-app-eth@npm%3A6.40.2#./.yarn/patches/@ledgerhq-hw-app-eth-npm-6.40.2-ffdc4add8c.patch", - "@ledgerhq/hw-transport@^6.31.4": "patch:@ledgerhq/hw-transport@npm%3A6.31.4#./.yarn/patches/@ledgerhq-hw-transport-npm-6.31.4-b439e9a1f8.patch", - "@scure/bip39@^1.3.0": "patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch", - "@scure/bip39@1.2.2": "patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch", - "@scure/bip39@1.2.1": "patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch", - "@scure/bip39@^1.2.1": "patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch", - "@scure/bip39@1.3.0": "patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch" } } diff --git a/packages/service-keyring/package.json b/packages/service-keyring/package.json index 350729929..69cee7629 100644 --- a/packages/service-keyring/package.json +++ b/packages/service-keyring/package.json @@ -25,11 +25,11 @@ "changelog:validate": "../../scripts/validate-changelog.sh @rabby-wallet/service-keyring", "cov:report": "open ./coverage/index.html", "publish:preview": "yarn npm publish --tag preview", - "tool:decrypt": "yarn ../../ build:deps && node ./scripts/decyrptKeyringState.js", "test": "jest --reporters=jest-silent-reporter", "test:clean": "jest --clearCache", "test:verbose": "jest --verbose", - "test:watch": "jest --watch" + "test:watch": "jest --watch", + "tool:decrypt": "yarn ../../ build:deps && node ./scripts/decyrptKeyringState.js" }, "dependencies": { "@metamask/obs-store": "^9.0.0", @@ -37,10 +37,10 @@ "@rabby-wallet/eth-keyring-watch": "^0.1.0", "@rabby-wallet/keyring-utils": "workspace:^", "@rabby-wallet/service-address": "workspace:^", - "@scure/bip39": "^1.3.0", "@types/readable-stream": "^4.0.10", "ethereumjs-util": "^7.1.5", - "loglevel": "^1.8.1" + "loglevel": "^1.8.1", + "react-native-quick-bip39": "0.0.9" }, "devDependencies": { "@metamask/auto-changelog": "^3.4.3", diff --git a/packages/service-keyring/src/global.d.ts b/packages/service-keyring/src/global.d.ts new file mode 100644 index 000000000..65f0aacb0 --- /dev/null +++ b/packages/service-keyring/src/global.d.ts @@ -0,0 +1 @@ +declare module 'react-native-quick-bip39'; diff --git a/packages/service-keyring/src/keyringService.ts b/packages/service-keyring/src/keyringService.ts index 16184d466..e5c8a2ecf 100644 --- a/packages/service-keyring/src/keyringService.ts +++ b/packages/service-keyring/src/keyringService.ts @@ -17,10 +17,9 @@ import type { KeyringTypeName, } from '@rabby-wallet/keyring-utils'; import type { ContactBookService } from '@rabby-wallet/service-address'; -import * as bip39 from '@scure/bip39'; -import { wordlist } from '@scure/bip39/wordlists/english'; import * as ethUtil from 'ethereumjs-util'; import log from 'loglevel'; +import * as bip39 from 'react-native-quick-bip39'; import type { KeyringClassType, KeyringInstance } from './types'; import { keyringSdks } from './types'; @@ -1020,7 +1019,7 @@ export class KeyringService extends RNEventEmitter { * Mnemonic Phrase */ generateMnemonic(): string { - return bip39.generateMnemonic(wordlist); + return bip39.generateMnemonic(); } async generatePreMnemonic(options?: { @@ -1067,7 +1066,7 @@ export class KeyringService extends RNEventEmitter { * @returns {Promise} A Promise that resolves to the state. */ createKeyringWithMnemonics(seed: string): Promise { - if (!bip39.validateMnemonic(seed, wordlist)) { + if (!bip39.validateMnemonic(seed, bip39.wordlists.english)) { return Promise.reject(new Error('background.error.invalidMnemonic')); } diff --git a/yarn.lock b/yarn.lock index 5ae7c8577..10e8df0c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2024,6 +2024,16 @@ __metadata: languageName: node linkType: hard +"@craftzdog/react-native-buffer@npm:^6.0.5": + version: 6.0.5 + resolution: "@craftzdog/react-native-buffer@npm:6.0.5" + dependencies: + ieee754: ^1.2.1 + react-native-quick-base64: ^2.0.5 + checksum: 921b8bc7f84778e355e81e475792399276d611a346a7e51b6266a45cf4aa82194beb3a8106af796ed143d958c8476070c59e3720c0eec0a3c31e368fbb08b350 + languageName: node + linkType: hard + "@cspotcode/source-map-support@npm:^0.8.0": version: 0.8.1 resolution: "@cspotcode/source-map-support@npm:0.8.1::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40cspotcode%2Fsource-map-support%2F-%2Fsource-map-support-0.8.1.tgz" @@ -5722,7 +5732,7 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:1.3.3": +"@noble/hashes@npm:1.3.3, @noble/hashes@npm:~1.3.0": version: 1.3.3 resolution: "@noble/hashes@npm:1.3.3" checksum: 8a6496d1c0c64797339bc694ad06cdfaa0f9e56cd0c3f68ae3666cfb153a791a55deb0af9c653c7ed2db64d537aa3e3054629740d2f2338bb1dcb7ab60cd205b @@ -5743,6 +5753,13 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:~1.6.0": + version: 1.6.1 + resolution: "@noble/hashes@npm:1.6.1" + checksum: 57c62f65ee217c0293b4321b547792aa6d79812bfe70a7d62dc83e0f936cc677b14ed981b4e88cf8fdad37cd6d3a0cbd3bd0908b0728adc9daf066e678be8901 + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.5": version: 2.1.5 resolution: "@nodelib/fs.scandir@npm:2.1.5::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40nodelib%2Ffs.scandir%2F-%2Ffs.scandir-2.1.5.tgz" @@ -6153,6 +6170,21 @@ __metadata: languageName: node linkType: hard +"@rabby-wallet/eth-hd-keyring@patch:@rabby-wallet/eth-hd-keyring@npm%3A4.3.1#./.yarn/patches/@rabby-wallet-eth-hd-keyring-npm-4.3.1-a1d8bbe289.patch::locator=%40rabby-wallet%2Fmobile-monorepo%40workspace%3A.": + version: 4.3.1 + resolution: "@rabby-wallet/eth-hd-keyring@patch:@rabby-wallet/eth-hd-keyring@npm%3A4.3.1#./.yarn/patches/@rabby-wallet-eth-hd-keyring-npm-4.3.1-a1d8bbe289.patch::version=4.3.1&hash=8efe41&locator=%40rabby-wallet%2Fmobile-monorepo%40workspace%3A." + dependencies: + "@ethereumjs/util": ^9.0.0 + "@metamask/eth-sig-util": ^4.0.0 + "@rabby-wallet/eth-simple-keyring": ^5.0.1 + "@scure/bip39": ^1.2.1 + eth-sig-util: ^3.0.1 + ethereum-cryptography: ^2.1.2 + slip39: ^0.1.9 + checksum: b9115887e7802005c85ab806af10687abb170af89978a10d79e37327c30976d837e735396858cf5d40f0bbb5699b91c42f6a10411698129ae1da9ac28d6bea3b + languageName: node + linkType: hard + "@rabby-wallet/eth-keyring-gnosis@workspace:^, @rabby-wallet/eth-keyring-gnosis@workspace:packages/eth-keyring-gnosis": version: 0.0.0-use.local resolution: "@rabby-wallet/eth-keyring-gnosis@workspace:packages/eth-keyring-gnosis" @@ -6620,7 +6652,6 @@ __metadata: "@rabby-wallet/eth-keyring-watch": ^0.1.0 "@rabby-wallet/keyring-utils": "workspace:^" "@rabby-wallet/service-address": "workspace:^" - "@scure/bip39": ^1.3.0 "@types/jest": ^27.4.1 "@types/readable-stream": ^4.0.10 "@types/sinon": ^9.0.10 @@ -6629,6 +6660,7 @@ __metadata: ethereumjs-wallet: ^1.0.2 jest: ^27.5.1 loglevel: ^1.8.1 + react-native-quick-bip39: 0.0.9 sinon: ^9.2.4 ts-jest: ^27.1.4 typedoc: ^0.24.8 @@ -7947,6 +7979,13 @@ __metadata: languageName: node linkType: hard +"@scure/base@npm:~1.2.1": + version: 1.2.1 + resolution: "@scure/base@npm:1.2.1" + checksum: 061e04e4f6ed7bada6cdad4c799e6a82f30dda3f4008895bdb2e556f333f9b41f44dc067d25c064357ed6c012ea9c8be1e7927caf8a083af865b8de27b52370c + languageName: node + linkType: hard + "@scure/bip32@npm:1.3.1": version: 1.3.1 resolution: "@scure/bip32@npm:1.3.1::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40scure%2Fbip32%2F-%2Fbip32-1.3.1.tgz" @@ -7991,6 +8030,26 @@ __metadata: languageName: node linkType: hard +"@scure/bip39@npm:1.2.1": + version: 1.2.1 + resolution: "@scure/bip39@npm:1.2.1" + dependencies: + "@noble/hashes": ~1.3.0 + "@scure/base": ~1.1.0 + checksum: c5bd6f1328fdbeae2dcdd891825b1610225310e5e62a4942714db51066866e4f7bef242c7b06a1b9dcc8043a4a13412cf5c5df76d3b10aa9e36b82e9b6e3eeaa + languageName: node + linkType: hard + +"@scure/bip39@npm:1.2.2": + version: 1.2.2 + resolution: "@scure/bip39@npm:1.2.2" + dependencies: + "@noble/hashes": ~1.3.2 + "@scure/base": ~1.1.4 + checksum: cb99505e6d2deef8e55e81df8c563ce8dbfdf1595596dc912bceadcf366c91b05a98130e928ecb090df74efdb20150b64acc4be55bc42768cab4d39a2833d234 + languageName: node + linkType: hard + "@scure/bip39@npm:1.3.0": version: 1.3.0 resolution: "@scure/bip39@npm:1.3.0" @@ -8001,13 +8060,13 @@ __metadata: languageName: node linkType: hard -"@scure/bip39@patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch::locator=%40rabby-wallet%2Fmobile-monorepo%40workspace%3A.": - version: 1.3.0 - resolution: "@scure/bip39@patch:@scure/bip39@npm%3A1.3.0#./.yarn/patches/@scure-bip39-npm-1.3.0-1d74c5c469.patch::version=1.3.0&hash=02aed9&locator=%40rabby-wallet%2Fmobile-monorepo%40workspace%3A." +"@scure/bip39@npm:^1.2.1": + version: 1.5.0 + resolution: "@scure/bip39@npm:1.5.0" dependencies: - "@noble/hashes": ~1.4.0 - "@scure/base": ~1.1.6 - checksum: ff0c4bf07ca604a5ee60e7fa59281d4139af8ea8c9e8ec11a89889d99fd1d21ebe8b58addd0b60214f02f4a8a88588ac46971b80ae179eaa5a66d10dbe0d7f37 + "@noble/hashes": ~1.6.0 + "@scure/base": ~1.2.1 + checksum: 03d1888f5d0d514eebc5c3adc1e071d225963d434fcf789abea5ef2c8b4b99f3ad9ebee8a597c0c13d5415e6b2b380f55f61560c1643cd871961ab91cbcf5122 languageName: node linkType: hard @@ -27505,7 +27564,6 @@ __metadata: "@rematch/core": ^2.2.0 "@rneui/base": ^4.0.0-rc.8 "@rneui/themed": ^4.0.0-rc.8 - "@scure/bip39": ^1.3.0 "@sentry/react-native": 5.31.0 "@tsconfig/react-native": ^3.0.0 "@types/highlight-words-core": 1.2.3 @@ -27592,6 +27650,8 @@ __metadata: react-native-pager-view: ^6.2.3 react-native-permissions: ^4.1.2 react-native-qrcode-svg: ^6.2.0 + react-native-quick-bip39: 0.0.9 + react-native-quick-crypto: 0.7.10 react-native-randombytes: ^3.6.1 react-native-reanimated: ^3.6.1 react-native-root-toast: ^3.5.1 @@ -28358,6 +28418,44 @@ __metadata: languageName: node linkType: hard +"react-native-quick-base64@npm:^2.0.5": + version: 2.1.2 + resolution: "react-native-quick-base64@npm:2.1.2" + dependencies: + base64-js: ^1.5.1 + peerDependencies: + react: "*" + react-native: "*" + checksum: 46f3b26f48b26978686b0c043336220d681e6a02af5abcf3eb4ab7b9216251d1eb2fac5c559e984d963e93f54bd9f323651daac09762196815558abbd551729b + languageName: node + linkType: hard + +"react-native-quick-bip39@npm:0.0.9": + version: 0.0.9 + resolution: "react-native-quick-bip39@npm:0.0.9" + dependencies: + "@craftzdog/react-native-buffer": ^6.0.5 + react-native-quick-crypto: ^0.7.7 + checksum: 1beb61bcf124fda8d803baaee18b9ca3f8aa6cf14dc18ed168c4c5e7f75095dc0edd619fd72049b40e7456d07cd90ee611b4e2071dcbeb1bcc64a2260c47727f + languageName: node + linkType: hard + +"react-native-quick-crypto@npm:0.7.10, react-native-quick-crypto@npm:^0.7.7": + version: 0.7.10 + resolution: "react-native-quick-crypto@npm:0.7.10" + dependencies: + "@craftzdog/react-native-buffer": ^6.0.5 + events: ^3.3.0 + readable-stream: ^4.5.2 + string_decoder: ^1.3.0 + util: ^0.12.5 + peerDependencies: + react: "*" + react-native: "*" + checksum: 45d936f25434ef2ef2e78172e56bb405dac6310aabfd3a25e7ca6b4ae5cf2621b0385db67a09ad6f1cc946f12fcc3026c159d7dd9e640f051420324064312034 + languageName: node + linkType: hard + "react-native-randombytes@npm:^3.5.1, react-native-randombytes@npm:^3.6.1": version: 3.6.1 resolution: "react-native-randombytes@npm:3.6.1::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Freact-native-randombytes%2F-%2Freact-native-randombytes-3.6.1.tgz" @@ -29078,6 +29176,19 @@ __metadata: languageName: node linkType: hard +"readable-stream@npm:^4.5.2": + version: 4.5.2 + resolution: "readable-stream@npm:4.5.2" + dependencies: + abort-controller: ^3.0.0 + buffer: ^6.0.3 + events: ^3.3.0 + process: ^0.11.10 + string_decoder: ^1.3.0 + checksum: c4030ccff010b83e4f33289c535f7830190773e274b3fcb6e2541475070bdfd69c98001c3b0cb78763fc00c8b62f514d96c2b10a8bd35d5ce45203a25fa1d33a + languageName: node + linkType: hard + "readdirp@npm:^3.6.0, readdirp@npm:~3.6.0": version: 3.6.0 resolution: "readdirp@npm:3.6.0::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Freaddirp%2F-%2Freaddirp-3.6.0.tgz"