mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-25 06:46:59 +00:00
- Added a new `actions.ts` file defining `WorkerActionMap` for better type management of worker actions. - Updated `client.ts`, `worker.ts`, and `decrypt.ts` to utilize the new action types, enhancing type safety. - Refactored `DecryptCommandPayload` to rename `id` to `fileId` for clarity and consistency. - Adjusted various components to align with the new payload structure and improved error handling in the worker event bus. - Enhanced tests to ensure compatibility with the new action type definitions and payload structures.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { DecipherInstance, DecipherOK, DecipherResult, Status } from '~/decrypt-worker/Deciphers';
|
|
import { KuwoHeader, KWMDecipher } from '@unlock-music/crypto';
|
|
import type { DecryptCommandOptions } from '~/decrypt-worker/types.ts';
|
|
import { chunkBuffer } from '~/decrypt-worker/util/buffer.ts';
|
|
|
|
export class KuwoMusicDecipher implements DecipherInstance {
|
|
cipherName = 'Kuwo';
|
|
|
|
async decrypt(buffer: Uint8Array, options: DecryptCommandOptions): Promise<DecipherResult | DecipherOK> {
|
|
let header: KuwoHeader | undefined;
|
|
let kwm: KWMDecipher | undefined;
|
|
|
|
try {
|
|
header = KuwoHeader.parse(buffer.subarray(0, 0x400));
|
|
kwm = new KWMDecipher(header, options.kwm2Key);
|
|
|
|
const audioBuffer = new Uint8Array(buffer.subarray(0x400));
|
|
for (const [block, offset] of chunkBuffer(audioBuffer)) {
|
|
kwm.decrypt(block, offset);
|
|
}
|
|
return Promise.resolve({
|
|
status: Status.OK,
|
|
cipherName: this.cipherName,
|
|
data: audioBuffer,
|
|
});
|
|
} finally {
|
|
kwm?.free();
|
|
header?.free();
|
|
}
|
|
}
|
|
|
|
public static make(this: void) {
|
|
return new KuwoMusicDecipher();
|
|
}
|
|
}
|