# How the check works, exactly

> The exact format of WonderOath sealed checklists: every hashed byte, the hash trees, the box and card codes, a worked example, a one-file checker and test vectors.

Source: https://wonderoath.com/transparency/format/

Concept designs · Nothing is for sale yet.

Release information

# How the check works, exactly.

Every byte that goes into a WonderOath fingerprint, written down so a programmer can check a box code without this website.

## Check it without us.

A check you cannot run yourself asks for trust. This page, one small program and a file of test vectors are everything needed to check a code. None of them contacts WonderOath.
- **The checker**: [verify.mjs](https://wonderoath.com/verify.mjs)
One file of 146 lines with no dependencies. It runs in Node.js 18 or later and is short enough to read first.
- **Test vectors**: [seal-vectors.json](https://wonderoath.com/seal-vectors.json)
191 codes with the result each must give: 89 that match, 36 that do not, and 66 that must be refused.
- **In a browser**: [Check a box](https://wonderoath.com/transparency/check/)
The same steps with the browser’s own SHA-256. The code never leaves your device.

Save the checker and run it with a code, or a whole check link, and the fingerprint published for the release:

`node verify.mjs CODE FINGERPRINT`

It prints `MATCH`, `NO MATCH` or `NOT CHECKED` and exits with 0, 1 or 2.

## What a match shows.

- A match shows that the cards named in the code went into the fingerprint you compared with. Change a card, its place, its box or the release and the fingerprint changes.
- The check reads the code, not the cards themselves, so compare the list it shows with the cards in your box.
- It does not describe card values or how cards were assigned to boxes.
- The check compares with a fingerprint. It cannot tell you when that fingerprint was published. Use the one WonderOath publishes for the release, not one handed over with the code. The release page shows it in short form and `/release-data.json` carries all 64 characters.
- The seal fixes the text in the code. When that text is a checklist entry id, the card name shown beside it comes from the published checklist.
- No release has been sealed yet. Every code on this site is an example or a test vector.

## Two formats.
| Version | A code shows | Code | Used by |
| --- | --- | --- | --- |
| 1 | One whole box | JSON text in base64url | The Castle Tree example |
| 2 | One whole box, or one card of a box | Bytes in base64url | The card by card example. The sealing tool writes this version. |

Both end in one SHA-256 fingerprint for the whole release. A version stays as it is once published: version 1 codes still check here against their fingerprints.

## Rules both formats share.

- The hash is SHA-256. A fingerprint is its 32 bytes as 64 lowercase hex characters.
- A code is bytes written in base64url (RFC 4648 section 5: `A-Z`, `a-z`, `0-9`, `-` and `_`) with no padding. The bits of the last character that carry no data must be zero, so every code has exactly one spelling.
- A check link is `https://wonderoath.com/transparency/check/#code=` followed by the code. Browsers do not send the part after `#` to the server.
- A checker may be handed a check link in place of a code: it reads what follows `#code=`. Before that it drops spaces, tabs and line breaks (line feed, carriage return, form feed) wherever they appear, because pasted codes get wrapped. No other character is dropped.
- The first byte gives the version: `0x7B`, the character `{`, is version 1 and `0x02` is version 2. Anything else is not a WonderOath code.
- A checker refuses any code that breaks a rule on this page. It never repairs or guesses.

On this page `u8(x)` is one byte, `u32(x)` is four bytes with the most significant first, and `str(x)` is one byte holding the length of `x` in bytes (1 to 255) followed by `x`. Lists of bytes are joined in the order written, with nothing between them.

## Version 2: card by card.

Each box is a small hash tree over its cards, and the release is a hash tree over its boxes. A code can open a whole box, or a single card while its neighbours stay hidden.

### The values
| Name | Size | Rule |
| --- | --- | --- |
| `release` | 1 to 255 bytes | The release name in ASCII: lowercase letters and digits in groups joined by single hyphens, `^[a-z0-9]+(-[a-z0-9]+)*$`. |
| `boxes` | u32 | How many boxes the release has, 1 to 4294967295. |
| `box` | u32 | This box, 1 to `boxes`. Boxes are numbered from 1 with no gaps. |
| `cards` | u8 | How many cards this box has, 1 to 255. |
| `card` | u8 | This card, 1 to `cards`. |
| `salt` | 16 bytes | A random value. Every card has its own. |
| `text` | 1 to 255 bytes | The card’s text in well-formed UTF-8, with no control characters (U+0000 to U+001F, U+007F to U+009F). For a release this is the checklist entry id. |

### The five hashes

Each is SHA-256 of the bytes listed, in order. A label is the ASCII text between the quotes with nothing after it.
- **Card leaf**: `"wonderoath-seal-v2/card-leaf:"`, `str(release)`, `u32(box)`, `u8(cards)`, `u8(card)`, `salt`, `str(text)`
- **Card node**: `"wonderoath-seal-v2/card-node:"`, `left hash`, `right hash`
- **Box leaf**: `"wonderoath-seal-v2/box-leaf:"`, `str(release)`, `u32(box)`, `u8(cards)`, `card root`
- **Box node**: `"wonderoath-seal-v2/box-node:"`, `left hash`, `right hash`
- **Fingerprint**: `"wonderoath-seal-v2/release:"`, `str(release)`, `u32(boxes)`, `box root`

No label is the start of another. A node can therefore never be read as a leaf, and a hash from a card tree can never be read as one from the box tree.

### The trees

A tree turns a list of hashes into one hash, its root:

1. If the list holds one hash, that hash is the root.
2. Otherwise pair the hashes from the start: first with second, third with fourth, and so on. Replace each pair by its node hash, left one first.
3. If one hash is left over at the end of an odd list, it moves up unchanged. It is never paired with itself.
4. Repeat with the new, shorter list.

The card root of a box is the tree of its card leaves in card order, built with card nodes. The box root is the tree of every box leaf in box order, built with box nodes. This is the tree shape of RFC 6962.

### Paths

A path is the list of sibling hashes met on the way from one leaf up to the root, lowest first. A version 2 code does not say which side each sibling is on. The side follows from the position. Below, `node(a, b)` is the node hash with `a` as the left hash and `b` as the right hash.

1. Start with `hash` as the leaf, `index` as one less than its position and `size` as the number of leaves. That is `card - 1` and `cards` in a card tree, `box - 1` and `boxes` in the box tree.
2. While `size` is more than 1, do one of three things. If `index` is odd, the sibling is on the left: take the next path hash `p` and set `hash` to `node(p, hash)`. If `index` is even and `index + 1` is less than `size`, the sibling is on the right: take the next path hash `p` and set `hash` to `node(hash, p)`. Otherwise this is the left-over hash: take nothing and leave `hash` as it is. Then halve `index`, rounding down, and halve `size`, rounding up.
3. When `size` is 1, `hash` is the root.

The number of path hashes is fixed by `index` and `size`. A code with one more or one fewer is refused.

### The two codes
- **Whole box**: `0x02`, `0x01`, `str(release)`, `u32(boxes)`, `u32(box)`, `u8(cards)`, then for each card in order `salt`, `str(text)`, then the box path.
- **One card**: `0x02`, `0x02`, `str(release)`, `u32(boxes)`, `u32(box)`, `u8(cards)`, `u8(card)`, `salt`, `str(text)`, then the card path, then the box path.

Each path hash is 32 bytes. The code ends exactly after the last one: a code that is cut short, or has bytes left over, is refused.

### Checking a code

1. Decode the base64url text and read the fields in order. Refuse the code if a value is outside its rule, the text is not well-formed UTF-8, or the length is not exact.
2. Whole box: compute every card leaf and build the card root as a tree. One card: compute its card leaf and follow the card path to the card root.
3. Compute the box leaf from the card root, and follow the box path to the box root.
4. Compute the fingerprint and compare it with the published one. Equal is a match.

### What this fixes

- The box count, the card count and every position go into the hashes, so one fingerprint holds one text for each card of each box.
- A code for card 2 cannot be passed off as card 3, or as a card of another box, and half a box cannot be passed off as a whole one.
- A single-card code carries the hashes of its neighbours, never their text or salt. Each of those hashes includes 16 random bytes of its own, so trying every card on the checklist does not reveal a neighbour.

## Version 1: whole box.

### The leaf text

A box is written as JSON text with these names in this order and no spaces:

`{"v":1,"release":R,"box":B,"contents":[C,C,C],"salt":S}`

`R` is the release name, under the same rule as in version 2, `B` the box number in decimal digits (1 to 9007199254740991), each `C` one card’s text, and `S` the salt, 32 to 64 lowercase hex characters. A box has at least one card and no card text is empty. Text is written the way JavaScript’s `JSON.stringify` writes it: inside double quotes, with `"` and `\` each preceded by a backslash, backspace, tab, line feed, form feed and carriage return as `\b`, `\t`, `\n`, `\f` and `\r`, any other character below U+0020 as `\u00xx` in lowercase hex, and every other character as itself in UTF-8. A lone surrogate, which UTF-8 cannot carry, is written as `\udxxx` in lowercase hex.

### The hashes
- **Leaf**: SHA-256 of `0x00`, `the leaf text in UTF-8`
- **Node**: SHA-256 of `0x01`, `left hash`, `right hash`

These are the prefixes of RFC 6962. The tree has the same shape as in version 2, and its root is the fingerprint.

### The code

`{"r":R,"b":B,"c":[C,C,C],"s":S,"p":[P,P,P]}`

The same values, plus the path. Each `P` is `L` or `R` followed by the 64 hex characters of one sibling hash, lowest first. `L` means the sibling is on the left. A release of one box has an empty path. The code is this JSON text in UTF-8, in base64url. It is valid only if writing the five values back out in this order, with no spaces, gives the very same text.

### Checking a code

1. Decode the base64url text, read it as JSON and check each value against its rule.
2. Build the leaf text and compute the leaf hash.
3. For each `P` in order, with `p` as its sibling hash: after `L` set the hash to the node of `p` then the hash, after `R` to the node of the hash then `p`.
4. Compare the result with the published fingerprint. Equal is a match.

### How version 1 differs

- It shows a whole box only. There are no single-card codes.
- The code states each sibling’s side, so the place of a box in the tree is not checked. Version 1 relies on the sealer listing each box number once. Version 2 checks the place.

## A worked example.

Card 2 of 4 in box 3 of the card by card example (Sebastian Walcott · 2024 · Bowman Chrome Prospect Autographs · PSA 10). It is an example, not a release. All values are hex unless marked.
- **The code**: [AgIUY2FyZC1ieS1jYXJkLWV4YW1wbGUAAAAFAAAAAwQCtCKpuQlXJngVaS6PMtkpugpleGFtcGxlLTEwgUT8FrZaK4w2afE5klnvWa0wBeF2GLeM536fjJ\_ZjdFb35ZAVDQi2R4SfxB86aKU4X3x3mePdQg9KU0aeE6ztHQb5WlLYVTzYUUd6Lj681blF-avO-RpvnLxifgrnanhwtGWOaH-EM\_plsfg7HYeeiuwhksBoEQAGvCB8FGmb1jkBOmJMIJqfDYxrTGoq9efwGsH9OpY6qTz2Dy\_2q3e1w](https://wonderoath.com/transparency/check/#code=AgIUY2FyZC1ieS1jYXJkLWV4YW1wbGUAAAAFAAAAAwQCtCKpuQlXJngVaS6PMtkpugpleGFtcGxlLTEwgUT8FrZaK4w2afE5klnvWa0wBeF2GLeM536fjJ_ZjdFb35ZAVDQi2R4SfxB86aKU4X3x3mePdQg9KU0aeE6ztHQb5WlLYVTzYUUd6Lj681blF-avO-RpvnLxifgrnanhwtGWOaH-EM_plsfg7HYeeiuwhksBoEQAGvCB8FGmb1jkBOmJMIJqfDYxrTGoq9efwGsH9OpY6qTz2Dy_2q3e1w)
- **Read from the code**: release `card-by-card-example`, boxes 5, box 3, cards 4, card 2, text `example-10`
- **Salt**: `b422a9b90957267815692e8f32d929ba`
- **Card leaf input**: `776f6e6465726f6174682d7365616c2d76322f636172642d6c6561663a14636172642d62792d636172642d6578616d706c65000000030402b422a9b90957267815692e8f32d929ba0a6578616d706c652d3130`
- **Card leaf**: `4e613afcf5428d22861066d6e77a4fcc4de5ad57ea94419defeaccc201fcf2cd`
- **Card path 1: sibling on the left**: `8144fc16b65a2b8c3669f1399259ef59ad3005e17618b78ce77e9f8c9fd98dd1`
gives `7b514e61709be56d281a9a0f15e512c9275e29cbfc08d921a49b0b2e81cb0d48`
- **Card path 2: sibling on the right**: `5bdf9640543422d91e127f107ce9a294e17df1de678f75083d294d1a784eb3b4`
gives `f6cd3e055d50c8d038d1612e0e2b7e7218dfdca9ea0955149116cbccfec981cb`
- **Card root**: `f6cd3e055d50c8d038d1612e0e2b7e7218dfdca9ea0955149116cbccfec981cb`
- **Box leaf input**: `776f6e6465726f6174682d7365616c2d76322f626f782d6c6561663a14636172642d62792d636172642d6578616d706c650000000304f6cd3e055d50c8d038d1612e0e2b7e7218dfdca9ea0955149116cbccfec981cb`
- **Box leaf**: `4c294e4910f97478a32d6fe60e44fe4672a8e383fbef4e6091ec12fce6fc6a07`
- **Box path 1: sibling on the right**: `741be5694b6154f361451de8b8faf356e517e6af3be469be72f189f82b9da9e1`
gives `ee6ed095a6ab193e2cc1cc62ebf7ca127a1816883068d897a77d68167e68d842`
- **Box path 2: sibling on the left**: `c2d19639a1fe10cfe996c7e0ec761e7a2bb0864b01a044001af081f051a66f58`
gives `8220dd8a2f9778a5f2c372c346b3189584d0bdecce7e4eb6b8bac0ba227d0bff`
- **Box path 3: sibling on the right**: `e404e98930826a7c3631ad31a8abd79fc06b07f4ea58eaa4f3d83cbfdaadded7`
gives `153ae57608e3996a4f491d502e11b3e590e675a9b10416fe780be53e7757a3f3`
- **Box root**: `153ae57608e3996a4f491d502e11b3e590e675a9b10416fe780be53e7757a3f3`
- **Fingerprint input**: `776f6e6465726f6174682d7365616c2d76322f72656c656173653a14636172642d62792d636172642d6578616d706c6500000005153ae57608e3996a4f491d502e11b3e590e675a9b10416fe780be53e7757a3f3`
- **Fingerprint**: `a1b8cd5597d28cc41aefecb6090505360b9b53286956356ecaada208c0645edf`

And in version 1, box 5 of the Castle Tree example, the last of 5, which has one sibling:
- **The code**: [eyJyIjoiY2FzdGxlLXRyZWUtZXhhbXBsZSIsImIiOjUsImMiOlsiZXhhbXBsZS0xNyIsImV4YW1wbGUtMTgiLCJleGFtcGxlLTE5IiwiZXhhbXBsZS0yMCJdLCJzIjoiMDUyOGIyNzU1N2FhMDA3YjY0YjJjN2U1YjRmNjBjZGUiLCJwIjpbIkxlZmYzOTExMTU4MjBhYmZhN2VmMWVjZWU2YTNiM2UxMjgxNDU4MmIxNjk1OTNmYTE0M2QwMGQ0MzI0NDI0ODY3Il19](https://wonderoath.com/transparency/check/#code=eyJyIjoiY2FzdGxlLXRyZWUtZXhhbXBsZSIsImIiOjUsImMiOlsiZXhhbXBsZS0xNyIsImV4YW1wbGUtMTgiLCJleGFtcGxlLTE5IiwiZXhhbXBsZS0yMCJdLCJzIjoiMDUyOGIyNzU1N2FhMDA3YjY0YjJjN2U1YjRmNjBjZGUiLCJwIjpbIkxlZmYzOTExMTU4MjBhYmZhN2VmMWVjZWU2YTNiM2UxMjgxNDU4MmIxNjk1OTNmYTE0M2QwMGQ0MzI0NDI0ODY3Il19)
- **Leaf text (as text)**: `{"v":1,"release":"castle-tree-example","box":5,"contents":["example-17","example-18","example-19","example-20"],"salt":"0528b27557aa007b64b2c7e5b4f60cde"}`
- **Leaf**: `86d4e8ede9afcf5008ccef4ccc78888130eb2736e1ec77642b32dac8177b6577`
- **Sibling on the left**: `eff391115820abfa7ef1ecee6a3b3e12814582b169593fa143d00d4324424867`
- **Fingerprint: the node of the sibling (left) and the leaf**: `604d89f6acd3e5afbcccc0fcb0af19257833fb2cf471a0be0074703bec34dac6`

## The test vectors.

[seal-vectors.json](https://wonderoath.com/seal-vectors.json) lists 191 codes under `vectors`. Each has a `code`, the `fingerprint` to compare it with, and `expect`:

- `match`: the code gives that fingerprint.
- `mismatch`: the code is well formed but gives another fingerprint, listed as `computed`. These include cards moved between places and boxes, half a box offered as a whole one, and paths reordered or borrowed.
- `invalid`: the code must be refused. These include codes cut short or extended, values out of range and text that is not UTF-8.

Readable vectors also say what the code holds (`version`, `kind`, `release`, `box`, `cards` and, for version 2, `boxes`, `card` and `of`). `releases` lists the fingerprint of each example and test release, and `worked` repeats the worked example above. A checker that agrees with every vector follows this page.

[Check a box ](https://wonderoath.com/transparency/check/)
