Skip to content

Commit bfb495d

Browse files
committed
fix: replace libsodium-wrappers with tweetsodium
1 parent 3883b70 commit bfb495d

6 files changed

Lines changed: 42 additions & 48 deletions

File tree

dist/index.js.cache

-21.6 KB
Binary file not shown.

dist/index.js.cache.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"dist",
88
"action.yml"
99
],
10-
"overrides": {
11-
"libsodium": "0.7.10"
12-
},
1310
"scripts": {
1411
"clean": "rimraf dist",
1512
"lint": "eslint 'src/**/*.{js,ts}?(x)' --fix",
@@ -38,14 +35,13 @@
3835
"@octokit/auth-app": "^4.0.13",
3936
"@octokit/core": "^4.2.4",
4037
"is-base64": "^1.1.0",
41-
"libsodium-wrappers": "^0.7.10"
38+
"tweetsodium": "^0.0.6"
4239
},
4340
"devDependencies": {
4441
"@bubkoo/commitlint-config": "^1.2.2",
4542
"@bubkoo/eslint-config": "^1.5.1",
4643
"@bubkoo/tsconfig": "^1.2.4",
4744
"@types/is-base64": "^1.1.3",
48-
"@types/libsodium-wrappers": "^0.7.10",
4945
"@types/node": "^18.19.130",
5046
"@vercel/ncc": "^0.34.0",
5147
"eslint": "^8.57.1",

src/tweetsodium.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'tweetsodium' {
2+
const sodium: {
3+
seal(message: Uint8Array, key: Uint8Array): Uint8Array
4+
}
5+
6+
export default sodium
7+
}

src/util.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
33
import isBase64 from 'is-base64'
4-
import sodium from 'libsodium-wrappers'
4+
import sodium from 'tweetsodium'
55
import { Octokit } from '@octokit/core'
66
import { createAppAuth } from '@octokit/auth-app'
77

@@ -59,22 +59,13 @@ async function makeSecret(octokit: Octokit, value: string) {
5959

6060
const { key } = res.data
6161

62-
await sodium.ready
63-
64-
// Convert Secret & Base64 key to Uint8Array.
65-
const binkey = sodium.from_base64(key, sodium.base64_variants.ORIGINAL)
66-
const binsec = sodium.from_string(value)
67-
68-
// Encrypt the secret using LibSodium
69-
const encryptedBytes = sodium.crypto_box_seal(binsec, binkey)
62+
const keyBytes = Buffer.from(key, 'base64')
63+
const messageBytes = Buffer.from(value)
64+
const encryptedBytes = sodium.seal(messageBytes, keyBytes)
7065

7166
return {
7267
key_id: res.data.key_id,
73-
// Base64 the encrypted secret
74-
encrypted_value: sodium.to_base64(
75-
encryptedBytes,
76-
sodium.base64_variants.ORIGINAL,
77-
),
68+
encrypted_value: Buffer.from(encryptedBytes).toString('base64'),
7869
}
7970
}
8071

0 commit comments

Comments
 (0)