diff --git a/package.json b/package.json index 3a1012e..b2c5e3b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/common/services/source-control/GithubService.test.ts b/src/common/services/source-control/GithubService.test.ts index ab3cb94..efe17cb 100644 --- a/src/common/services/source-control/GithubService.test.ts +++ b/src/common/services/source-control/GithubService.test.ts @@ -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'; diff --git a/src/common/services/source-control/GithubService.ts b/src/common/services/source-control/GithubService.ts index c488d7e..0e0ef59 100644 --- a/src/common/services/source-control/GithubService.ts +++ b/src/common/services/source-control/GithubService.ts @@ -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'; @@ -273,18 +274,7 @@ export class GithubService implements SourceControlService { } async #encryptForGithub(value: string, publicKeyBase64: string): Promise { - 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); diff --git a/tsconfig.json b/tsconfig.json index efe5d45..b7353a8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "jsx": "react-jsx", "allowJs": true, "strict": true, + "allowSyntheticDefaultImports": true, "noUnusedLocals": true, "types": ["vitest/globals"] }, diff --git a/yarn.lock b/yarn.lock index a65a7e3..f04ae07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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: