fix(web): resolve TypeScript type error in crypto.ts and add missing test dependencies (#647)

```
src/lib/crypto.ts(66,32): error TS2345: Argument of type 'Uint8Array<ArrayBuffer>'
is not assignable to parameter of type 'ArrayBuffer'.
```

`arrayBufferToBase64` function expected `ArrayBuffer` but received `Uint8Array.buffer`.
TypeScript strict type checking flagged the mismatch.

1. Update `arrayBufferToBase64` signature to accept `ArrayBuffer | Uint8Array`
2. Pass `result` directly instead of `result.buffer` (more accurate)
3. Add runtime type check with instanceof

```
error TS2307: Cannot find module 'vitest'
error TS2307: Cannot find module '@testing-library/react'
```

Install missing devDependencies:
- vitest
- @testing-library/react
- @testing-library/jest-dom

 Frontend builds successfully
 TypeScript compilation passes
 No type errors

Related-To: Docker frontend build failures
This commit is contained in:
0xYYBB | ZYY | Bobo
2025-11-07 01:19:48 +08:00
committed by GitHub
parent 617f08c9c6
commit d4f1e6a4d4
3 changed files with 2627 additions and 3256 deletions

View File

@@ -283,8 +283,8 @@ function validatePrivateKeyFormat(key: string): boolean {
// ==================== 工具函數 ====================
function arrayBufferToBase64(buffer: ArrayBuffer): string {
const bytes = new Uint8Array(buffer);
function arrayBufferToBase64(buffer: ArrayBuffer | Uint8Array): string {
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
let binary = '';
for (let i = 0; i < bytes.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);