Skip to content

Commit

Permalink
Support importing and decoding v1/v2 Login Files
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Nov 17, 2024
1 parent 7308b93 commit 4da1229
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/request/import/ImportFile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global Constants */
/* global Nimiq */
/* global NimiqPoW */
/* global Key */
/* global ImportWords */
/* global FileImporter */
Expand Down Expand Up @@ -250,8 +251,24 @@ class ImportFile {
// Make sure read position is at 0 even after a wrong password
this._encryptedKey.reset();

// TODO: Load NimiqPoW for v1 and v2 encrypted keys
const secret = await Nimiq.Secret.fromEncrypted(this._encryptedKey, encryptionKey);
/** @type {Nimiq.Entropy | Nimiq.PrivateKey} */
let secret;

const version = this._encryptedKey[0];
if (version >= 3) {
// Nimiq PoS supports encryption from version 3
secret = await Nimiq.Secret.fromEncrypted(this._encryptedKey, encryptionKey);
} else {
// Load Nimiq PoW module to decode old encryptions
const _secret = await NimiqPoW.Secret.fromEncrypted(this._encryptedKey, encryptionKey);

// Convert PoW Entropy/PrivateKey objects to their PoS equivalent
if (_secret instanceof NimiqPoW.Entropy) {
secret = Nimiq.Entropy.deserialize(new Nimiq.SerialBuffer(_secret.serialize()));
} else {
secret = Nimiq.PrivateKey.deserialize(new Nimiq.SerialBuffer(_secret.serialize()));
}
}

// If this code runs, the password was correct and the request returns
/** @type {HTMLElement} */
Expand Down

0 comments on commit 4da1229

Please sign in to comment.