# byigitt/tr-esign architecture

> Architecture diagram of the GitHub repository byigitt/tr-esign, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/byigitt/tr-esign
- Repository: https://github.com/byigitt/tr-esign

## Overview

tr-esign is a Node/TypeScript electronic-signature library for Turkish XAdES, CAdES, PAdES and ASiC workflows. Users provide documents and signing credentials, then sign, verify, counter-sign or upgrade signatures; verification returns a shared result. The map also includes documented PKCS#11, mobile-signature, trust-bootstrap and CLI capabilities. Relationships are based on README statements and SOURCE INDEX references; unsampled modules are represented by their exact paths, without assuming internal calls not evidenced there.

Main entry points: [`src/cli.ts`](https://github.com/byigitt/tr-esign/blob/main/src/cli.ts) (CLI), [`src/sign.ts`](https://github.com/byigitt/tr-esign/blob/main/src/sign.ts) (XAdES sign), [`src/cades-sign.ts`](https://github.com/byigitt/tr-esign/blob/main/src/cades-sign.ts) (CAdES sign), [`src/pades-sign.ts`](https://github.com/byigitt/tr-esign/blob/main/src/pades-sign.ts) (PAdES sign)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_formats["Signature formats"]
  node_xades_sign["XAdES sign<br/>[sign.ts]"]
  node_xades_verify["XAdES verify<br/>[verify.ts]"]
  node_xades_upgrade["XAdES upgrade<br/>[upgrade.ts]"]
  node_xades_counter["XAdES counter-sign<br/>[counter-sign.ts]"]
  node_cades_sign["CAdES sign<br/>[cades-sign.ts]"]
  node_cades_verify["CAdES verify<br/>[cades-verify.ts]"]
  node_cades_upgrade["CAdES upgrade<br/>[cades-upgrade.ts]"]
  node_cades_counter["CAdES counter-sign"]
  node_pades_sign["PAdES sign<br/>[pades-sign.ts]"]
  node_pades_verify["PAdES verify<br/>[pades-verify.ts]"]
  node_pades_upgrade["PAdES upgrade<br/>[pades-upgrade.ts]"]
  node_pdf_visible["Visible PDF signatures<br/>[pades-visible.ts]"]
  node_pdf_dss["PDF validation data<br/>[pades-dss.ts]"]
  node_pdf_core["PDF incremental core<br/>[pades-core.ts]"]
  node_pdf_xref["PDF xref handling<br/>[pades-xref.ts]"]
  node_asic["ASiC containers<br/>[asic.ts]"]
end

subgraph group_core["Signature core"]
  node_references["XML references<br/>[references.ts]"]
  node_signed_props["XAdES properties"]
  node_canonical["Canonicalization<br/>[c14n.ts]"]
  node_crypto["Cryptography<br/>[crypto.ts]"]
  node_policy["Signature policy<br/>[policy.ts]"]
  node_cades_attrs["CMS attributes"]
  node_cades_constants["CMS constants<br/>[cades-constants.ts]"]
end

subgraph group_trust["Trust and timestamps"]
  node_chain["Certificate chain<br/>[chain.ts]"]
  node_roots[("Kamu SM roots")]
  node_crl["CRL validation<br/>[crl.ts]"]
  node_ocsp["OCSP validation<br/>[ocsp.ts]"]
  node_tsp["Timestamp client<br/>[tsp.ts]"]
end

subgraph group_interfaces["Interfaces and signing"]
  node_cli["CLI<br/>[cli.ts]"]
  node_pfx["PFX credentials<br/>[pfx.ts]"]
  node_pkcs11["PKCS&#35;11 signer<br/>[pkcs11.ts]"]
  node_mss["Mobile signature<br/>[mss.ts]"]
end

node_user(("Application user"))
node_tsa(("Timestamp authority"))

node_user -->|"invokes"| node_cli
node_user -->|"signs XML"| node_xades_sign
node_user -->|"verifies XML"| node_xades_verify
node_user -->|"upgrades XML"| node_xades_upgrade
node_user -->|"counter-signs"| node_xades_counter
node_user -->|"signs binary"| node_cades_sign
node_user -->|"verifies CMS"| node_cades_verify
node_user -->|"upgrades CMS"| node_cades_upgrade
node_user -->|"signs PDF"| node_pades_sign
node_user -->|"verifies PDF"| node_pades_verify
node_user -->|"upgrades PDF"| node_pades_upgrade
node_user -->|"creates or reads"| node_asic
node_user -->|"requests mobile signing"| node_mss
node_user -->|"provides HSM signer"| node_pkcs11
node_cli -->|"dispatches"| node_xades_sign
node_cli -->|"dispatches"| node_xades_verify
node_cli -->|"dispatches"| node_xades_upgrade
node_cli -->|"dispatches"| node_cades_sign
node_cli -->|"dispatches"| node_cades_verify
node_cli -->|"dispatches"| node_cades_upgrade
node_cli -->|"dispatches"| node_pades_sign
node_cli -->|"dispatches"| node_pades_verify
node_cli -->|"dispatches"| node_pades_upgrade
node_xades_sign -->|"builds digests"| node_references
node_xades_sign -->|"builds properties"| node_signed_props
node_xades_sign -->|"loads credentials"| node_pfx
node_xades_sign -->|"uses signer"| node_pkcs11
node_xades_sign -->|"signs data"| node_crypto
node_xades_sign -->|"canonicalizes XML"| node_canonical
node_xades_verify -->|"checks digests"| node_references
node_xades_verify -->|"checks signature"| node_crypto
node_xades_verify -->|"canonicalizes XML"| node_canonical
node_xades_upgrade -->|"requests timestamp"| node_tsp
node_cades_sign -->|"builds attributes"| node_cades_attrs
node_cades_sign -->|"signs CMS"| node_crypto
node_cades_sign -->|"applies policy"| node_policy
node_cades_sign -->|"uses properties"| node_signed_props
node_cades_sign -->|"shares signing core"| node_xades_sign
node_cades_verify -->|"parses CMS types"| node_cades_constants
node_cades_verify -->|"uses verification logic"| node_xades_verify
node_cades_upgrade -->|"adds attributes"| node_cades_attrs
node_cades_upgrade -->|"requests timestamp"| node_tsp
node_pades_sign -->|"prepares PDF"| node_pdf_core
node_pades_sign -->|"adds visible mark"| node_pdf_visible
node_pades_sign -->|"creates CMS signature"| node_cades_sign
node_pades_sign -->|"uses signing core"| node_xades_sign
node_pades_verify -->|"reads PDF signature"| node_pdf_core
node_pades_verify -->|"checks CMS signature"| node_cades_verify

click node_cli "https://github.com/byigitt/tr-esign/blob/main/src/cli.ts"
click node_xades_sign "https://github.com/byigitt/tr-esign/blob/main/src/sign.ts"
click node_xades_verify "https://github.com/byigitt/tr-esign/blob/main/src/verify.ts"
click node_xades_upgrade "https://github.com/byigitt/tr-esign/blob/main/src/upgrade.ts"
click node_xades_counter "https://github.com/byigitt/tr-esign/blob/main/src/counter-sign.ts"
click node_cades_sign "https://github.com/byigitt/tr-esign/blob/main/src/cades-sign.ts"
click node_cades_verify "https://github.com/byigitt/tr-esign/blob/main/src/cades-verify.ts"
click node_cades_upgrade "https://github.com/byigitt/tr-esign/blob/main/src/cades-upgrade.ts"
click node_cades_counter "https://github.com/byigitt/tr-esign/blob/main/src/cades-counter-sign.ts"
click node_pades_sign "https://github.com/byigitt/tr-esign/blob/main/src/pades-sign.ts"
click node_pades_verify "https://github.com/byigitt/tr-esign/blob/main/src/pades-verify.ts"
click node_pades_upgrade "https://github.com/byigitt/tr-esign/blob/main/src/pades-upgrade.ts"
click node_pdf_visible "https://github.com/byigitt/tr-esign/blob/main/src/pades-visible.ts"
click node_pdf_dss "https://github.com/byigitt/tr-esign/blob/main/src/pades-dss.ts"
click node_pdf_core "https://github.com/byigitt/tr-esign/blob/main/src/pades-core.ts"
click node_pdf_xref "https://github.com/byigitt/tr-esign/blob/main/src/pades-xref.ts"
click node_asic "https://github.com/byigitt/tr-esign/blob/main/src/asic.ts"
click node_references "https://github.com/byigitt/tr-esign/blob/main/src/references.ts"
click node_signed_props "https://github.com/byigitt/tr-esign/blob/main/src/signed-properties.ts"
click node_canonical "https://github.com/byigitt/tr-esign/blob/main/src/c14n.ts"
click node_crypto "https://github.com/byigitt/tr-esign/blob/main/src/crypto.ts"
click node_policy "https://github.com/byigitt/tr-esign/blob/main/src/policy.ts"
click node_cades_attrs "https://github.com/byigitt/tr-esign/blob/main/src/cades-attributes.ts"
click node_cades_constants "https://github.com/byigitt/tr-esign/blob/main/src/cades-constants.ts"
click node_pfx "https://github.com/byigitt/tr-esign/blob/main/src/pfx.ts"
click node_pkcs11 "https://github.com/byigitt/tr-esign/blob/main/src/pkcs11.ts"
click node_mss "https://github.com/byigitt/tr-esign/blob/main/src/mss.ts"
click node_chain "https://github.com/byigitt/tr-esign/blob/main/src/chain.ts"
click node_roots "https://github.com/byigitt/tr-esign/blob/main/src/kamusm-roots-snapshot.ts"
click node_crl "https://github.com/byigitt/tr-esign/blob/main/src/crl.ts"
click node_ocsp "https://github.com/byigitt/tr-esign/blob/main/src/ocsp.ts"
click node_tsp "https://github.com/byigitt/tr-esign/blob/main/src/tsp.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_xades_sign,node_xades_verify,node_xades_upgrade,node_xades_counter,node_cades_sign,node_cades_verify,node_cades_upgrade,node_cades_counter,node_pades_sign,node_pades_verify,node_pades_upgrade,node_pdf_visible,node_pdf_dss,node_pdf_core,node_pdf_xref,node_asic,node_user toneBlue
class node_references,node_signed_props,node_canonical,node_crypto,node_policy,node_cades_attrs,node_cades_constants toneAmber
class node_chain,node_roots,node_crl,node_ocsp,node_tsp toneMint
class node_cli,node_pfx,node_pkcs11,node_mss toneRose
class node_tsa toneIndigo
```

## Components

### Signature formats

- [XAdES sign](https://github.com/byigitt/tr-esign/blob/main/src/sign.ts): `src/sign.ts`
- [XAdES verify](https://github.com/byigitt/tr-esign/blob/main/src/verify.ts): `src/verify.ts`
- [XAdES upgrade](https://github.com/byigitt/tr-esign/blob/main/src/upgrade.ts): `src/upgrade.ts`
- [XAdES counter-sign](https://github.com/byigitt/tr-esign/blob/main/src/counter-sign.ts): `src/counter-sign.ts`
- [CAdES sign](https://github.com/byigitt/tr-esign/blob/main/src/cades-sign.ts): `src/cades-sign.ts`
- [CAdES verify](https://github.com/byigitt/tr-esign/blob/main/src/cades-verify.ts): `src/cades-verify.ts`
- [CAdES upgrade](https://github.com/byigitt/tr-esign/blob/main/src/cades-upgrade.ts): `src/cades-upgrade.ts`
- [CAdES counter-sign](https://github.com/byigitt/tr-esign/blob/main/src/cades-counter-sign.ts): `src/cades-counter-sign.ts`
- [PAdES sign](https://github.com/byigitt/tr-esign/blob/main/src/pades-sign.ts): `src/pades-sign.ts`
- [PAdES verify](https://github.com/byigitt/tr-esign/blob/main/src/pades-verify.ts): `src/pades-verify.ts`
- [PAdES upgrade](https://github.com/byigitt/tr-esign/blob/main/src/pades-upgrade.ts): `src/pades-upgrade.ts`
- [Visible PDF signatures](https://github.com/byigitt/tr-esign/blob/main/src/pades-visible.ts): `src/pades-visible.ts`
- [PDF validation data](https://github.com/byigitt/tr-esign/blob/main/src/pades-dss.ts): `src/pades-dss.ts`
- [PDF incremental core](https://github.com/byigitt/tr-esign/blob/main/src/pades-core.ts): `src/pades-core.ts`
- [PDF xref handling](https://github.com/byigitt/tr-esign/blob/main/src/pades-xref.ts): `src/pades-xref.ts`
- [ASiC containers](https://github.com/byigitt/tr-esign/blob/main/src/asic.ts): `src/asic.ts`

### Signature core

- [XML references](https://github.com/byigitt/tr-esign/blob/main/src/references.ts): `src/references.ts`
- [XAdES properties](https://github.com/byigitt/tr-esign/blob/main/src/signed-properties.ts): `src/signed-properties.ts`
- [Canonicalization](https://github.com/byigitt/tr-esign/blob/main/src/c14n.ts): `src/c14n.ts`
- [Cryptography](https://github.com/byigitt/tr-esign/blob/main/src/crypto.ts): `src/crypto.ts`
- [Signature policy](https://github.com/byigitt/tr-esign/blob/main/src/policy.ts): `src/policy.ts`
- [CMS attributes](https://github.com/byigitt/tr-esign/blob/main/src/cades-attributes.ts): `src/cades-attributes.ts`
- [CMS constants](https://github.com/byigitt/tr-esign/blob/main/src/cades-constants.ts): `src/cades-constants.ts`

### Trust and timestamps

- [Certificate chain](https://github.com/byigitt/tr-esign/blob/main/src/chain.ts): `src/chain.ts`
- [Kamu SM roots](https://github.com/byigitt/tr-esign/blob/main/src/kamusm-roots-snapshot.ts): `src/kamusm-roots-snapshot.ts`
- [CRL validation](https://github.com/byigitt/tr-esign/blob/main/src/crl.ts): `src/crl.ts`
- [OCSP validation](https://github.com/byigitt/tr-esign/blob/main/src/ocsp.ts): `src/ocsp.ts`
- [Timestamp client](https://github.com/byigitt/tr-esign/blob/main/src/tsp.ts): `src/tsp.ts`

### Interfaces and signing

- [CLI](https://github.com/byigitt/tr-esign/blob/main/src/cli.ts): `src/cli.ts`
- [PFX credentials](https://github.com/byigitt/tr-esign/blob/main/src/pfx.ts): `src/pfx.ts`
- [PKCS#11 signer](https://github.com/byigitt/tr-esign/blob/main/src/pkcs11.ts): `src/pkcs11.ts`
- [Mobile signature](https://github.com/byigitt/tr-esign/blob/main/src/mss.ts): `src/mss.ts`

### Other components

- **Application user**
- **Timestamp authority**

## Connections

- Application user → CLI: invokes (evidence: `README.md`)
- Application user → XAdES sign: signs XML (evidence: `README.md`)
- Application user → XAdES verify: verifies XML (evidence: `README.md`)
- Application user → XAdES upgrade: upgrades XML (evidence: `README.md`)
- Application user → XAdES counter-sign: counter-signs (evidence: `README.md`)
- Application user → CAdES sign: signs binary (evidence: `README.md`)
- Application user → CAdES verify: verifies CMS (evidence: `README.md`)
- Application user → CAdES upgrade: upgrades CMS (evidence: `README.md`)
- Application user → PAdES sign: signs PDF (evidence: `README.md`)
- Application user → PAdES verify: verifies PDF (evidence: `README.md`)
- Application user → PAdES upgrade: upgrades PDF (evidence: `README.md`)
- Application user → ASiC containers: creates or reads (evidence: `README.md`)
- Application user → Mobile signature: requests mobile signing (evidence: `README.md`)
- Application user → PKCS#11 signer: provides HSM signer (evidence: `README.md`)
- CLI → XAdES sign: dispatches (evidence: `src/cli.ts`)
- CLI → XAdES verify: dispatches (evidence: `src/cli.ts`)
- CLI → XAdES upgrade: dispatches (evidence: `src/cli.ts`)
- CLI → CAdES sign: dispatches (evidence: `src/cli.ts`)
- CLI → CAdES verify: dispatches (evidence: `src/cli.ts`)
- CLI → CAdES upgrade: dispatches (evidence: `src/cli.ts`)
- CLI → PAdES sign: dispatches (evidence: `src/cli.ts`)
- CLI → PAdES verify: dispatches (evidence: `src/cli.ts`)
- CLI → PAdES upgrade: dispatches (evidence: `src/cli.ts`)
- XAdES sign → XML references: builds digests (evidence: `src/sign.ts`)
- XAdES sign → XAdES properties: builds properties (evidence: `src/sign.ts`)
- XAdES sign → PFX credentials: loads credentials (evidence: `src/sign.ts`)
- XAdES sign → PKCS#11 signer: uses signer (evidence: `src/sign.ts`)
- XAdES sign → Cryptography: signs data (evidence: `src/sign.ts`)
- XAdES sign → Canonicalization: canonicalizes XML (evidence: `src/sign.ts`)
- XAdES verify → XML references: checks digests (evidence: `src/verify.ts`)
- XAdES verify → Cryptography: checks signature (evidence: `src/verify.ts`)
- XAdES verify → Canonicalization: canonicalizes XML (evidence: `src/verify.ts`)
- XAdES upgrade → Timestamp client: requests timestamp (evidence: `src/upgrade.ts`)
- CAdES sign → CMS attributes: builds attributes (evidence: `src/cades-sign.ts`)
- CAdES sign → Cryptography: signs CMS (evidence: `src/cades-sign.ts`)
- CAdES sign → Signature policy: applies policy (evidence: `src/cades-sign.ts`)
- CAdES sign → XAdES properties: uses properties (evidence: `src/cades-sign.ts`)
- CAdES sign → XAdES sign: shares signing core (evidence: `src/cades-sign.ts`)
- CAdES verify → CMS constants: parses CMS types (evidence: `src/cades-verify.ts`)
- CAdES verify → XAdES verify: uses verification logic (evidence: `src/cades-verify.ts`)
- CAdES upgrade → CMS attributes: adds attributes (evidence: `src/cades-upgrade.ts`)
- CAdES upgrade → Timestamp client: requests timestamp (evidence: `src/cades-upgrade.ts`)
- PAdES sign → PDF incremental core: prepares PDF (evidence: `src/pades-sign.ts`)
- PAdES sign → Visible PDF signatures: adds visible mark (evidence: `src/pades-sign.ts`)
- PAdES sign → CAdES sign: creates CMS signature (evidence: `src/pades-sign.ts`)
- PAdES sign → XAdES sign: uses signing core (evidence: `src/pades-sign.ts`)
- PAdES verify → PDF incremental core: reads PDF signature (evidence: `src/pades-verify.ts`)
- PAdES verify → CAdES verify: checks CMS signature (evidence: `src/pades-verify.ts`)
