Skip to content

Commit

Permalink
Merge pull request #245 from nimiq/soeren/result-flags
Browse files Browse the repository at this point in the history
Return file/words flags when importing and removing keys
  • Loading branch information
sisou authored Mar 18, 2019
2 parents 462e0fe + 0ec8840 commit e3018fb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nimiq/keyguard-client",
"version": "0.2.5-beta.3",
"version": "0.2.6-beta.3",
"description": "Nimiq Keyguard client library",
"main": "dist/KeyguardClient.common.js",
"module": "dist/KeyguardClient.es.js",
Expand Down
6 changes: 4 additions & 2 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 Expand Up @@ -74,8 +76,8 @@ export type ExportRequest = SimpleRequest & {
};

export type ExportResult = {
file: boolean,
words: boolean,
fileExported: boolean,
wordsExported: boolean,
};

export type SignTransactionRequest = SimpleRequest & 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
8 changes: 4 additions & 4 deletions src/request/export/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Export { // eslint-disable-line no-unused-vars
this._reject = reject;

this.exported = {
words: false,
file: false,
wordsExported: false,
fileExported: false,
};

this._exportWordsHandler = new ExportWords(request,
Expand Down Expand Up @@ -53,7 +53,7 @@ class Export { // eslint-disable-line no-unused-vars
* @param {KeyguardRequest.SimpleResult} fileResult
*/
_fileExportSuccessful(fileResult) {
this.exported.file = fileResult.success;
this.exported.fileExported = fileResult.success;
this._exportWordsHandler.run();
}

Expand All @@ -62,7 +62,7 @@ class Export { // eslint-disable-line no-unused-vars
* @param {KeyguardRequest.SimpleResult} wordsResult
*/
_wordsExportSuccessful(wordsResult) {
this.exported.words = wordsResult.success;
this.exported.wordsExported = wordsResult.success;
this._resolve(this.exported);
}
}
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 e3018fb

Please sign in to comment.