import { ProjPointType } from '@noble/curves/abstract/weierstrass'; interface KeyPair { privateKey: string; publicKey: string; } /** * 生成密钥对:publicKey = privateKey * G */ declare function generateKeyPairHex(str?: string): KeyPair; /** * 生成压缩公钥 */ declare function compressPublicKeyHex(s: string): string; /** * utf8串转16进制串 */ declare function utf8ToHex(input: string): string; /** * 补全16进制字符串 */ declare function leftPad(input: string, num: number): string; /** * 转成16进制串 */ declare function arrayToHex(arr: number[]): string; /** * 转成utf8串 */ declare function arrayToUtf8(arr: Uint8Array): string; /** * 转成字节数组 */ declare function hexToArray(hexStr: string): Uint8Array; /** * 验证公钥是否为椭圆曲线上的点 */ declare function verifyPublicKey(publicKey: string): boolean; /** * 验证公钥是否等价,等价返回true */ declare function comparePublicKeyHex(publicKey1: string, publicKey2: string): boolean; declare function initRNGPool(): Promise; declare function calculateSharedKey(keypairA: KeyPair, ephemeralKeypairA: KeyPair, publicKeyB: string, ephemeralPublicKeyB: string, sharedKeyLength: number, isRecipient?: boolean, idA?: string, idB?: string): Uint8Array; declare const EmptyArray: Uint8Array; /** * 加密 */ declare function doEncrypt(msg: string | Uint8Array, publicKey: string | ProjPointType, cipherMode?: number, options?: { asn1?: boolean; }): string; /** * 解密 */ declare function doDecrypt(encryptData: string, privateKey: string, cipherMode?: number, options?: { output: "array"; asn1?: boolean; }): Uint8Array; declare function doDecrypt(encryptData: string, privateKey: string, cipherMode?: number, options?: { output: "string"; asn1?: boolean; }): string; interface SignaturePoint { k: bigint; x1: bigint; } /** * 签名 */ declare function doSignature(msg: Uint8Array | string, privateKey: string, options?: { pointPool?: SignaturePoint[]; der?: boolean; hash?: boolean; publicKey?: string; userId?: string; }): string; /** * 验签 */ declare function doVerifySignature(msg: string | Uint8Array, signHex: string, publicKey: string | ProjPointType, options?: { der?: boolean; hash?: boolean; userId?: string; }): boolean; declare function getZ(publicKey: string, userId?: string): Uint8Array; /** * sm3杂凑算法 */ declare function getHash(hashHex: string | Uint8Array, publicKey: string, userId?: string): string; /** * 预计算公钥点,可用于提升加密性能 * @export * @param {string} publicKey 公钥 * @param windowSize 计算窗口大小,默认为 8 * @returns {ProjPointType} 预计算的点 */ declare function precomputePublicKey(publicKey: string, windowSize?: number): ProjPointType; /** * 计算公钥 */ declare function getPublicKeyFromPrivateKey(privateKey: string): string; /** * 获取椭圆曲线点 */ declare function getPoint(): { k: bigint; x1: bigint; privateKey: string; publicKey: string; }; declare const index$1_EmptyArray: typeof EmptyArray; type index$1_KeyPair = KeyPair; type index$1_SignaturePoint = SignaturePoint; declare const index$1_arrayToHex: typeof arrayToHex; declare const index$1_arrayToUtf8: typeof arrayToUtf8; declare const index$1_calculateSharedKey: typeof calculateSharedKey; declare const index$1_comparePublicKeyHex: typeof comparePublicKeyHex; declare const index$1_compressPublicKeyHex: typeof compressPublicKeyHex; declare const index$1_doDecrypt: typeof doDecrypt; declare const index$1_doEncrypt: typeof doEncrypt; declare const index$1_doSignature: typeof doSignature; declare const index$1_doVerifySignature: typeof doVerifySignature; declare const index$1_generateKeyPairHex: typeof generateKeyPairHex; declare const index$1_getHash: typeof getHash; declare const index$1_getPoint: typeof getPoint; declare const index$1_getPublicKeyFromPrivateKey: typeof getPublicKeyFromPrivateKey; declare const index$1_getZ: typeof getZ; declare const index$1_hexToArray: typeof hexToArray; declare const index$1_initRNGPool: typeof initRNGPool; declare const index$1_leftPad: typeof leftPad; declare const index$1_precomputePublicKey: typeof precomputePublicKey; declare const index$1_utf8ToHex: typeof utf8ToHex; declare const index$1_verifyPublicKey: typeof verifyPublicKey; declare namespace index$1 { 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 }; } /** * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123' */ declare function bytesToHex(bytes: Uint8Array): string; type Input = Uint8Array | string; declare abstract class Hash> { abstract blockLen: number; abstract outputLen: number; abstract update(buf: Input): this; abstract digestInto(buf: Uint8Array): void; abstract digest(): Uint8Array; /** * Resets internal state. Makes Hash instance unusable. * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed * by user, they will need to manually call `destroy()` when zeroing is necessary. */ abstract destroy(): void; /** * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()` * when no options are passed. * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal * buffers are overwritten => causes buffer overwrite which is used for digest in some cases. * There are no guarantees for clean-up because it's impossible in JS. */ abstract _cloneInto(to?: T): T; clone(): T; } /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */ declare abstract class SHA2> extends Hash { readonly blockLen: number; outputLen: number; readonly padOffset: number; readonly isLE: boolean; protected abstract process(buf: DataView, offset: number): void; protected abstract get(): number[]; protected abstract set(...args: number[]): void; abstract destroy(): void; protected abstract roundClean(): void; protected buffer: Uint8Array; protected view: DataView; protected finished: boolean; protected length: number; protected pos: number; protected destroyed: boolean; constructor(blockLen: number, outputLen: number, padOffset: number, isLE: boolean); update(data: Input): this; digestInto(out: Uint8Array): void; digest(): Uint8Array; _cloneInto(to?: T): T; } declare class SM3 extends SHA2 { A: number; B: number; C: number; D: number; E: number; F: number; G: number; H: number; constructor(); protected get(): [ number, number, number, number, number, number, number, number ]; protected set(A: number, B: number, C: number, D: number, E: number, F: number, G: number, H: number): void; protected process(view: DataView, offset: number): void; protected roundClean(): void; destroy(): void; } declare function sm3(input: string | Uint8Array, options?: { key: Uint8Array | string; mode?: 'hmac' | 'mac'; }): string; interface SM4Options { padding?: 'pkcs#7' | 'pkcs#5' | 'none' | null; mode?: 'cbc' | 'ecb'; iv?: Uint8Array | string; output?: 'string' | 'array'; } declare function sm4(inArray: Uint8Array | string, key: Uint8Array | string, cryptFlag: 0 | 1, options?: SM4Options): string | Uint8Array; declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: { output: 'array'; } | SM4Options): Uint8Array; declare function encrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: { output: 'string'; } | SM4Options): string; declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: { output: 'array'; } | SM4Options): Uint8Array; declare function decrypt(inArray: Uint8Array | string, key: Uint8Array | string, options?: { output: 'string'; } | SM4Options): string; type index_SM4Options = SM4Options; declare const index_decrypt: typeof decrypt; declare const index_encrypt: typeof encrypt; declare const index_sm4: typeof sm4; declare namespace index { export { type index_SM4Options as SM4Options, index_decrypt as decrypt, index_encrypt as encrypt, index_sm4 as sm4 }; } export { SM3, bytesToHex, hexToArray, index$1 as sm2, sm3, index as sm4 };