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: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.6.1",
"@types/libsodium-wrappers": "^0.8.2",
"@types/node": "^22.0.0",
"@types/react": "^17.0.37",
"@types/react-router-dom": "^5.3.3",
Expand Down
17 changes: 8 additions & 9 deletions src/common/services/source-control/GithubService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import { FileEntry, RepoMetadata, RepoSecret } from '../types';

vi.mock('libsodium-wrappers', () => {
const fakeSealed = new Uint8Array([1, 2, 3, 4]);
return {
default: {
ready: Promise.resolve(),
base64_variants: { ORIGINAL: 1 },
from_base64: () => new Uint8Array([10, 20, 30]),
from_string: () => new Uint8Array([5, 6, 7]),
crypto_box_seal: () => fakeSealed,
to_base64: () => 'AQIDBA==',
},
const sodium = {
ready: Promise.resolve(),
base64_variants: { ORIGINAL: 1 },
from_base64: () => new Uint8Array([10, 20, 30]),
from_string: () => new Uint8Array([5, 6, 7]),
crypto_box_seal: () => fakeSealed,
to_base64: () => 'AQIDBA==',
};
return { default: sodium };
});

const GITHUB_API = 'https://api.github.com';
Expand Down
12 changes: 1 addition & 11 deletions src/common/services/source-control/GithubService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from '@octokit/rest';
import sodium from 'libsodium-wrappers';
import { FileEntry, ForgeUser, RepoMetadata, RepoSecret } from '../types';
import { SourceControlService } from './SourceControlService';

Expand Down Expand Up @@ -273,18 +274,7 @@ export class GithubService implements SourceControlService {
}

async #encryptForGithub(value: string, publicKeyBase64: string): Promise<string> {
const mod = await import('libsodium-wrappers');
// The default export is the mutable sodium object where crypto functions
// are populated after ready. The ES module namespace is immutable and
// only exposes static utility exports.
type SodiumFull = typeof mod & {
crypto_box_seal(message: Uint8Array, publicKey: Uint8Array): Uint8Array;
};
const sodium = ((mod as unknown as { default?: SodiumFull }).default ?? mod) as SodiumFull;
await sodium.ready;
if (typeof sodium.crypto_box_seal !== 'function') {
throw new Error('libsodium crypto_box_seal not available');
}
const publicKey = sodium.from_base64(publicKeyBase64, sodium.base64_variants.ORIGINAL);
const encrypted = sodium.crypto_box_seal(sodium.from_string(value), publicKey);
return sodium.to_base64(encrypted, sodium.base64_variants.ORIGINAL);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"jsx": "react-jsx",
"allowJs": true,
"strict": true,
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"types": ["vitest/globals"]
},
Expand Down
12 changes: 1 addition & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3281,15 +3281,6 @@ __metadata:
languageName: node
linkType: hard

"@types/libsodium-wrappers@npm:^0.8.2":
version: 0.8.2
resolution: "@types/libsodium-wrappers@npm:0.8.2"
dependencies:
libsodium-wrappers: "npm:*"
checksum: 10c0/c19cffdad50b49e9c8e9a5c036803e6dbd345f5b81aadd875360487fc06f4f58c3f02b0e6c991e809c56d3fddb290d27c5a555fe69148e655e4c053b747417e9
languageName: node
linkType: hard

"@types/lodash@npm:^4.14.175":
version: 4.14.202
resolution: "@types/lodash@npm:4.14.202"
Expand Down Expand Up @@ -5552,7 +5543,6 @@ __metadata:
"@testing-library/jest-dom": "npm:^6.9.1"
"@testing-library/react": "npm:^12.1.5"
"@testing-library/user-event": "npm:^14.6.1"
"@types/libsodium-wrappers": "npm:^0.8.2"
"@types/node": "npm:^22.0.0"
"@types/react": "npm:^17.0.37"
"@types/react-router-dom": "npm:^5.3.3"
Expand Down Expand Up @@ -10369,7 +10359,7 @@ __metadata:
languageName: node
linkType: hard

"libsodium-wrappers@npm:*, libsodium-wrappers@npm:^0.8.4":
"libsodium-wrappers@npm:^0.8.4":
version: 0.8.4
resolution: "libsodium-wrappers@npm:0.8.4"
dependencies:
Expand Down