Docs
Start

What Seraphin is

Seraphin seals a model. Its weights are written on Solana as ciphertext anyone can fetch, they open only inside an enclave whose runtime the chain has measured, and every answer comes back with a receipt anyone can check.

Why seal a model

A model you publish is a model you give away. A model you keep on your own server is a model nobody can audit. A sealed model sits between the two: the bytes are public and fixed by hash, so anyone can see that the model exists and has not changed, and the key that opens them lives only where the owner allows.

The four parts

PartWhat it isWhere it lives
ModelThe ciphertext of the weights, its SHA-256, its price and the measurements allowed to open it.Model and weights accounts
Enclave recordAn enclave's signing key, encryption key, measurement, hardware type and expiry.Record account
GrantThe model key wrapped to one enclave's encryption key, 125 bytes.Grant account, beside the model
ReceiptThe enclave's signature over the call, the slot and both hashes.Receipt account

codex-16

codex-16 is the first sealed model. It recognises 16 drawings: circle, triangle, square, star, heart, moon, arrow, check, cross, spiral, lightning, house, fish, sun, eye and infinity. It is a $P point-cloud recogniser: 96 templates of 32 points each, 6,351 bytes of weights, 6,471 bytes of ciphertext.

NOTEThe enclave that answers codex-16 today has hardware type dev: the runtime runs as a Web Worker in your tab. Every step is real cryptography, and every check on this site runs on real bytes. What dev hardware cannot give you is secrecy from the person at the keyboard; see the threat model.
Start

Call a model in five minutes

One import, one call. The SDK is a single ES module served from this site, with no dependencies.

Import

import { call } from 'https://seraphinus.vercel.app/lib/seraph.js'

// strokes: an array of strokes, each an array of [x, y] in any units
const { answer, receipt, verified } = await call('codex-16', strokes)

console.log(answer.label, answer.p)   // 'star' 0.98
console.log(verified.ok)              // true
<script type="module">
import { call, doodle } from 'https://seraphinus.vercel.app/lib/seraph.js'
const r = await call('codex-16', doodle('moon', 7))
document.body.textContent = r.answer.label + ' · ' + (r.verified.ok ? 'verified' : 'check failed')
</script>

The SDK fetches the model's manifest and ciphertext, checks the ciphertext against the sealed SHA-256, starts the enclave runtime, encrypts your input to it, and verifies the receipt before it hands you the answer.

Try it

LIVE · codex-16
Ask it to read a doodle of
// press Run

From another site

The module, the manifest and the ciphertext are static files, so a page on any origin can import the SDK by its full address. The enclave starts as a module Worker from the same origin as the SDK.

Start

Seal a model in ten minutes

The Seal page walks through six steps. The same steps in code:

seal.js
import { train, seal, grant, slot, unb64, b64 } from 'https://seraphinus.vercel.app/lib/seraph.js'

// 1 · prepare: labelled drawings become SRPH weights
const weights = train([{ label: 'frog', strokes }, { label: 'boat', strokes: s2 }])
// 2–3 · encrypt and create: a fresh 256-bit key, 1 KiB chunks, an address
const sealed = await seal(weights)          // { key, ciphertext, sha256, address }
// 4–5 · write the ciphertext, fix the hash at a slot
const sealedAt = await slot()
// 6 · grant: wrap the key to an enclave, then forget it
const record = await (await fetch('https://seraphinus.vercel.app/models/enclave.json')).json()
const wrapped = await grant(sealed.key, unb64(record.encKey))
sealed.key.fill(0)

const model = { name: 'my-codex', address: sealed.address, sha256: sealed.sha256,
  ciphertext: b64(sealed.ciphertext), grant: b64(wrapped), measurements: [record.measurement], sealedAt }

Pass model to call(model, strokes) and it answers. The key existed in plaintext in your tab between seal and fill(0), and nowhere else.

Concepts

Sealed models

A sealed model is a ciphertext with a fixed hash, a price and a list of runtimes allowed to open it.

Ciphertext

The weights are encrypted with AES-256-GCM under a random 256-bit model key, in 1,024-byte chunks. The ciphertext starts with an 8-byte nonce prefix; each chunk's nonce is that prefix followed by the chunk index as a big-endian u32, and each chunk's additional data is srph-chunk-<index>. A chunk cannot be moved or swapped without its tag failing.

Address and hash

The SHA-256 of the whole ciphertext is fixed at sealing. The model's address is that hash in base58. The SDK refuses to call a model whose fetched bytes hash to anything else.

The manifest

/models/codex-16.json
…
Concepts

Enclaves and attestation

An enclave is a runtime that holds two keys and runs models in its own memory. Its record says which runtime it is and until when it may be trusted.

Two keys

  • Encryption key, ECDH P-256. Grants and call inputs are encrypted to it.
  • Signing key, ECDSA P-256. Every receipt is signed with it.

Measurement

The measurement is the SHA-256 of the runtime file as served: /lib/enclave.js. Change one byte of the runtime and the measurement changes, and no model that lists the old one will be granted to it. Your browser can check it right now:

LIVE · measure the runtime
// press Measure

The record

/models/enclave.json
…
Hardware typeWhere the runtime runsKeeps keys from
devA module Web Worker in the caller's tabOther sites, the network
teeA confidential VM with a hardware attestation reportThe operator, the host, the network
Concepts

Grants

A grant is the model key wrapped to one enclave. 125 bytes, on chain, useless to everyone else.

How the key is wrapped

  1. Make an ephemeral ECDH P-256 key pair.
  2. Derive a shared secret with the enclave's encryption key.
  3. HKDF-SHA256 it with info srph/grant into an AES-256-GCM key.
  4. Encrypt the 32-byte model key under a random 12-byte IV.
BytesField
0–64Ephemeral public key, uncompressed P-256
65–76IV
77–124Wrapped key and its 16-byte tag

Granting the next enclave

The owner makes the first grant. A granted enclave can grant another one: it reads the newcomer's record, checks its measurement against the model's list and its expiry against the current slot, wraps the key inside its own memory and signs the grant.

Concepts

Calls and receipts

A call carries an input encrypted to the enclave, a reply key made for that call, the price in escrow and a deadline.

One call

  1. The caller normalises the drawing to 32 points and encrypts it to the enclave (srph/input).
  2. The caller makes a reply key pair; only its public half travels.
  3. The enclave unwraps the grant, opens the weights, runs the model.
  4. The output is encrypted to the reply key (srph/output).
  5. The enclave signs a receipt over seraphin-receipt|v1|model|call|slot|input|output.

A receipt

receipt.json
{
  "v": 1,
  "model": "8ta8EXsVrMQAHTQJs5yVhNz7q7vW8kifCGv1e2RySUwP",
  "call": "87nVVP…G3WVCQ",
  "slot": 472079882,
  "input": "3650b30b…",   // SHA-256 of the encrypted input
  "output": "6318e647…",  // SHA-256 of the answer JSON
  "enclave": "6NGtXp…5E86aG",
  "sig": "hN2c9vQ…",     // ECDSA P-256, raw r‖s, base64
  "answer": { … }      // only when the call asked for an open answer
}

Sealed or open answers

By default the answer exists in plaintext only in the enclave and in the caller's tab. Pass { open: true } and the enclave also writes it into the receipt, so a program or a stranger can act on it.

Deadline

A call not settled within 450 slots, about three minutes, returns the escrow to the caller. There is no third way out of escrow.

Concepts

Fees and the token

A call has one price, set by the owner and split at settlement between the owner, the operator and the protocol.

The split

PartyReceives
Operatorprice × operator share, set by the owner per model
Protocolprice × 5%
Ownerthe rest

codex-16 runs on dev hardware, so its price is 0 SOL and every share of it is also 0 SOL. The arithmetic is very reliable.

The token

FactValue
SymbolSERAPH
Supply1,000,000,000
Launchfair launch
Mintsoon
Protocol share5% of every settled call, to the protocol wallet
Buy $SERAPHChartX
Guides

Verify a receipt

Five checks, all in the browser, against the enclave record the chain holds.

CheckPasses when
signatureThe record's signing key verifies the signature over the receipt message.
attestationThe record's measurement is in the model's list, and equals the SHA-256 of the runtime as served.
expiryThe receipt's slot is between the record's recordedAt and expires.
open answerThe answer you hold hashes to the signed output hash.
modelThe receipt names the model you meant to call.
verify.js
import { verifyReceipt, enclaveSource } from 'https://seraphinus.vercel.app/lib/seraph.js'
const record = await (await fetch('https://seraphinus.vercel.app/models/enclave.json')).json()
const { ok, checks } = await verifyReceipt(receipt, record, { enclaveSource: await enclaveSource() })

Try it

LIVE · verify
// press Verify
Guides

Run an enclave

The runtime is one file. Serve it, and it boots, reads its record and answers calls for every model granted to it.

worker.js
const w = new Worker('https://seraphinus.vercel.app/lib/enclave.js', { type: 'module' })
w.onmessage = e => console.log(e.data)   // { type: 'boot', record } then one reply per job
// job: { id, address, grant, ciphertext, input, reply, call, slot, open }
WARNINGA worker can only start from its own origin, so a page elsewhere should go through call(), which starts the runtime for you. A runtime you modify gets a new measurement and needs its own record and grants.
Guides

The script

Every byte on this site is drawn as one of 256 glyphs. Byte 0 always looks the same; nobody has ever read a sentence in it.

Each glyph is built on a 3 × 4 lattice from a seeded generator: an optional stem, one to three lines, hooks, arcs or loops, sometimes a dot. drawGlyph(ctx, byte, x, y, w, h) draws one on a canvas, glyphSVG(byte, size) returns it as SVG.

LIVE · write in it
Reference

SDK

/lib/seraph.js, about 20 KB, no dependencies, browsers and Node 20+.

FunctionReturns
call(model, strokes, opts?){ answer, receipt, verified, timings }. model is a name or a manifest.
open(model)A handle with call(), after checking the ciphertext hash.
normalize(strokes, n = 32)n points, resampled, scaled to a unit box, centred.
recognize(points, templates){ label, p, top }. Runs inside the enclave.
train(samples)SRPH weights from [{ label, strokes }].
seal(weights, key?){ key, ciphertext, sha256, address }
unseal(key, ct, from?, to?)Plaintext, or only the chunks you ask for.
grant(key, encPub) / ungrant(priv, wrapped)125-byte wrapped key / the model key.
boxTo(pub, bytes, info) / boxOpen(priv, box, info)ECDH + HKDF + AES-GCM boxes.
verifyReceipt(r, record, opts?){ ok, checks }
slot()The current Solana slot, read from a public RPC.
doodle(label, seed, amount?)Strokes of one of the 16 shapes, wobbled.
glyphSVG(byte, size)One glyph of the script.
Reference

Weights format · SRPH v1

The plaintext a sealed model hides. Small enough to read with a pencil, if you had the key.

BytesField
4Magic SRPH
1Version, 1
1N, points per template (32)
1Label count L
L × (1 + len)Labels: length, then UTF-8
2Template count T, big-endian
T × (1 + 2N)Templates: label index, then N × (x, y), each u8 = round((v + 1) × 127.5)

codex-16 has 16 labels and 96 templates: 7 + 112 + 2 + 96 × 65 = 6,351 bytes.

Reference

Ciphers and constants

Everything is WebCrypto. Nothing is hand-rolled except base58.

NameValue
Weights cipheraes-256-gcm-1k-v1: AES-256-GCM, 1,024-byte chunks, 96-bit nonce = prefix(8) ‖ index(4)
BoxECDH P-256 → HKDF-SHA256 (salt 32 × 0x00) → AES-256-GCM
Box infossrph/grant, srph/input, srph/output
Receipt signatureECDSA P-256 with SHA-256, raw r ‖ s
Receipt messageseraphin-receipt|v1|model|call|slot|input|output
Points per drawing32
Call deadline450 slots
Protocol share500 basis points
Reference

Errors

What the SDK throws, and what it means.

MessageMeaning
empty drawingFewer than two points reached normalize.
ciphertext hash does not match the sealed hashThe bytes you fetched are not the bytes that were sealed. Do not call.
not SRPH weightsThe key opened something, but not a Seraphin model.
The operation failed for some operation-specific reasonWebCrypto's way of saying a tag failed: wrong key, wrong enclave, or a changed byte.
enclave failed to bootModule workers are blocked, or the runtime was served from another origin.
More

Threat model

What sealing protects, and from whom.

It protects against

  • Anyone who reads the chain: the ciphertext is AES-256-GCM under a key that never touches it in plaintext.
  • Swapped or edited weights: the hash is fixed, every chunk carries a tag.
  • A forged answer: the receipt is signed by a key the record binds to a measured runtime.
  • A changed runtime: a new measurement gets no grant.

It does not protect against

  • The operator of dev hardware. The dev runtime's keys sit in its public source, which is why it is called dev. Secrecy from the operator needs tee hardware.
  • A model owner who leaks their own key before granting.
  • Model extraction by asking many questions. Price per call is the defence, and codex-16 is free.
More

FAQ

Short answers.

Why does everything look like a manuscript?

Because ciphertext is a book in a language nobody speaks. We just gave it an alphabet.

Is codex-16 a neural network?

No. It is a point-cloud recogniser with 96 templates. Sealing does not care what the weights mean; a larger model is a longer ciphertext.

Can I see the weights?

Every byte, on the front page and in /models/codex-16.bin. Reading them is the part we cannot help with.

What does $SERAPH do?

It takes the protocol share of every settled call. On dev hardware calls cost 0 SOL, so it takes 5% of nothing, faithfully.

Where is my sealed model stored?

In your browser's local storage: the ciphertext and the grant. The key is never stored anywhere.