@cloudpss/crypto 0.5.46 → 0.5.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/wasm.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Encrypts the given data using PBKDF2 and AES-GCM.
5
+ */
6
+ export function encrypt(passphrase: Uint8Array, data: Uint8Array, aad: Uint8Array, nonce: Uint8Array, pbkdf2_iterations: number, aes_key_size: number, aes_tag_size: number): Uint8Array;
7
+ /**
8
+ * Decrypts the given data using PBKDF2 and AES-GCM.
9
+ */
10
+ export function decrypt(passphrase: Uint8Array, data: Uint8Array, aad: Uint8Array, nonce: Uint8Array, pbkdf2_iterations: number, aes_key_size: number, aes_tag_size: number): Uint8Array;
package/lib/wasm.js ADDED
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./wasm_bg.wasm";
2
+ export * from "./wasm_bg.js";
3
+ import { __wbg_set_wasm } from "./wasm_bg.js";
4
+ __wbg_set_wasm(wasm);
package/lib/wasm_bg.js ADDED
@@ -0,0 +1,103 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ let cachedUint8ArrayMemory0 = null;
8
+
9
+ function getUint8ArrayMemory0() {
10
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8ArrayMemory0;
14
+ }
15
+
16
+ let WASM_VECTOR_LEN = 0;
17
+
18
+ function passArray8ToWasm0(arg, malloc) {
19
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
20
+ getUint8ArrayMemory0().set(arg, ptr / 1);
21
+ WASM_VECTOR_LEN = arg.length;
22
+ return ptr;
23
+ }
24
+
25
+ let cachedDataViewMemory0 = null;
26
+
27
+ function getDataViewMemory0() {
28
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
29
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
30
+ }
31
+ return cachedDataViewMemory0;
32
+ }
33
+
34
+ function getArrayU8FromWasm0(ptr, len) {
35
+ ptr = ptr >>> 0;
36
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
37
+ }
38
+ /**
39
+ * Encrypts the given data using PBKDF2 and AES-GCM.
40
+ * @param {Uint8Array} passphrase
41
+ * @param {Uint8Array} data
42
+ * @param {Uint8Array} aad
43
+ * @param {Uint8Array} nonce
44
+ * @param {number} pbkdf2_iterations
45
+ * @param {number} aes_key_size
46
+ * @param {number} aes_tag_size
47
+ * @returns {Uint8Array}
48
+ */
49
+ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
50
+ try {
51
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
52
+ const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export_0);
53
+ const len0 = WASM_VECTOR_LEN;
54
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
55
+ const len1 = WASM_VECTOR_LEN;
56
+ const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export_0);
57
+ const len2 = WASM_VECTOR_LEN;
58
+ const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export_0);
59
+ const len3 = WASM_VECTOR_LEN;
60
+ wasm.encrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pbkdf2_iterations, aes_key_size, aes_tag_size);
61
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
62
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
63
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
64
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
65
+ return v5;
66
+ } finally {
67
+ wasm.__wbindgen_add_to_stack_pointer(16);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Decrypts the given data using PBKDF2 and AES-GCM.
73
+ * @param {Uint8Array} passphrase
74
+ * @param {Uint8Array} data
75
+ * @param {Uint8Array} aad
76
+ * @param {Uint8Array} nonce
77
+ * @param {number} pbkdf2_iterations
78
+ * @param {number} aes_key_size
79
+ * @param {number} aes_tag_size
80
+ * @returns {Uint8Array}
81
+ */
82
+ export function decrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
83
+ try {
84
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
85
+ const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export_0);
86
+ const len0 = WASM_VECTOR_LEN;
87
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
88
+ const len1 = WASM_VECTOR_LEN;
89
+ const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export_0);
90
+ const len2 = WASM_VECTOR_LEN;
91
+ const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export_0);
92
+ const len3 = WASM_VECTOR_LEN;
93
+ wasm.decrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pbkdf2_iterations, aes_key_size, aes_tag_size);
94
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
95
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
96
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
97
+ wasm.__wbindgen_export_1(r0, r1 * 1, 1);
98
+ return v5;
99
+ } finally {
100
+ wasm.__wbindgen_add_to_stack_pointer(16);
101
+ }
102
+ }
103
+
Binary file
@@ -0,0 +1,8 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const encrypt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
5
+ export const decrypt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
6
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
7
+ export const __wbindgen_export_0: (a: number, b: number) => number;
8
+ export const __wbindgen_export_1: (a: number, b: number, c: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudpss/crypto",
3
- "version": "0.5.46",
3
+ "version": "0.5.48",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "scripts": {
20
20
  "build": "pnpm clean && pnpm build:wasm && tsc --build --force",
21
- "build:wasm": "wasm-pack build --target bundler --release --no-pack --out-dir ../lib wasm",
21
+ "build:wasm": "wasm-pack build --target bundler --release --no-pack --out-dir ../lib wasm && rimraf lib/.gitignore",
22
22
  "test": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --experimental-vm-modules\" jest",
23
23
  "benchmark": "node ./benchmark",
24
24
  "clean": "rimraf dist lib"