Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to libsodium #77

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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