ncantu 26a53327a4 Enhance: Complete dashboard documentation and new services integration
**Motivations:**
- Complete documentation for dashboard, domains, ports and environment configuration
- Add new services (ClamAV API, Watermark API) to the infrastructure
- Enhance dashboard with new pages and improved functionality
- Improve deployment scripts and service configurations

**Root causes:**
- Missing comprehensive documentation for infrastructure setup
- Need for antivirus scanning service integration
- Need for watermark service integration
- Dashboard required additional pages and features

**Correctifs:**
- Added comprehensive documentation in docs/ (DASHBOARD.md, DOMAINS_AND_PORTS.md, ENVIRONMENT.md)
- Updated systemd service files with proper environment variables
- Enhanced nginx proxy configuration script
- Updated maintenance documentation

**Evolutions:**
- Added new ClamAV API service (api-clamav) for file scanning
- Added new Watermark API service (api-filigrane) for document watermarking
- Enhanced signet-dashboard with new learn.html page
- Improved dashboard UI with better styles and navigation
- Enhanced app.js with new functionality and better error handling
- Updated API documentation page with complete endpoint descriptions
- Added deployment scripts for watermark and nginx configuration
- Updated hash and UTXO lists with latest data
- Enhanced server.js with new routes and improved Bitcoin RPC integration

**Pages affectées:**
- docs/DASHBOARD.md: New comprehensive dashboard documentation
- docs/DOMAINS_AND_PORTS.md: New infrastructure domains and ports documentation
- docs/ENVIRONMENT.md: New environment variables documentation
- docs/MAINTENANCE.md: Updated maintenance procedures
- docs/README.md: Updated main documentation
- signet-dashboard/public/app.js: Enhanced with new features
- signet-dashboard/public/styles.css: Improved styling
- signet-dashboard/public/index.html: Enhanced main page
- signet-dashboard/public/learn.html: New educational page
- signet-dashboard/public/api-docs.html: Enhanced API documentation
- signet-dashboard/public/hash-list.html: Updated hash list page
- signet-dashboard/public/utxo-list.html: Updated UTXO list page
- signet-dashboard/public/join-signet.html: Updated join signet page
- signet-dashboard/src/server.js: Enhanced server with new routes
- signet-dashboard/start.sh: Updated startup script
- signet-dashboard/signet-dashboard.service: Updated systemd service
- api-anchorage/anchorage-api.service: Updated systemd service
- api-faucet/faucet-api.service: Updated systemd service
- configure-nginx-proxy.sh: Enhanced nginx configuration script
- add-watermark-certificate.sh: New watermark certificate script
- deploy-watermark-nginx.sh: New deployment script
- api-clamav/: New ClamAV API service
- api-filigrane/: New Watermark API service
- hash_list.txt, utxo_list.txt: Updated with latest data
- anchor_count.txt: Updated anchor count
2026-01-25 17:43:05 +01:00

167 lines
4.0 KiB
JavaScript

const utils = require('./utils');
class Pointer {
constructor(offsetType, type, options = {}) {
this.offsetType = offsetType;
this.type = type;
this.options = options;
if (this.type === 'void') { this.type = null; }
if (this.options.type == null) { this.options.type = 'local'; }
if (this.options.allowNull == null) { this.options.allowNull = true; }
if (this.options.nullValue == null) { this.options.nullValue = 0; }
if (this.options.lazy == null) { this.options.lazy = false; }
if (this.options.relativeTo) {
if (typeof this.options.relativeTo !== 'function') {
throw new Error('relativeTo option must be a function');
}
this.relativeToGetter = options.relativeTo;
}
}
decode(stream, ctx) {
const offset = this.offsetType.decode(stream, ctx);
// handle NULL pointers
if ((offset === this.options.nullValue) && this.options.allowNull) {
return null;
}
let relative;
switch (this.options.type) {
case 'local': relative = ctx._startOffset; break;
case 'immediate': relative = stream.pos - this.offsetType.size(); break;
case 'parent': relative = ctx.parent._startOffset; break;
default:
var c = ctx;
while (c.parent) {
c = c.parent;
}
relative = c._startOffset || 0;
}
if (this.options.relativeTo) {
relative += this.relativeToGetter(ctx);
}
const ptr = offset + relative;
if (this.type != null) {
let val = null;
const decodeValue = () => {
if (val != null) { return val; }
const { pos } = stream;
stream.pos = ptr;
val = this.type.decode(stream, ctx);
stream.pos = pos;
return val;
};
// If this is a lazy pointer, define a getter to decode only when needed.
// This obviously only works when the pointer is contained by a Struct.
if (this.options.lazy) {
return new utils.PropertyDescriptor({
get: decodeValue});
}
return decodeValue();
} else {
return ptr;
}
}
size(val, ctx) {
const parent = ctx;
switch (this.options.type) {
case 'local': case 'immediate':
break;
case 'parent':
ctx = ctx.parent;
break;
default: // global
while (ctx.parent) {
ctx = ctx.parent;
}
}
let { type } = this;
if (type == null) {
if (!(val instanceof VoidPointer)) {
throw new Error("Must be a VoidPointer");
}
({ type } = val);
val = val.value;
}
if (val && ctx) {
ctx.pointerSize += type.size(val, parent);
}
return this.offsetType.size();
}
encode(stream, val, ctx) {
let relative;
const parent = ctx;
if ((val == null)) {
this.offsetType.encode(stream, this.options.nullValue);
return;
}
switch (this.options.type) {
case 'local':
relative = ctx.startOffset;
break;
case 'immediate':
relative = stream.pos + this.offsetType.size(val, parent);
break;
case 'parent':
ctx = ctx.parent;
relative = ctx.startOffset;
break;
default: // global
relative = 0;
while (ctx.parent) {
ctx = ctx.parent;
}
}
if (this.options.relativeTo) {
relative += this.relativeToGetter(parent.val);
}
this.offsetType.encode(stream, ctx.pointerOffset - relative);
let { type } = this;
if (type == null) {
if (!(val instanceof VoidPointer)) {
throw new Error("Must be a VoidPointer");
}
({ type } = val);
val = val.value;
}
ctx.pointers.push({
type,
val,
parent
});
return ctx.pointerOffset += type.size(val, parent);
}
}
// A pointer whose type is determined at decode time
class VoidPointer {
constructor(type, value) {
this.type = type;
this.value = value;
}
}
exports.Pointer = Pointer;
exports.VoidPointer = VoidPointer;