Skip to content

Commit

Permalink
perf(wallet): switch to native bip39 (#2382)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr authored Dec 2, 2024
1 parent 8d7c662 commit 88247bc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ const config = {
assetExts: assetExts.filter((ext) => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
extraNodeModules: {
bip39: path.resolve(__dirname, './node_modules/react-native-quick-bip39'),
buffer: path.resolve(__dirname, './node_modules/@craftzdog/react-native-buffer'),
crypto: path.resolve(__dirname, './node_modules/react-native-quick-crypto'),
stream: path.resolve(__dirname, './node_modules/readable-stream'),
'sodium-universal': path.resolve(__dirname, './node_modules/sodium-react-native-direct'),
},
blacklistRE: exclusionList([
/\/node_modules\/bip39\/.*/,
/\/node_modules\/sodium-universal\/.*/,
/\/android\/build\/*/,
]),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"beignet": "0.0.48",
"bip21": "2.0.3",
"bip32": "4.0.0",
"bip39": "3.1.0",
"bitcoin-address-validation": "2.2.3",
"bitcoin-units": "0.3.0",
"bitcoinjs-lib": "6.1.5",
Expand Down Expand Up @@ -102,6 +101,7 @@
"react-native-qrcode-svg": "6.3.0",
"react-native-quick-actions": "0.3.13",
"react-native-quick-base64": "2.1.2",
"react-native-quick-bip39": "0.0.9",
"react-native-quick-crypto": "0.7.1",
"react-native-reanimated": "3.15.0",
"react-native-reanimated-carousel": "3.5.1",
Expand Down
12 changes: 0 additions & 12 deletions src/utils/lightning/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EmitterSubscription } from 'react-native';
import Keychain from 'react-native-keychain';
import * as bitcoin from 'bitcoinjs-lib';
import ecc from '@bitcoinerlab/secp256k1';
import RNFS from 'react-native-fs';
import { err, ok, Result } from '@synonymdev/result';
Expand Down Expand Up @@ -1015,17 +1014,6 @@ export const getDefaultLdkAccount = async ({
};
};

/**
* Get sha256 hash of a given string.
* @param {string} str
* @returns {string}
*/
export const getSha256 = (str: string): string => {
const buffer = Buffer.from(str, 'utf8');
const hash = bitcoin.crypto.sha256(buffer);
return hash.toString('hex');
};

/**
* Returns the last known block header when Electrum is connected.
* @returns {Promise<THeader>}
Expand Down
5 changes: 3 additions & 2 deletions src/utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,16 @@ export const seedHash = (seed: Buffer): string => {
};

export const ldkSeed = async (
mnumonic: string,
mnemonic: string,
bip39Passphrase: string,
selectedNetwork: EAvailableNetwork = getSelectedNetwork(),
): Promise<string> => {
const mnemonicSeed = await bip39.mnemonicToSeed(mnumonic, bip39Passphrase);
const mnemonicSeed = await bip39.mnemonicToSeed(mnemonic, bip39Passphrase);
const network = networks[selectedNetwork];
const root = bip32.fromSeed(mnemonicSeed, network);
return root.privateKey!.toString('hex');
};

export const keyDerivationAccountTypes: {
onchain: TKeyDerivationAccount;
} = {
Expand Down
28 changes: 27 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6626,7 +6626,6 @@ __metadata:
beignet: 0.0.48
bip21: 2.0.3
bip32: 4.0.0
bip39: 3.1.0
bitcoin-address-validation: 2.2.3
bitcoin-json-rpc: ^1.3.3
bitcoin-units: 0.3.0
Expand Down Expand Up @@ -6676,6 +6675,7 @@ __metadata:
react-native-qrcode-svg: 6.3.0
react-native-quick-actions: 0.3.13
react-native-quick-base64: 2.1.2
react-native-quick-bip39: 0.0.9
react-native-quick-crypto: 0.7.1
react-native-reanimated: 3.15.0
react-native-reanimated-carousel: 3.5.1
Expand Down Expand Up @@ -14461,6 +14461,16 @@ __metadata:
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.1":
version: 0.7.1
resolution: "react-native-quick-crypto@npm:0.7.1"
Expand All @@ -14474,6 +14484,22 @@ __metadata:
languageName: node
linkType: hard

"react-native-quick-crypto@npm:^0.7.7":
version: 0.7.7
resolution: "react-native-quick-crypto@npm:0.7.7"
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: 92974b2dd3113bf6021699c43e462abbbffea17021ce57f637526f5d387de1c89834467bc3b30fba59887854f7dcbb9c42a97fda88fe31cf1acb80b06a82a287
languageName: node
linkType: hard

"react-native-reanimated-carousel@npm:3.5.1":
version: 3.5.1
resolution: "react-native-reanimated-carousel@npm:3.5.1"
Expand Down

0 comments on commit 88247bc

Please sign in to comment.