opentrustprotocol 3.0.0

๐Ÿฆ€ Official Rust SDK for OpenTrust Protocol - The mathematical embodiment of trust itself. Features neutrosophic judgments, fusion operators, OTP mappers, REVOLUTIONARY Conformance Seals, and Performance Oracle with Circle of Trust for real-world outcome tracking.
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
# ๐Ÿฆ€ OpenTrust Protocol (OTP) - Rust SDK

[![Crates.io](https://img.shields.io/crates/v/opentrustprotocol.svg)](https://crates.io/crates/opentrustprotocol)
[![Documentation](https://docs.rs/opentrustprotocol/badge.svg)](https://docs.rs/opentrustprotocol)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org)

> **๐Ÿฆ€ The official Rust implementation of the OpenTrust Protocol - The MATHEMATICAL EMBODIMENT OF TRUST ITSELF**

## ๐Ÿ”ฅ **REVOLUTIONARY UPDATE: v3.0.0 - Performance Oracle & Circle of Trust**

**OTP v3.0.0 introduces:**
- **Zero Pillar**: Proof-of-Conformance Seals (cryptographic proof of specification compliance)
- **First Pillar**: Performance Oracle (Circle of Trust for real-world outcome tracking)

Every fusion operation now generates a **cryptographic fingerprint** (SHA-256 hash) that proves the operation was performed according to the exact OTP specification. Additionally, the Performance Oracle system enables tracking real-world outcomes to measure the effectiveness of OTP-based decisions.

This transforms OTP from a trust protocol into **the mathematical embodiment of trust itself**.

### **๐Ÿ›ก๏ธ What are Conformance Seals?**

- **๐Ÿ” Cryptographic Proof**: SHA-256 hash of the fusion operation
- **โœ… Mathematical Verification**: Anyone can verify conformance independently  
- **๐Ÿšจ Tamper Detection**: Any modification breaks the seal instantly
- **โšก Self-Auditing**: OTP audits itself through mathematics

### **๐ŸŽฏ The Revolution**

This solves the fundamental paradox: **"Who audits the auditor?"**

With Conformance Seals, OTP audits itself through mathematics. No more blind trust in implementations - every operation is mathematically provable.

### **๐Ÿ”ฎ What is the Performance Oracle?**

The Performance Oracle is the **First Pillar** of OTP, enabling the **Circle of Trust**:

- **๐Ÿ†” Judgment IDs**: Unique SHA-256 identifiers for every decision
- **๐ŸŒ Outcome Tracking**: Link decisions with real-world results
- **๐Ÿ“Š Performance Measurement**: Measure calibration and effectiveness
- **๐Ÿ”„ Learning Loop**: Continuous improvement through feedback
- **๐ŸŽฏ Trust Validation**: Prove that OTP decisions lead to better outcomes

### **๐Ÿ”„ The Circle of Trust**

1. **Decision**: OTP makes a decision with a unique Judgment ID
2. **Action**: The decision is acted upon in the real world
3. **Outcome**: The Performance Oracle records the actual result
4. **Learning**: The system learns from the decision-outcome pair
5. **Improvement**: Future decisions become more accurate and trustworthy

## ๐Ÿš€ **What is OpenTrust Protocol?**

The OpenTrust Protocol (OTP) is a revolutionary framework for representing and managing **uncertainty, trust, and auditability** in AI systems, blockchain applications, and distributed networks. Built on **neutrosophic logic**, OTP provides a mathematical foundation for handling incomplete, inconsistent, and uncertain information.

### **๐ŸŽฏ Why OTP Matters**

- **๐Ÿ”’ Trust & Security**: Quantify trust levels in AI decisions and blockchain transactions
- **๐Ÿ“Š Uncertainty Management**: Handle incomplete and contradictory information gracefully  
- **๐Ÿ” Full Auditability**: Complete provenance chain for every decision
- **๐ŸŒ Cross-Platform**: Interoperable across Python, JavaScript, Rust, and more
- **โšก Performance**: Zero-cost abstractions with memory safety guarantees

## ๐Ÿฆ€ **Rust SDK Features**

### **Core Components**
- **Neutrosophic Judgments**: Represent evidence as (T, I, F) values where T + I + F โ‰ค 1.0
- **Fusion Operators**: Combine multiple judgments with conflict-aware algorithms
- **OTP Mappers**: Transform raw data into neutrosophic judgments
- **Provenance Chain**: Complete audit trail for every transformation

## ๐Ÿš€ **Quick Start with Conformance Seals**

```rust
use opentrustprotocol::{NeutrosophicJudgment, conflict_aware_weighted_average, verify_conformance_seal_with_inputs};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create judgments
    let judgment1 = NeutrosophicJudgment::new(
        0.8, 0.2, 0.0,
        vec![("sensor1".to_string(), "2023-01-01T00:00:00Z".to_string())]
    )?;
    
    let judgment2 = NeutrosophicJudgment::new(
        0.6, 0.3, 0.1,
        vec![("sensor2".to_string(), "2023-01-01T00:00:00Z".to_string())]
    )?;
    
    // Fuse judgments (now with automatic Conformance Seal generation)
    let fused = conflict_aware_weighted_average(
        &[&judgment1, &judgment2],
        &[0.6, 0.4]
    )?;
    
    // Verify mathematical proof of conformance
    let is_mathematically_proven = verify_conformance_seal_with_inputs(
        &fused,
        &[&judgment1, &judgment2],
        &[0.6, 0.4]
    )?;
    
    if is_mathematically_proven {
        println!("โœ… MATHEMATICAL PROOF: This judgment is 100% conformant!");
    } else {
        println!("โŒ WARNING: Conformance verification failed!");
    }
    
    // Extract the Conformance Seal
    let seal = fused.provenance_chain.last().unwrap().conformance_seal.as_ref().unwrap();
    println!("๐Ÿ” Conformance Seal: {}", seal);
    
    Ok(())
}
```

### **๐Ÿ†• OTP Mapper System (v0.2.0)**

Transform any data type into neutrosophic judgments:

```rust
use opentrustprotocol::*;

// DeFi Health Factor Mapping
let health_mapper = NumericalMapper::new(NumericalParams {
    base: BaseMapperParams {
        id: "defi-health-factor".to_string(),
        version: "1.0.0".to_string(),
        mapper_type: MapperType::Numerical,
        description: Some("DeFi health factor mapper".to_string()),
        metadata: None,
    },
    falsity_point: 1.0,    // Liquidation threshold
    indeterminacy_point: 1.5, // Warning zone  
    truth_point: 2.0,      // Safe zone
    clamp_to_range: Some(true),
})?;

// Transform health factor to neutrosophic judgment
let judgment = health_mapper.apply(1.8)?;
println!("Health Factor 1.8: T={:.3}, I={:.3}, F={:.3}", 
         judgment.t, judgment.i, judgment.f);
```

### **Available Mappers**

| Mapper Type | Use Case | Example |
|-------------|----------|---------|
| **NumericalMapper** | Continuous data interpolation | DeFi health factors, IoT sensors |
| **CategoricalMapper** | Discrete category mapping | KYC status, product categories |
| **BooleanMapper** | Boolean value transformation | SSL certificates, feature flags |

## ๐Ÿ“ฆ **Installation**

Add to your `Cargo.toml`:

```toml
[dependencies]
opentrustprotocol = "0.2.0"
```

## ๐Ÿš€ **Quick Start**

### **Basic Neutrosophic Judgment**

```rust
use opentrustprotocol::*;

// Create judgments with provenance
let judgment1 = NeutrosophicJudgment::new(
    0.8, 0.2, 0.0,  // T=0.8, I=0.2, F=0.0
    vec![("sensor1".to_string(), "2023-01-01T00:00:00Z".to_string())]
)?;

let judgment2 = NeutrosophicJudgment::new(
    0.6, 0.3, 0.1,  // T=0.6, I=0.3, F=0.1
    vec![("sensor2".to_string(), "2023-01-01T00:00:00Z".to_string())]
)?;

// Fuse judgments with conflict-aware weighted average
let fused = conflict_aware_weighted_average(
    &[&judgment1, &judgment2],
    &[0.6, 0.4]  // weights
)?;

println!("Fused: {}", fused);
```

### **Real-World Example: DeFi Risk Assessment**

```rust
use opentrustprotocol::*;
use std::collections::HashMap;

// 1. Health Factor Mapper
let health_mapper = NumericalMapper::new(NumericalParams {
    base: BaseMapperParams {
        id: "health-factor".to_string(),
        version: "1.0.0".to_string(),
        mapper_type: MapperType::Numerical,
        description: None,
        metadata: None,
    },
    falsity_point: 1.0,
    indeterminacy_point: 1.5,
    truth_point: 2.0,
    clamp_to_range: Some(true),
})?;

// 2. KYC Status Mapper
let mut kyc_mappings = HashMap::new();
kyc_mappings.insert("VERIFIED".to_string(), JudgmentData {
    T: 0.9, I: 0.1, F: 0.0,
});

let kyc_mapper = CategoricalMapper::new(CategoricalParams {
    base: BaseMapperParams {
        id: "kyc-status".to_string(),
        version: "1.0.0".to_string(),
        mapper_type: MapperType::Categorical,
        description: None,
        metadata: None,
    },
    mappings: kyc_mappings,
    default_judgment: None,
})?;

// 3. SSL Certificate Mapper
let ssl_mapper = BooleanMapper::new(BooleanParams {
    base: BaseMapperParams {
        id: "ssl-cert".to_string(),
        version: "1.0.0".to_string(),
        mapper_type: MapperType::Boolean,
        description: None,
        metadata: None,
    },
    true_map: JudgmentData { T: 0.9, I: 0.1, F: 0.0 },
    false_map: JudgmentData { T: 0.0, I: 0.0, F: 1.0 },
})?;

// 4. Transform data to judgments
let health_judgment = health_mapper.apply(1.8)?;
let kyc_judgment = kyc_mapper.apply("VERIFIED")?;
let ssl_judgment = ssl_mapper.apply(true)?;

// 5. Fuse for final risk assessment
let risk_assessment = conflict_aware_weighted_average(
    &[&health_judgment, &kyc_judgment, &ssl_judgment],
    &[0.5, 0.3, 0.2]  // Health factor most important
)?;

println!("DeFi Risk Assessment: T={:.3}, I={:.3}, F={:.3}", 
         risk_assessment.t, risk_assessment.i, risk_assessment.f);
```

## ๐Ÿ—๏ธ **Architecture**

### **Memory Safety & Performance**

- **๐Ÿ”’ Memory Safe**: No null pointers, no data races
- **โšก Zero-Cost Abstractions**: Zero runtime overhead
- **๐Ÿ”„ Thread Safe**: `Arc<RwLock<>>` for concurrent access
- **๐Ÿ“ฆ Minimal Dependencies**: Only `serde`, `serde_json`, and `thiserror`

### **Mapper Registry System**

```rust
use opentrustprotocol::*;

let registry = get_global_registry();

// Register mappers
registry.register(Box::new(health_mapper))?;
registry.register(Box::new(kyc_mapper))?;

// Retrieve and use
let mapper = registry.get("health-factor")?;
let judgment = mapper.apply(1.5)?;

// Export configurations
let configs = registry.export();
```

## ๐Ÿงช **Testing**

Run the comprehensive test suite:

```bash
cargo test
```

Run examples:

```bash
cargo run --example mapper_examples
```

## ๐Ÿ“Š **Use Cases**

### **๐Ÿ”— Blockchain & DeFi**
- **Risk Assessment**: Health factors, liquidation risks
- **KYC/AML**: Identity verification, compliance scoring
- **Oracle Reliability**: Data source trust evaluation

### **๐Ÿค– AI & Machine Learning**
- **Uncertainty Quantification**: Model confidence scoring
- **Data Quality**: Input validation and reliability
- **Decision Fusion**: Multi-model ensemble decisions

### **๐ŸŒ IoT & Sensors**
- **Sensor Reliability**: Temperature, pressure, motion sensors
- **Data Fusion**: Multi-sensor decision making
- **Anomaly Detection**: Trust-based outlier identification

### **๐Ÿญ Supply Chain**
- **Product Tracking**: Status monitoring and verification
- **Quality Control**: Defect detection and classification
- **Compliance**: Regulatory requirement tracking

## ๐Ÿ”ง **Advanced Features**

### **Custom Mapper Creation**

```rust
// Create your own mapper by implementing the Mapper trait
struct CustomMapper {
    // Your implementation
}

impl Mapper for CustomMapper {
    fn apply(&self, input: &dyn std::any::Any) -> Result<NeutrosophicJudgment> {
        // Your transformation logic
    }
    
    fn get_params(&self) -> &dyn std::any::Any {
        // Return your parameters
    }
    
    fn get_type(&self) -> MapperType {
        // Return your mapper type
    }
    
    fn validate(&self) -> Result<()> {
        // Validate your parameters
    }
}
```

### **JSON Schema Validation**

```rust
let validator = MapperValidator::new();
let result = validator.validate(&mapper_params);

if result.valid {
    println!("โœ… Valid mapper configuration");
} else {
    for error in result.errors {
        println!("โŒ Validation error: {}", error);
    }
}
```

## ๐ŸŒŸ **Why Choose OTP Rust SDK?**

### **๐Ÿš€ Performance**
- **Zero-cost abstractions** - No runtime overhead
- **Memory safe** - No garbage collector, no memory leaks
- **Fast compilation** - Optimized for development speed

### **๐Ÿ”’ Safety**
- **Memory safety** - Compile-time guarantees
- **Thread safety** - Safe concurrent access
- **Type safety** - Strong typing prevents errors

### **๐Ÿ”ง Developer Experience**
- **Rich error messages** - Clear, actionable feedback
- **Comprehensive docs** - Extensive documentation and examples
- **Active community** - Growing ecosystem and support

## ๐Ÿ“ˆ **Performance Benchmarks**

| Operation | Time | Memory |
|-----------|------|--------|
| Judgment Creation | < 1ฮผs | 48 bytes |
| Mapper Application | < 2ฮผs | 64 bytes |
| Fusion (10 judgments) | < 5ฮผs | 256 bytes |

## ๐Ÿค **Contributing**

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### **Development Setup**

```bash
git clone https://github.com/draxork/opentrustprotocol-rs.git
cd opentrustprotocol-rs
cargo test
cargo run --example mapper_examples
```

## ๐Ÿ“š **Documentation**

- **[API Documentation]https://docs.rs/opentrustprotocol** - Complete API reference
- **[Examples]examples/** - Real-world usage examples
- **[Specification]https://github.com/draxork/opentrustprotocol-specification** - OTP v2.0 specification

## ๐ŸŒ **Ecosystem**

OTP is available across multiple platforms:

| Platform | Package | Status |
|----------|---------|--------|
| **Rust** | `opentrustprotocol` | โœ… v0.2.0 |
| **Python** | `opentrustprotocol` | โœ… v1.0.6 |
| **JavaScript** | `opentrustprotocol` | โœ… v1.0.3 |

## ๐Ÿ“„ **License**

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ **Acknowledgments**

- **Neutrosophic Logic**: Founded by Florentin Smarandache
- **Rust Community**: For the amazing language and ecosystem
- **Open Source Contributors**: Making trust auditable for everyone

---

<div align="center">

**๐ŸŒŸ Star this repository if you find it useful!**

[![GitHub stars](https://img.shields.io/github/stars/draxork/opentrustprotocol-rs?style=social)](https://github.com/draxork/opentrustprotocol-rs)

**Made with โค๏ธ by the OpenTrust Protocol Team**

</div>