Skip to content

Commit

Permalink
Return file/words flags with import results
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Mar 15, 2019
1 parent a3a7509 commit 8bcfeb0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type SingleKeyResult = {
keyPath: string,
address: Uint8Array,
}>;
fileExported: boolean;
wordsExported: boolean;
};

export type TransactionInfo = {
Expand Down
2 changes: 2 additions & 0 deletions src/request/create/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class Create {
address: key.deriveAddress(keyPath).serialize(),
keyPath,
}],
fileExported: false,
wordsExported: false,
}];

this._resolve(result);
Expand Down
2 changes: 2 additions & 0 deletions src/request/import/ImportFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class ImportFile {
keyId: /** @type {number} */ (key.id),
keyType: key.type,
addresses,
fileExported: true,
wordsExported: false,
}];

this._resolve(result);
Expand Down
12 changes: 12 additions & 0 deletions src/request/import/ImportWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ class ImportWords {
);

downloadLoginFile.on(DownloadLoginFile.Events.DOWNLOADED, () => {
for (let i = 0; i < this._keyResults.length; i++) {
this._keyResults[i].fileExported = true;
}
this._resolve(this._keyResults);
});
window.location.hash = ImportWords.Pages.DOWNLOAD_LOGINFILE;
Expand Down Expand Up @@ -180,18 +183,23 @@ class ImportWords {
try {
if (this._secrets.entropy) {
const key = new Key(this._secrets.entropy, false);

/** @type {{keyPath: string, address: Uint8Array}[]} */
const addresses = this._request.requestedKeyPaths.map(keyPath => ({
keyPath,
address: key.deriveAddress(keyPath).serialize(),
}));

/** @type {KeyguardRequest.SingleKeyResult} */
const result = {
keyId: await KeyStore.instance.put(key, encryptionKey || undefined),
keyType: Nimiq.Secret.Type.ENTROPY,
addresses,
fileExported: false,
wordsExported: true,
};
this._keyResults.push(result);

const secretString = Nimiq.BufferUtils.toBase64(key.secret.serialize());
sessionStorage.setItem(ImportApi.SESSION_STORAGE_KEY_PREFIX + result.keyId, secretString);

Expand All @@ -208,13 +216,17 @@ class ImportWords {
}
if (this._secrets.privateKey) {
const key = new Key(this._secrets.privateKey, false);

/** @type {KeyguardRequest.SingleKeyResult} */
const result = {
keyId: await KeyStore.instance.put(key, encryptionKey || undefined),
keyType: Nimiq.Secret.Type.PRIVATE_KEY,
addresses: [{
keyPath: Constants.LEGACY_DERIVATION_PATH,
address: key.deriveAddress(Constants.LEGACY_DERIVATION_PATH).serialize(),
}],
fileExported: false,
wordsExported: true,
};
this._keyResults.push(result);
} else {
Expand Down

0 comments on commit 8bcfeb0

Please sign in to comment.