# microsoft/msr-javascript-crypto architecture

> Architecture diagram of the GitHub repository microsoft/msr-javascript-crypto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/msr-javascript-crypto
- Repository: https://github.com/microsoft/msr-javascript-crypto

## Overview

msrCrypto is a JavaScript Web Cryptography API polyfill. The main workflow is an application calling `msrCrypto.subtle`, which validates and prepares an operation, dispatches it to a worker or synchronous fallback, and returns the cryptographic result. The algorithm layer covers encryption, signatures, hashing, key derivation, and key wrapping; key management and arithmetic support these operations. The README documents the broader algorithm set; sampled excerpts confirm the API, worker dispatch, key storage, and core math mechanisms, but not every algorithm’s internal wiring.

Main entry points: [`src/worker.js`](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/worker.js) (Worker Runner), [`src/subtle/workerManager.js`](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/workerManager.js) (Worker Manager), [`src/subtle/subtleInterface.js`](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/subtleInterface.js) (SubtleCrypto API), [`src/global.js`](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/global.js) (Public API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["WebCrypto API"]
  node_global["Public API<br/>[global.js]"]
  node_subtle["SubtleCrypto API<br/>[subtleInterface.js]"]
  node_keymanager[("Key Manager<br/>[keyManager.js]")]
end

subgraph group_dispatch["Execution Dispatch"]
  node_operations["Operation Registry<br/>[operations.js]"]
  node_worker_manager["Worker Manager<br/>[workerManager.js]"]
  node_sync_worker["Sync Worker<br/>[syncWorker.js]"]
  node_worker["Worker Runner<br/>[worker.js]"]
end

subgraph group_algorithms["Crypto Algorithms"]
  node_aes["AES<br/>[aes.js]"]
  node_rsa["RSA<br/>[rsa.js]"]
  node_hashes["Hash Functions<br/>[sha.js]"]
  node_hmac["HMAC<br/>[hmac.js]"]
  node_ecc["Elliptic Curves<br/>[cryptoECC.js]"]
  node_ecdsa["ECDSA<br/>[ecdsa.js]"]
  node_ecdh["ECDH<br/>[ecdh.js]"]
  node_kdf["Key Derivation<br/>[pbkdf2.js]"]
  node_concat_kdf["Concat KDF<br/>[concat.js]"]
end

subgraph group_primitives["Crypto Primitives"]
  node_random["Random Generator<br/>[random.js]"]
  node_math["Big-Number Math<br/>[cryptoMath.js]"]
  node_utilities["Byte Utilities<br/>[utilities.js]"]
end

node_application(("Application"))

node_application -->|"uses polyfill"| node_global
node_global -->|"exposes API"| node_subtle
node_subtle -->|"dispatches jobs"| node_worker_manager
node_subtle -->|"manages keys"| node_keymanager
node_worker_manager -->|"posts jobs"| node_worker
node_worker_manager -.->|"falls back to"| node_sync_worker
node_sync_worker -->|"runs handler"| node_worker
node_worker -->|"looks up handler"| node_operations
node_worker -->|"invokes handler"| node_aes
node_worker -->|"invokes handler"| node_rsa
node_worker -->|"invokes handler"| node_hashes
node_worker -->|"invokes handler"| node_hmac
node_worker -->|"invokes handler"| node_ecdsa
node_worker -->|"invokes handler"| node_ecdh
node_worker -->|"invokes handler"| node_kdf
node_worker -->|"invokes handler"| node_concat_kdf
node_worker -->|"seeds from"| node_random
node_ecc -->|"uses arithmetic"| node_math
node_rsa -->|"uses arithmetic"| node_math
node_aes -->|"uses byte helpers"| node_utilities
node_worker_manager -->|"seeds workers"| node_random

click node_global "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/global.js"
click node_subtle "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/subtleInterface.js"
click node_keymanager "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/keyManager.js"
click node_operations "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/operations.js"
click node_worker_manager "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/workerManager.js"
click node_sync_worker "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/syncWorker.js"
click node_worker "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/worker.js"
click node_aes "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/aes.js"
click node_rsa "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/rsa.js"
click node_hashes "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/sha.js"
click node_hmac "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/hmac.js"
click node_ecc "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/cryptoECC.js"
click node_ecdsa "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/ecdsa.js"
click node_ecdh "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/ecdh.js"
click node_kdf "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/pbkdf2.js"
click node_concat_kdf "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/concat.js"
click node_random "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/random.js"
click node_math "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/cryptoMath.js"
click node_utilities "https://github.com/microsoft/msr-javascript-crypto/blob/master/src/utilities.js"

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_global,node_subtle,node_keymanager toneBlue
class node_operations,node_worker_manager,node_sync_worker,node_worker toneAmber
class node_aes,node_rsa,node_hashes,node_hmac,node_ecc,node_ecdsa,node_ecdh,node_kdf,node_concat_kdf toneMint
class node_random,node_math,node_utilities toneRose
class node_application toneIndigo
```

## Components

### WebCrypto API

- [Public API](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/global.js): `src/global.js`
- [SubtleCrypto API](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/subtleInterface.js): `src/subtle/subtleInterface.js`
- [Key Manager](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/keyManager.js): `src/subtle/keyManager.js`

### Execution Dispatch

- [Operation Registry](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/operations.js): `src/operations.js`
- [Worker Manager](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/workerManager.js): `src/subtle/workerManager.js`
- [Sync Worker](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/subtle/syncWorker.js): `src/subtle/syncWorker.js`
- [Worker Runner](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/worker.js): `src/worker.js`

### Crypto Algorithms

- [AES](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/aes.js): `src/aes.js`
- [RSA](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/rsa.js): `src/rsa.js`
- [Hash Functions](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/sha.js): `src/sha.js`
- [HMAC](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/hmac.js): `src/hmac.js`
- [Elliptic Curves](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/cryptoECC.js): `src/cryptoECC.js`
- [ECDSA](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/ecdsa.js): `src/ecdsa.js`
- [ECDH](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/ecdh.js): `src/ecdh.js`
- [Key Derivation](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/pbkdf2.js): `src/pbkdf2.js`
- [Concat KDF](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/concat.js): `src/concat.js`

### Crypto Primitives

- [Random Generator](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/random.js): `src/random.js`
- [Big-Number Math](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/cryptoMath.js): `src/cryptoMath.js`
- [Byte Utilities](https://github.com/microsoft/msr-javascript-crypto/blob/master/src/utilities.js): `src/utilities.js`

### Other components

- **Application**

## Connections

- Application → Public API: uses polyfill
- Public API → SubtleCrypto API: exposes API
- SubtleCrypto API → Worker Manager: dispatches jobs
- SubtleCrypto API → Key Manager: manages keys
- Worker Manager → Worker Runner: posts jobs
- Worker Manager → Sync Worker: falls back to
- Sync Worker → Worker Runner: runs handler
- Worker Runner → Operation Registry: looks up handler
- Worker Runner → AES: invokes handler
- Worker Runner → RSA: invokes handler
- Worker Runner → Hash Functions: invokes handler
- Worker Runner → HMAC: invokes handler
- Worker Runner → ECDSA: invokes handler
- Worker Runner → ECDH: invokes handler
- Worker Runner → Key Derivation: invokes handler
- Worker Runner → Concat KDF: invokes handler
- Worker Runner → Random Generator: seeds from
- Elliptic Curves → Big-Number Math: uses arithmetic
- RSA → Big-Number Math: uses arithmetic
- AES → Byte Utilities: uses byte helpers
- Worker Manager → Random Generator: seeds workers
