# byte-fe/gm-crypto architecture

> Architecture diagram of the GitHub repository byte-fe/gm-crypto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/byte-fe/gm-crypto
- Repository: https://github.com/byte-fe/gm-crypto

## Overview

##### Project type and purpose
- This is an open-source JavaScript/TypeScript library (published to npm) implementing the Chinese GM/T cryptographic standards SM2 (ECC public-key), SM3 (hash), and SM4 (block cipher).
- It targets both Node.js and browser environments, exposing a single entry point and type declarations.

##### File structure
- Top level
- package.json, README.md, LICENSE, .github/workflows (CI for code coverage & npm publish), specs/ (official PDF standards)
- src/index.js: library entry point
- src/lib: algorithm implementations
- test/: unit tests per algorithm
- types/index.d.ts: TypeScript definitions
- src/lib breakdown
- sm2/: elliptic-curve submodules (const.js, ec.js, index.js)
- sm3.js, sm4.js: core algorithm logic
- utils.js: encoding/decoding and buffer helpers

##### README for additional insights
- Emphasis on pure-JS implementation, no native dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    subgraph "External Actors"
        Consumer["Consumer Application"]:::actor
    end

    %% Reference Artifacts
    subgraph "Reference Artifacts"
        Specs["Specs Reference"]:::artifact
        Types["Type Declarations"]:::artifact
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI_Codecov["Codecov Workflow"]:::ci
        CI_Npm["npm-publish Workflow"]:::ci
    end

    %% Library Modules
    subgraph "gm-crypto Library"
        Entry["Entry Module"]:::core
        subgraph "Algorithm Modules"
            SM2["SM2 Module"]:::core
            SM3["SM3 Module"]:::core
            SM4["SM4 Module"]:::core
            Utils["Utils Module"]:::core
        end
        subgraph "SM2 Submodules"
            SM2Const["Constants"]:::core
            SM2EC["EC Math"]:::core
        end
    end

    %% Test Suite
    subgraph "Test Suite"
        SM2Test["SM2 Tests"]:::actor
        SM3Test["SM3 Tests"]:::actor
        SM4Test["SM4 Tests"]:::actor
    end

    %% Relationships
    Consumer -->|imports| Entry
    Entry -->|uses| SM2
    Entry -->|uses| SM3
    Entry -->|uses| SM4
    Entry -->|uses| Utils

    SM2 -->|delegates| SM2Const
    SM2 -->|delegates| SM2EC
    SM2 -->|calls| Utils
    SM3 -->|calls| Utils
    SM4 -->|calls| Utils

    SM2Test -->|tests| Entry
    SM2Test -->|tests| SM2
    SM3Test -->|tests| Entry
    SM3Test -->|tests| SM3
    SM4Test -->|tests| Entry
    SM4Test -->|tests| SM4

    CI_Codecov -.->|runs tests| SM2Test
    CI_Codecov -.->|runs tests| SM3Test
    CI_Codecov -.->|runs tests| SM4Test
    CI_Codecov -.->|reports to| Specs

    CI_Npm -.->|publishes| Entry
    CI_Npm -.->|reads| Types

    Specs -->|reference for| SM2
    Specs -->|reference for| SM3
    Specs -->|reference for| SM4

    Types -->|types for| Entry

    %% Click Events
    click Entry "https://github.com/byte-fe/gm-crypto/blob/main/src/index.js"
    click SM2 "https://github.com/byte-fe/gm-crypto/blob/main/src/lib/sm2/index.js"
    click SM2Const "https://github.com/byte-fe/gm-crypto/blob/main/src/lib/sm2/const.js"
    click SM2EC "https://github.com/byte-fe/gm-crypto/blob/main/src/lib/sm2/ec.js"
    click SM3 "https://github.com/byte-fe/gm-crypto/blob/main/src/lib/sm3.js"
    click SM4 "https://github.com/byte-fe/gm-crypto/blob/main/src/lib/sm4.js"
    click Utils "https://github.com/byte-fe/gm-crypto/blob/main/src/lib/utils.js"
    click Types "https://github.com/byte-fe/gm-crypto/blob/main/types/index.d.ts"
    click SM2Test "https://github.com/byte-fe/gm-crypto/blob/main/test/sm2.js"
    click SM3Test "https://github.com/byte-fe/gm-crypto/blob/main/test/sm3.js"
    click SM4Test "https://github.com/byte-fe/gm-crypto/blob/main/test/sm4.js"
    click CI_Codecov "https://github.com/byte-fe/gm-crypto/blob/main/.github/workflows/codecov.yml"
    click CI_Npm "https://github.com/byte-fe/gm-crypto/blob/main/.github/workflows/npm-publish.yml"
    click Specs "https://github.com/byte-fe/gm-crypto/tree/main/specs/"

    %% Styles
    classDef core fill:#D0E8FF,stroke:#003366,color:#003366
    classDef actor fill:#DFFFD0,stroke:#336600,color:#336600
    classDef ci fill:#FFE5CC,stroke:#CC6600,color:#CC6600
    classDef artifact fill:#F0F0F0,stroke:#666666,color:#666666
```
