<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/OnionService",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor12OnionServiceV"
  },
  "title" : "OnionService"
}
-->

# OnionService

A successfully-created onion service, as returned by `ADD_ONION`.

```
struct OnionService
```

## Overview

Value-type record carrying the service identifier, an optional
private key (present iff [`OnionKeySpec.newV3(discardPrivateKey:)`](/documentation/Tor/OnionKeySpec/newV3(discardPrivateKey:))
was called with `discardPrivateKey: false`), and the creation
timestamp. Constructed by [`addOnion(key:ports:detach:)`](/documentation/Tor/TorControlClient/addOnion(key:ports:detach:))
from the parsed `ADD_ONION` reply; callers can also construct one
directly for tests or persisted state replay.

Per rend-spec-v3 §6, a v3 service identifier is a 56-character
base32-encoded string (without the `.onion` suffix). Combine with
[`onionAddress`](/documentation/Tor/OnionService/onionAddress) for the fully-qualified address clients dial.

> Note: Conformance is `Sendable`. Deliberately **not** `Hashable`:
> ``doc://Tor/documentation/Tor/OnionService/privateKey`` carries secret material, and the creation
> timestamp would poison any hash.

> Important: ``doc://Tor/documentation/Tor/OnionService/privateKey`` is secret material. Never log, diff, or
> serialise it to stdout. Persist only via Keychain (Apple) or an
> equivalent credential store.

## Topics

### Creating

[`init(serviceID:privateKey:createdAt:)`](/documentation/Tor/OnionService/init(serviceID:privateKey:createdAt:))

Memberwise initialiser for test fixtures and replay.

### Inspection

[`serviceID`](/documentation/Tor/OnionService/serviceID)

The 56-character v3 service identifier (without `.onion`).

[`onionAddress`](/documentation/Tor/OnionService/onionAddress)

Fully-qualified `.onion` address: `"<serviceID>.onion"`.

[`privateKey`](/documentation/Tor/OnionService/privateKey)

Base64-encoded ED25519-V3 private key, or `nil` if discarded.

[`createdAt`](/documentation/Tor/OnionService/createdAt)

Wall-clock time at which this value was constructed.

