@cloudpss/crypto 0.6.0-alpha.8 → 0.6.0-beta.1

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.
@@ -11,16 +11,16 @@ export declare const
11
11
  * 加密数据
12
12
  * @throws {TypeError} 如果密码无效
13
13
  */
14
- encrypt: (data: BufferSource, passphrase: string) => Promise<Uint8Array>,
14
+ encrypt: (data: BufferSource, passphrase: string) => Promise<Uint8Array<ArrayBuffer>>,
15
15
  /**
16
16
  * 加密数据,包含不加密的附加数据
17
17
  * @throws {TypeError} 如果密码无效
18
18
  */
19
- encryptAad: (data: BufferSource, aad: BufferSource | undefined, passphrase: string) => Promise<Uint8Array>,
19
+ encryptAad: (data: BufferSource, aad: BufferSource | undefined, passphrase: string) => Promise<Uint8Array<ArrayBuffer>>,
20
20
  /**
21
21
  * 解密数据
22
22
  * @throws {TypeError} 如果数据不是有效的加密数据
23
23
  * @throws {TypeError} 如果密码无效
24
24
  */
25
- decrypt: (data: BufferSource, passphrase: string) => Promise<Uint8Array>;
25
+ decrypt: (data: BufferSource, passphrase: string) => Promise<Uint8Array<ArrayBuffer>>;
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,0BAA0B;AAC1B,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,SAAS,CAQrE;AAED,eAAO;AACH;;;GAGG;AAEH,OAAO;AACP;;;GAGG;AAEH,UAAU;AACV;;;;GAIG;AAEH,OAAO,iEACW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,0BAA0B;AAC1B,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,SAAS,CAQrE;AAED,eAAO;AACH;;;GAGG;AAEH,OAAO;AACP;;;GAGG;AAEH,UAAU;AACV;;;;GAIG;AAEH,OAAO,8EACW,CAAC"}
@@ -4,18 +4,18 @@ interface Module {
4
4
  * 加密数据
5
5
  * @throws {TypeError} 如果密码无效
6
6
  */
7
- encrypt(data: BufferSource, passphrase: string): Promise<Uint8Array>;
7
+ encrypt(data: BufferSource, passphrase: string): Promise<Uint8Array<ArrayBuffer>>;
8
8
  /**
9
9
  * 加密数据,包含不加密的附加数据
10
10
  * @throws {TypeError} 如果密码无效
11
11
  */
12
- encryptAad(data: BufferSource, aad: BufferSource | undefined, passphrase: string): Promise<Uint8Array>;
12
+ encryptAad(data: BufferSource, aad: BufferSource | undefined, passphrase: string): Promise<Uint8Array<ArrayBuffer>>;
13
13
  /**
14
14
  * 解密数据
15
15
  * @throws {TypeError} 如果数据不是有效的加密数据
16
16
  * @throws {TypeError} 如果密码无效
17
17
  */
18
- decrypt(data: BufferSource, passphrase: string): Promise<Uint8Array>;
18
+ decrypt(data: BufferSource, passphrase: string): Promise<Uint8Array<ArrayBuffer>>;
19
19
  }
20
20
  /** 创建模块 */
21
21
  export declare function createModule(impl: typeof import('#encryption') | typeof import('./wasm.js')): Module;
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/encryption/module.ts"],"names":[],"mappings":"AAsBA,SAAS;AACT,UAAU,MAAM;IACZ;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACrE;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACvG;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACxE;AAED,WAAW;AACX,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,aAAa,CAAC,GAAG,cAAc,WAAW,CAAC,GAAG,MAAM,CAkDpG"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/encryption/module.ts"],"names":[],"mappings":"AAsBA,SAAS;AACT,UAAU,MAAM;IACZ;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IAClF;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IACpH;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;CACrF;AAED,WAAW;AACX,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,aAAa,CAAC,GAAG,cAAc,WAAW,CAAC,GAAG,MAAM,CAkDpG"}
package/lib/wasm.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  /* tslint:disable */
2
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;
3
+
7
4
  /**
8
5
  * Decrypts the given data using PBKDF2 and AES-GCM.
9
6
  */
10
7
  export function decrypt(passphrase: Uint8Array, data: Uint8Array, aad: Uint8Array, nonce: Uint8Array, pbkdf2_iterations: number, aes_key_size: number, aes_tag_size: number): Uint8Array;
8
+
9
+ /**
10
+ * Encrypts the given data using PBKDF2 and AES-GCM.
11
+ */
12
+ export function encrypt(passphrase: Uint8Array, data: Uint8Array, aad: Uint8Array, nonce: Uint8Array, pbkdf2_iterations: number, aes_key_size: number, aes_tag_size: number): Uint8Array;
package/lib/wasm_bg.js CHANGED
@@ -3,9 +3,20 @@ export function __wbg_set_wasm(val) {
3
3
  wasm = val;
4
4
  }
5
5
 
6
+ function getArrayU8FromWasm0(ptr, len) {
7
+ ptr = ptr >>> 0;
8
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
9
+ }
6
10
 
7
- let cachedUint8ArrayMemory0 = null;
11
+ let cachedDataViewMemory0 = null;
12
+ function getDataViewMemory0() {
13
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
14
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
15
+ }
16
+ return cachedDataViewMemory0;
17
+ }
8
18
 
19
+ let cachedUint8ArrayMemory0 = null;
9
20
  function getUint8ArrayMemory0() {
10
21
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
22
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -13,8 +24,6 @@ function getUint8ArrayMemory0() {
13
24
  return cachedUint8ArrayMemory0;
14
25
  }
15
26
 
16
- let WASM_VECTOR_LEN = 0;
17
-
18
27
  function passArray8ToWasm0(arg, malloc) {
19
28
  const ptr = malloc(arg.length * 1, 1) >>> 0;
20
29
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -22,21 +31,10 @@ function passArray8ToWasm0(arg, malloc) {
22
31
  return ptr;
23
32
  }
24
33
 
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
- }
34
+ let WASM_VECTOR_LEN = 0;
33
35
 
34
- function getArrayU8FromWasm0(ptr, len) {
35
- ptr = ptr >>> 0;
36
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
37
- }
38
36
  /**
39
- * Encrypts the given data using PBKDF2 and AES-GCM.
37
+ * Decrypts the given data using PBKDF2 and AES-GCM.
40
38
  * @param {Uint8Array} passphrase
41
39
  * @param {Uint8Array} data
42
40
  * @param {Uint8Array} aad
@@ -46,22 +44,22 @@ function getArrayU8FromWasm0(ptr, len) {
46
44
  * @param {number} aes_tag_size
47
45
  * @returns {Uint8Array}
48
46
  */
49
- export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
47
+ export function decrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
50
48
  try {
51
49
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
52
- const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export_0);
50
+ const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export);
53
51
  const len0 = WASM_VECTOR_LEN;
54
- const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
52
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export);
55
53
  const len1 = WASM_VECTOR_LEN;
56
- const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export_0);
54
+ const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export);
57
55
  const len2 = WASM_VECTOR_LEN;
58
- const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export_0);
56
+ const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export);
59
57
  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);
58
+ wasm.decrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pbkdf2_iterations, aes_key_size, aes_tag_size);
61
59
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
62
60
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
63
61
  var v5 = getArrayU8FromWasm0(r0, r1).slice();
64
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
62
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
65
63
  return v5;
66
64
  } finally {
67
65
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -69,7 +67,7 @@ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key
69
67
  }
70
68
 
71
69
  /**
72
- * Decrypts the given data using PBKDF2 and AES-GCM.
70
+ * Encrypts the given data using PBKDF2 and AES-GCM.
73
71
  * @param {Uint8Array} passphrase
74
72
  * @param {Uint8Array} data
75
73
  * @param {Uint8Array} aad
@@ -79,25 +77,24 @@ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key
79
77
  * @param {number} aes_tag_size
80
78
  * @returns {Uint8Array}
81
79
  */
82
- export function decrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
80
+ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
83
81
  try {
84
82
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
85
- const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export_0);
83
+ const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export);
86
84
  const len0 = WASM_VECTOR_LEN;
87
- const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export_0);
85
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export);
88
86
  const len1 = WASM_VECTOR_LEN;
89
- const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export_0);
87
+ const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export);
90
88
  const len2 = WASM_VECTOR_LEN;
91
- const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export_0);
89
+ const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export);
92
90
  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);
91
+ wasm.encrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pbkdf2_iterations, aes_key_size, aes_tag_size);
94
92
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
95
93
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
96
94
  var v5 = getArrayU8FromWasm0(r0, r1).slice();
97
- wasm.__wbindgen_export_1(r0, r1 * 1, 1);
95
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
98
96
  return v5;
99
97
  } finally {
100
98
  wasm.__wbindgen_add_to_stack_pointer(16);
101
99
  }
102
100
  }
103
-
package/lib/wasm_bg.wasm CHANGED
Binary file
@@ -1,8 +1,8 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
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
4
  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;
5
+ 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;
6
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;
7
+ export const __wbindgen_export: (a: number, b: number) => number;
8
+ export const __wbindgen_export2: (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.6.0-alpha.8",
3
+ "version": "0.6.0-beta.1",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,18 +26,18 @@ interface Module {
26
26
  * 加密数据
27
27
  * @throws {TypeError} 如果密码无效
28
28
  */
29
- encrypt(data: BufferSource, passphrase: string): Promise<Uint8Array>;
29
+ encrypt(data: BufferSource, passphrase: string): Promise<Uint8Array<ArrayBuffer>>;
30
30
  /**
31
31
  * 加密数据,包含不加密的附加数据
32
32
  * @throws {TypeError} 如果密码无效
33
33
  */
34
- encryptAad(data: BufferSource, aad: BufferSource | undefined, passphrase: string): Promise<Uint8Array>;
34
+ encryptAad(data: BufferSource, aad: BufferSource | undefined, passphrase: string): Promise<Uint8Array<ArrayBuffer>>;
35
35
  /**
36
36
  * 解密数据
37
37
  * @throws {TypeError} 如果数据不是有效的加密数据
38
38
  * @throws {TypeError} 如果密码无效
39
39
  */
40
- decrypt(data: BufferSource, passphrase: string): Promise<Uint8Array>;
40
+ decrypt(data: BufferSource, passphrase: string): Promise<Uint8Array<ArrayBuffer>>;
41
41
  }
42
42
 
43
43
  /** 创建模块 */
@@ -97,14 +97,13 @@ describe('Encryption root export', () => {
97
97
 
98
98
  /**
99
99
  * 检查实现模块
100
- * @param {any} module wrapped module
101
100
  */
102
- function checkModule(module) {
101
+ function checkModule(module: { encrypt: typeof encrypt; decrypt: typeof decrypt; encryptAad: typeof encryptAad }) {
103
102
  it('has correct exports', () => {
104
103
  expect(module).toMatchObject({
105
- encrypt: expect.any(Function),
106
- decrypt: expect.any(Function),
107
- encryptAad: expect.any(Function),
104
+ encrypt: expect.any(Function) as unknown,
105
+ decrypt: expect.any(Function) as unknown,
106
+ encryptAad: expect.any(Function) as unknown,
108
107
  });
109
108
  });
110
109
 
@@ -148,10 +147,11 @@ function checkModule(module) {
148
147
 
149
148
  /**
150
149
  * 检查实现
151
- * @param {Function} encrypt encrypt
152
- * @param {Function} decrypt decrypt
153
150
  */
154
- function checkImplEncryption(encrypt, decrypt) {
151
+ function checkImplEncryption(
152
+ encrypt: typeof webImpl.encrypt | typeof wasmImpl.encrypt | typeof nodeImpl.encrypt,
153
+ decrypt: typeof webImpl.decrypt | typeof wasmImpl.decrypt | typeof nodeImpl.decrypt,
154
+ ) {
155
155
  it.each(data)(
156
156
  `$type[$length] ($tag)`,
157
157
  async ({ raw }) => {
@@ -185,6 +185,7 @@ function checkImplEncryption(encrypt, decrypt) {
185
185
 
186
186
  await expect(async () => {
187
187
  await decrypt(
188
+ // @ts-expect-error no aad
188
189
  {
189
190
  nonce: encrypted.nonce,
190
191
  data: encrypted.data,