Skip to content

Commit

Permalink
Merge pull request #555 from alephium/fix-old-wallet-unlock
Browse files Browse the repository at this point in the history
Fix unversioned mnemonic unlock
  • Loading branch information
nop33 committed May 13, 2024
2 parents 9a97f4b + 5457348 commit 1c9a988
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/keyring/src/mnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ export const encryptMnemonic = async (mnemonic: Uint8Array, password: string) =>
}

export const decryptMnemonic = async (encryptedMnemonic: string, password: string): Promise<DecryptMnemonicResult> => {
const { version, mnemonic } = (await encryptor.decrypt(password, encryptedMnemonic)) as
const { version: _v, mnemonic } = (await encryptor.decrypt(password, encryptedMnemonic)) as
| EncryptedMnemonicStoredAsUint8Array
| EncryptedMnemonicStoredAsString

// When we started versioning the mnemonic with 1 we didn't create a migration script (see
// https://github.com/alephium/js-sdk/commit/514bd8b920958dbfac68257bd3ce1c53f6bdde27). This resulted in unversioned
// mnemonic data. To fix this, we assume that undefined versioning is the same as version 1.
const version = _v ?? 1

if (version === 1) {
console.warn(
'☣️ Mnemonic is leaked to memory as a string while decrypting, needs to be stored as an Uint8Array (EncryptedMnemonicStoredAsUint8Array).'
Expand Down

0 comments on commit 1c9a988

Please sign in to comment.