polar_codec_wasm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +150 -0
- package/dist/index.cjs +793 -0
- package/dist/index.d.cts +389 -0
- package/dist/index.d.mts +389 -0
- package/dist/index.iife.js +2 -0
- package/dist/index.mjs +789 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 Aluria
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# polar_codec_wasm
|
|
2
|
+
|
|
3
|
+
A WebAssembly implementation of **Polar Codes** -- a class of error-correcting codes that achieve the capacity of symmetric binary-input discrete memoryless channels.
|
|
4
|
+
|
|
5
|
+
The codec is written in Rust ([`polar_codec`](https://crates.io/crates/polar_codec)), compiled to WebAssembly via [wasm-pack](https://rustwasm.github.io/wasm-pack/), and wrapped in a zero-dependency TypeScript package that works in **Node.js**, **browsers**, and **Deno**.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install polar_codec_wasm
|
|
11
|
+
# or
|
|
12
|
+
pnpm add polar_codec_wasm
|
|
13
|
+
# or
|
|
14
|
+
yarn add polar_codec_wasm
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { PolarCodec, Crc } from "polar_codec_wasm";
|
|
21
|
+
|
|
22
|
+
// K=96 information bits, N=128 codeword length (default 5G frozen bits, no CRC)
|
|
23
|
+
const codec = new PolarCodec(96, 128);
|
|
24
|
+
|
|
25
|
+
// Encode
|
|
26
|
+
const data = new Uint8Array([1, 0, 1, 1, 0, 0, 1, 0 /* ... */]);
|
|
27
|
+
const encoded = codec.encode_bit(data);
|
|
28
|
+
|
|
29
|
+
// Decode (LLR: negative = bit 1, positive = bit 0)
|
|
30
|
+
const llr = to_llr(encoded);
|
|
31
|
+
const decoded = codec.decode_bit(llr);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
| Feature | Description |
|
|
37
|
+
|---------|-------------|
|
|
38
|
+
| **SCL decoding** | Successive Cancellation List decoding with configurable list size `L` |
|
|
39
|
+
| **CRC-aided** | 80+ built-in CRC algorithms (CRC-8 through CRC-82) + user-defined |
|
|
40
|
+
| **Frozen bits** | 5G NR, Reed-Muller, and Gaussian Approximation construction methods |
|
|
41
|
+
| **Byte & bit APIs** | `encode` / `decode` for byte arrays, `encode_bit` / `decode_bit` for 0/1 arrays |
|
|
42
|
+
| **Zero deps** | The Wasm binary is embedded as Base64 -- no file loading at runtime |
|
|
43
|
+
| **Cross-platform** | Node.js >= 16, browsers (ESM / IIFE), Deno |
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### `new PolarCodec(k, n, l?, options?)`
|
|
48
|
+
|
|
49
|
+
| Param | Type | Default | Description |
|
|
50
|
+
|-------|------|---------|-------------|
|
|
51
|
+
| `k` | `number` | | Information bits per codeword |
|
|
52
|
+
| `n` | `number` | | Codeword length (power of two, >= k) |
|
|
53
|
+
| `l` | `number` | `4` | SCL list size (higher = better correction, slower) |
|
|
54
|
+
| `options.frozenBits` | `FrozenBitsMethod` | auto | `"5G"`, `"RM"`, or `{ type: "GA", sigma?: number }` |
|
|
55
|
+
| `options.crc` | `Crc \| DefinedCrc \| null` | `null` | CRC algorithm or `null` for none |
|
|
56
|
+
|
|
57
|
+
### Methods
|
|
58
|
+
|
|
59
|
+
| Method | Input | Output | Description |
|
|
60
|
+
|--------|-------|--------|-------------|
|
|
61
|
+
| `encode_bit(src)` | `Uint8Array` of 0/1 | `Uint8Array` of 0/1 (length n) | Encode information bits |
|
|
62
|
+
| `decode_bit(llr)` | `Float32Array` (length n) | `Uint8Array` of 0/1 (length k) | Decode LLRs to information bits |
|
|
63
|
+
| `encode(src)` | `Uint8Array` (bytes) | `Uint8Array` (packed bytes) | Byte-level encode |
|
|
64
|
+
| `decode(llr)` | `Float32Array` (length n) | `Uint8Array` (packed bytes) | Byte-level decode |
|
|
65
|
+
|
|
66
|
+
### Frozen-bits Methods
|
|
67
|
+
|
|
68
|
+
| Method | Description |
|
|
69
|
+
|--------|-------------|
|
|
70
|
+
| `"5G"` | 5G NR standard frozen-bits pattern (default for N <= 1024) |
|
|
71
|
+
| `"RM"` | Reed-Muller based construction (default for N > 1024) |
|
|
72
|
+
| `"GA"` | Gaussian Approximation with configurable `sigma` parameter |
|
|
73
|
+
|
|
74
|
+
### User-defined CRC
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { PolarCodec, Crc } from "polar_codec_wasm";
|
|
78
|
+
|
|
79
|
+
const codec = new PolarCodec(96, 128, 4, {
|
|
80
|
+
crc: {
|
|
81
|
+
name: "My CRC",
|
|
82
|
+
width: 16,
|
|
83
|
+
poly: 0x8005,
|
|
84
|
+
init: 0xFFFF,
|
|
85
|
+
refin: true,
|
|
86
|
+
refout: true,
|
|
87
|
+
xorout: 0xFFFF,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Built-in CRC Algorithms
|
|
93
|
+
|
|
94
|
+
All variants from the `crc` crate are available via the `Crc` enum:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { Crc } from "polar_codec_wasm";
|
|
98
|
+
|
|
99
|
+
new PolarCodec(96, 128, 4, { crc: Crc.CRC_16_UMTS });
|
|
100
|
+
new PolarCodec(96, 128, 4, { crc: Crc.CRC_24_LTE_A });
|
|
101
|
+
new PolarCodec(96, 128, 4, { crc: Crc.CRC_32_ISCSI });
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Examples
|
|
105
|
+
|
|
106
|
+
The `examples/` directory contains runnable demos:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Basic round-trip (bit-level and byte-level)
|
|
110
|
+
npx tsx examples/basic.ts
|
|
111
|
+
|
|
112
|
+
# Frozen-bits and CRC parameter combinations
|
|
113
|
+
npx tsx examples/paramaters.ts
|
|
114
|
+
|
|
115
|
+
# BER simulation under Gaussian noise
|
|
116
|
+
npx tsx examples/noise.ts
|
|
117
|
+
|
|
118
|
+
# Encode/decode latency benchmark
|
|
119
|
+
npx tsx examples/performanec.ts
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Architecture
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
TypeScript API ──► wasm-bindgen ──► Rust Codec ──► polar_codec crate
|
|
126
|
+
│
|
|
127
|
+
└── Wasm binary embedded as Base64 (no file I/O needed)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The build pipeline (`pnpm run build`):
|
|
131
|
+
|
|
132
|
+
1. Compiles Rust to `wasm32-unknown-unknown` via `wasm-pack build --target web`.
|
|
133
|
+
2. Converts the `.wasm` file to a Base64 string embedded in `lib/wasm-b64.ts`.
|
|
134
|
+
3. Bundles three output formats via esbuild: **ESM**, **CJS**, and **IIFE** (for `<script>` tags).
|
|
135
|
+
4. Generates `.d.ts` declaration files with `tsc`.
|
|
136
|
+
|
|
137
|
+
## Build from Source
|
|
138
|
+
|
|
139
|
+
Requires: [Rust](https://rustup.rs/), [wasm-pack](https://rustwasm.github.io/wasm-pack/), [pnpm](https://pnpm.io/).
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git clone https://github.com/Wu-Yijun/polar-codec-wasm.git
|
|
143
|
+
cd polar-codec-wasm
|
|
144
|
+
pnpm install
|
|
145
|
+
pnpm run build # compiles Rust -> wasm -> Base64 -> ESM/CJS/IIFE bundles
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT
|