> ## Documentation Index
> Fetch the complete documentation index at: https://whiterail.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Security

### 보안 흐름

1. **클라이언트**: 임시 P-256 키페어 생성 (개인키는 메모리에만 존재)
2. **전송**: 압축된 공개키(33바이트)만 백엔드로 전송
3. **백엔드**: Turnkey와 통신, 지갑 생성 (첫 인증 시)
4. **결과**: 세션 토큰 + 지갑 주소 반환
5. **서명**: 클라이언트 측에서만 트랜잭션 서명

<Warning>
  **중요**: 개인키는 절대 백엔드로 전송되지 않습니다. 백엔드는 서명 권한이
  없습니다.
</Warning>

### 완전한 Non-custodial 설계

```mermaid theme={null}
sequenceDiagram
    participant Client as Client<br/>(React)
    participant Backend as Backend<br/>(Node)
    participant Turnkey as Turnkey<br/>API

    Note over Client,Turnkey: 1. Create Account
    Client->>Backend: createAccount
    Backend->>Turnkey: createSubOrg()<br/>+ wallet creation
    Turnkey-->>Backend: subOrgId + wallet
    Backend->>Backend: DB: save account<br/>+ address
    Backend-->>Client: subOrgId + address

    Note over Client,Turnkey: 2. Init Auth
    Client->>Backend: initAuth
    Backend->>Backend: DB: check account
    Backend->>Turnkey: initOtp()
    Turnkey-->>Backend: OTP sent via email
    Backend-->>Client: OTP sent

    Note over Client,Turnkey: 3. Complete Auth<br/>+ OTP + publicKey
    Client->>Backend: completeAuth
    Backend->>Turnkey: verifyOtp()<br/>(root-org context)
    Turnkey-->>Backend: verificationToken
    Backend->>Turnkey: otpLogin()<br/>+ publicKey<br/>(→ sub-org session)
    Turnkey-->>Backend: sessionToken
    Backend-->>Client: Auth success<br/>+ address + session
```
