# @types/sm-crypto

> TypeScript definitions for sm-crypto

Latest version **0.3.4** (published 2023-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/sm-crypto
pnpm add @types/sm-crypto
yarn add @types/sm-crypto
bun add @types/sm-crypto
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2023-11-07 |
| First published | 2020-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51438 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/sm-crypto
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sm-crypto
- npm.io page: https://npm.io/package/@types/sm-crypto

## Dependencies (1)

- [@types/bigi](https://npm.io/package/@types/bigi.md) *

## Recent versions

- 0.3.4 (latest) — 2023-11-07
- 0.3.1 (ts4.3) — 2023-08-04
- 0.3.0 (ts3.7) — 2021-09-26
- 0.1.1 (ts3.6) — 2021-07-06
- 0.1.0 (ts2.8) — 2020-02-25
- 0.3.3 — 2023-10-18
- 0.3.2 — 2023-09-25

## README

# Installation
> `npm install --save @types/sm-crypto`

# Summary
This package contains type definitions for sm-crypto (https://github.com/JuneAndGreen/sm-crypto#readme).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sm-crypto.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sm-crypto/index.d.ts)
````ts
import BigInteger = require("bigi");

export interface KeyPairHex {
    privateKey: string;
    publicKey: string;
}

export interface KeyPairPoint extends KeyPairHex {
    k: BigInteger;
    x1: BigInteger;
}

/**
 * Cipher Mode
 * - `0`：C1C2C3
 * - `1`：C1C3C2
 */
export type CipherMode = 0 | 1;

export namespace sm2 {
    // TODO Type of parameter of jsbn.BigInteger constructor
    function generateKeyPairHex(): KeyPairHex;
    function doEncrypt(msg: string | ArrayLike<number>, publicKey: string, cipherMode?: CipherMode): string;
    function doDecrypt(encryptData: string, privateKey: string, cipherMode?: CipherMode, outputType?: {
        output?: "string" | "array";
    }): string;
    function doSignature(msg: string | number[], privateKey: string, options?: {
        pointPool?: KeyPairPoint[] | undefined;
        der?: boolean | undefined;
        hash?: boolean | undefined;
        publicKey?: string | undefined;
        userId?: string | undefined;
    }): string;
    function doVerifySignature(msg: string | number[], signHex: string, publicKey: string, options?: {
        der?: boolean | undefined;
        hash?: boolean | undefined;
        userId?: string | undefined;
    }): boolean;
    function getPoint(): KeyPairPoint;
}

export function sm3(input: string | ArrayLike<number>, hmac?: {
    key: HexString | ArrayLike<number>;
    mode?: "hmac";
}): string;

// SM4.encrypt() expects UTF8 strings (such as "hello"), while SM4.decrypt() expects hex strings (such as "8d0a1f").
export type HexString = string;
export type UTF8String = string;

export interface SM4ModeBase {
    padding?: "none" | "pkcs#5" | "pkcs#7";
    mode?: "cbc";
    iv?: number[] | HexString;
}

export interface SM4Mode_StringOutput extends SM4ModeBase {
    output: "string";
}

export interface SM4Mode_ArrayOutput extends SM4ModeBase {
    output: "array";
}

export namespace sm4 {
    function encrypt(
        inArray: number[] | UTF8String,
        key: number[] | HexString,
        mode?: SM4ModeBase | SM4Mode_StringOutput,
    ): string;
    function encrypt(inArray: number[] | UTF8String, key: number[] | HexString, mode: SM4Mode_ArrayOutput): number[];

    function decrypt(
        inArray: number[] | HexString,
        key: number[] | HexString,
        mode?: SM4ModeBase | SM4Mode_StringOutput,
    ): string;
    function decrypt(inArray: number[] | HexString, key: number[] | HexString, mode: SM4Mode_ArrayOutput): number[];
}

````

### Additional Details
 * Last updated: Tue, 07 Nov 2023 15:11:36 GMT
 * Dependencies: [@types/bigi](https://npmjs.com/package/@types/bigi)

# Credits
These definitions were written by [Thermod](https://github.com/Moonisky).

---
_Source: https://npm.io/package/@types/sm-crypto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
