Skip to content

Commit 88247bc

Browse files
authored
perf(wallet): switch to native bip39 (#2382)
1 parent 8d7c662 commit 88247bc

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

metro.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ const config = {
2121
assetExts: assetExts.filter((ext) => ext !== 'svg'),
2222
sourceExts: [...sourceExts, 'svg'],
2323
extraNodeModules: {
24+
bip39: path.resolve(__dirname, './node_modules/react-native-quick-bip39'),
2425
buffer: path.resolve(__dirname, './node_modules/@craftzdog/react-native-buffer'),
2526
crypto: path.resolve(__dirname, './node_modules/react-native-quick-crypto'),
2627
stream: path.resolve(__dirname, './node_modules/readable-stream'),
2728
'sodium-universal': path.resolve(__dirname, './node_modules/sodium-react-native-direct'),
2829
},
2930
blacklistRE: exclusionList([
31+
/\/node_modules\/bip39\/.*/,
3032
/\/node_modules\/sodium-universal\/.*/,
3133
/\/android\/build\/*/,
3234
]),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"beignet": "0.0.48",
6666
"bip21": "2.0.3",
6767
"bip32": "4.0.0",
68-
"bip39": "3.1.0",
6968
"bitcoin-address-validation": "2.2.3",
7069
"bitcoin-units": "0.3.0",
7170
"bitcoinjs-lib": "6.1.5",
@@ -102,6 +101,7 @@
102101
"react-native-qrcode-svg": "6.3.0",
103102
"react-native-quick-actions": "0.3.13",
104103
"react-native-quick-base64": "2.1.2",
104+
"react-native-quick-bip39": "0.0.9",
105105
"react-native-quick-crypto": "0.7.1",
106106
"react-native-reanimated": "3.15.0",
107107
"react-native-reanimated-carousel": "3.5.1",

src/utils/lightning/index.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EmitterSubscription } from 'react-native';
22
import Keychain from 'react-native-keychain';
3-
import * as bitcoin from 'bitcoinjs-lib';
43
import ecc from '@bitcoinerlab/secp256k1';
54
import RNFS from 'react-native-fs';
65
import { err, ok, Result } from '@synonymdev/result';
@@ -1015,17 +1014,6 @@ export const getDefaultLdkAccount = async ({
10151014
};
10161015
};
10171016

1018-
/**
1019-
* Get sha256 hash of a given string.
1020-
* @param {string} str
1021-
* @returns {string}
1022-
*/
1023-
export const getSha256 = (str: string): string => {
1024-
const buffer = Buffer.from(str, 'utf8');
1025-
const hash = bitcoin.crypto.sha256(buffer);
1026-
return hash.toString('hex');
1027-
};
1028-
10291017
/**
10301018
* Returns the last known block header when Electrum is connected.
10311019
* @returns {Promise<THeader>}

src/utils/wallet/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,16 @@ export const seedHash = (seed: Buffer): string => {
382382
};
383383

384384
export const ldkSeed = async (
385-
mnumonic: string,
385+
mnemonic: string,
386386
bip39Passphrase: string,
387387
selectedNetwork: EAvailableNetwork = getSelectedNetwork(),
388388
): Promise<string> => {
389-
const mnemonicSeed = await bip39.mnemonicToSeed(mnumonic, bip39Passphrase);
389+
const mnemonicSeed = await bip39.mnemonicToSeed(mnemonic, bip39Passphrase);
390390
const network = networks[selectedNetwork];
391391
const root = bip32.fromSeed(mnemonicSeed, network);
392392
return root.privateKey!.toString('hex');
393393
};
394+
394395
export const keyDerivationAccountTypes: {
395396
onchain: TKeyDerivationAccount;
396397
} = {

yarn.lock

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6626,7 +6626,6 @@ __metadata:
66266626
beignet: 0.0.48
66276627
bip21: 2.0.3
66286628
bip32: 4.0.0
6629-
bip39: 3.1.0
66306629
bitcoin-address-validation: 2.2.3
66316630
bitcoin-json-rpc: ^1.3.3
66326631
bitcoin-units: 0.3.0
@@ -6676,6 +6675,7 @@ __metadata:
66766675
react-native-qrcode-svg: 6.3.0
66776676
react-native-quick-actions: 0.3.13
66786677
react-native-quick-base64: 2.1.2
6678+
react-native-quick-bip39: 0.0.9
66796679
react-native-quick-crypto: 0.7.1
66806680
react-native-reanimated: 3.15.0
66816681
react-native-reanimated-carousel: 3.5.1
@@ -14461,6 +14461,16 @@ __metadata:
1446114461
languageName: node
1446214462
linkType: hard
1446314463

14464+
"react-native-quick-bip39@npm:0.0.9":
14465+
version: 0.0.9
14466+
resolution: "react-native-quick-bip39@npm:0.0.9"
14467+
dependencies:
14468+
"@craftzdog/react-native-buffer": ^6.0.5
14469+
react-native-quick-crypto: ^0.7.7
14470+
checksum: 1beb61bcf124fda8d803baaee18b9ca3f8aa6cf14dc18ed168c4c5e7f75095dc0edd619fd72049b40e7456d07cd90ee611b4e2071dcbeb1bcc64a2260c47727f
14471+
languageName: node
14472+
linkType: hard
14473+
1446414474
"react-native-quick-crypto@npm:0.7.1":
1446514475
version: 0.7.1
1446614476
resolution: "react-native-quick-crypto@npm:0.7.1"
@@ -14474,6 +14484,22 @@ __metadata:
1447414484
languageName: node
1447514485
linkType: hard
1447614486

14487+
"react-native-quick-crypto@npm:^0.7.7":
14488+
version: 0.7.7
14489+
resolution: "react-native-quick-crypto@npm:0.7.7"
14490+
dependencies:
14491+
"@craftzdog/react-native-buffer": ^6.0.5
14492+
events: ^3.3.0
14493+
readable-stream: ^4.5.2
14494+
string_decoder: ^1.3.0
14495+
util: ^0.12.5
14496+
peerDependencies:
14497+
react: "*"
14498+
react-native: "*"
14499+
checksum: 92974b2dd3113bf6021699c43e462abbbffea17021ce57f637526f5d387de1c89834467bc3b30fba59887854f7dcbb9c42a97fda88fe31cf1acb80b06a82a287
14500+
languageName: node
14501+
linkType: hard
14502+
1447714503
"react-native-reanimated-carousel@npm:3.5.1":
1447814504
version: 3.5.1
1447914505
resolution: "react-native-reanimated-carousel@npm:3.5.1"

0 commit comments

Comments
 (0)