https://gitbuster.com/memdeklaro/memdeklaro.github.io
- 📅 2026-04-23T14:05:38.560Z
- 👁️ 31 katselukertaa
- 🔓 Julkinen
Hey! I took a look at the code for [memdeklaro.github.io](https://github.com/memdeklaro/memdeklaro.github.io). It’s a really interesting project—essentially a client-side tool for generating "Self-Declaration" ID cards to help people who are excluded from traditional government systems.
Here’s a breakdown of how the core logic is working. 🛠️
### 1. The Rendering Engine
The heart of the app is the `update_declaration()` function in `index.html`.
```javascript
// index.html lines 541-567
function update_declaration() {
document.querySelector("#submit").innerText = "Generating, please wait...";
document.fonts.load("54px OCR-B").then(() => {
var surname = document.querySelector("#surname").value.toUpperCase();
// ... other field captures ...
var canvas_front = document.querySelector("#canvas_front");
var ctx_front = canvas_front.getContext("2d");
// ... drawing logic ...
```
**How it works:**
* **Font Loading:** It waits for the `OCR-B` font to load. This is crucial because `OCR-B` is the standard typeface used in passports and IDs worldwide.
* **Canvas API:** It uses the HTML5 Canvas API to "paint" the user's data onto a template image. This is a smart way to do it because all the processing happens in the user's browser—no data is sent to a server, which is great for privacy. 🛡️
### 2. The MRZ Checksum Logic
In `index.html` (lines 511-531), there is a `checksum(str)` function. This is a technical implementation of the **ICAO 9303 standard** used for Machine Readable Zones (MRZ) on passports.
```javascript
function checksum(str) {
var counter = 0;
var total = 0;
for(var i = 0; i < str.length; i++) {
// Weighting pattern: 7, 3, 1
if(counter == 0) { total = total + (parseInt(str[i]) * 7); }
if(counter == 1) { total = total + (parseInt(str[i]) * 3); }
if(counter == 2) { total = total + (parseInt(str[i]) * 1); }
// ...
}
return total % 10;
}
```
**The Analogy:**
Think of this like a "barcode validator." It takes a string of numbers (like a birthdate or ID number) and multiplies each digit by a repeating sequence of weights (7, 3, 1). The remainder (`total % 10`) becomes the check digit. This makes the generated ID look "authentic" to MRZ scanners. 🔍
### 3. Project Context & Purpose
The HTML content (lines 151-156 and 421-430) explains the "Why" behind the code. The project highlights that millions of people are stateless or lack ID due to circumstances of birth.
* **The Problem:** Lack of ID leads to economic exclusion (no housing, no bank accounts).
* **The Solution:** Providing a way to self-declare identity, similar to how things worked for most of human history before modern nation-states.
### Practical Observations 🚀
* **Privacy First:** Since the `update_declaration` function handles everything locally on the `canvas`, users don't have to worry about their sensitive photos or signatures being uploaded to a database.
* **Actionable Tip:** If you're looking to modify the layout, you'll want to look further down in `index.html` where `ctx_front.drawImage` and `ctx_front.fillText` are called. That's where the exact X/Y coordinates for the text placement are defined.
It's a solid example of using simple web tech to solve a complex social problem. Let me know if you want to dive deeper into the Canvas drawing logic! ✨