From 02af645a7622643d5f29599f318254361efdccbf Mon Sep 17 00:00:00 2001 From: xhacker-zzz <63585800+xhacker-zzz@users.noreply.github.com> Date: Fri, 20 Jan 2023 00:19:14 +0800 Subject: [PATCH] add files for npm package --- npm/.npmrc | 1 + npm/KgmLegacy.d.ts | 63 ++++++++++++++++++++++++++++++++++++++++++ npm/KgmWasm.d.ts | 63 ++++++++++++++++++++++++++++++++++++++++++ npm/KgmWasmBundle.d.ts | 63 ++++++++++++++++++++++++++++++++++++++++++ npm/package.json | 24 ++++++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 npm/.npmrc create mode 100644 npm/KgmLegacy.d.ts create mode 100644 npm/KgmWasm.d.ts create mode 100644 npm/KgmWasmBundle.d.ts create mode 100644 npm/package.json diff --git a/npm/.npmrc b/npm/.npmrc new file mode 100644 index 0000000..ae64359 --- /dev/null +++ b/npm/.npmrc @@ -0,0 +1 @@ +//registry.npmjs.org/:_authToken=${NPM_TOKEN} diff --git a/npm/KgmLegacy.d.ts b/npm/KgmLegacy.d.ts new file mode 100644 index 0000000..194fc00 --- /dev/null +++ b/npm/KgmLegacy.d.ts @@ -0,0 +1,63 @@ +export type WASM_ptr = number; +export type WASM_NUMBER = "i8" | "i16" | "i32" | "i64" | "float" | "double"; + +export declare interface WASMExportedRuntime { + /** + * Emscripten HEAP, use this for raw memory access. + * @type {Uint8Array} + */ + HEAPU8: Uint8Array; + + /** + * Allocate a block of {@link size} bytes of memory in Emscripten HEAP + * @param size Size of the memory block, in bytes. + * @returns {WASM_ptr} Returns a pointer to the beginning of the block. + */ + _malloc(size: number): WASM_ptr; + + /** + * Free an allocated block of memory. + * @param ptr Pointer to a memory block previously allocated with `malloc`. + */ + _free(ptr: WASM_ptr): void; + + /** + * Write an uint8 array to the Emscripten HEAP. + * @param data Data to be written inside the Emscripten HEAP. + * @param bufferPointer Address pointer + */ + writeArrayToMemory(data: Uint8Array, bufferPointer: WASM_ptr): void; +} + +export declare interface KgmCrypto extends WASMExportedRuntime { + /** + * Decryption preparations using the beginning-of-file buffer. + * @param blob WASM ptr points to the beginning of the beginning-of-file buffer. + * @param blobSize size of {@link blob}. + * @param ext extension of the _original file_. + */ + preDec( + blob: WASM_ptr, + blobSize: number, + ext: string + ): number; + + /** + * Decrypt a block. + * @param blob Pointer to buffer allocated using {@link _malloc}. + * Data can be written here using {@link writeArrayToMemory}. + * @param size Size of the provided buffer. + * @param offset Offset of the buffer from _original file_. + * This parameter is _required_ to derive correct key. + */ + decBlob( + blob: WASM_ptr, + blobSize: number, + offset: number + ): void; +} + +/** + * Factory to initialise KgmCryptoModule. + */ +export default function KgmCryptoModule(): Promise; \ No newline at end of file diff --git a/npm/KgmWasm.d.ts b/npm/KgmWasm.d.ts new file mode 100644 index 0000000..194fc00 --- /dev/null +++ b/npm/KgmWasm.d.ts @@ -0,0 +1,63 @@ +export type WASM_ptr = number; +export type WASM_NUMBER = "i8" | "i16" | "i32" | "i64" | "float" | "double"; + +export declare interface WASMExportedRuntime { + /** + * Emscripten HEAP, use this for raw memory access. + * @type {Uint8Array} + */ + HEAPU8: Uint8Array; + + /** + * Allocate a block of {@link size} bytes of memory in Emscripten HEAP + * @param size Size of the memory block, in bytes. + * @returns {WASM_ptr} Returns a pointer to the beginning of the block. + */ + _malloc(size: number): WASM_ptr; + + /** + * Free an allocated block of memory. + * @param ptr Pointer to a memory block previously allocated with `malloc`. + */ + _free(ptr: WASM_ptr): void; + + /** + * Write an uint8 array to the Emscripten HEAP. + * @param data Data to be written inside the Emscripten HEAP. + * @param bufferPointer Address pointer + */ + writeArrayToMemory(data: Uint8Array, bufferPointer: WASM_ptr): void; +} + +export declare interface KgmCrypto extends WASMExportedRuntime { + /** + * Decryption preparations using the beginning-of-file buffer. + * @param blob WASM ptr points to the beginning of the beginning-of-file buffer. + * @param blobSize size of {@link blob}. + * @param ext extension of the _original file_. + */ + preDec( + blob: WASM_ptr, + blobSize: number, + ext: string + ): number; + + /** + * Decrypt a block. + * @param blob Pointer to buffer allocated using {@link _malloc}. + * Data can be written here using {@link writeArrayToMemory}. + * @param size Size of the provided buffer. + * @param offset Offset of the buffer from _original file_. + * This parameter is _required_ to derive correct key. + */ + decBlob( + blob: WASM_ptr, + blobSize: number, + offset: number + ): void; +} + +/** + * Factory to initialise KgmCryptoModule. + */ +export default function KgmCryptoModule(): Promise; \ No newline at end of file diff --git a/npm/KgmWasmBundle.d.ts b/npm/KgmWasmBundle.d.ts new file mode 100644 index 0000000..194fc00 --- /dev/null +++ b/npm/KgmWasmBundle.d.ts @@ -0,0 +1,63 @@ +export type WASM_ptr = number; +export type WASM_NUMBER = "i8" | "i16" | "i32" | "i64" | "float" | "double"; + +export declare interface WASMExportedRuntime { + /** + * Emscripten HEAP, use this for raw memory access. + * @type {Uint8Array} + */ + HEAPU8: Uint8Array; + + /** + * Allocate a block of {@link size} bytes of memory in Emscripten HEAP + * @param size Size of the memory block, in bytes. + * @returns {WASM_ptr} Returns a pointer to the beginning of the block. + */ + _malloc(size: number): WASM_ptr; + + /** + * Free an allocated block of memory. + * @param ptr Pointer to a memory block previously allocated with `malloc`. + */ + _free(ptr: WASM_ptr): void; + + /** + * Write an uint8 array to the Emscripten HEAP. + * @param data Data to be written inside the Emscripten HEAP. + * @param bufferPointer Address pointer + */ + writeArrayToMemory(data: Uint8Array, bufferPointer: WASM_ptr): void; +} + +export declare interface KgmCrypto extends WASMExportedRuntime { + /** + * Decryption preparations using the beginning-of-file buffer. + * @param blob WASM ptr points to the beginning of the beginning-of-file buffer. + * @param blobSize size of {@link blob}. + * @param ext extension of the _original file_. + */ + preDec( + blob: WASM_ptr, + blobSize: number, + ext: string + ): number; + + /** + * Decrypt a block. + * @param blob Pointer to buffer allocated using {@link _malloc}. + * Data can be written here using {@link writeArrayToMemory}. + * @param size Size of the provided buffer. + * @param offset Offset of the buffer from _original file_. + * This parameter is _required_ to derive correct key. + */ + decBlob( + blob: WASM_ptr, + blobSize: number, + offset: number + ): void; +} + +/** + * Factory to initialise KgmCryptoModule. + */ +export default function KgmCryptoModule(): Promise; \ No newline at end of file diff --git a/npm/package.json b/npm/package.json new file mode 100644 index 0000000..e0c345c --- /dev/null +++ b/npm/package.json @@ -0,0 +1,24 @@ +{ + "name": "@xhacker/kgmwasm", + "version": "1.0.0", + "description": "WASM for Kgm Encryption & Decryption", + "main": "KgmWasmBundle.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/xhacker-zzz/KgmWasm.git" + }, + "keywords": [ + "unlock-music", + "kgm", + "WASM" + ], + "author": "xhacker-zzz", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/xhacker-zzz/KgmWasm/issues" + }, + "homepage": "https://github.com/xhacker-zzz/KgmWasm#readme" +}