From d78ce127e24cefd650870781316cdeea5839db69 Mon Sep 17 00:00:00 2001 From: ost-ptk Date: Wed, 24 Jul 2024 18:38:43 +0300 Subject: [PATCH 1/2] add jszip package and pack all files in a zip file and then download one zip file --- package-lock.json | 31 ++++++------------- package.json | 1 + .../pages/download-account-keys/index.tsx | 12 ++++--- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0d8b27cda..295f27d2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "Casper Wallet", - "version": "1.11.0", + "version": "1.11.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "Casper Wallet", - "version": "1.11.0", + "version": "1.11.1", "dependencies": { "@formatjs/intl": "2.6.2", "@hookform/resolvers": "2.9.10", @@ -32,6 +32,7 @@ "i18next-browser-languagedetector": "^7.2.1", "i18next-http-backend": "2.5.0", "i18next-parser": "7.9.0", + "jszip": "^3.10.1", "lodash.throttle": "4.1.1", "mac-scrollbar": "^0.13.6", "md5": "^2.3.0", @@ -16952,8 +16953,7 @@ "node_modules/immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=", - "dev": true + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" }, "node_modules/immer": { "version": "9.0.21", @@ -20247,7 +20247,6 @@ "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", - "dev": true, "dependencies": { "lie": "~3.3.0", "pako": "~1.0.2", @@ -20259,7 +20258,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", - "dev": true, "dependencies": { "immediate": "~3.0.5" } @@ -20268,7 +20266,6 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -20283,7 +20280,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -23031,8 +23027,7 @@ "node_modules/pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", - "dev": true + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" }, "node_modules/param-case": { "version": "3.0.4", @@ -25507,8 +25502,7 @@ "node_modules/setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=", - "dev": true + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" }, "node_modules/setprototypeof": { "version": "1.2.0", @@ -42150,8 +42144,7 @@ "immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=", - "dev": true + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" }, "immer": { "version": "9.0.21", @@ -44567,7 +44560,6 @@ "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", - "dev": true, "requires": { "lie": "~3.3.0", "pako": "~1.0.2", @@ -44579,7 +44571,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", - "dev": true, "requires": { "immediate": "~3.0.5" } @@ -44588,7 +44579,6 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -44603,7 +44593,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "requires": { "safe-buffer": "~5.1.0" } @@ -46670,8 +46659,7 @@ "pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", - "dev": true + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" }, "param-case": { "version": "3.0.4", @@ -48550,8 +48538,7 @@ "setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=", - "dev": true + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" }, "setprototypeof": { "version": "1.2.0", diff --git a/package.json b/package.json index 329e9b02f..52825b703 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "i18next-browser-languagedetector": "^7.2.1", "i18next-http-backend": "2.5.0", "i18next-parser": "7.9.0", + "jszip": "^3.10.1", "lodash.throttle": "4.1.1", "mac-scrollbar": "^0.13.6", "md5": "^2.3.0", diff --git a/src/apps/popup/pages/download-account-keys/index.tsx b/src/apps/popup/pages/download-account-keys/index.tsx index 2b4484b81..1c4c5ed37 100644 --- a/src/apps/popup/pages/download-account-keys/index.tsx +++ b/src/apps/popup/pages/download-account-keys/index.tsx @@ -1,3 +1,4 @@ +import JSZip from 'jszip'; import React, { useCallback, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; @@ -43,16 +44,19 @@ export const DownloadAccountKeysPage = () => { } const downloadKeys = () => { + const zip = new JSZip(); + selectedAccounts.forEach(account => { const asymmetricKey = createAsymmetricKey( account.publicKey, account.secretKey ); const file = asymmetricKey.exportPrivateKeyInPem(); - downloadFile( - new Blob([file], { type: 'text/plain;charset=utf-8' }), - `${account.name}_secret_key.pem` - ); + zip.file(`${account.name}_public_key.pem`, file); + }); + + zip.generateAsync({ type: 'blob' }).then(function (content) { + downloadFile(new Blob([content]), 'casper-wallet-public-keys.zip'); }); setDownloadAccountKeysStep(DownloadAccountKeysSteps.Success); From e903d38baa3cb6db045e82e66527e32106be10a6 Mon Sep 17 00:00:00 2001 From: ost-ptk Date: Thu, 25 Jul 2024 10:44:32 +0300 Subject: [PATCH 2/2] fix naming for downloading files --- src/apps/popup/pages/download-account-keys/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/popup/pages/download-account-keys/index.tsx b/src/apps/popup/pages/download-account-keys/index.tsx index 1c4c5ed37..c0eb01379 100644 --- a/src/apps/popup/pages/download-account-keys/index.tsx +++ b/src/apps/popup/pages/download-account-keys/index.tsx @@ -52,11 +52,11 @@ export const DownloadAccountKeysPage = () => { account.secretKey ); const file = asymmetricKey.exportPrivateKeyInPem(); - zip.file(`${account.name}_public_key.pem`, file); + zip.file(`${account.name}_secret_key.pem`, file); }); zip.generateAsync({ type: 'blob' }).then(function (content) { - downloadFile(new Blob([content]), 'casper-wallet-public-keys.zip'); + downloadFile(new Blob([content]), 'casper-wallet-secret_keys.zip'); }); setDownloadAccountKeysStep(DownloadAccountKeysSteps.Success);