@@ -19,9 +19,12 @@ import {
19
19
type MessageTypes ,
20
20
type EIP7702Authorization ,
21
21
} from '@metamask/eth-sig-util' ;
22
+ import { mnemonicPhraseToBytes } from '@metamask/key-tree' ;
22
23
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english' ;
23
24
import { assert , bytesToHex , hexToBytes , type Hex } from '@metamask/utils' ;
24
25
import { webcrypto } from 'crypto' ;
26
+ // eslint-disable-next-line n/no-sync
27
+ import { mnemonicToSeedSync } from 'ethereum-cryptography/bip39' ;
25
28
import { keccak256 } from 'ethereum-cryptography/keccak' ;
26
29
// eslint-disable-next-line @typescript-eslint/naming-convention
27
30
import OldHdKeyring from 'old-hd-keyring' ;
@@ -37,6 +40,10 @@ const sampleMnemonic =
37
40
const firstAcct = '0x1c96099350f13d558464ec79b9be4445aa0ef579' ;
38
41
const secondAcct = '0x1b00aed43a693f3a957f9feb5cc08afa031e37a0' ;
39
42
43
+ const sampleMnemonicBytes = mnemonicPhraseToBytes ( sampleMnemonic ) ;
44
+ // eslint-disable-next-line n/no-sync
45
+ const sampleMnemonicSeed = mnemonicToSeedSync ( sampleMnemonic ) ;
46
+
40
47
const notKeyringAddress = '0xbD20F6F5F1616947a39E11926E78ec94817B3931' ;
41
48
42
49
const getAddressAtIndex = ( keyring : HdKeyring , index : number ) : Hex => {
@@ -175,6 +182,8 @@ describe('hd-keyring', () => {
175
182
const accounts = keyring . getAccounts ( ) ;
176
183
expect ( accounts [ 0 ] ) . toStrictEqual ( firstAcct ) ;
177
184
expect ( accounts [ 1 ] ) . toStrictEqual ( secondAcct ) ;
185
+ expect ( keyring . mnemonic ) . toStrictEqual ( sampleMnemonicBytes ) ;
186
+ expect ( keyring . seed ) . toStrictEqual ( sampleMnemonicSeed ) ;
178
187
} ) ;
179
188
180
189
it ( 'deserializes with a typeof buffer mnemonic' , async ( ) => {
@@ -188,6 +197,8 @@ describe('hd-keyring', () => {
188
197
const accounts = keyring . getAccounts ( ) ;
189
198
expect ( accounts [ 0 ] ) . toStrictEqual ( firstAcct ) ;
190
199
expect ( accounts [ 1 ] ) . toStrictEqual ( secondAcct ) ;
200
+ expect ( keyring . mnemonic ) . toStrictEqual ( sampleMnemonicBytes ) ;
201
+ expect ( keyring . seed ) . toStrictEqual ( sampleMnemonicSeed ) ;
191
202
} ) ;
192
203
193
204
it ( 'deserializes with a typeof Uint8Array mnemonic' , async ( ) => {
@@ -207,6 +218,8 @@ describe('hd-keyring', () => {
207
218
const accounts = keyring . getAccounts ( ) ;
208
219
expect ( accounts [ 0 ] ) . toStrictEqual ( firstAcct ) ;
209
220
expect ( accounts [ 1 ] ) . toStrictEqual ( secondAcct ) ;
221
+ expect ( keyring . mnemonic ) . toStrictEqual ( sampleMnemonicBytes ) ;
222
+ expect ( keyring . seed ) . toStrictEqual ( sampleMnemonicSeed ) ;
210
223
} ) ;
211
224
212
225
it ( 'deserializes using custom cryptography' , async ( ) => {
@@ -251,6 +264,8 @@ describe('hd-keyring', () => {
251
264
const accounts = keyring . getAccounts ( ) ;
252
265
expect ( accounts [ 0 ] ) . toStrictEqual ( firstAcct ) ;
253
266
expect ( accounts [ 1 ] ) . toStrictEqual ( secondAcct ) ;
267
+ expect ( keyring . mnemonic ) . toStrictEqual ( sampleMnemonicBytes ) ;
268
+ expect ( keyring . seed ) . toStrictEqual ( sampleMnemonicSeed ) ;
254
269
expect ( cryptographicFunctions . pbkdf2Sha512 ) . toHaveBeenCalledTimes ( 1 ) ;
255
270
} ) ;
256
271
0 commit comments