docs: ajustements mineurs post-alignement (USAGE, ARCHITECTURE)
This commit is contained in:
parent
b4dcadbb34
commit
034fd62370
@ -172,17 +172,17 @@ impl SilentPaymentGenerator {
|
||||
pub fn new(wallet: Wallet, network: Network) -> Self {
|
||||
Self { wallet, network }
|
||||
}
|
||||
|
||||
|
||||
pub fn generate_payment(&self) -> Result<SilentPayment, SdkError> {
|
||||
// 1. Générer la clé de scan
|
||||
let scan_key = self.generate_scan_key()?;
|
||||
|
||||
|
||||
// 2. Générer la clé de dépense
|
||||
let spend_key = self.generate_spend_key()?;
|
||||
|
||||
|
||||
// 3. Créer l'adresse silencieuse
|
||||
let address = self.create_silent_address(&scan_key, &spend_key)?;
|
||||
|
||||
|
||||
Ok(SilentPayment {
|
||||
scan_key,
|
||||
spend_key,
|
||||
@ -203,16 +203,16 @@ pub struct TransactionScanner {
|
||||
impl TransactionScanner {
|
||||
pub fn scan_transaction(&self, tx: &Transaction) -> Result<Vec<Output>, SdkError> {
|
||||
let mut outputs = Vec::new();
|
||||
|
||||
|
||||
for (index, output) in tx.outputs.iter().enumerate() {
|
||||
// 1. Extraire les données de l'output
|
||||
let script_pubkey = &output.script_pubkey;
|
||||
|
||||
|
||||
// 2. Vérifier si c'est un paiement silencieux
|
||||
if self.is_silent_payment_output(script_pubkey)? {
|
||||
// 3. Dériver la clé de scan
|
||||
let derived_key = self.derive_scan_key(script_pubkey)?;
|
||||
|
||||
|
||||
// 4. Vérifier la correspondance
|
||||
if self.matches_scan_key(&derived_key)? {
|
||||
outputs.push(Output {
|
||||
@ -224,7 +224,7 @@ impl TransactionScanner {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(outputs)
|
||||
}
|
||||
}
|
||||
@ -242,7 +242,7 @@ impl OutputCreator {
|
||||
pub fn create_output(&self, amount: u64, address: &Address) -> Result<TxOut, SdkError> {
|
||||
// 1. Créer le script de sortie
|
||||
let script_pubkey = self.create_output_script(address)?;
|
||||
|
||||
|
||||
// 2. Créer la sortie
|
||||
Ok(TxOut {
|
||||
value: amount,
|
||||
@ -267,13 +267,13 @@ impl SecureKeyManager {
|
||||
// Générer une clé privée sécurisée
|
||||
let private_key = SecureKey::generate()?;
|
||||
let public_key = private_key.public_key()?;
|
||||
|
||||
|
||||
Ok(Self {
|
||||
private_key,
|
||||
public_key,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn sign(&self, message: &[u8]) -> Result<Signature, SdkError> {
|
||||
// Signature sécurisée avec protection contre les attaques par timing
|
||||
self.private_key.sign_secure(message)
|
||||
@ -302,20 +302,20 @@ impl InputValidator {
|
||||
if tx.serialized_size() > self.max_tx_size {
|
||||
return Err(SdkError::TransactionTooLarge);
|
||||
}
|
||||
|
||||
|
||||
// 2. Vérifier les entrées
|
||||
for input in &tx.inputs {
|
||||
self.validate_input(input)?;
|
||||
}
|
||||
|
||||
|
||||
// 3. Vérifier les sorties
|
||||
for output in &tx.outputs {
|
||||
self.validate_output(output)?;
|
||||
}
|
||||
|
||||
|
||||
// 4. Vérifier la cohérence
|
||||
self.validate_consistency(tx)?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -333,13 +333,13 @@ impl SecurityManager {
|
||||
pub fn process_request(&self, request: &Request) -> Result<Response, SdkError> {
|
||||
// 1. Rate limiting
|
||||
self.rate_limiter.check_limit(&request.source)?;
|
||||
|
||||
|
||||
// 2. Sanitisation des entrées
|
||||
let sanitized_request = self.input_sanitizer.sanitize(request)?;
|
||||
|
||||
|
||||
// 3. Validation
|
||||
self.validate_request(&sanitized_request)?;
|
||||
|
||||
|
||||
// 4. Traitement sécurisé
|
||||
self.process_secure(&sanitized_request)
|
||||
}
|
||||
@ -377,7 +377,7 @@ pub fn create_large_wallet() -> Box<Wallet> {
|
||||
#[cfg(feature = "wasm")]
|
||||
pub mod wasm_optimizations {
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
||||
// Utilisation de Web Workers pour les calculs lourds
|
||||
#[wasm_bindgen]
|
||||
pub fn process_payment_async(payment_data: JsValue) -> js_sys::Promise {
|
||||
@ -386,7 +386,7 @@ pub mod wasm_optimizations {
|
||||
process_payment_worker(payment_data)
|
||||
).into()
|
||||
}
|
||||
|
||||
|
||||
// Utilisation de SharedArrayBuffer pour les gros datasets
|
||||
#[wasm_bindgen]
|
||||
pub fn process_large_dataset(data: &js_sys::Uint8Array) -> Result<(), JsValue> {
|
||||
@ -411,11 +411,11 @@ impl CacheManager {
|
||||
tx_cache: LruCache::new(1000),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_wallet(&mut self, id: &str) -> Option<&Wallet> {
|
||||
self.wallet_cache.get(id)
|
||||
}
|
||||
|
||||
|
||||
pub fn cache_wallet(&mut self, id: String, wallet: Wallet) {
|
||||
self.wallet_cache.put(id, wallet);
|
||||
}
|
||||
@ -437,11 +437,11 @@ impl PerformanceMetrics {
|
||||
pub fn record_operation(&mut self, operation: &str, duration: Duration) {
|
||||
self.operation_times.insert(operation.to_string(), duration);
|
||||
}
|
||||
|
||||
|
||||
pub fn record_error(&mut self, error_type: &str) {
|
||||
*self.error_counts.entry(error_type.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
|
||||
pub fn get_memory_usage(&self) -> MemoryUsage {
|
||||
self.memory_usage.current_usage()
|
||||
}
|
||||
@ -462,15 +462,15 @@ impl Logger {
|
||||
self.output.write(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn debug(&self, message: &str) {
|
||||
self.log(LogLevel::Debug, message);
|
||||
}
|
||||
|
||||
|
||||
pub fn info(&self, message: &str) {
|
||||
self.log(LogLevel::Info, message);
|
||||
}
|
||||
|
||||
|
||||
pub fn error(&self, message: &str) {
|
||||
self.log(LogLevel::Error, message);
|
||||
}
|
||||
@ -529,13 +529,13 @@ mod tests {
|
||||
fn test_wallet_creation() {
|
||||
// Test de base
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "wasm")]
|
||||
#[test]
|
||||
fn test_wasm_integration() {
|
||||
// Test WASM
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "blindbit-wasm")]
|
||||
#[test]
|
||||
fn test_blindbit_wasm() {
|
||||
|
@ -70,14 +70,14 @@ use sdk_common::{
|
||||
fn main() -> Result<(), SdkError> {
|
||||
// Créer un wallet
|
||||
let wallet = Wallet::new()?;
|
||||
|
||||
|
||||
// Générer un paiement silencieux
|
||||
let payment = SilentPayment::generate(&wallet)?;
|
||||
|
||||
|
||||
// Traiter une transaction
|
||||
let tx = Transaction::from_hex("...")?;
|
||||
let result = wallet.process_transaction(&tx)?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
@ -98,13 +98,13 @@ import { init, Wallet, SilentPayment } from '@4nk/sdk-common';
|
||||
async function main() {
|
||||
// Initialiser le module WASM
|
||||
await init();
|
||||
|
||||
|
||||
// Créer un wallet
|
||||
const wallet = new Wallet();
|
||||
|
||||
|
||||
// Générer un paiement silencieux
|
||||
const payment = SilentPayment.generate(wallet);
|
||||
|
||||
|
||||
console.log('Payment:', payment);
|
||||
}
|
||||
|
||||
@ -124,20 +124,20 @@ main().catch(console.error);
|
||||
<body>
|
||||
<script type="module">
|
||||
import init, { Wallet, SilentPayment } from './pkg/sdk_common.js';
|
||||
|
||||
|
||||
async function main() {
|
||||
await init();
|
||||
|
||||
|
||||
const wallet = new Wallet();
|
||||
const payment = SilentPayment.generate(wallet);
|
||||
|
||||
document.getElementById('result').textContent =
|
||||
|
||||
document.getElementById('result').textContent =
|
||||
JSON.stringify(payment, null, 2);
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
</script>
|
||||
|
||||
|
||||
<h1>SDK Common Demo</h1>
|
||||
<pre id="result"></pre>
|
||||
</body>
|
||||
@ -177,7 +177,7 @@ impl WalletOperations for MyWallet {
|
||||
fn generate_address(&self) -> Result<Address, SdkError> {
|
||||
// Implémentation personnalisée
|
||||
}
|
||||
|
||||
|
||||
fn sign_transaction(&self, tx: &Transaction) -> Result<Signature, SdkError> {
|
||||
// Implémentation personnalisée
|
||||
}
|
||||
@ -437,10 +437,10 @@ use std::time::Instant;
|
||||
|
||||
fn benchmark_operation() {
|
||||
let start = Instant::now();
|
||||
|
||||
|
||||
// Opération à mesurer
|
||||
let result = perform_operation();
|
||||
|
||||
|
||||
let duration = start.elapsed();
|
||||
println!("Opération terminée en {:?}", duration);
|
||||
}
|
||||
@ -453,7 +453,7 @@ use log::{info, warn, error, debug};
|
||||
|
||||
fn process_payment(payment: &SilentPayment) -> Result<(), SdkError> {
|
||||
debug!("Traitement du paiement: {:?}", payment);
|
||||
|
||||
|
||||
match payment.process() {
|
||||
Ok(_) => {
|
||||
info!("Paiement traité avec succès");
|
||||
|
Loading…
x
Reference in New Issue
Block a user