@bigdreamsweb3/wordbin 1.0.6 → 1.0.8
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/CONTRIBUTING.md +156 -67
- package/README.md +364 -149
- package/dist/{dictionary-D3gr2Ala.js → builder-vFphFQMU.js} +16 -19
- package/dist/builder-vFphFQMU.js.map +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/core/binary-payload.d.ts +6 -0
- package/dist/core/comp/latin1-compressor.d.ts +9 -0
- package/dist/core/comp/onebyte-encoder.d.ts +2 -0
- package/dist/core/index.d.ts +58 -0
- package/dist/data/wordbin-v1-bip39.json +13 -11
- package/dist/{dictionary.d.ts → dict/builder.d.ts} +1 -1
- package/dist/{dictionary-loader.d.ts → dict/dictionary-loader.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +425 -142
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +7 -3
- package/package.json +6 -2
- package/dist/core.d.ts +0 -19
- package/dist/dictionary-D3gr2Ala.js.map +0 -1
package/CONTRIBUTING.md
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
Here's the **CONTRIBUTING.md** file ready for you to download and use in your project.
|
|
2
|
-
|
|
3
|
-
You can copy the content below and save it as `CONTRIBUTING.md` in the root of your repository.
|
|
4
|
-
|
|
5
|
-
```markdown
|
|
6
1
|
# Contributing to WordBin
|
|
7
2
|
|
|
8
3
|
Thank you for your interest in contributing to WordBin!
|
|
9
|
-
We welcome all kinds of help — bug reports, documentation improvements, new features, dictionary variants, tests, or
|
|
4
|
+
We welcome all kinds of help — bug reports, documentation improvements, new features, dictionary variants, tests, or small fixes.
|
|
10
5
|
|
|
11
6
|
This guide explains how to contribute effectively and what would be most valuable to the project right now.
|
|
12
7
|
|
|
8
|
+
---
|
|
9
|
+
|
|
13
10
|
## Table of Contents
|
|
14
11
|
|
|
15
12
|
- [Code of Conduct](#code-of-conduct)
|
|
@@ -19,15 +16,22 @@ This guide explains how to contribute effectively and what would be most valuabl
|
|
|
19
16
|
- [Submitting Pull Requests](#submitting-pull-requests)
|
|
20
17
|
- [Good First Issues](#good-first-issues)
|
|
21
18
|
- [Development Setup](#development-setup)
|
|
19
|
+
- [Project Layout](#project-layout)
|
|
20
|
+
- [Running Tests](#running-tests)
|
|
21
|
+
- [Where Things Live](#where-things-live)
|
|
22
22
|
- [Current Priorities (2026)](#current-priorities-2026)
|
|
23
23
|
- [Code Style & Conventions](#code-style--conventions)
|
|
24
24
|
- [License](#license)
|
|
25
25
|
|
|
26
|
+
---
|
|
27
|
+
|
|
26
28
|
## Code of Conduct
|
|
27
29
|
|
|
28
30
|
This project follows the [Contributor Covenant Code of Conduct v2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).
|
|
29
31
|
Be respectful, inclusive, and constructive in all interactions.
|
|
30
32
|
|
|
33
|
+
---
|
|
34
|
+
|
|
31
35
|
## How to Contribute
|
|
32
36
|
|
|
33
37
|
### Reporting Bugs
|
|
@@ -36,66 +40,72 @@ If you find a bug:
|
|
|
36
40
|
|
|
37
41
|
1. Check if it's already reported in [existing issues](https://github.com/bigdreamsweb3/wordbin/issues).
|
|
38
42
|
2. If not, open a new issue and include:
|
|
39
|
-
-
|
|
43
|
+
- A clear, descriptive title
|
|
40
44
|
- Steps to reproduce
|
|
41
|
-
- Expected vs actual
|
|
42
|
-
- Node.js
|
|
43
|
-
- Dictionary version used (v1/v2/custom)
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
Use the **Bug report** template when available.
|
|
45
|
+
- Expected vs actual behaviour
|
|
46
|
+
- Node.js version (`node -v`)
|
|
47
|
+
- Dictionary version used (v1 / v2 / custom)
|
|
48
|
+
- The payload format involved (hex / base58 / base64 / bin21 / bytes)
|
|
49
|
+
- A minimal code snippet or failing test case
|
|
47
50
|
|
|
48
51
|
### Suggesting Features or Improvements
|
|
49
52
|
|
|
50
|
-
Have an idea for a new feature, better performance, UX improvement, or new dictionary type?
|
|
51
|
-
|
|
52
53
|
Open an issue with:
|
|
53
|
-
- Problem or opportunity you're addressing
|
|
54
|
-
- Proposed solution (as detailed as you want)
|
|
55
|
-
- Any alternatives you've considered
|
|
56
|
-
- Rough estimate of impact/benefit
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
- The problem or opportunity you're addressing
|
|
56
|
+
- Your proposed solution (as detailed as you like)
|
|
57
|
+
- Any alternatives you considered
|
|
58
|
+
- Rough estimate of impact
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
For larger architectural changes — new payload formats, new dictionary structures, changes to the encode/decode pipeline — please open an issue to discuss before writing code.
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
### Submitting Pull Requests
|
|
63
63
|
|
|
64
64
|
1. **Fork** the repository and **clone** your fork
|
|
65
|
-
2. Create a
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
2. Create a focused branch:
|
|
66
|
+
```bash
|
|
67
|
+
git checkout -b fix/decode-bin21-format
|
|
68
|
+
# or
|
|
69
|
+
git checkout -b feat/add-top-20k-dictionary
|
|
70
|
+
```
|
|
68
71
|
3. Make your changes
|
|
69
|
-
4. Add or update tests
|
|
70
|
-
5. Run the test suite:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
4. Add or update tests in `test/test.spec.ts` for any new behaviour
|
|
73
|
+
5. Run the full test suite and confirm everything passes:
|
|
74
|
+
```bash
|
|
75
|
+
npm test
|
|
76
|
+
```
|
|
77
|
+
6. Commit with clear, semantic messages:
|
|
78
|
+
```
|
|
79
|
+
fix: correct bin21 format detection in detectAndConvert
|
|
80
|
+
feat: add partialScan fallback for non-WordBin payloads
|
|
81
|
+
docs: update decode API in README
|
|
82
|
+
test: add round-trip cases for base58 and bin21 formats
|
|
83
|
+
```
|
|
77
84
|
7. Push your branch and open a pull request against `main`
|
|
78
85
|
|
|
79
|
-
Small, focused PRs are
|
|
80
|
-
Larger changes might be reviewed in stages — feel free to open a draft PR early to discuss.
|
|
86
|
+
Small, focused PRs are merged quickly. For larger changes, open a draft PR early — it's easier to align on approach before a lot of code is written.
|
|
81
87
|
|
|
82
88
|
### Good First Issues
|
|
83
89
|
|
|
84
|
-
Looking for an easy entry point? These
|
|
90
|
+
Looking for an easy entry point? These are beginner-friendly:
|
|
85
91
|
|
|
86
|
-
-
|
|
87
|
-
- Add case
|
|
92
|
+
- Fix documentation or README examples
|
|
93
|
+
- Add case normalisation (lowercase) to dictionary building
|
|
88
94
|
- Create a smaller curated dictionary (e.g. top 10k–50k English words)
|
|
89
95
|
- Add more helpful messages or progress indicators to the CLI
|
|
90
|
-
- Write tests for edge cases (empty strings, very long phrases,
|
|
91
|
-
-
|
|
96
|
+
- Write tests for edge cases (empty strings, very long phrases, single-word inputs)
|
|
97
|
+
- Build a simple browser demo (CodeSandbox, StackBlitz, or a static HTML page)
|
|
98
|
+
|
|
99
|
+
Look for issues labelled **[good first issue]** on GitHub.
|
|
92
100
|
|
|
93
|
-
|
|
101
|
+
---
|
|
94
102
|
|
|
95
103
|
## Development Setup
|
|
96
104
|
|
|
105
|
+
**Prerequisites:** Node.js ≥ 18, npm ≥ 9
|
|
106
|
+
|
|
97
107
|
```bash
|
|
98
|
-
# 1. Fork
|
|
108
|
+
# 1. Fork and clone
|
|
99
109
|
git clone https://github.com/bigdreamsweb3/wordbin.git
|
|
100
110
|
cd wordbin
|
|
101
111
|
|
|
@@ -105,51 +115,130 @@ npm install
|
|
|
105
115
|
# 3. Build the library
|
|
106
116
|
npm run build
|
|
107
117
|
|
|
108
|
-
# 4. Run tests
|
|
118
|
+
# 4. Run the tests
|
|
109
119
|
npm test
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
112
123
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
## Project Layout
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
wordbin/
|
|
128
|
+
├── src/
|
|
129
|
+
│ ├── core/
|
|
130
|
+
│ │ └── wordbin.ts # WordBin class — encode(), decode(), format detection
|
|
131
|
+
│ ├── dict/
|
|
132
|
+
│ │ ├── dictionary-loader.ts # loadLatestDictionary, loadDictionaryByVersion
|
|
133
|
+
│ │ ├── builder.ts # buildDictionary() — constructs dict from a wordlist
|
|
134
|
+
│ │ └── data/ # Bundled v1 (BIP-39) dictionary JSON
|
|
135
|
+
│ ├── utils/
|
|
136
|
+
│ │ └── buffer.ts # toHex, toBase64, encodeVarint, decodeVarint, utf8*
|
|
137
|
+
│ └── constants.ts # LITERAL token value and other shared constants
|
|
138
|
+
├── test/
|
|
139
|
+
│ └── test.spec.ts # Vitest suites — encode, decode, round-trip, non-WordBin
|
|
140
|
+
├── data/ # Built dictionary files — generated, gitignored
|
|
141
|
+
└── dist/ # Compiled output — generated on build, not committed
|
|
117
142
|
```
|
|
118
143
|
|
|
119
|
-
|
|
120
|
-
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Running Tests
|
|
147
|
+
|
|
148
|
+
The test suite is organised into four independently-controllable suites.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm test # run everything once
|
|
152
|
+
npm run test:watch # watch mode — re-runs on save
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Run a single suite via CLI
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx vitest -t "Encode only"
|
|
159
|
+
npx vitest -t "Decode only"
|
|
160
|
+
npx vitest -t "Encode then decode"
|
|
161
|
+
npx vitest -t "Non-WordBin decode"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Toggle suites without touching the CLI
|
|
165
|
+
|
|
166
|
+
At the top of `test/test.spec.ts`:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const RUN = {
|
|
170
|
+
ENCODE_ONLY: true, // encode text → verify all payload representations
|
|
171
|
+
DECODE_ONLY: true, // decode a pre-built payload → verify result
|
|
172
|
+
ENCODE_THEN_DECODE: true, // full round-trip across all 5 formats
|
|
173
|
+
NON_WORDBIN_DECODE: true, // arbitrary payloads → graceful fallback behaviour
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Set any flag to `false` to skip that suite entirely. Skipped suites are reported as skipped — they are never silently removed.
|
|
178
|
+
|
|
179
|
+
### What each suite covers
|
|
180
|
+
|
|
181
|
+
| Suite | What it tests |
|
|
182
|
+
| ---------------------- | -------------------------------------------------------------------------------------------- |
|
|
183
|
+
| **Encode only** | All payload formats (hex, base58, base64, bin21), compression ratio, format validity |
|
|
184
|
+
| **Decode only** | Known hex payload, known base64 payload, non-WordBin fallback |
|
|
185
|
+
| **Encode then decode** | Full round-trip for hex, base58, base64, bin21, and raw `Uint8Array` |
|
|
186
|
+
| **Non-WordBin decode** | 4 foreign payloads — verifies `isWordBin: false`, `notice` is set, `text` is always a string |
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Where Things Live
|
|
191
|
+
|
|
192
|
+
| What you want to change | File |
|
|
193
|
+
| -------------------------------------------------------- | ------------------------------------ |
|
|
194
|
+
| Encode / decode logic | `src/core/wordbin.ts` |
|
|
195
|
+
| Payload format detection (hex / base58 / base64 / bin21) | `detectAndConvert()` in `wordbin.ts` |
|
|
196
|
+
| `DecodeResult` type or `PayloadFormat` union | top of `wordbin.ts` |
|
|
197
|
+
| Partial scan / best-effort fallback | `partialScan()` in `wordbin.ts` |
|
|
198
|
+
| Dictionary loading and versioning | `src/dict/dictionary-loader.ts` |
|
|
199
|
+
| Building a dictionary from a wordlist | `src/dict/builder.ts` |
|
|
200
|
+
| Buffer utilities (varint, hex, utf8) | `src/utils/buffer.ts` |
|
|
201
|
+
| Shared constants (LITERAL byte value) | `src/constants.ts` |
|
|
202
|
+
| Tests | `test/test.spec.ts` |
|
|
203
|
+
|
|
204
|
+
---
|
|
121
205
|
|
|
122
206
|
## Current Priorities (2026)
|
|
123
207
|
|
|
124
208
|
These improvements would have the biggest impact right now:
|
|
125
209
|
|
|
126
|
-
- Case-insensitive dictionaries
|
|
127
|
-
- Smaller curated dictionaries
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
210
|
+
- **Case-insensitive dictionaries** — normalise to lowercase during dictionary building so `"Hello"` and `"hello"` encode identically
|
|
211
|
+
- **Smaller curated dictionaries** — top 10k–50k common English words, programming keywords, domain-specific lists (DeFi, medical, etc.)
|
|
212
|
+
- **Bin21 safety** — audit which Latin-1 characters survive common transports (databases, JSON fields) without corruption; document safe subsets
|
|
213
|
+
- **Performance benchmarks** — encode/decode throughput across dictionary sizes and phrase lengths
|
|
214
|
+
- **Browser demo** — a minimal CodeSandbox or static HTML page showing encode/decode live
|
|
215
|
+
- **CLI enhancements** — progress bars, `--lowercase` flag, `--output-dir`, improved help text
|
|
216
|
+
- **Error messages** — clearer messages when a dictionary is missing, input is invalid, or a version mismatch is detected
|
|
132
217
|
|
|
133
|
-
If you're unsure where to begin —
|
|
218
|
+
If you're unsure where to begin, open an issue or a draft PR — we're happy to help you find a good starting point.
|
|
219
|
+
|
|
220
|
+
---
|
|
134
221
|
|
|
135
222
|
## Code Style & Conventions
|
|
136
223
|
|
|
137
|
-
- ESM
|
|
138
|
-
- TypeScript
|
|
139
|
-
- Vitest for
|
|
140
|
-
-
|
|
141
|
-
- Small, focused functions
|
|
142
|
-
- JSDoc
|
|
224
|
+
- **ESM** — `import` / `export` throughout, no CommonJS
|
|
225
|
+
- **TypeScript** — all source files, strict mode preferred
|
|
226
|
+
- **Vitest** — for all tests; no Jest
|
|
227
|
+
- **async/await** — preferred over `.then()` chains
|
|
228
|
+
- **Small, focused functions** — each function does one thing
|
|
229
|
+
- **JSDoc** on all public methods and exported types
|
|
143
230
|
|
|
144
|
-
|
|
231
|
+
Run these before committing:
|
|
145
232
|
|
|
146
233
|
```bash
|
|
147
234
|
npm run lint
|
|
148
235
|
npm run format
|
|
149
236
|
```
|
|
150
237
|
|
|
238
|
+
---
|
|
239
|
+
|
|
151
240
|
## License
|
|
152
241
|
|
|
153
|
-
By contributing
|
|
242
|
+
By contributing code to this project, you agree that your contribution will be licensed under the same [MIT License](./LICENSE) as the rest of the project.
|
|
154
243
|
|
|
155
|
-
Thank you for helping make WordBin better
|
|
244
|
+
Thank you for helping make WordBin better — we up 🚀
|