@cloudpss/crypto 0.6.0-alpha.1 → 0.6.0-alpha.11

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,10 @@
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;
7
3
  /**
8
4
  * Decrypts the given data using PBKDF2 and AES-GCM.
9
5
  */
10
6
  export function decrypt(passphrase: Uint8Array, data: Uint8Array, aad: Uint8Array, nonce: Uint8Array, pbkdf2_iterations: number, aes_key_size: number, aes_tag_size: number): Uint8Array;
7
+ /**
8
+ * Encrypts the given data using PBKDF2 and AES-GCM.
9
+ */
10
+ 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
@@ -36,7 +36,7 @@ function getArrayU8FromWasm0(ptr, len) {
36
36
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
37
37
  }
38
38
  /**
39
- * Encrypts the given data using PBKDF2 and AES-GCM.
39
+ * Decrypts the given data using PBKDF2 and AES-GCM.
40
40
  * @param {Uint8Array} passphrase
41
41
  * @param {Uint8Array} data
42
42
  * @param {Uint8Array} aad
@@ -46,7 +46,7 @@ function getArrayU8FromWasm0(ptr, len) {
46
46
  * @param {number} aes_tag_size
47
47
  * @returns {Uint8Array}
48
48
  */
49
- export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
49
+ export function decrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
50
50
  try {
51
51
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
52
52
  const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export_0);
@@ -57,7 +57,7 @@ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key
57
57
  const len2 = WASM_VECTOR_LEN;
58
58
  const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export_0);
59
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);
60
+ wasm.decrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pbkdf2_iterations, aes_key_size, aes_tag_size);
61
61
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
62
62
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
63
63
  var v5 = getArrayU8FromWasm0(r0, r1).slice();
@@ -69,7 +69,7 @@ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key
69
69
  }
70
70
 
71
71
  /**
72
- * Decrypts the given data using PBKDF2 and AES-GCM.
72
+ * Encrypts the given data using PBKDF2 and AES-GCM.
73
73
  * @param {Uint8Array} passphrase
74
74
  * @param {Uint8Array} data
75
75
  * @param {Uint8Array} aad
@@ -79,7 +79,7 @@ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key
79
79
  * @param {number} aes_tag_size
80
80
  * @returns {Uint8Array}
81
81
  */
82
- export function decrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
82
+ export function encrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key_size, aes_tag_size) {
83
83
  try {
84
84
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
85
85
  const ptr0 = passArray8ToWasm0(passphrase, wasm.__wbindgen_export_0);
@@ -90,7 +90,7 @@ export function decrypt(passphrase, data, aad, nonce, pbkdf2_iterations, aes_key
90
90
  const len2 = WASM_VECTOR_LEN;
91
91
  const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export_0);
92
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);
93
+ wasm.encrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pbkdf2_iterations, aes_key_size, aes_tag_size);
94
94
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
95
95
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
96
96
  var v5 = getArrayU8FromWasm0(r0, r1).slice();
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
7
  export const __wbindgen_export_0: (a: number, b: number) => number;
8
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.6.0-alpha.1",
3
+ "version": "0.6.0-alpha.11",
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,
package/jest.config.js DELETED
@@ -1,3 +0,0 @@
1
- import { config } from '../jest.config.js';
2
-
3
- export default { ...config };
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.test"
3
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../tsconfig.build",
3
- "compilerOptions": {
4
- "paths": {
5
- "#encryption": ["./src/encryption/node.ts", "./src/encryption/browser.ts"],
6
- "#lib-wasm": ["./lib/wasm.d.ts"]
7
- }
8
- }
9
- }