Skip to content

Commit

Permalink
Switch to libsodium
Browse files Browse the repository at this point in the history
  • Loading branch information
xt0rted committed Apr 14, 2022
1 parent 7282fa9 commit c8442b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 44 deletions.
79 changes: 40 additions & 39 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 @@ -36,12 +36,13 @@
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^3.6.2",
"js-yaml": "^4.1.0",
"tweetsodium": "^0.0.5"
"libsodium-wrappers": "^0.7.10"
},
"devDependencies": {
"@types/eslint": "^8.4.1",
"@types/jest": "^27.4.1",
"@types/js-yaml": "^4.0.5",
"@types/libsodium-wrappers": "^0.7.9",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.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 c8442b9

Please sign in to comment.