webylib 0.2.0

Webcash HD wallet library โ€” bearer e-cash with BIP32-style key derivation, SQLite storage, AES-256-GCM encryption, and full C FFI for cross-platform SDKs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# Build Instructions

## ๐ŸŽฏ **Quick Build**

```bash
# Clone repository
git clone <repository-url>
cd webcash-rust

# Build everything
cargo build

# Build optimized release
cargo build --release

# Run tests
cargo test

# Run the CLI
cargo run --bin webyc -- --version
```

## ๐Ÿ—๏ธ **Build System Overview**

### **Cargo Build System**
This project uses **Cargo**, Rust's package manager and build system:

- **Dependencies**: Automatically downloaded and managed
- **Cross-platform**: Works on Linux, macOS, Windows
- **Incremental**: Only rebuilds changed code
- **Optimized**: Release builds are highly optimized

### **Build Profiles**
```toml
# Debug build (default)
cargo build          # Development with debug symbols
cargo build --debug  # Explicit debug build

# Release build
cargo build --release  # Optimized production build

# Custom profiles
cargo build --profile dev     # Development profile
cargo build --profile release # Release profile
```

## ๐Ÿ“ฆ **Dependencies**

### **Core Dependencies**
```toml
[dependencies]
# Cryptography
sha2 = "0.10"          # SHA256 hashing
hex = "0.4"            # Hex encoding/decoding
getrandom = "0.2"      # Secure random generation

# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"     # JSON serialization

# Database
rusqlite = "0.28"      # SQLite database

# HTTP client
reqwest = { version = "0.11", features = ["json", "rustls-tls"] }

# Error handling
thiserror = "1.0"      # Error types
anyhow = "1.0"         # Error handling

# CLI
clap = { version = "4.0", features = ["derive"] }

# Utilities
zeroize = "1.5"        # Secure memory zeroization
```

### **Development Dependencies**
```toml
[dev-dependencies]
tokio-test = "0.4"     # Async testing
tempfile = "3.0"       # Temporary files for testing
```

## ๐Ÿ”ง **Build Commands**

### **Basic Builds**
```bash
# Standard debug build
cargo build

# Optimized release build
cargo build --release

# Build specific binary
cargo build --bin webyc

# Build library only
cargo build --lib
```

### **Advanced Builds**
```bash
# Build with specific features
cargo build --features "extra-security"

# Build for specific target
cargo build --target x86_64-unknown-linux-gnu

# Build with custom linker
RUSTFLAGS="-C linker=clang" cargo build

# Build with verbose output
cargo build --verbose
```

### **Cross-Compilation**
```bash
# Install cross-compilation tools
cargo install cross

# Build for different architectures
cross build --target aarch64-unknown-linux-gnu
cross build --target x86_64-pc-windows-gnu
cross build --target x86_64-apple-darwin
```

## ๐Ÿงช **Testing**

### **Unit Tests**
```bash
# Run all tests
cargo test

# Run specific test
cargo test test_amount_arithmetic

# Run tests in specific module
cargo test amount::

# Run with output
cargo test -- --nocapture

# Run release tests
cargo test --release
```

### **Integration Tests**
```bash
# Run integration tests (when implemented)
cargo test --test integration

# Run tests with different features
cargo test --features "mock-server"
```

### **Documentation Tests**
```bash
# Test code examples in documentation
cargo test --doc

# Test specific documentation
cargo test --doc amount
```

## ๐Ÿ“Š **Code Quality**

### **Formatting**
```bash
# Format all code
cargo fmt

# Check formatting (CI)
cargo fmt --check

# Format specific files
cargo fmt -- src/main.rs
```

### **Linting**
```bash
# Run clippy linter
cargo clippy

# Run with warnings as errors
cargo clippy -- -D warnings

# Fix auto-fixable issues
cargo clippy --fix
```

### **Security Scanning**
```bash
# Run security audit (when cargo-audit is installed)
cargo audit

# Check for vulnerabilities
cargo audit check

# Update advisory database
cargo audit update
```

## ๐Ÿ“ˆ **Performance Optimization**

### **Release Build Optimizations**
```bash
# Build with maximum optimizations
cargo build --release

# Build with Link-Time Optimization (LTO)
cargo build --release --config profile.release.lto=true

# Build with specific optimization level
cargo build --release --config profile.release.opt-level=3
```

### **Binary Size Optimization**
```bash
# Strip debug symbols
cargo build --release
strip target/release/webyc

# Analyze binary size
cargo bloat --release --crates

# Build minimal binary
cargo build --release --features "minimal"
```

### **Benchmarking**
```bash
# Run benchmarks (when implemented)
cargo bench

# Profile performance
cargo build --release
perf record target/release/webyc --version
perf report
```

## ๐Ÿ” **Debug Builds**

### **Debug Symbols**
```bash
# Build with debug symbols
cargo build

# Build with maximum debug info
cargo build --config profile.dev.debug=2
```

### **Debugging Tools**
```bash
# Use debugger
rust-gdb target/debug/webyc

# Use lldb (macOS)
rust-lldb target/debug/webyc

# Memory profiling (Linux)
valgrind --tool=massif target/debug/webyc

# Memory leak detection
valgrind --tool=memcheck target/debug/webyc
```

## ๐Ÿ“š **Documentation**

### **Generate Documentation**
```bash
# Generate API documentation
cargo doc

# Open documentation in browser
cargo doc --open

# Generate documentation with private items
cargo doc --document-private-items

# Generate for specific package
cargo doc --package webylib
```

### **Documentation Testing**
```bash
# Test documentation examples
cargo test --doc

# Test specific documentation
cargo test --doc -- lib::amount
```

## ๐Ÿš€ **Deployment**

### **Binary Distribution**
```bash
# Build for distribution
cargo build --release

# Create distribution package
tar -czf webylib-v0.1.0.tar.gz target/release/webyc

# Cross-platform builds
cargo build --release --target x86_64-unknown-linux-gnu
cargo build --release --target x86_64-pc-windows-gnu
cargo build --release --target x86_64-apple-darwin
```

### **Library Distribution**
```bash
# Build library for crates.io
cargo build --release

# Test library publication
cargo publish --dry-run

# Publish to crates.io
cargo publish
```

## ๐Ÿ”ง **Build Configuration**

### **Cargo.toml Configuration**
```toml
[package]
name = "webylib"
version = "0.1.0"
edition = "2021"
authors = ["Webcash Developers"]
description = "Secure Rust implementation of Webcash"
license = "MPL-2.0"

[features]
default = ["server", "wallet"]
server = ["reqwest"]
wallet = ["rusqlite"]
minimal = []  # Minimal feature set

[profile.release]
opt-level = 3
lto = true
codegen-units = 1
panic = "abort"
strip = true

[profile.dev]
opt-level = 0
debug = true
overflow-checks = true
```

### **Custom Build Scripts**
```rust
// build.rs (if needed)
fn main() {
    // Custom build logic
    println!("cargo:rerun-if-changed=build.rs");

    // Generate version information
    let version = env!("CARGO_PKG_VERSION");
    println!("cargo:rustc-env=VERSION={}", version);
}
```

## ๐Ÿ› **Troubleshooting Builds**

### **Common Build Issues**

#### **1. Dependency Resolution**
```bash
# Clear dependency cache
cargo clean
rm -rf ~/.cargo/registry/cache/
rm -rf ~/.cargo/git/db/

# Update dependencies
cargo update

# Check for conflicts
cargo tree
```

#### **2. Compilation Errors**
```bash
# Get detailed error information
cargo build --verbose

# Check Rust version compatibility
rustc --version
cargo --version

# Update Rust
rustup update
```

#### **3. Linker Issues**
```bash
# Linux: Install system dependencies
sudo apt-get install libsqlite3-dev libssl-dev pkg-config

# macOS: Install dependencies
brew install sqlite openssl pkg-config

# Check library paths
pkg-config --libs sqlite3
```

#### **4. Memory Issues**
```bash
# Increase memory limits
export CARGO_BUILD_JOBS=1

# Use less aggressive optimization
cargo build --config profile.release.opt-level=2
```

### **Performance Issues**

#### **1. Slow Builds**
```bash
# Use incremental compilation
echo "incremental = true" >> ~/.cargo/config

# Use more RAM for compilation
export RUSTFLAGS="-C codegen-units=1"

# Use faster linker (Linux)
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=lld"
```

#### **2. Large Binaries**
```bash
# Analyze binary size
cargo bloat --release

# Strip debug symbols
strip target/release/webyc

# Use UPX compression
upx target/release/webyc
```

## ๐Ÿ“‹ **CI/CD Integration**

### **GitHub Actions**
```yaml
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo build
      - run: cargo test
      - run: cargo clippy
      - run: cargo fmt --check
```

### **Local CI Simulation**
```bash
# Run all CI checks locally
cargo fmt --check
cargo clippy -- -D warnings
cargo test
cargo doc
cargo build --release
```

## ๐ŸŽฏ **Build Success Criteria**

### **โœ… Successful Build Checklist**
- [ ] `cargo build` completes without errors
- [ ] `cargo test` passes all tests
- [ ] `cargo clippy` reports no warnings
- [ ] `cargo fmt --check` passes
- [ ] `cargo doc` generates documentation
- [ ] Binary runs correctly: `cargo run --bin webyc -- --version`

### **๐Ÿ“Š Quality Metrics**
- **Build Time**: < 30 seconds for incremental builds
- **Binary Size**: < 5MB for release builds
- **Test Coverage**: > 80% (when measured)
- **Zero Warnings**: Clean clippy output
- **Memory Safe**: No unsafe code blocks

---

## ๐Ÿš€ **Next Steps**

After successful build:

1. **Run Tests**: [TESTING.md]TESTING.md
2. **Start Development**: [IMPLEMENTATION_STATUS.md]../IMPLEMENTATION_STATUS.md
3. **Contribute**: [CONTRIBUTING.md]../../CONTRIBUTING.md

---

**๐Ÿ—๏ธ Happy building! Remember: `cargo build && cargo test` is your friend!**