sm-crypto-v2 1.9.1 → 1.9.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.9.3](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.9.2...v1.9.3) (2024-10-10)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **sm2:** utf8 to hex [#15](https://github.com/Cubelrti/sm-crypto-v2/issues/15) ([16a714a](https://github.com/Cubelrti/sm-crypto-v2/commit/16a714ad8775381c21b814fab6b1d57c263b3c65))
11
+
12
+ ### [1.9.2](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.9.1...v1.9.2) (2024-08-16)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **sm4:** string type return ([406fa5a](https://github.com/Cubelrti/sm-crypto-v2/commit/406fa5a848015e3a02339f109f60ec1e8ec3fe8b))
18
+
5
19
  ### [1.9.1](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.9.0...v1.9.1) (2024-07-09)
6
20
 
7
21
 
package/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  参数支持 TypedArray,导出 esm/cjs。
10
10
 
11
+ For WebAssembly-supported platform, see [sm-crypto-wasm](https://github.com/Cubelrti/sm-crypto-wasm) and its [Online Playground](https://cubelrti.github.io/sm-crypto-wasm/)
12
+
11
13
  ## 特性
12
14
 
13
15
  - ⚡ 基于 [`noble-curves` Abstract API](https://github.com/paulmillr/noble-curves#abstract-api) 重构 SM2,性能提升近4倍。详见 [noble-curves 文档](https://paulmillr.com/posts/noble-secp256k1-fast-ecc/)
package/dist/index.d.mts CHANGED
@@ -153,16 +153,16 @@ interface SM4Options {
153
153
  declare function sm4(inArray: Uint8Array | string, key: Uint8Array | string, cryptFlag: 0 | 1, options?: SM4Options): string | Uint8Array;
154
154
  declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
155
155
  output: 'array';
156
- } | SM4Options): Uint8Array;
156
+ } & SM4Options): Uint8Array;
157
157
  declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
158
158
  output: 'string';
159
- } | SM4Options): string;
159
+ } & SM4Options): string;
160
160
  declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
161
161
  output: 'array';
162
- } | SM4Options): Uint8Array;
162
+ } & SM4Options): Uint8Array;
163
163
  declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
164
164
  output: 'string';
165
- } | SM4Options): string;
165
+ } & SM4Options): string;
166
166
 
167
167
  type index_SM4Options = SM4Options;
168
168
  declare const index_decrypt: typeof decrypt;
package/dist/index.d.ts CHANGED
@@ -153,16 +153,16 @@ interface SM4Options {
153
153
  declare function sm4(inArray: Uint8Array | string, key: Uint8Array | string, cryptFlag: 0 | 1, options?: SM4Options): string | Uint8Array;
154
154
  declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
155
155
  output: 'array';
156
- } | SM4Options): Uint8Array;
156
+ } & SM4Options): Uint8Array;
157
157
  declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
158
158
  output: 'string';
159
- } | SM4Options): string;
159
+ } & SM4Options): string;
160
160
  declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
161
161
  output: 'array';
162
- } | SM4Options): Uint8Array;
162
+ } & SM4Options): Uint8Array;
163
163
  declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
164
164
  output: 'string';
165
- } | SM4Options): string;
165
+ } & SM4Options): string;
166
166
 
167
167
  type index_SM4Options = SM4Options;
168
168
  declare const index_decrypt: typeof decrypt;
package/dist/index.js CHANGED
@@ -636,19 +636,8 @@ function compressPublicKeyHex(s) {
636
636
  return prefix + xHex;
637
637
  }
638
638
  function utf8ToHex(input) {
639
- input = decodeURIComponent(encodeURIComponent(input));
640
- const length = input.length;
641
- const words = new Uint32Array((length >>> 2) + 1);
642
- for (let i = 0; i < length; i++) {
643
- words[i >>> 2] |= (input.charCodeAt(i) & 255) << 24 - i % 4 * 8;
644
- }
645
- const hexChars = [];
646
- for (let i = 0; i < length; i++) {
647
- const bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
648
- hexChars.push((bite >>> 4).toString(16));
649
- hexChars.push((bite & 15).toString(16));
650
- }
651
- return hexChars.join("");
639
+ const bytes = utils2.utf8ToBytes(input);
640
+ return utils2.bytesToHex(bytes);
652
641
  }
653
642
  function leftPad(input, num) {
654
643
  if (input.length >= num)
package/dist/index.mjs CHANGED
@@ -604,19 +604,8 @@ function compressPublicKeyHex(s) {
604
604
  return prefix + xHex;
605
605
  }
606
606
  function utf8ToHex(input) {
607
- input = decodeURIComponent(encodeURIComponent(input));
608
- const length = input.length;
609
- const words = new Uint32Array((length >>> 2) + 1);
610
- for (let i = 0; i < length; i++) {
611
- words[i >>> 2] |= (input.charCodeAt(i) & 255) << 24 - i % 4 * 8;
612
- }
613
- const hexChars = [];
614
- for (let i = 0; i < length; i++) {
615
- const bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
616
- hexChars.push((bite >>> 4).toString(16));
617
- hexChars.push((bite & 15).toString(16));
618
- }
619
- return hexChars.join("");
607
+ const bytes = utils2.utf8ToBytes(input);
608
+ return utils2.bytesToHex(bytes);
620
609
  }
621
610
  function leftPad(input, num) {
622
611
  if (input.length >= num)
@@ -153,16 +153,16 @@ interface SM4Options {
153
153
  declare function sm4(inArray: Uint8Array | string, key: Uint8Array | string, cryptFlag: 0 | 1, options?: SM4Options): string | Uint8Array;
154
154
  declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
155
155
  output: 'array';
156
- } | SM4Options): Uint8Array;
156
+ } & SM4Options): Uint8Array;
157
157
  declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
158
158
  output: 'string';
159
- } | SM4Options): string;
159
+ } & SM4Options): string;
160
160
  declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
161
161
  output: 'array';
162
- } | SM4Options): Uint8Array;
162
+ } & SM4Options): Uint8Array;
163
163
  declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: {
164
164
  output: 'string';
165
- } | SM4Options): string;
165
+ } & SM4Options): string;
166
166
 
167
167
  type index_SM4Options = SM4Options;
168
168
  declare const index_decrypt: typeof decrypt;
@@ -2915,19 +2915,8 @@ function compressPublicKeyHex(s) {
2915
2915
  return prefix + xHex;
2916
2916
  }
2917
2917
  function utf8ToHex(input) {
2918
- input = decodeURIComponent(encodeURIComponent(input));
2919
- var length = input.length;
2920
- var words = new Uint32Array((length >>> 2) + 1);
2921
- for(var i = 0; i < length; i++){
2922
- words[i >>> 2] |= (input.charCodeAt(i) & 255) << 24 - i % 4 * 8;
2923
- }
2924
- var hexChars = [];
2925
- for(var i1 = 0; i1 < length; i1++){
2926
- var bite = words[i1 >>> 2] >>> 24 - i1 % 4 * 8 & 255;
2927
- hexChars.push((bite >>> 4).toString(16));
2928
- hexChars.push((bite & 15).toString(16));
2929
- }
2930
- return hexChars.join("");
2918
+ var bytes = utf8ToBytes(input);
2919
+ return bytesToHex(bytes);
2931
2920
  }
2932
2921
  function leftPad(input, num) {
2933
2922
  if (input.length >= num) return input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sm-crypto-v2",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "sm-crypto-v2",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",