Skip to content
Merged
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
1 change: 1 addition & 0 deletions worker/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ['eslint:recommended'],
parserOptions: {
Expand Down
14 changes: 14 additions & 0 deletions worker/src/services/crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { box } from 'tweetnacl'

export async function encryptForGitHub(base64PublicKey, secretValue) {
const repoKey = Uint8Array.from(atob(base64PublicKey), (c) => c.charCodeAt(0))
const ephemeral = box.keyPair()
const nonce = crypto.getRandomValues(new Uint8Array(24))
const msg = new TextEncoder().encode(secretValue)
const sealed = box(msg, nonce, repoKey, ephemeral.secretKey)
const out = new Uint8Array(ephemeral.publicKey.length + nonce.length + sealed.length)
out.set(ephemeral.publicKey, 0)
out.set(nonce, ephemeral.publicKey.length)
out.set(sealed, ephemeral.publicKey.length + nonce.length)
return btoa(String.fromCharCode(...out))
}
Loading