# Security

#### Privacy Guarantees

**What Observers See**:

```
Transaction on Blockchain:
├─ Sender: <HIDDEN via ZK proof>
├─ Recipient: 0xMerchant... (public)
├─ Amount: <ENCRYPTED with ElGamal>
├─ Timestamp: 2024-10-29 12:34:56
└─ Proof: <Valid ZK proof data>
```

**What You See:**

```
Your Private View:
├─ Sender: You (+1234567890)
├─ Recipient: Merchant (+0987654321)
├─ Amount: 0.10 USDC (decrypted)
├─ Privacy: FULL (ZK + Encryption)
└─ Status: Confirmed ✓
```

#### Security Best Practices

1. **Never Expose Private Keys**

```typescript
// ❌ WRONG
const privateKey = "0x123abc...";
console.log(privateKey);

// ✓ CORRECT
const privateKey = process.env.PRIVATE_KEY;
// Never log or expose
```

2. **Always Verify Backend-Side**

```typescript
// ❌ WRONG - Client says payment is valid
if (req.body.paymentValid) {
  grantAccess();
}

// ✓ CORRECT - Verify with NumPay
const verified = await numpay.verifyPaymentToken(token);
if (verified) {
  grantAccess();
}
```

3. **Prevent Replay Attacks**

```typescript
// Store used payment tokens
const usedTokens = new Set();

if (usedTokens.has(paymentToken)) {
  throw new Error('Payment already processed');
}

usedTokens.add(paymentToken);
```

4. **Rate Limit Proof Generation**&#x20;

```typescript
// Client-side: Prevent spam proof generation
const lastProofTime = localStorage.getItem('lastProof');
if (Date.now() - lastProofTime < 10000) {
  throw new Error('Please wait before generating another proof');
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://numpay.gitbook.io/numpay/technology-architecture/numpay-shadow-protocol-zk-+-x402/security.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
