Skip to content

Commit

Permalink
feat: slip39 (#2304)
Browse files Browse the repository at this point in the history
* wip

* feat: supports slip39

* chore: update eth-hd-keyring

* fix: clear all

* fix: error state

* fix: trust value label

* chore: update hd keyring

---------

Co-authored-by: DMY <147dmy@gmail.com>
  • Loading branch information
heisenberg-2077 and dmy147 authored Jun 7, 2024
1 parent 1cb317b commit 02f7262
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 47 deletions.
8 changes: 7 additions & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"advancedSettings": "Advanced Settings",
"amount": "Amount",
"contract": "Smart contract",
"trustValueTitle": "Risk exposure",
"trustValueTitle": "Trust value",
"typedDataMessage": "Typed data message",
"label": "Label",
"addressSource": "Address Source"
Expand Down Expand Up @@ -1265,6 +1265,12 @@
"fillInTheBackupSeedPhraseInOrder": "Fill in the backup seed phrase in order",
"wordPhrase": "I have a <1>{{count}}</1>-word phrase",
"wordPhraseAndPassphrase": "I have a <1>{{count}}</1>-word phrase with Passphrase",
"slip39SeedPhrase": "I have a <0>{{SLIP39}}</0> Seed Phrase",
"slip39SeedPhraseWithPassphrase": "I have a <0>{{SLIP39}}</0> Seed Phrase with Passphrase",
"slip39SeedPhrasePlaceholder_one": "Enter your {{count}}st seed phrase shares here",
"slip39SeedPhrasePlaceholder_two": "Enter your {{count}}nd seed phrase shares here",
"slip39SeedPhrasePlaceholder_few": "Enter your {{count}}rd seed phrase shares here",
"slip39SeedPhrasePlaceholder_other": "Enter your {{count}}th seed phrase shares here",
"clearAll": "Clear All",
"pastedAndClear": "Pasted and clipboard cleared",
"invalidContent": "Invalid content",
Expand Down
2 changes: 1 addition & 1 deletion _raw/locales/zh-CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@
"address": "地址",
"advancedSettings": "高级设置",
"amount": "数量",
"trustValueTitle": "风险暴露",
"trustValueTitle": "信任值",
"addressSource": "地址来源"
},
"signTypedData": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@onekeyfe/hd-web-sdk": "0.3.27",
"@rabby-wallet/eth-coinbase-keyring": "0.0.0-beta.8",
"@rabby-wallet/eth-gnosis-keyring": "0.0.1",
"@rabby-wallet/eth-hd-keyring": "4.2.0",
"@rabby-wallet/eth-hd-keyring": "4.3.0",
"@rabby-wallet/eth-lattice-keyring": "1.1.1",
"@rabby-wallet/eth-simple-keyring": "5.0.1",
"@rabby-wallet/eth-trezor-keyring": "2.5.1",
Expand Down
19 changes: 9 additions & 10 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as ethUtil from 'ethereumjs-util';
import Wallet, { thirdparty } from 'ethereumjs-wallet';
import { ethErrors } from 'eth-rpc-errors';
import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { ethers, Contract } from 'ethers';
import { flatten, groupBy, keyBy, set, uniq } from 'lodash';
import abiCoder, { AbiCoder } from 'web3-eth-abi';
Expand Down Expand Up @@ -2111,16 +2109,9 @@ export class WalletController extends BaseController {
const serialized = await keyring.serialize();
const seedWords = serialized.mnemonic;

this._lastGetAddress = address;
return seedWords;
};

_lastGetAddress = '';

getLastGetAddress = () => {
return this._lastGetAddress;
};

clearAddressPendingTransactions = (address: string, chainId?: number) => {
transactionHistoryService.clearPendingTransactions(address, chainId);
transactionWatcher.clearPendingTx(address, chainId);
Expand Down Expand Up @@ -2405,7 +2396,7 @@ export class WalletController extends BaseController {
// keep passphrase is empty string if not set
passphrase = passphrase || '';

if (!bip39.validateMnemonic(mnemonic, wordlist)) {
if (!HdKeyring.validateMnemonic(mnemonic)) {
throw new Error(t('background.error.invalidMnemonic'));
}
// If import twice use same keyring
Expand All @@ -2431,6 +2422,14 @@ export class WalletController extends BaseController {
return result;
};

slip39DecodeMnemonics = (secretShares: string[]) => {
return HdKeyring.slip39DecodeMnemonics(secretShares);
};

slip39DecodeMnemonic = (secretShare: string) => {
return HdKeyring.slip39DecodeMnemonic(secretShare);
};

addKeyringToStash = (keyring) => {
const stashId = Object.values(stashKeyrings).length + 1;
stashKeyrings[stashId] = keyring;
Expand Down
13 changes: 13 additions & 0 deletions src/ui/assets/import/mnemonics-hide.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/ui/assets/import/mnemonics-show.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 02f7262

Please sign in to comment.