szld-libs 0.2.49 → 0.2.50

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/es/index.js CHANGED
@@ -128,8 +128,9 @@ const Demo = () => {
128
128
  const unitText = "条@";
129
129
  const jumpText = "跳至@";
130
130
  const pageText = "页@";
131
- const sha = new HmacSM3("123");
132
- sha.encrypt("abc");
131
+ const sm3key = "Aa123456#";
132
+ const message = "username=admin&timestamp=1758782465&modelid=19955BC7B61A43B3A982F0B2053ABC34";
133
+ HmacSM3.hmac(sm3key, message);
133
134
  return /* @__PURE__ */ jsxs("div", { style: { height: "100vh", display: "flex", flexDirection: "column", gap: 20 }, children: [
134
135
  /* @__PURE__ */ jsx(BackHeader, { title: "页头组件", isBack: true }),
135
136
  /* @__PURE__ */ jsxs(Flex, { gap: 20, align: "center", children: [
package/es/main.d.ts CHANGED
@@ -16,7 +16,7 @@ import * as utils from './utils/index';
16
16
  import * as verfyCode from './utils/verify-code';
17
17
  import AES from './utils/aes';
18
18
  import HmacSHA512 from './utils/hmacSHA512';
19
- import HmacSM3 from './utils/hmacsm3';
19
+ import HmacSM3 from './utils/hmacSM3';
20
20
  import useCaptcha from './hooks/useCaptcha';
21
21
  import useChangePwd from './hooks/useChangePwd';
22
22
  import useConfig from './hooks/useConfig';
package/es/main.js CHANGED
@@ -16,7 +16,7 @@ import * as index from "./utils/index";
16
16
  import * as verifyCode from "./utils/verify-code";
17
17
  import { default as default13 } from "./utils/aes";
18
18
  import { default as default14 } from "./utils/hmacSHA512";
19
- import { default as default15 } from "./utils/hmacsm3";
19
+ import { default as default15 } from "./utils/hmacSM3";
20
20
  import { default as default16 } from "./hooks/useCaptcha";
21
21
  import { default as default17 } from "./hooks/useChangePwd";
22
22
  import { default as default18 } from "./hooks/useConfig";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * HMAC-SM3 实现
3
+ */
4
+ declare class HmacSM3 {
5
+ private key;
6
+ constructor(key: string | Uint8Array);
7
+ /**
8
+ * 计算HMAC-SM3值
9
+ */
10
+ digest(message: string | Uint8Array): Uint8Array;
11
+ /**
12
+ * 计算HMAC-SM3值并返回十六进制字符串
13
+ */
14
+ digestHex(message: string | Uint8Array): string;
15
+ /**
16
+ * 静态方法:快速计算HMAC-SM3
17
+ */
18
+ static hmac(key: string | Uint8Array, message: string | Uint8Array): string;
19
+ }
20
+ export default HmacSM3;
@@ -0,0 +1,173 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ const _SM3 = class {
8
+ static rotateLeft(x, n) {
9
+ return x << n | x >>> 32 - n;
10
+ }
11
+ static FFj(X, Y, Z, j) {
12
+ if (j >= 0 && j <= 15) {
13
+ return X ^ Y ^ Z;
14
+ } else {
15
+ return X & Y | X & Z | Y & Z;
16
+ }
17
+ }
18
+ static GGj(X, Y, Z, j) {
19
+ if (j >= 0 && j <= 15) {
20
+ return X ^ Y ^ Z;
21
+ } else {
22
+ return X & Y | ~X & Z;
23
+ }
24
+ }
25
+ static P0(X) {
26
+ return X ^ _SM3.rotateLeft(X, 9) ^ _SM3.rotateLeft(X, 17);
27
+ }
28
+ static P1(X) {
29
+ return X ^ _SM3.rotateLeft(X, 15) ^ _SM3.rotateLeft(X, 23);
30
+ }
31
+ static pad(message) {
32
+ const bitLength = message.length * 8;
33
+ const paddingLength = (448 - (bitLength + 1) % 512 + 512) % 512;
34
+ const totalLength = (bitLength + 1 + paddingLength + 64) / 8;
35
+ const padded = new Uint8Array(totalLength);
36
+ padded.set(message);
37
+ padded[message.length] = 128;
38
+ const lengthBytes = new Uint8Array(8);
39
+ const lengthView = new DataView(lengthBytes.buffer);
40
+ lengthView.setBigUint64(0, BigInt(bitLength), false);
41
+ padded.set(lengthBytes, totalLength - 8);
42
+ return padded;
43
+ }
44
+ static processBlock(block, state) {
45
+ const W = new Uint32Array(68);
46
+ const W1 = new Uint32Array(64);
47
+ for (let i = 0; i < 16; i++) {
48
+ const view = new DataView(block.buffer, block.byteOffset + i * 4, 4);
49
+ W[i] = view.getUint32(0, false);
50
+ }
51
+ for (let j = 16; j < 68; j++) {
52
+ W[j] = _SM3.P1(W[j - 16] ^ W[j - 9] ^ _SM3.rotateLeft(W[j - 3], 15)) ^ _SM3.rotateLeft(W[j - 13], 7) ^ W[j - 6];
53
+ }
54
+ for (let j = 0; j < 64; j++) {
55
+ W1[j] = W[j] ^ W[j + 4];
56
+ }
57
+ let A = state[0];
58
+ let B = state[1];
59
+ let C = state[2];
60
+ let D = state[3];
61
+ let E = state[4];
62
+ let F = state[5];
63
+ let G = state[6];
64
+ let H = state[7];
65
+ for (let j = 0; j < 64; j++) {
66
+ const SS1 = _SM3.rotateLeft(_SM3.rotateLeft(A, 12) + E + _SM3.rotateLeft(_SM3.T[j], j), 7);
67
+ const SS2 = SS1 ^ _SM3.rotateLeft(A, 12);
68
+ const TT1 = _SM3.FFj(A, B, C, j) + D + SS2 + W1[j];
69
+ const TT2 = _SM3.GGj(E, F, G, j) + H + SS1 + W[j];
70
+ D = C;
71
+ C = _SM3.rotateLeft(B, 9);
72
+ B = A;
73
+ A = TT1;
74
+ H = G;
75
+ G = _SM3.rotateLeft(F, 19);
76
+ F = E;
77
+ E = _SM3.P0(TT2);
78
+ }
79
+ state[0] ^= A;
80
+ state[1] ^= B;
81
+ state[2] ^= C;
82
+ state[3] ^= D;
83
+ state[4] ^= E;
84
+ state[5] ^= F;
85
+ state[6] ^= G;
86
+ state[7] ^= H;
87
+ }
88
+ static hash(message) {
89
+ const padded = _SM3.pad(message);
90
+ const state = new Uint32Array(_SM3.IV);
91
+ for (let i = 0; i < padded.length; i += 64) {
92
+ const block = padded.slice(i, i + 64);
93
+ _SM3.processBlock(block, state);
94
+ }
95
+ const result = new Uint8Array(32);
96
+ const resultView = new DataView(result.buffer);
97
+ for (let i = 0; i < 8; i++) {
98
+ resultView.setUint32(i * 4, state[i], false);
99
+ }
100
+ return result;
101
+ }
102
+ static hashHex(message) {
103
+ const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
104
+ const hashBytes = _SM3.hash(msgArray);
105
+ return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
106
+ }
107
+ };
108
+ let SM3 = _SM3;
109
+ __publicField(SM3, "IV", new Uint32Array([
110
+ 1937774191,
111
+ 1226093241,
112
+ 388252375,
113
+ 3666478592,
114
+ 2842636476,
115
+ 372324522,
116
+ 3817729613,
117
+ 2969243214
118
+ ]));
119
+ __publicField(SM3, "T", new Uint32Array(64));
120
+ (() => {
121
+ for (let j = 0; j < 16; j++) {
122
+ _SM3.T[j] = 2043430169;
123
+ }
124
+ for (let j = 16; j < 64; j++) {
125
+ _SM3.T[j] = 2055708042;
126
+ }
127
+ })();
128
+ class HmacSM3 {
129
+ constructor(key) {
130
+ __publicField(this, "key");
131
+ this.key = typeof key === "string" ? new TextEncoder().encode(key) : key;
132
+ }
133
+ digest(message) {
134
+ const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
135
+ const blockSize = 64;
136
+ let keyBuffer;
137
+ if (this.key.length > blockSize) {
138
+ keyBuffer = SM3.hash(this.key);
139
+ } else {
140
+ keyBuffer = new Uint8Array(blockSize);
141
+ keyBuffer.set(this.key);
142
+ for (let i = this.key.length; i < blockSize; i++) {
143
+ keyBuffer[i] = 0;
144
+ }
145
+ }
146
+ const ipadKey = new Uint8Array(blockSize);
147
+ const opadKey = new Uint8Array(blockSize);
148
+ for (let i = 0; i < blockSize; i++) {
149
+ ipadKey[i] = keyBuffer[i] ^ 54;
150
+ opadKey[i] = keyBuffer[i] ^ 92;
151
+ }
152
+ const innerData = new Uint8Array(ipadKey.length + msgArray.length);
153
+ innerData.set(ipadKey);
154
+ innerData.set(msgArray, ipadKey.length);
155
+ const innerHash = SM3.hash(innerData);
156
+ const outerData = new Uint8Array(opadKey.length + innerHash.length);
157
+ outerData.set(opadKey);
158
+ outerData.set(innerHash, opadKey.length);
159
+ const finalHash = SM3.hash(outerData);
160
+ return finalHash;
161
+ }
162
+ digestHex(message) {
163
+ const hashBytes = this.digest(message);
164
+ return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
165
+ }
166
+ static hmac(key, message) {
167
+ const hmac = new HmacSM3(key);
168
+ return hmac.digestHex(message);
169
+ }
170
+ }
171
+ export {
172
+ HmacSM3 as default
173
+ };
package/lib/index.js CHANGED
@@ -129,8 +129,9 @@ const Demo = () => {
129
129
  const unitText = "条@";
130
130
  const jumpText = "跳至@";
131
131
  const pageText = "页@";
132
- const sha = new main.HmacSM3("123");
133
- sha.encrypt("abc");
132
+ const sm3key = "Aa123456#";
133
+ const message = "username=admin&timestamp=1758782465&modelid=19955BC7B61A43B3A982F0B2053ABC34";
134
+ main.HmacSM3.hmac(sm3key, message);
134
135
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh", display: "flex", flexDirection: "column", gap: 20 }, children: [
135
136
  /* @__PURE__ */ jsxRuntime.jsx(main.BackHeader, { title: "页头组件", isBack: true }),
136
137
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 20, align: "center", children: [
package/lib/main.d.ts CHANGED
@@ -16,7 +16,7 @@ import * as utils from './utils/index';
16
16
  import * as verfyCode from './utils/verify-code';
17
17
  import AES from './utils/aes';
18
18
  import HmacSHA512 from './utils/hmacSHA512';
19
- import HmacSM3 from './utils/hmacsm3';
19
+ import HmacSM3 from './utils/hmacSM3';
20
20
  import useCaptcha from './hooks/useCaptcha';
21
21
  import useChangePwd from './hooks/useChangePwd';
22
22
  import useConfig from './hooks/useConfig';
package/lib/main.js CHANGED
@@ -18,7 +18,7 @@ const index = require("./utils/index");
18
18
  const verifyCode = require("./utils/verify-code");
19
19
  const aes = require("./utils/aes");
20
20
  const hmacSHA512 = require("./utils/hmacSHA512");
21
- const hmacsm3 = require("./utils/hmacsm3");
21
+ const hmacSM3 = require("./utils/hmacSM3");
22
22
  const useCaptcha = require("./hooks/useCaptcha");
23
23
  const useChangePwd = require("./hooks/useChangePwd");
24
24
  const useConfig = require("./hooks/useConfig");
@@ -67,7 +67,7 @@ exports.utils = index__namespace;
67
67
  exports.verfyCode = verifyCode__namespace;
68
68
  exports.AES = aes;
69
69
  exports.HmacSHA512 = hmacSHA512;
70
- exports.HmacSM3 = hmacsm3;
70
+ exports.HmacSM3 = hmacSM3;
71
71
  exports.useCaptcha = useCaptcha;
72
72
  exports.useChangePwd = useChangePwd;
73
73
  exports.useConfig = useConfig;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * HMAC-SM3 实现
3
+ */
4
+ declare class HmacSM3 {
5
+ private key;
6
+ constructor(key: string | Uint8Array);
7
+ /**
8
+ * 计算HMAC-SM3值
9
+ */
10
+ digest(message: string | Uint8Array): Uint8Array;
11
+ /**
12
+ * 计算HMAC-SM3值并返回十六进制字符串
13
+ */
14
+ digestHex(message: string | Uint8Array): string;
15
+ /**
16
+ * 静态方法:快速计算HMAC-SM3
17
+ */
18
+ static hmac(key: string | Uint8Array, message: string | Uint8Array): string;
19
+ }
20
+ export default HmacSM3;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => {
5
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ return value;
7
+ };
8
+ const _SM3 = class {
9
+ static rotateLeft(x, n) {
10
+ return x << n | x >>> 32 - n;
11
+ }
12
+ static FFj(X, Y, Z, j) {
13
+ if (j >= 0 && j <= 15) {
14
+ return X ^ Y ^ Z;
15
+ } else {
16
+ return X & Y | X & Z | Y & Z;
17
+ }
18
+ }
19
+ static GGj(X, Y, Z, j) {
20
+ if (j >= 0 && j <= 15) {
21
+ return X ^ Y ^ Z;
22
+ } else {
23
+ return X & Y | ~X & Z;
24
+ }
25
+ }
26
+ static P0(X) {
27
+ return X ^ _SM3.rotateLeft(X, 9) ^ _SM3.rotateLeft(X, 17);
28
+ }
29
+ static P1(X) {
30
+ return X ^ _SM3.rotateLeft(X, 15) ^ _SM3.rotateLeft(X, 23);
31
+ }
32
+ static pad(message) {
33
+ const bitLength = message.length * 8;
34
+ const paddingLength = (448 - (bitLength + 1) % 512 + 512) % 512;
35
+ const totalLength = (bitLength + 1 + paddingLength + 64) / 8;
36
+ const padded = new Uint8Array(totalLength);
37
+ padded.set(message);
38
+ padded[message.length] = 128;
39
+ const lengthBytes = new Uint8Array(8);
40
+ const lengthView = new DataView(lengthBytes.buffer);
41
+ lengthView.setBigUint64(0, BigInt(bitLength), false);
42
+ padded.set(lengthBytes, totalLength - 8);
43
+ return padded;
44
+ }
45
+ static processBlock(block, state) {
46
+ const W = new Uint32Array(68);
47
+ const W1 = new Uint32Array(64);
48
+ for (let i = 0; i < 16; i++) {
49
+ const view = new DataView(block.buffer, block.byteOffset + i * 4, 4);
50
+ W[i] = view.getUint32(0, false);
51
+ }
52
+ for (let j = 16; j < 68; j++) {
53
+ W[j] = _SM3.P1(W[j - 16] ^ W[j - 9] ^ _SM3.rotateLeft(W[j - 3], 15)) ^ _SM3.rotateLeft(W[j - 13], 7) ^ W[j - 6];
54
+ }
55
+ for (let j = 0; j < 64; j++) {
56
+ W1[j] = W[j] ^ W[j + 4];
57
+ }
58
+ let A = state[0];
59
+ let B = state[1];
60
+ let C = state[2];
61
+ let D = state[3];
62
+ let E = state[4];
63
+ let F = state[5];
64
+ let G = state[6];
65
+ let H = state[7];
66
+ for (let j = 0; j < 64; j++) {
67
+ const SS1 = _SM3.rotateLeft(_SM3.rotateLeft(A, 12) + E + _SM3.rotateLeft(_SM3.T[j], j), 7);
68
+ const SS2 = SS1 ^ _SM3.rotateLeft(A, 12);
69
+ const TT1 = _SM3.FFj(A, B, C, j) + D + SS2 + W1[j];
70
+ const TT2 = _SM3.GGj(E, F, G, j) + H + SS1 + W[j];
71
+ D = C;
72
+ C = _SM3.rotateLeft(B, 9);
73
+ B = A;
74
+ A = TT1;
75
+ H = G;
76
+ G = _SM3.rotateLeft(F, 19);
77
+ F = E;
78
+ E = _SM3.P0(TT2);
79
+ }
80
+ state[0] ^= A;
81
+ state[1] ^= B;
82
+ state[2] ^= C;
83
+ state[3] ^= D;
84
+ state[4] ^= E;
85
+ state[5] ^= F;
86
+ state[6] ^= G;
87
+ state[7] ^= H;
88
+ }
89
+ static hash(message) {
90
+ const padded = _SM3.pad(message);
91
+ const state = new Uint32Array(_SM3.IV);
92
+ for (let i = 0; i < padded.length; i += 64) {
93
+ const block = padded.slice(i, i + 64);
94
+ _SM3.processBlock(block, state);
95
+ }
96
+ const result = new Uint8Array(32);
97
+ const resultView = new DataView(result.buffer);
98
+ for (let i = 0; i < 8; i++) {
99
+ resultView.setUint32(i * 4, state[i], false);
100
+ }
101
+ return result;
102
+ }
103
+ static hashHex(message) {
104
+ const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
105
+ const hashBytes = _SM3.hash(msgArray);
106
+ return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
107
+ }
108
+ };
109
+ let SM3 = _SM3;
110
+ __publicField(SM3, "IV", new Uint32Array([
111
+ 1937774191,
112
+ 1226093241,
113
+ 388252375,
114
+ 3666478592,
115
+ 2842636476,
116
+ 372324522,
117
+ 3817729613,
118
+ 2969243214
119
+ ]));
120
+ __publicField(SM3, "T", new Uint32Array(64));
121
+ (() => {
122
+ for (let j = 0; j < 16; j++) {
123
+ _SM3.T[j] = 2043430169;
124
+ }
125
+ for (let j = 16; j < 64; j++) {
126
+ _SM3.T[j] = 2055708042;
127
+ }
128
+ })();
129
+ class HmacSM3 {
130
+ constructor(key) {
131
+ __publicField(this, "key");
132
+ this.key = typeof key === "string" ? new TextEncoder().encode(key) : key;
133
+ }
134
+ digest(message) {
135
+ const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
136
+ const blockSize = 64;
137
+ let keyBuffer;
138
+ if (this.key.length > blockSize) {
139
+ keyBuffer = SM3.hash(this.key);
140
+ } else {
141
+ keyBuffer = new Uint8Array(blockSize);
142
+ keyBuffer.set(this.key);
143
+ for (let i = this.key.length; i < blockSize; i++) {
144
+ keyBuffer[i] = 0;
145
+ }
146
+ }
147
+ const ipadKey = new Uint8Array(blockSize);
148
+ const opadKey = new Uint8Array(blockSize);
149
+ for (let i = 0; i < blockSize; i++) {
150
+ ipadKey[i] = keyBuffer[i] ^ 54;
151
+ opadKey[i] = keyBuffer[i] ^ 92;
152
+ }
153
+ const innerData = new Uint8Array(ipadKey.length + msgArray.length);
154
+ innerData.set(ipadKey);
155
+ innerData.set(msgArray, ipadKey.length);
156
+ const innerHash = SM3.hash(innerData);
157
+ const outerData = new Uint8Array(opadKey.length + innerHash.length);
158
+ outerData.set(opadKey);
159
+ outerData.set(innerHash, opadKey.length);
160
+ const finalHash = SM3.hash(outerData);
161
+ return finalHash;
162
+ }
163
+ digestHex(message) {
164
+ const hashBytes = this.digest(message);
165
+ return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
166
+ }
167
+ static hmac(key, message) {
168
+ const hmac = new HmacSM3(key);
169
+ return hmac.digestHex(message);
170
+ }
171
+ }
172
+ module.exports = HmacSM3;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.2.49",
4
+ "version": "0.2.50",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -18,8 +18,7 @@
18
18
  "react-dom": "^18.2.0",
19
19
  "react-resizable": "^3.0.5",
20
20
  "react-router-dom": "^6.6.1",
21
- "react-window": "^1.8.9",
22
- "sm-crypto": "^0.3.13"
21
+ "react-window": "^1.8.9"
23
22
  },
24
23
  "devDependencies": {
25
24
  "@types/crypto-js": "^4.2.1",
@@ -1,7 +0,0 @@
1
- declare class HmacSM3 {
2
- /** 密钥 */
3
- secretKey?: string;
4
- constructor(secretKey?: string);
5
- encrypt(message: string): string;
6
- }
7
- export default HmacSM3;
@@ -1,20 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import { sm3 } from "sm-crypto";
8
- class HmacSM3 {
9
- constructor(secretKey) {
10
- __publicField(this, "secretKey");
11
- this.secretKey = secretKey;
12
- }
13
- encrypt(message) {
14
- const params = this.secretKey ? { key: this.secretKey } : void 0;
15
- return sm3(message, params);
16
- }
17
- }
18
- export {
19
- HmacSM3 as default
20
- };
@@ -1,7 +0,0 @@
1
- declare class HmacSM3 {
2
- /** 密钥 */
3
- secretKey?: string;
4
- constructor(secretKey?: string);
5
- encrypt(message: string): string;
6
- }
7
- export default HmacSM3;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
8
- const smCrypto = require("sm-crypto");
9
- class HmacSM3 {
10
- constructor(secretKey) {
11
- __publicField(this, "secretKey");
12
- this.secretKey = secretKey;
13
- }
14
- encrypt(message) {
15
- const params = this.secretKey ? { key: this.secretKey } : void 0;
16
- return smCrypto.sm3(message, params);
17
- }
18
- }
19
- module.exports = HmacSM3;