Skip to content

Commit

Permalink
Merge pull request #1541 from synonymdev/remove-generate-mnemonic
Browse files Browse the repository at this point in the history
refactor(wallet): Remove Generate Mnemonic
  • Loading branch information
coreyphillips authored Feb 8, 2024
2 parents d79acaf + abe0a92 commit faa3fb3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 87 deletions.
16 changes: 0 additions & 16 deletions nodejs-assets/nodejs-project/bitcoin-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ class BitcoinActions {
});
}

generateMnemonic({
id,
method = 'generateMnemonic',
data: {
strength = 128,
}}) {
return new Promise((resolve) => {
try {
const mnemonic = bip39.generateMnemonic(strength);
return resolve({id, method, error: false, value: mnemonic});
} catch (e) {
return resolve({id, method, error: true, value: e});
}
});
}

getPrivateKey({
id,
method = 'getPrivateKey',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
"@synonymdev/web-relay": "1.0.7",
"backpack-client": "github:synonymdev/bitkit-backup-client#f08fdb28529d8a3f8bfecc789443c43b966a7581",
"bech32": "2.0.0",
"beignet": "0.0.20",
"beignet": "0.0.22",
"bip21": "2.0.3",
"bip32": "4.0.0",
"bip39": "3.0.4",
"bip39": "3.1.0",
"bitcoin-address-validation": "2.2.3",
"bitcoin-units": "0.3.0",
"bitcoinjs-lib": "6.1.5",
Expand Down
1 change: 0 additions & 1 deletion src/utils/nodejs-mobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
let isSetup = false;
const methods = {
[ENodeJsMethod.setup]: {},
[ENodeJsMethod.generateMnemonic]: {},
[ENodeJsMethod.getPrivateKey]: {},
[ENodeJsMethod.getScriptHash]: {},
[ENodeJsMethod.getAddress]: {},
Expand Down
10 changes: 0 additions & 10 deletions src/utils/nodejs-mobile/shapes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { v4 as uuidv4 } from 'uuid';
import {
ENodeJsMethod,
INodeJsGenerateMnemonic,
INodeJsGetAddress,
INodeJsGetPrivateKey,
INodeJsGetScriptHash,
Expand All @@ -20,15 +19,6 @@ export const DefaultNodeJsMethodsShape = {
},
};
},
generateMnemonic: (): INodeJsGenerateMnemonic => {
return {
id: uuidv4(),
method: ENodeJsMethod.generateMnemonic,
data: {
strength: 256,
},
};
},
getScriptHash: (): INodeJsGetScriptHash => {
return {
id: uuidv4(),
Expand Down
10 changes: 0 additions & 10 deletions src/utils/nodejs-mobile/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EAvailableNetwork } from '../networks';

export enum ENodeJsMethod {
setup = 'setup',
generateMnemonic = 'generateMnemonic',
getPrivateKey = 'getPrivateKey',
getScriptHash = 'getScriptHash',
getAddress = 'getAddress',
Expand All @@ -11,7 +10,6 @@ export enum ENodeJsMethod {
export type TNodeJsMethodsData =
| INodeJsSetup
| INodeJsGetPrivateKey
| INodeJsGenerateMnemonic
| INodeJsGetAddress
| INodeJsGetScriptHash;

Expand All @@ -29,14 +27,6 @@ export interface INodeJsSetup {
};
}

export interface INodeJsGenerateMnemonic {
id: string;
method: ENodeJsMethod.generateMnemonic;
data: {
strength?: number;
};
}

export interface INodeJsGetPrivateKey {
id: string;
method: ENodeJsMethod.getPrivateKey;
Expand Down
5 changes: 2 additions & 3 deletions src/utils/startup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { InteractionManager } from 'react-native';
import { err, ok, Result } from '@synonymdev/result';

import {
generateMnemonic,
getAddressTypesToMonitor,
getBip39Passphrase,
getMnemonicPhrase,
Expand All @@ -24,7 +23,7 @@ import { promiseTimeout } from '../helpers';
import { EAvailableNetwork } from '../networks';
import { TWalletName } from '../../store/types/wallet';
import { runChecks } from '../wallet/checks';
import { TServer } from 'beignet';
import { generateMnemonic, TServer } from 'beignet';

/**
* Creates a new wallet from scratch
Expand All @@ -35,7 +34,7 @@ export const createNewWallet = async ({
}: {
bip39Passphrase?: string;
} = {}): Promise<Result<string>> => {
const mnemonic = await generateMnemonic();
const mnemonic = generateMnemonic();
if (!mnemonic) {
return err('Unable to generate mnemonic.');
}
Expand Down
20 changes: 0 additions & 20 deletions src/utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,26 +394,6 @@ export const getMnemonicPhrase = async (
}
};

/**
* Generate a mnemonic phrase.
* @async
* @param {number} strength
* @return {Promise<string>}
*/
export const generateMnemonic = async (strength = 128): Promise<string> => {
try {
const data = DefaultNodeJsMethodsShape.generateMnemonic();
data.data.strength = strength;
const generatedMnemonic = await invokeNodeJsMethod<string>(data);
if (generatedMnemonic.error) {
return '';
}
return generatedMnemonic.value;
} catch (e) {
return '';
}
};

/**
* Get bip39 passphrase for a specified wallet.
* @async
Expand Down
35 changes: 10 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4780,11 +4780,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==

"@types/[email protected]":
version "11.11.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.6.tgz#df929d1bb2eee5afdda598a41930fe50b43eaa6a"
integrity sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==

"@types/node@>=12.12.47":
version "20.3.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.3.2.tgz#fa6a90f2600e052a03c18b8cb3fd83dd4e599898"
Expand Down Expand Up @@ -5716,10 +5711,10 @@ bech32@^1.1.2, bech32@^1.1.4:
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==

[email protected].20:
version "0.0.20"
resolved "https://registry.yarnpkg.com/beignet/-/beignet-0.0.20.tgz#2f11389dacac1957eb36bf26b7bb7319d69ff241"
integrity sha512-m816N3mJ/wfIcHpX+bpFMsyrvn6yviXQqekMvmqcB1QNKNJ0MFp4Nt9b3+rRB4HvwmayJqyHDvhI+TAyZ+UUJA==
[email protected].22:
version "0.0.22"
resolved "https://registry.yarnpkg.com/beignet/-/beignet-0.0.22.tgz#07fb67299b4c7c99c2537252e9adaa27a51f57c0"
integrity sha512-Xb/L7HPUdc0yC/dy2kv1/AoZ6Alej8k8IGQGx2QIuAKTeu9kVVispJFDwe30xcyAuTFMwj2AYM8GJmoAuwkFdA==
dependencies:
"@bitcoinerlab/secp256k1" "1.0.5"
bech32 "2.0.0"
Expand All @@ -5732,7 +5727,7 @@ [email protected]:
ecpair "2.1.0"
lodash.clonedeep "4.5.0"
net "1.0.2"
rn-electrum-client "0.0.10"
rn-electrum-client "0.0.11"

bencode@^2.0.0, bencode@^2.0.3:
version "2.0.3"
Expand Down Expand Up @@ -5818,16 +5813,6 @@ bip32@^2.0.6:
typeforce "^1.11.5"
wif "^2.0.6"

[email protected]:
version "3.0.4"
resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.0.4.tgz#5b11fed966840b5e1b8539f0f54ab6392969b2a0"
integrity sha512-YZKQlb752TrUWqHWj7XAwCSjYEgGAk+/Aas3V7NyjQeZYsztO8JnQUaCWhcnL4T+jL8nvB8typ2jRPzTlgugNw==
dependencies:
"@types/node" "11.11.6"
create-hash "^1.1.0"
pbkdf2 "^3.0.9"
randombytes "^2.0.1"

[email protected], bip39@^3.0.4:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.1.0.tgz#c55a418deaf48826a6ceb34ac55b3ee1577e18a3"
Expand Down Expand Up @@ -11986,7 +11971,7 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

pbkdf2@^3.0.3, pbkdf2@^3.0.9:
pbkdf2@^3.0.3:
version "3.1.2"
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.1.2.tgz#dd822aa0887580e52f1a039dc3eda108efae3075"
integrity sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==
Expand Down Expand Up @@ -13309,10 +13294,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/rn-android-keyboard-adjust/-/rn-android-keyboard-adjust-2.1.2.tgz#f2b792628700dcb026215420192317ce43fd954f"
integrity sha512-pUYiMT7aucw5YnV4geGdalyl6o6rEwRYhDnw2oPQwDym1BZHtmKsxFLupky1Kj2ZNkNKadpEyoyHOElLo+f3sA==

[email protected].10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/rn-electrum-client/-/rn-electrum-client-0.0.10.tgz#a889e30967484b1312c2afd260501e9b19cd845d"
integrity sha512-sYP9mdPGEnDjQZtMrv1JWc4pWEFTUBcGqe/K64whnmmz67aYppUAyblPCzyndsNr3Eu4KdjUK3tgmMh+Ha4v9g==
[email protected].11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/rn-electrum-client/-/rn-electrum-client-0.0.11.tgz#150372294c9712ffd54b237820042c63a5b38081"
integrity sha512-XfpUPyWf+/Bqcc67DmvBvCtlzc/FLaCSikOrUtFaba6zunWDCmXRgNNtvHQEoC40FrfDIo1bh8wv4oymyx+2xg==

"rn-electrum-client@github:synonymdev/react-native-electrum-client#a32a292d4e4918a04d280137e24e5961c74c543f":
version "0.0.8"
Expand Down

0 comments on commit faa3fb3

Please sign in to comment.