Skip to content

Commit

Permalink
Switch to libsodium
Browse files Browse the repository at this point in the history
  • Loading branch information
xt0rted committed Sep 26, 2022
1 parent 533551b commit c9dd926
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 65 deletions.
100 changes: 40 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^4.1.0",
"js-yaml": "^4.1.0",
"tweetsodium": "^0.0.5"
"libsodium-wrappers": "^0.7.10"
},
"devDependencies": {
"@types/eslint": "^8.4.6",
"@types/jest": "^28.1.7",
"@types/js-yaml": "^4.0.5",
"@types/libsodium-wrappers": "^0.7.9",
"@types/node": "^18.7.21",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
Expand Down
8 changes: 5 additions & 3 deletions src/encrypt.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import tweetsodium from "tweetsodium"; // eslint-disable-line import/default
import libsodium from "libsodium-wrappers";

export function encrypt(publicKey: string, message: string) {
export async function encrypt(publicKey: string, message: string): Promise<string> {
const messageBytes = Buffer.from(message);
const keyBytes = Buffer.from(publicKey, "base64");

await libsodium.ready;

const encryptedBytes = tweetsodium.seal(messageBytes, keyBytes);
const encryptedBytes = libsodium.crypto_box_seal(messageBytes, keyBytes);

const encrypted = Buffer.from(encryptedBytes).toString("base64");

Expand Down
2 changes: 1 addition & 1 deletion src/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function setOrDeleteSecret(environment: SecretEnvironment, owner: s
owner,
repo,
});
const encryptedValue = encrypt(publicKey.key, value);
const encryptedValue = await encrypt(publicKey.key, value);

await setSecret({
environment,
Expand Down

0 comments on commit c9dd926

Please sign in to comment.