sm-crypto-v2 1.13.0 → 1.15.0
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 +14 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/index.mjs +5 -2
- package/dist/index.umd.js +3139 -0
- package/miniprogram_dist/index.d.ts +5 -2
- package/miniprogram_dist/index.js +9 -4
- package/package.json +4 -2
- package/tsup.config.umd.ts +20 -0
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.15.0](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.14.0...v1.15.0) (2025-10-11)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* support umd ([1fe0ddb](https://github.com/Cubelrti/sm-crypto-v2/commit/1fe0ddb4874ea7ade10beff7e43b7bb5f3335c71))
|
11
|
+
|
12
|
+
## [1.14.0](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.13.0...v1.14.0) (2025-09-05)
|
13
|
+
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* **sm2:** expose ecdh interface and test cases ([68af176](https://github.com/Cubelrti/sm-crypto-v2/commit/68af176fd4013ea0e3165ad31c21f9cae590fcf7))
|
18
|
+
|
5
19
|
## [1.13.0](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.12.0...v1.13.0) (2025-07-15)
|
6
20
|
|
7
21
|
|
package/dist/index.d.mts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as utils from '@noble/curves/abstract/utils';
|
1
2
|
import { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
2
3
|
|
3
4
|
interface KeyPair {
|
@@ -45,6 +46,8 @@ declare function initRNGPool(): Promise<void>;
|
|
45
46
|
|
46
47
|
declare function calculateSharedKey(keypairA: KeyPair, ephemeralKeypairA: KeyPair, publicKeyB: string, ephemeralPublicKeyB: string, sharedKeyLength: number, isRecipient?: boolean, idA?: string, idB?: string): Uint8Array<ArrayBuffer>;
|
47
48
|
|
49
|
+
declare const getSharedSecret: (privateA: utils.PrivKey, publicB: utils.Hex, isCompressed?: boolean) => Uint8Array;
|
50
|
+
|
48
51
|
declare const EmptyArray: Uint8Array<ArrayBuffer>;
|
49
52
|
/**
|
50
53
|
* 加密
|
@@ -136,7 +139,7 @@ declare const index$1_precomputePublicKey: typeof precomputePublicKey;
|
|
136
139
|
declare const index$1_utf8ToHex: typeof utf8ToHex;
|
137
140
|
declare const index$1_verifyPublicKey: typeof verifyPublicKey;
|
138
141
|
declare namespace index$1 {
|
139
|
-
export { index$1_EmptyArray as EmptyArray, type index$1_KeyPair as KeyPair, type index$1_SignaturePoint as SignaturePoint, index$1_arrayToHex as arrayToHex, index$1_arrayToUtf8 as arrayToUtf8, index$1_calculateSharedKey as calculateSharedKey, index$1_comparePublicKeyHex as comparePublicKeyHex, index$1_compressPublicKeyHex as compressPublicKeyHex, index$1_doDecrypt as doDecrypt, index$1_doEncrypt as doEncrypt, index$1_doSignature as doSignature, index$1_doVerifySignature as doVerifySignature, index$1_generateKeyPairHex as generateKeyPairHex, index$1_getHash as getHash, index$1_getPoint as getPoint, index$1_getPublicKeyFromPrivateKey as getPublicKeyFromPrivateKey, index$1_getZ as getZ, index$1_hexToArray as hexToArray, index$1_initRNGPool as initRNGPool, index$1_leftPad as leftPad, index$1_precomputePublicKey as precomputePublicKey, index$1_utf8ToHex as utf8ToHex, index$1_verifyPublicKey as verifyPublicKey };
|
142
|
+
export { index$1_EmptyArray as EmptyArray, type index$1_KeyPair as KeyPair, type index$1_SignaturePoint as SignaturePoint, index$1_arrayToHex as arrayToHex, index$1_arrayToUtf8 as arrayToUtf8, index$1_calculateSharedKey as calculateSharedKey, index$1_comparePublicKeyHex as comparePublicKeyHex, index$1_compressPublicKeyHex as compressPublicKeyHex, index$1_doDecrypt as doDecrypt, index$1_doEncrypt as doEncrypt, index$1_doSignature as doSignature, index$1_doVerifySignature as doVerifySignature, getSharedSecret as ecdh, index$1_generateKeyPairHex as generateKeyPairHex, index$1_getHash as getHash, index$1_getPoint as getPoint, index$1_getPublicKeyFromPrivateKey as getPublicKeyFromPrivateKey, index$1_getZ as getZ, index$1_hexToArray as hexToArray, index$1_initRNGPool as initRNGPool, index$1_leftPad as leftPad, index$1_precomputePublicKey as precomputePublicKey, index$1_utf8ToHex as utf8ToHex, index$1_verifyPublicKey as verifyPublicKey };
|
140
143
|
}
|
141
144
|
|
142
145
|
/**
|
@@ -145,7 +148,7 @@ declare namespace index$1 {
|
|
145
148
|
* @param keylen Desired key length in bytes
|
146
149
|
* @returns Derived key as Uint8Array
|
147
150
|
*/
|
148
|
-
declare function kdf(z: string | Uint8Array, keylen: number): Uint8Array<ArrayBuffer>;
|
151
|
+
declare function kdf(z: string | Uint8Array, keylen: number, iv?: string | Uint8Array): Uint8Array<ArrayBuffer>;
|
149
152
|
|
150
153
|
declare function sm3(input: string | Uint8Array, options?: {
|
151
154
|
key: Uint8Array | string;
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as utils from '@noble/curves/abstract/utils';
|
1
2
|
import { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
2
3
|
|
3
4
|
interface KeyPair {
|
@@ -45,6 +46,8 @@ declare function initRNGPool(): Promise<void>;
|
|
45
46
|
|
46
47
|
declare function calculateSharedKey(keypairA: KeyPair, ephemeralKeypairA: KeyPair, publicKeyB: string, ephemeralPublicKeyB: string, sharedKeyLength: number, isRecipient?: boolean, idA?: string, idB?: string): Uint8Array<ArrayBuffer>;
|
47
48
|
|
49
|
+
declare const getSharedSecret: (privateA: utils.PrivKey, publicB: utils.Hex, isCompressed?: boolean) => Uint8Array;
|
50
|
+
|
48
51
|
declare const EmptyArray: Uint8Array<ArrayBuffer>;
|
49
52
|
/**
|
50
53
|
* 加密
|
@@ -136,7 +139,7 @@ declare const index$1_precomputePublicKey: typeof precomputePublicKey;
|
|
136
139
|
declare const index$1_utf8ToHex: typeof utf8ToHex;
|
137
140
|
declare const index$1_verifyPublicKey: typeof verifyPublicKey;
|
138
141
|
declare namespace index$1 {
|
139
|
-
export { index$1_EmptyArray as EmptyArray, type index$1_KeyPair as KeyPair, type index$1_SignaturePoint as SignaturePoint, index$1_arrayToHex as arrayToHex, index$1_arrayToUtf8 as arrayToUtf8, index$1_calculateSharedKey as calculateSharedKey, index$1_comparePublicKeyHex as comparePublicKeyHex, index$1_compressPublicKeyHex as compressPublicKeyHex, index$1_doDecrypt as doDecrypt, index$1_doEncrypt as doEncrypt, index$1_doSignature as doSignature, index$1_doVerifySignature as doVerifySignature, index$1_generateKeyPairHex as generateKeyPairHex, index$1_getHash as getHash, index$1_getPoint as getPoint, index$1_getPublicKeyFromPrivateKey as getPublicKeyFromPrivateKey, index$1_getZ as getZ, index$1_hexToArray as hexToArray, index$1_initRNGPool as initRNGPool, index$1_leftPad as leftPad, index$1_precomputePublicKey as precomputePublicKey, index$1_utf8ToHex as utf8ToHex, index$1_verifyPublicKey as verifyPublicKey };
|
142
|
+
export { index$1_EmptyArray as EmptyArray, type index$1_KeyPair as KeyPair, type index$1_SignaturePoint as SignaturePoint, index$1_arrayToHex as arrayToHex, index$1_arrayToUtf8 as arrayToUtf8, index$1_calculateSharedKey as calculateSharedKey, index$1_comparePublicKeyHex as comparePublicKeyHex, index$1_compressPublicKeyHex as compressPublicKeyHex, index$1_doDecrypt as doDecrypt, index$1_doEncrypt as doEncrypt, index$1_doSignature as doSignature, index$1_doVerifySignature as doVerifySignature, getSharedSecret as ecdh, index$1_generateKeyPairHex as generateKeyPairHex, index$1_getHash as getHash, index$1_getPoint as getPoint, index$1_getPublicKeyFromPrivateKey as getPublicKeyFromPrivateKey, index$1_getZ as getZ, index$1_hexToArray as hexToArray, index$1_initRNGPool as initRNGPool, index$1_leftPad as leftPad, index$1_precomputePublicKey as precomputePublicKey, index$1_utf8ToHex as utf8ToHex, index$1_verifyPublicKey as verifyPublicKey };
|
140
143
|
}
|
141
144
|
|
142
145
|
/**
|
@@ -145,7 +148,7 @@ declare namespace index$1 {
|
|
145
148
|
* @param keylen Desired key length in bytes
|
146
149
|
* @returns Derived key as Uint8Array
|
147
150
|
*/
|
148
|
-
declare function kdf(z: string | Uint8Array, keylen: number): Uint8Array<ArrayBuffer>;
|
151
|
+
declare function kdf(z: string | Uint8Array, keylen: number, iv?: string | Uint8Array): Uint8Array<ArrayBuffer>;
|
149
152
|
|
150
153
|
declare function sm3(input: string | Uint8Array, options?: {
|
151
154
|
key: Uint8Array | string;
|
package/dist/index.js
CHANGED
@@ -55,6 +55,7 @@ __export(sm2_exports, {
|
|
55
55
|
doEncrypt: () => doEncrypt,
|
56
56
|
doSignature: () => doSignature,
|
57
57
|
doVerifySignature: () => doVerifySignature,
|
58
|
+
ecdh: () => getSharedSecret,
|
58
59
|
generateKeyPairHex: () => generateKeyPairHex,
|
59
60
|
getHash: () => getHash,
|
60
61
|
getPoint: () => getPoint,
|
@@ -790,8 +791,9 @@ function sm32(input, options) {
|
|
790
791
|
}
|
791
792
|
|
792
793
|
// src/sm2/kdf.ts
|
793
|
-
function kdf(z, keylen) {
|
794
|
+
function kdf(z, keylen, iv) {
|
794
795
|
z = typeof z === "string" ? utf8ToArray(z) : z;
|
796
|
+
const IV2 = iv == null ? EmptyArray : typeof iv === "string" ? utf8ToArray(iv) : iv;
|
795
797
|
let msg = new Uint8Array(keylen);
|
796
798
|
let ct = 1;
|
797
799
|
let offset = 0;
|
@@ -802,7 +804,7 @@ function kdf(z, keylen) {
|
|
802
804
|
ctShift[1] = ct >> 16 & 255;
|
803
805
|
ctShift[2] = ct >> 8 & 255;
|
804
806
|
ctShift[3] = ct & 255;
|
805
|
-
t = sm3(utils3.concatBytes(z, ctShift));
|
807
|
+
t = sm3(utils3.concatBytes(z, ctShift, IV2));
|
806
808
|
ct++;
|
807
809
|
offset = 0;
|
808
810
|
};
|
@@ -843,6 +845,7 @@ function calculateSharedKey(keypairA, ephemeralKeypairA, publicKeyB, ephemeralPu
|
|
843
845
|
}
|
844
846
|
|
845
847
|
// src/sm2/index.ts
|
848
|
+
var { getSharedSecret } = sm2Curve;
|
846
849
|
function xorCipherStream(x2, y2, msg) {
|
847
850
|
const stream = kdf(utils5.concatBytes(x2, y2), msg.length);
|
848
851
|
for (let i = 0, len = msg.length; i < len; i++) {
|
package/dist/index.mjs
CHANGED
@@ -22,6 +22,7 @@ __export(sm2_exports, {
|
|
22
22
|
doEncrypt: () => doEncrypt,
|
23
23
|
doSignature: () => doSignature,
|
24
24
|
doVerifySignature: () => doVerifySignature,
|
25
|
+
ecdh: () => getSharedSecret,
|
25
26
|
generateKeyPairHex: () => generateKeyPairHex,
|
26
27
|
getHash: () => getHash,
|
27
28
|
getPoint: () => getPoint,
|
@@ -757,8 +758,9 @@ function sm32(input, options) {
|
|
757
758
|
}
|
758
759
|
|
759
760
|
// src/sm2/kdf.ts
|
760
|
-
function kdf(z, keylen) {
|
761
|
+
function kdf(z, keylen, iv) {
|
761
762
|
z = typeof z === "string" ? utf8ToArray(z) : z;
|
763
|
+
const IV2 = iv == null ? EmptyArray : typeof iv === "string" ? utf8ToArray(iv) : iv;
|
762
764
|
let msg = new Uint8Array(keylen);
|
763
765
|
let ct = 1;
|
764
766
|
let offset = 0;
|
@@ -769,7 +771,7 @@ function kdf(z, keylen) {
|
|
769
771
|
ctShift[1] = ct >> 16 & 255;
|
770
772
|
ctShift[2] = ct >> 8 & 255;
|
771
773
|
ctShift[3] = ct & 255;
|
772
|
-
t = sm3(utils3.concatBytes(z, ctShift));
|
774
|
+
t = sm3(utils3.concatBytes(z, ctShift, IV2));
|
773
775
|
ct++;
|
774
776
|
offset = 0;
|
775
777
|
};
|
@@ -810,6 +812,7 @@ function calculateSharedKey(keypairA, ephemeralKeypairA, publicKeyB, ephemeralPu
|
|
810
812
|
}
|
811
813
|
|
812
814
|
// src/sm2/index.ts
|
815
|
+
var { getSharedSecret } = sm2Curve;
|
813
816
|
function xorCipherStream(x2, y2, msg) {
|
814
817
|
const stream = kdf(utils5.concatBytes(x2, y2), msg.length);
|
815
818
|
for (let i = 0, len = msg.length; i < len; i++) {
|