From 15557a982a135251f48a0315a07e0e33267544be Mon Sep 17 00:00:00 2001 From: Nicolas Talfer Date: Tue, 19 Nov 2024 17:46:35 +0100 Subject: [PATCH] feat(E2EE-2406): add npm script to generate a libsodium crypto box keypair --- .vscode/settings.json | 2 +- package.json | 3 ++- packages/crypto/src/generate_keypair.ts | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 packages/crypto/src/generate_keypair.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 510d61ee..52b34187 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "eslint.validate": [ "javascript", diff --git a/package.json b/package.json index b789f2fd..4694f6e1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "debug:errors": "karma start packages/errors/config/karma.config.debug.js", "debug:streams": "karma start packages/stream/config/karma.config.debug.js", "proof": "poetry install && poetry run python run-ci.py lint && npm run test", - "coverage": "nyc npm run test" + "coverage": "nyc npm run test", + "gen:keypair": "npm run build:crypto && node ./packages/crypto/dist/node/generate_keypair.js" }, "devDependencies": { "@types/chai": "^4.3.4", diff --git a/packages/crypto/src/generate_keypair.ts b/packages/crypto/src/generate_keypair.ts new file mode 100644 index 00000000..faa19f6c --- /dev/null +++ b/packages/crypto/src/generate_keypair.ts @@ -0,0 +1,12 @@ +import sodium from 'libsodium-wrappers'; +import { toBase64 } from './utils'; + +(async () => { + await sodium.ready; + const keypair = sodium.crypto_box_keypair(); + const b64keypair = { + privateKey: toBase64(keypair.privateKey), + publicKey: toBase64(keypair.publicKey), + }; + console.log(b64keypair); // eslint-disable-line no-console +})();